Centos6.5安装配置keepalived
Centos keepalived 虚拟IP    2017-07-19 22:45:23    841   
lightingfire   Centos keepalived 虚拟IP
下载keepalived

http://www.keepalived.org/software/


首先检查安装openssl-devel

yum install openssl-devel

如果是离线,借鉴文章:http://blog.csdn.net/gsying1474/article/details/48396205

# ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.x86_64



当出现如下字样
Keepalived configuration
------------------------
Keepalived version       : 1.2.19
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lssl -lcrypto -lcrypt
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS use libnl           : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
SNMP support             : No
SHA1 support             : No
Use Debug flags          : No

执行安装命令

# 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秒无响应超时)
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
   

    }

}

real_server 192.168.30.13 80 {

       weight 3          #(权重)

    TCP_CHECK {   

       connect_timeout 10       #(10秒无响应超时)
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
   

    }

}

}

 



配置完成后启动keepalived,


如果是要配置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

keepalived+LVS超时设置产生的realserver的tcp连接不释放问题:

http://blog.csdn.net/xqj198404/article/details/15815497

怎么样让 LVS 和 realserver 工作在同一台机器上

 

http://www.linuxde.net/2012/05/10652.html

keepalived的健康检查方式
http://www.360doc.com/content/14/0415/10/1123425_369112331.shtml

lvs & keepalived的tcp 长连接的有关问题解决方法


 



 

by 刘迎光@萤火虫工作室 
OpenBI交流群:495266201 
MicroService 微服务交流群:217722918 
mail: liuyg#liuyingguang.cn 
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

Pre: CentOS6.5安装redis(3.0.3)

Next: failed to open gcomm backend connection: 13: error while trying to listen 'tcp:/


Table of content