标签:keepalived 高可用 lvs 集群
lvs+keepalived配置高可用集群
说明:
上周使用keepalived实现了mysql主主同步的高可用,借着刚研究了keepalived,顺便把lvs集群搞一下
参考文档:
lvs集群简介:http://732233048.blog.51cto.com/9323668/1617201
LVS、Nginx和HAProxy负载均衡区别:http://732233048.blog.51cto.com/9323668/1623375
环境:
前段LB | 后端web | 底端共享存储 | vip |
(主)192.168.186.132 | (R1)192.168.186.128 | 192.168.186.131 | 192.168.186.150 |
(备)192.168.186.133 | (R2)192.168.186.129 |
步骤:
安装keepalived:
在(主)192.168.186.132和(备)192.168.186.133分别进行如下操作:
安装keepalived:
cd /usr/local/src/
wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
tar -zxf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-504.16.2.el6.i686/
make
make install
注意:--with-kernel-dir=/usr/src/kernels/2.6.32-504.16.2.el6.i686/ 这个选项一定要加;这个选项并不是把keepalived编译进内核,而是指定使用内核源码中的头文件,即include目录(只有在配置lvs时才用此选项,其他时候不需要)
拷贝文件:
cp -a /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp -a /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived/
cp -a /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp -a /usr/local/keepalived/sbin/keepalived /usr/sbin/
注意:/etc/sysconfig/keepalived 和 /etc/keepalived/keepalived.conf 的路径一定要正确,因为在执行/etc/init.d/keepalived这个启动脚本时,会读取/etc/sysconfig/keepalived 和 /etc/keepalived/keepalived.conf 这两个文件
配置keepalived:
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.old
vi /etc/keepalived/keepalived.conf #主LB
! Configuration File for keepalived global_defs { notification_email { 732233048@qq.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id lvs } vrrp_instance VI_1 { state master interface eth0 virtual_router_id 51 priority 150 advert_int 1 #nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.186.150 } } virtual_server 192.168.186.150 80 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.186.128 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.186.129 80 { weight 2 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 } } }
在(备)192.168.186.133,对配置文件做如下修改:
将state master改为state backup
将priority 150改为priority 100
注意:在配置keepalived.conf时,要特别注意配置文件的语法格式,因为keepalived在启动的时候不会去检测配置文件的正确性,即使没有配置文件,keepalived也可以正常启动
本文出自 “见” 博客,请务必保留此出处http://732233048.blog.51cto.com/9323668/1650353
标签:keepalived 高可用 lvs 集群
原文地址:http://732233048.blog.51cto.com/9323668/1650353