RHEL6.6-x86-64
主要软件:
keepalived-1.2.16.tar.gz
ipvsadm-1.26-4.el6.x86_64.rpm
Master Directory Server :192.168.1.5
Backup Directory Server:192.168.1.8
Real Server 1 :192.168.1.6
Real Server 2 : 192.168.1.7
VIP: 192.168.1.10
编译安装keepalived
# tar xf keepalived-1.2.16.tar.gz # cd keepalived-1.2.16 # ./configure --prefix=/usr/local/keepalived --sysconfdir=/etc # make # make install
编辑keepalived配置文件
vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [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 eth1 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.10/24 dev eth1 label eth1:0 } } virtual_server 192.168.1.10 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 #persistence_timeout 50 protocol TCP sorry_server 127.0.0.1 80 real_server 192.168.1.6 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.1.7 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
# yum install ivsadm
192.168.1.8主机中
安装keepalived同192.168.1.5
配置文件中:
将“state MASTER" 改为 ”state BACKUP"
将"priority 100"改为比100小的值,这里改为“priority 70".
# yum install ipvsadm
配置Real server
编写Real Server脚本
#/bin/bash # Author xiaoming # mail: [email protected] VIP=192.168.1.10 . /etc/init.d/functions case "$1" in start) echo "Start Real Server " /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up route add -host $VIP dev lo:0 echo 1 > /proc/sys/net/ipv4/conf/eth1/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/eth1/arp_announce echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce ;; stop) echo "Stop Real Server" /sbin/ifconfig lo:0 down route del $VIP echo 0 > /proc/sys/net/ipv4/conf/eth1/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce echo 0 > /proc/sys/net/ipv4/conf/eth1/arp_announce ;; *) echo "Usage: $0 {start|stop}" exit 1 esac
分别在Real Server1和Real Server2上执行此脚本
配置完毕,分别在director server上启动keepalived服务,
查看LVS路由表信息
# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.10:80 rr -> 192.168.1.6:80 Route 1 0 0 -> 192.168.1.7:80 Route 1 0 0
时间: 2024-10-13 01:47:32