初次使用keepalived
使用keepalived,是因为keepalvied的切换时间非常短,我在Linux用ping进行测试基本4秒左右就可以切换了,这样的时间还是可以接受的。
做LVS最讨厌的就是有太多的机器做LVS的时候会浪费一半的机器。这样其实是非常不合算的。
而heardbeat实在是太麻烦了。keepalived问题就是文档实在不怎么全,最新的完整文档还是2002年的。
在测试环境中我使用了3台机器,其中每台机器都是前端,但是又各自备了其它的其它2个前端。健康检查是通过实际IP进行的,而所有的服务端口都是跑在vip的端口上。vip也可以指定多个。
机器分配如下:
a: 10.1.41.90 vip 10.1.41.141
b: 10.1.41.91 vip 10.1.41.142
c: 10.1.41.92 vip 10.1.41.144
keepalived安装很容易,基本的安装就可以了。
修改keepalived.conf配置文件。下面这个是a机的keepalived.conf文件,其它2台注意修改MASTER和SLAVE,以及priority,priority值越大说明权重越高。
!This is keepalived config file global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 lvs_id LVS_DEVEL_1 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass hdtv } virtual_ipaddress { 10.1.41.141 } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 52 priority 10 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass hdtv } virtual_ipaddress { 10.1.41.142 } } vrrp_instance VI_3 { state BACKUP interface eth0 virtual_router_id 53 priority 10 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass hdtv } virtual_ipaddress { 10.1.41.144 } }
然后我们就可以启动keepalived。它的启动方式如下:
/usr/sbin/keepalived -f /etc/keepalived.conf
keepalived的启动方式还有很多选择。
keepalived --vrrp -P Only run with VRRP subsystem. keepalived --check -C Only run with Health-checker subsystem. keepalived --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop. keepalived --dont-release-ipvs -I Dont remove IPVS topology on daemon stop. keepalived --dont-fork -n Dont fork the daemon process. keepalived --use-file -f Use the specified configuration file. Default is /etc/keepalived/keepalived.conf. keepalived --dump-conf -d Dump the configuration data. keepalived --log-console -l Log message to local console. keepalived --log-detail -D Detailed log messages. keepalived --log-facility -S 0-7 Set syslog facility to LOG_LOCAL\[0-7\]. (default=LOG_DAEMON) keepalived --help -h Display this short inlined help screen. keepalived --version -v Display the version number keepalived --pid -p pidfile keepalived --checkers_pid -c checkers pidfile keepalived --vrrp_pid -r vrrp pidfile
续:明日会继续测试keepalived其它功能,比如对服务进行健康检查等。