标签:serve ignore port res cal glob cas lob keepaliv
拓扑 VIP=192.168.2.133 主keepalived IP=192.168.2.129 备keepalived=192.168.2.130[root@Qj01 ~]# yum install –y keepalived ipvsadm
[root@Qj11 ~]# yum install –y keepalived ipvsadm
[root@Qj11 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from root@localhost
smtp_server localhost
smtp_connect_timeout 30
router_id node1
}
vrrp_instance apache {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.133
}
}
virtual_server 192.168.2.133 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
protocol TCP
real_server 192.168.2.131 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.2.132 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
二、编辑主keepalived配置文件
三、将配置文件传至备份keepalived上并修改参数[root@Qj11 keepalived]# scp keepalived.conf 192.168.2.130:/etc/keepalived/
注:修改下列参数
router_id node2 #运行 keepalived 的机器标示符
}
vrrp_instance apache {
state BACKUP #当前 LVS 状态为备用分发器
interface ens32
virtual_router_id 51
priority 90 #LVS 优先级,备的要比主的小
……
RS自动化配置脚本:
[root@Qj ~]# vim /etc/init.d/lvsrsdr #写一个配置RS的脚本
#!/bin/bash
#description:start relserver
VIP=192.168.2.133
source /etc/init.d/functions #加载环境变量(可以加载所有的环境变量)
case $1 in
start)
echo ‘start LVS of Realserver DR‘
/sbin/ifconfig lo:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:1
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:1 down
echo ‘Close LVS of Realserver DR‘
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
[root@Qj ~]# chmod +x /etc/init.d/lvsrsdr
[root@Qj ~]# /etc/init.d/lvsrsdr start
[root@Qj ~]# echo "/etc/init.d/lvsrsdr start" >> /etc/rc.local
[root@Qj ~]# ifconfig -a
标签:serve ignore port res cal glob cas lob keepaliv
原文地址:http://blog.51cto.com/13719714/2173386