centos6中三台物理机配置nginx+keepalived+lvs

以下只是简单的安装配置,并没有测试这套负载,各种参数大家可以自己测试

vip:10.0.50.170

lvs server:10.0.50.183

real server:10.0.50.184/185

183/184/185同步时间,并且安装nginx

# ntpdate time.nist.gov

# yum install nginx

# /etc/init.d/nginx start

在184/185上编写测试页面/usr/share/nginx/html/index.html

183上安装ipvsadm*和keepalived

# yum install keepalived ipvsadm*

# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

# sysctl -p

# vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

[email protected]

}

notification_email_from [email protected]

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state MASTER

interface em1

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

10.0.50.170

}

}

virtual_server 10.0.50.170 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 50

protocol TCP

real_server 10.0.50.184 80 {

weight 1

TCP_CHECK {

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}

real_server 10.0.50.185 80 {

weight 1

TCP_CHECK {

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}

}

# /etc/init.d/keepalived start

# chkconfig keepalived on

# cd /etc/init.d/

# vi lvs

#!/bin/sh

# description: Start LVS of Director server

WEB_VIP=10.0.50.170

WEB_RIP1=10.0.50.184

WEB_RIP2=10.0.50.185

SET_VIP () {

/sbin/ifconfig em1:0 $WEB_VIP netmask 255.255.255.0 broadcast $WEB_VIP up

/sbin/route add -host $WEB_VIP dev em1:0

/sbin/ipvsadm -A -t $WEB_VIP:80 -s wrr -p 3

/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP1:80 -g -w 1

/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP2:80 -g -w 1

}

case "$1" in

start)

/sbin/ipvsadm -C

SET_VIP

touch /var/lock/ipvsadm >/dev/null 2>&1

echo "ipvsadm start"

;;

stop)

/sbin/ipvsadm -C

/sbin/ipvsadm -Z

/sbin/ifconfig em1:0 down

route del $WEB_VIP > /dev/null 2>&1

rm -fr /var/lock/ipvsadm >/dev/null 2>&1

echo "ipvsadm stoped"

;;

status)

if [ ! -e /var/lock/ipvsadm ];then

echo "ipvsadm is stoped "

exit 1

else

/sbin/ipvsadm -ln

echo "ipvsadm is ok"

fi

;;

restart)

/sbin/ipvsadm -C

/sbin/ipvsadm -Z

/sbin/ifconfig em1:0 down

route del $WEB_VIP > /dev/null 2>&1

rm -fr /var/lock/ipvsadm >/dev/null 2>&1

SET_VIP

touch /var/lock/ipvsadm >/dev/null 2>&1

echo "ipvsadm  restart .."

;;

*)

echo "Usage :$0 {start|stop|status}"

exit 1

esac

exit 0

# /etc/init.d/lvs start

184/185机器都执行lvsrs脚本

# vi lvsrs

#!/bin/bash

#!/bin/bash

#description : start Real Server

VIP=10.0.50.170

./etc/rc.d/init.d/functions

case "$1" in

start)

echo " Start LVS of Real Server "

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $VIP dev lo:0

#注释:这四句目的是为了关闭ARP广播响应,使VIP不能向网络内发送广播,以防止网络出现混乱

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

;;

stop)

/sbin/ifconfig lo:0 down

echo "close LVS Director server"

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

;;

*)

echo "Usage: $0 {start|stop}"

exit 1

esac

# /etc/init.d/lvsrs start

参考http://blog.sina.com.cn/s/blog_6e834de50100pnfr.html

1.我同事曾经问过两台物理机的实现:

例如以上183/184上同时安装并启动nginx\keepalived\lvs脚本\lvsrs脚本

2.关于以下两个区别:

/sbin/ipvsadm -A -t $WEB_VIP:80 -s wrr -p 3

或者/sbin/ipvsadm -A -t $WEB_VIP:80 -s rr

时间: 2024-10-26 21:35:18

centos6中三台物理机配置nginx+keepalived+lvs的相关文章

Centos6.5安装及简单配置nginx

