keepalived用的http_get

阅读更多

部署两台keepalived, master和backup, 两台realserver, 一台sorry_server. 操作系统为centos6.8

ip:    master: 192.168.254.129

        back:     192.168.254.131

        real_server: 192.168.254.128

        real_server: 192.168.254.130

        sorry_server: 192.168.254.132

1.安装master的keepalived

   1.1.下载keepalived安装包keepalived-1.2.15.tar.gz, 下载地址:http://www.keepalived.org/download.html

   1.2 安装之前先装工具包:yum install curl gcc openssl-devel libnl3-devel net-snmp-devel

   1.3 执行以下命令:

          tar -xzvf keepalived-1.2.15.tar.gz

          cd keepalived-1.2.15

          mkdir /usr/local/keepalived-1.2.15

          ./configure --prefix=/usr/local/keepalived-1.2.15

          make

          mak install

    1.4 拷贝各文件至相应目录

          mv /usr/local/keepalived-1.2.15/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/

          mv /usr/local/keepalived-1.2.15/etc/sysconfig/keepalived /etc/sysconfig/

          mv /usr/local/keepalived-1.2.15/sbin/keepalived /usr/sbin/

    1.5 创建目录: /etc/keepalived, 将/usr/local/keepalived-1.2.15/etc/keepalived/keepalived.conf放至此目录,keepalived.conf内容如下:

! Configuration File for keepalived

#global_defs {
#   notification_email {
#     [email protected]
#     [email protected]
#     [email protected]
#   }
#   notification_email_from [email protected]
#   smtp_server 192.168.200.1
#   smtp_connect_timeout 30
#   lvs_id LVS_MAIN
#}

vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 51
   priority 2
   advert_int 1
   authentication {
      auth_type PASS
      auth_pass kevin
   }
   virtual_ipaddress {
      192.168.254.80
   }
}

virtual_server 192.168.254.80 8080 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    sorry_server 192.168.254.129 8080

    real_server 192.168.254.128 8080 {
        weight 2
        HTTP_GET {
            url {
              path /heartcheck
              status_code 200
            }
            connect_timeout 6
            retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.254.130 8080 {
        weight 1
        HTTP_GET {
            url {
              path /heartcheck
              status_code 200
            }
            connect_timeout 6
            retry 3
            delay_before_retry 3
        }
    }
}

    1.6 启动keepalived: service keepalived start

2.安装backup的keepalived, 步骤同1.  keepalived.conf配置文件中,修改以下内容:

   state BACKUP

   priority 1

3.启动backup的keepalived: service keepalived start

4. 安装real_server: 在/etc/init.d目录下增加lvsrs文件,内容如下:

#!/bin/bash
#description : Start Real Server
VIP=192.168.254.80
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo " Start LVS of Real Server "
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
    ;;
     stop)
/sbin/ifconfig lo:0 down
    echo "close LVS Director server"
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    ;;
     *)
    echo "Usage: $0 {start|stop}"
    exit 1
esac
5. 启动各real_server, 增加VIP:  service lvsrs start

6. 注意sorry_server所在机器,配置同real_server, 也需要启动: service lvsrs start

备注:各配置文件在附件中.

   

  • keepalived.zip (1.7 KB)
  • 下载次数: 1

你可能感兴趣的:(keepalived)