CentOS6.4环境下布署LVS+keepalived笔记

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://400053.blog.51cto.com/390053/713566

环境:

1.CentOS 6.4

2.ipvsadm 1.2.4

3.keepalived 1.1.17


在安装之前需要做些准备公司,查看kernel-devel是否安装.之前由于这个没有装,导致keepalived没有与内核结合,在ipvsadm -ln 就无法看到lvs信息。

安装步骤:

[root@alpha keepalived]#wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz

[root@alpha keepalived]#wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz

[root@alpha keepalived]#ln -s /usr/src/kernels/2.6.18-194.el5-x86_64/ /usr/src/linux

[root@alpha keepalived]# tar -zxvf ipvsadm-1.24.tar.gz
[root@alpha keepalived]# cd ipvsadm-1.24
[root@alpha keepalived]# make;make install
[root@alpha keepalived]# cd ..
[root@alpha keepalived]# tar -zxvf keepalived-1.1.17.tar.gz
[root@alpha keepalived]# cd keepalived-1.1.17
[root@alpha keepalived]# ./configure
configure: error:
  !!! OpenSSL is not properly installed on your system. !!!
  !!! Can not include OpenSSL headers files.
解决办法:
[root@alpha keepalived]# yum -y install openssl-devel
[root@alpha keepalived]# ./configure
[root@alpha keepalived]# make;make install
编译的时候出现这个提示,说明keepalived和内核结合了,如果不是这样的,需要加上这个参数./configure --with-kernel-

dir=/kernel/path
Keepalived configuration
------------------------
Keepalived version       : 1.1.17
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
Use VRRP Framework       : Yes
Use LinkWatch            : No
Use Debug flags          : No

安装完之后keepalived的配置:
[root@alpha keepalived]#  cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@alpha keepalived]#  cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@alpha keepalived]#  mkdir /etc/keepalived
[root@alpha keepalived]#  cp /usr/local/sbin/keepalived /usr/sbin/

[root@alpha keepalived]#vi /etc/keepalived/keepalived.conf

!Configuration File for keepalived

#lvs出故障报警。
global_defs {
    notification_email {
          sa@fminutes.com
   }
    notification_email_from defage@163.com
    smtp_server smtp.163.com
    smtp_connect_timeout 30
    router_id LVS_DEVEL
}


vrrp_instance VI_1 {
     state MASTER             #备份服务器上将MASTER改为BACKUP
     nopreempt
     interface eth0
     virtual_router_id 51
     priority 100    # 备份服务上将100改为99
     advert_int 1
     authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
        192.168.0.104
         #(如果有多个VIP,继续换行填写.)

     }
}

virtual_server 192.168.0.104 80 {
     delay_loop 6                  #(每隔10秒查询realserver状态)
     lb_algo wrr                  #(lvs 算法)
     lb_kind DR                  #(Direct Route)
     persistence_timeout 30        #(同一IP的连接60秒内被分配到同一台realserver)
     protocol TCP                #(用TCP协议检查realserver状态)


     real_server 192.168.2.137 80 {
         weight 8               #(权重)
         TCP_CHECK {
         connect_timeout 10       #(10秒无响应超时)
         nb_get_retry 3
         delay_before_retry 3
         connect_port 80
         }
     }
}

如果需要添加vip或者更改lvs信息,只需要编辑/etc/keepalived/keepalived.conf即可。






本文出自 “SPringYu” 博客,请务必保留此出处http://400053.blog.51cto.com/390053/713566

posted @ 2014-06-27 14:20  弹着钢琴设计  阅读(285)  评论(0编辑  收藏  举报