Centos6.5安装及简单配置nginx 一.准备事项 (1) 因为nginx需要访问80端口所以请先关闭或者开放防火墙端口,和selinux. 参考命令 关闭防火墙: [[email protected] ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT [[email protected] ~]# service iptables save 关闭selinux: [[email protected] ~]# setenforce 0 [[e

配置nginx+keepalived高可用负载均衡的时候。主从服务器都出现了VIP 阿里云问题

配置nginx+keepalived高可用负载均衡的时候.主从服务器都出现了VIP 出现这问题的场景是在阿里VPS云服务器网络环境中,因为路由交换层禁用了ARP的广播限制,造成KEEPALIVE主备协议无法通过广播的方式进行通信,造成主备两台服务器都强占HAVIP地址,出现同时两台服务器都有VIP地址的情况出现,必须通过配置来指定IP的两台服务器间进行通讯(阿里说明文档中解释只能支持两台使用同一个HAVIP地址),基于以下方法可以的情况下,多备方式用同样的方式也应该可行 ,有需要的兄弟可以测试下

虚拟机中映射物理机磁盘

虚拟机中映射物理机磁盘,布布扣,bubuko.com

LVS DR配置和keepalived+LVS

LVS DR 准备工作群集的虚拟VIP:192.168.1.222dir分发器:192.168.1.220rs1:192.168.1.223rs2:192.168.1.234 rs1和rs2安装需要的web服务 [[email protected] src]# yum install -y nginx 在dir上安装ipvsadm,并配置路由转发和ipvsadm转发 #! /bin/bash echo 1 > /proc/sys/net/ipv4/ip_forward ipv=/usr/sbin

生产环境下戴尔 R820 kvm虚拟化部署一(centos6.6 kvm物理机安装)

=================================================== 环境: 服务器:戴尔R820 CPU:Intel(R) Xeon(R) CPU E5-4620 v2 @ 2.60GHz  2颗,共16核 硬盘:SAS 600G*4 内存:8G*4 RAID:10 分区情况: =================================================== 一.R820物理主机系统安装 U盘启动盘的制作: 1.用命令将系统写入U盘:dd

CentOS6.3上安装与配置nginx+php+mysql环境

1. 目前nginx采用是源码包安装的方式(yum安装失败),下载地址:http://nginx.org/en/download.html 我这里的安装包是:nginx-1.12.0.tar.gz 2.在安装nginx前需要安装pcre,我这里的pcre源码包是:pcre-8.35.tar.gz 文件存放路径:/home/nginx/pcre-8.35.tar.gz tar  zxvf  pcre-8.35.tar.gz cd  pcre-8.35 ./configure --prefix=/u

Nginx+Keepalived 实现反代 负载均衡 高可用(HA)配置

Nginx+Keepalived实现反代负载均衡高可用(HA)配置 Nginx+Keepalived实现反代负载均衡高可用配置 OS IP 子网掩码 路由网关 Centos6.6 nginx Keepalived Eth0:192.168.26.210 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6 Nginx Keepalived Eth0:192.168.26.211 255.255.252.0 192.168.25.3 VIP

keepalived + lvs + nginx 主备配置案例

一.keepalived lvs 集群1.结构2.主备修改内核参数net.ipv4.ip_forward = 1net.ipv4.ip_nonlocal_bind = 1net.ipv4.conf.lo.arp_ignore = 1net.ipv4.conf.lo.arp_announce = 2net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce = 2 注:如果遇到提示是缺少包,yum 安装即可 3.启动keepaliv

vmware虚拟机网络配置(物理机能用ssh连接虚拟机, 虚拟机能共享物理机网卡上外网)仅主机模式,nat模式应该也可以

1.环境: 物理机:windows7 虚拟机:centos7  ...xx.xx.x 虚拟化软件:vmware 13 2.准备阶段: vmware安装centos操作系统(easy),网卡地址简单配置,虚拟网卡连接方式先设置为“仅主机模式”. 3.物理机配置 在物理机win7中, win+r,  services.msc,  找到windows firewall 服务,启动防火墙: 在物理机win7中, 打开“网络和共享设置”,适配器设置,如果物理机用的是无线网卡上网,就在“无线网络连接”选中属