下载keepalived
http://www.keepalived.org/software/
yum install openssl-devel
如果是离线,借鉴文章:http://blog.csdn.net/gsying1474/article/details/48396205
当出现如下字样
# make
# make install
设置keepalived开机启动脚本 cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ chkconfig keepalived on 新建一个配置文件,默认keepalived启动会去/etc/keepalived目录下寻找配置文件 # mkdir /etc/keepalived # vi /etc/keepalived/keepalived.conf
global_defs { notification_email { test@163.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL }
vrrp_instance VI_1 { state MASTER # 备份服务器上将 MASTER 改为 BACKUP interface eth0 # HA 监测网络接口 virtual_router_id 51 # 主、备机的 virtual_router_id 必须相同 priority 100 # 主、备机取不同的优先级,主机值较大,备份机值较小 advert_int 2 # VRRP Multicast 广播周期秒数 authentication { auth_type PASS #VRRP 认证方式 auth_pass 1111 #VRRP 口令字 } virtual_ipaddress { 192.168.30.20 # VRRP HA 虚拟地址 如果有多个VIP,继续换行填写 } }
virtual_server 192.168.30.20 80 { delay_loop 2 # 每隔 6 秒查询 realserver 状态 lb_algo rr #lvs 算法 lb_kind DR # Direct Route persistence_timeout 50 # 同一IP 的连接60 秒内被分配到同一台realserver protocol TCP # 用 TCP 协议检查 realserver 状态
real_server 192.168.30.12 80 { weight 3 #(权重) TCP_CHECK {
connect_timeout 10 #(10秒无响应超时) } } real_server 192.168.30.13 80 { weight 3 #(权重) TCP_CHECK {
connect_timeout 10 #(10秒无响应超时) } } }
如果是要配置mysql HA,那么需要在启动mysql相关服务前,要启动keepalived,否则将会无法连接到服务器
如果需要配置读写优先级分离,可以配置权重即可,参考文章:http://www.elesos.com/index.php?title=MySQL%E9%9B%86%E7%BE%A4%E7%B3%BB%E5%88%972%EF%BC%9A%E9%80%9A%E8%BF%87keepalived%E5%AE%9E%E7%8E%B0%E5%8F%8C%E4%B8%BB%E9%9B%86%E7%BE%A4%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB&printable=yes#.E6.B5.8B.E8.AF.95.E8.AF.BB.E5.86.99.E5.88.86.E7.A6.BB
相关参考文档:
http://blog.csdn.net/jiedushi/article/details/4379372
http://www.showerlee.com/archives/702
http://blog.csdn.net/xqj198404/article/details/15815497
http://www.linuxde.net/2012/05/10652.html
keepalived的健康检查方式
http://www.360doc.com/content/14/0415/10/1123425_369112331.shtml
lvs & keepalived的tcp 长连接的有关问题解决方法
http://www.csdn123.com/html/exception/110/110689_110683_110687.htm
(责任编辑:IT) |