四:配置keepalived.conf
1,MASTER 的keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email { #发送email 的地址
rui.tong@XXX.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port { #执行监控的服务
script "/tmp/dd.sh" #监控的脚本(脚本在下文写,详情见下文)
interval 2 #监控的时间
weight 2
}
vrrp_instance VI_1 {
state MASTER #设置为主
interface eth0 #监控的网卡
virtual_router_id 51i #暂时不知道什么,但是这个两台服务器必须一样!!!
mcast_src_ip 192.168.126.173 #主nginx地址
priority 150 #优先级,优先级MASTRE一定要高于BAUCKUP(其实叫权重值)
advert_int 1
authentication {
auth_type PASS #加密
auth_pass 1111 #加密的密码,两台服务器一定要一样!!!
}
virtual_ipaddress {
192.168.200.16 #VIP地址,就是本对应的虚拟IP,ip addr可以查看到
}
}
2,BACKUP keepalived.conf(这里我就不解释参数了!)
! Configuration File for keepalived
global_defs {
notification_email {
rui.tong@XXX.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/tmp/dd.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.126.176
priority 100 # 记住keepalived是根据这里来判断MASTER还是BACKUP!
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.16
}
}
/etc/init.d/keepalived start !
为什么我编译keepalived之前要做一个内核的软链接呢?因为之前我编译的时候指定系统默认的内核文件,结果最后安装完毕之后ps -ef | grep keepalived ,显示只有两个进程,但是正常情况下应该有3个keepalived的进程才对!
查阅相关资料,是因为当前linux系统未指定内核文件,可是我系统有啊,我就做了一个软链接,ln -s /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linux,重新编译一下。有3个进程在跑了!
[root@localhost tmp]# ps -ef | grep keepalived
root 17708 1 0 12:18 ? 00:00:00 keepalived -D
root 17709 17708 0 12:18 ? 00:00:00 keepalived -D
root 17710 17708 0 12:18 ? 00:00:00 keepalived -D
root 17756 2490 0 15:51 pts/2 00:00:00 grep keepalived