keepalived+LVS高可用的负载均衡

 

1.安装keepalived(在两台调度服务器上安装)
vim /etc/yum.repo.d/rhel.repo
[local-cdrom]
name=local from cdrom
baseurl=file:///mnt/
enable=1
gpgcheck=0

yum -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 0

3.配置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=yes

echo "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 lo

vi /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 = 2

sysctl -p
yum install -y httpd
vi /var/www/html/index.html
test page!!!!

/etc/init.d/httpd start
chkconfig httpd on
iptables -F
setenforce 0

4.测试lvs+Keepalived高可用集群
在客户机浏览器访问192.168.13.100,调度服务器可用坏一个,节点服务器至少要有一个是好的。
通过/var/log/message日志文件,跟踪故障切换过程。使用ipvsadm -Ln查看LVS。

你可能感兴趣的:(linux,File,local,start,enabled)