Keepalived+HAProxy完成集群配置(2)

五.Keepalived配置(master)
我们已经实现在haproxy的负载均衡,但是,我们不可以一下发布两个地址,所以要使用keepalived高可用特性来实现虚拟ip,达到高可用性的目的.
1.keepalived的安装
[root@master~]# yum install kernel-devel openssl-devel popt-devel    //安装依赖文件
[root@master~]# tar -zxvf keepalived-1.2.2.tar.gz
[root@master~]# cd keepalived-1.2.2
[root@masterkeepalived-1.2.2]# ./configure--with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.x86_64/
如果出现以下提示,即为成功
Keepalivedconfiguration
------------------------
Keepalivedversion      : 1.2.2
Compiler                : gcc
Compilerflags          : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVSFramework      : Yes
IPVS syncdaemon support : Yes
IPVS uselibnl          : No
Use VRRPFramework      : Yes
Use Debugflags          : No
[root@masterkeepalived-1.2.2]#
[root@masterkeepalived-1.2.2]# make && make install
[root@masterkeepalived-1.2.2]# cp keepalived/etc/init.d/keepalived.rh.init/etc/init.d/keepalived                            //copy启动脚本
[root@masterkeepalived-1.2.2]# chmod +x /etc/init.d/keepalived    //可执行权限
[root@masterkeepalived-1.2.2]# chkconfig --level 35 keepalived on  //在35级别开机启动
[root@masterkeepalived-1.2.2]# cp keepalived/etc/init.d/keepalived.sysconfig/etc/sysconfig/keepalived                        //copy启动初始化文件
[root@masterkeepalived-1.2.2]# cp /usr/local/sbin/keepalived /usr/sbin/    //copy启动文件
2.keepalived配置
[root@masterkeepalived-1.2.2]# vim /usr/local/etc/keepalived/keepalived.conf
! ConfigurationFile for keepalived


global_defs {
  notification_email {
    root@master.rhel.com
  }
  notification_email_from admin@master.rhel.com
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
vrrp_sync_groupVG1 {              //创建同步组,只有此组内的两块网卡都正常的情况下,数据流才从此网卡通过.否则如果有一块网卡不同,则就断开此主机的全部连接,而转向其它主机


      group {


              VI_1
              VI_2


            }


}
vrrp_instanceVI_1 {
  state MASTER
  interface eth1
  virtual_router_id 51          //id号,不可重复
  priority 100
  advert_int 1
  authentication {
      auth_type PASS
      auth_pass 1111
  }
  virtual_ipaddress {
      192.168.1.100
  }
}
vrrp_instanceVI_2 {
  state MASTER
  interface eth2
  virtual_router_id 52
  priority 100
  advert_int 1
  authentication {
      auth_type PASS
      auth_pass 1111
  }
  virtual_ipaddress {
      10.1.13.54
  }
}
virtual_server192.168.1.100 80 {
  delay_loop 6
  lb_algo rr
  lb_kind DR
  nat_mask 255.255.255.0
  persistence_timeout 50
  protocol TCP


  real_server 192.168.1.13 80 {
      weight 1
          TCP_CHECK {
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
      }
  }
 real_server 192.168.1.14 80 {
      weight 1
          TCP_CHECK {
          connect_timeout 3
          nb_get_retry 3
          delay_before_retry 3
      }
  }
}
由于在启动脚本/etc/init.d/keepalived的配置中,默认的配置文件为config:/etc/keepalived/keepalived.conf,所以,我们要建立一个链接
[root@masterkeepalived]# ln -s /usr/local/etc/keepalived/keepalived.conf/etc/keepalived/keepalived.conf
启动keepalived即可
[root@masterkeepalived-1.2.2]# service keepalived start

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/324428c31d6fb29750a37463af22c7f8.html