wuli 发表于 2013-9-27 09:55:07

keepalived+LVS高可用的负载均衡

1.安装keepalived(在两台调度服务器上安装)
vim /etc/yum.repo.d/rhel.repo

name=local from cdrom
baseurl=file:///mnt/
enable=1
gpgcheck=0yum -y install kernel-devel openssl-devel popt-devel
rpm -ivh /mnt/Packgets/ipvsadm-1.25-9.el6.i686.rpm
tar zxvf keepalived-1.2.2.tar.gz -C /usr/src/
cd /usr/src/keepalived-1.2.2/
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-131.0.15.el6.i686
make &&make install
chkconfig --add keepalived
chkconfig keepalived on
2.配置调度器(主:192.168.13.95,备:192.168.13.96,漂移ip:192.168.13.100)web服务器池(节点1:192.168.13.41、节点2:192.168.13.47)
1)、配置主HA调度服务器
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
#################全局配置#################33
global_defs {
    router_id LVS_HA_R1
}
##################高可用HA的设置##############
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_route_id 1
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123123
            }
    virtual_ipaddress {
      192.168.13.100
      }
}
###################服务器池的配置######################
virtual_server 192.168.13.100 80 {
    delay_loop 15
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 192.168.13.41 80 {
      weight 1
      TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 4               
            }   
                  }
    real_server 192.168.13.41 80 {
      weight 1
      TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 4               
            }   
                  }      
}modprobe ip_vs
lsmod |grep ip_vs
echo "modprobe ip_vs" >>/etc/rc.local
/etc/init.d/keepalived restart
chkconfig ipvsadm off
ip addr show dev eth0
2)、配置HA从调度服务器
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
#################全局配置#################33
global_defs {
    router_id LVS_HA_R2
}
##################高可用HA的设置##############
vrrp_instance VI_1 {
    state SLAVE
    interface eth0
    virtual_route_id 1
    priority 99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123123
            }
    virtual_ipaddress {
      192.168.13.100
      }
}
###################服务器池的配置######################
virtual_server 192.168.13.100 80 {
    delay_loop 15
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 192.168.13.41 80 {
      weight 1
      TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 4               
            }   
                  }
    real_server 192.168.13.47 80 {
      weight 1
      TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 4               
            }   
                  }      
}modprobe ip_vs
lsmod |grep ip_vs
echo "modprobe ip_vs" >>/etc/rc.local
/etc/init.d/keepalived restart
chkconfig ipvsadm off
ip addr show dev eth0
######设置防火墙和selinux(此处为测试)#########
iptables -F
setenforce 03.配置Web节点服务器(DR工作模式的配置,分别在节点服务器上做如下设置)
cd /etc/sysconfig/network-script/
cp ifcfg-lo ifcfg-lo:0
vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.13.100
NETMASK=255.255.255.255
ONBOOT=yesecho "route add -host 192.168.13.100 dev lo:0" >>/etc/rc.local
route add -host 192.168.13.100 dev lo:0
ip addr show dev lovi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2sysctl -p
yum install -y httpd
vi /var/www/html/index.html
test page!!!!/etc/init.d/httpd start
chkconfig httpd on
iptables -F
setenforce 04.测试lvs+Keepalived高可用集群
在客户机浏览器访问192.168.13.100,调度服务器可用坏一个,节点服务器至少要有一个是好的。
通过/var/log/message日志文件,跟踪故障切换过程。使用ipvsadm -Ln查看LVS。

冰恋 发表于 2013-10-3 02:02:15

我喜欢孩子,更喜欢造孩子的过程!

ssplyh 发表于 2013-10-10 09:34:12

下雨了,别忘了打伞,湿身是小,淋病就麻烦啦*^_^*

liyao20060101 发表于 2013-10-18 15:02:18

有道理。。。

LOCKLOSE 发表于 2013-10-27 00:54:06

人生不能像做菜、把所有的料都准备好才下锅!

yanfei 发表于 2013-11-6 03:09:19

真是 收益 匪浅

刘伟 发表于 2013-11-25 09:11:46

如果恐龙是人,那人是什么?
页: [1]
查看完整版本: keepalived+LVS高可用的负载均衡