keeplived安装

yum install -y gcc openssl openssl-devel kernel-devel
ln -s /usr/src/kernels/3 /usr/src/linux
./configure

./configure –prefix=/usr –bindir=/usr/bin –sbindir=/usr/bin –sysconfdir=/etc
./configure –prefix=/opt/keepalived –with-kernel-dir=/usr/src/kernels/

cp keepalived/etc/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived -p
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
/etc/init.d/keepalived start
ps -ef|grep keep

在/etc/sysconfig/keepalived中的KEEPALIVED_OPTIONS修改为:
KEEPALIVED_OPTIONS=”-f [配置文件路径] -D”
需要修改的数据有以下几项:

# config: /etc/keepalived/keepalived.conf 文件的位置;
# Source configuration file (we set KEEPALIVED_OPTIONS there) 文件的位置。. /etc/sysconfig/keepalived

修改为实际安装的文件路径,我的安装路径如下:

# config: /usr/local/keepalived/etc/keepalived/keepalived.conf
. /usr/local/keepalived/etc/sysconfig/keepalived

另外添加如下变量,并修改文件中相应的部分:

keepalived=/usr/local/keepalived/sbin/keepalived
keepalived_config=/usr/local/keepalived/etc/keepalived/keepalived.conf
keepalived_pid=/usr/local/keepalived/run/keepalived.pid
vrrp_instance VI_1 {
    state MASTER
    interface ens32
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.37/24
    }
}


virtual_server 192.168.200.37 80 {
    delay_loop 2
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP


    real_server 192.168.200.236 80 {
        weight 1
            TCP_CHECK
        {
            connect port 80
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
}

多实例配置模板

global_defs {
  notification_email {
  48211701@qq.com
  }
  notification_email_from 48211701@qq.com
  

  smtp_server smtp.qq.com
  smtp_connect_timeout 30
  

  router_id HAPROXY
  }
  vrrp_script chk_haproxy {
  script "/etc/keepalived/scripts/chk_haproxy.sh"
  interval 4
  #  weight 2
  }
  

  vrrp_sync_group VG1 {
  group {
  VI1_GATEWAY
  }
  }
  vrrp_sync_group VG2 {
  group {
  VI2_GATEWAY
  }
  }
  

  

  vrrp_instance VI1_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 56
  priority 51
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.50
  192.168.8.51
  192.168.8.52
  192.168.8.53
  192.168.8.54
  192.168.8.55
  192.168.8.56
  192.168.8.57
  192.168.8.58
  192.168.8.59
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }
  vrrp_instance VI2_GATEWAY {
  state MASTER
  interface eth0
  lvs_sync_daemon_interface eth0
  

  virtual_router_id 57
  priority 50
  smtp_alert
  advert_int 1
  sorry_server 127.0.0.1 80
  

  authentication {
  auth_type PASS
  auth_pass hapass8
  }
  track_script {
  chk_haproxy
  }
  

  virtual_ipaddress {
  192.168.8.60
  192.168.8.61
  192.168.8.62
  192.168.8.63
  192.168.8.64
  192.168.8.65
  }
  notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
  notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
  }

多实例配置模板2

vrrp_instance VI_1 {
    state BACKUP
    interface ens38
    virtual_router_id 51
    priority 95
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.100.33/24
    }
}

virtual_server 192.168.100.33 80 {
    delay_loop 2
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.100.232 80 {
        weight 1
            TCP_CHECK
        {
            connect port 80
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
}


    real_server 192.168.100.233 80 {
        weight 1
    TCP_CHECK 
           {
            connect_port 80
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }
}


vrrp_instance VI_2 {

    state MASTER

    interface ens38

    virtual_router_id 52

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.100.34/24

    }

}



virtual_server 192.168.100.34 80 {

    delay_loop 2

    lb_algo rr

    lb_kind DR

    persistence_timeout 50

    protocol TCP



    real_server 192.168.100.232 80 {

        weight 1

            TCP_CHECK

                {

            connect port 80

            connect_timeout 3

            retry 3

            delay_before_retry 3

        }

}





    real_server 192.168.100.233 80 {

        weight 1

        TCP_CHECK

           {

            connect_port 80

            connect_timeout 3

            retry 3

            delay_before_retry 3

        }

    }

}
文档更新时间: 2019-12-15 14:31   作者:老王