“Keepalived安装和配置”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
docker>Evan
 
(导入1个版本)
 

2019年10月14日 (一) 13:48的最新版本

总的为

搭建keepalived+haproxy双主高可用负载均衡系统

master and backup 都要

keepalived安装

yum install  openssl  pcre-devel   libnfnetlink libnfnetlink-devel   popt popt-devel libnl libnl-devel openssl-devel wget  vim  -y
# wget http://www.keepalived.org/software/keepalived-1.2.20.tar.gz
wget -c http://www.keepalived.org/software/keepalived-1.2.12.tar.gz

tar xvf keepalived-1.2.12.tar.gz && cd keepalived-1.2.12
#centos 6.7

#4 centos6.8
./configure --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-573.el6.x86_64
./configure --sysconf=/etc --prefix=/usr/local/keepalived

#4 centos7
./configure --sysconf=/etc 

#  --with-kernel-dir  使用LVS时 才一定 要 p302 chapter 11 
#./configure --sysconf=/etc  --with-kernel-dir=/usr/src/kernels/3.10.0-514.el7.x86_64
make -j3 && make install
# ./configure --prefix=/usr/local/keepalived --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-573.el6.x86_64
ln -s /usr/local/sbin/keepalived /sbin/
chkconfig --add keepalived
chkconfig --level 35 keepalived on

master上的keepalived 相关配置

mv  /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.confbak
vim /etc/keepalived/keepalived.conf


keepalived配置

master Keepalved

! Configuration File for keepalived
# cat /etc/keepalived/keepalived.conf
global_defs {
   notification_email {    #通知邮件地址 notification_email用于设置报警邮件地址
     root@localhost   # # 设置邮件报警,需开启本机Sendmail 服务
     evan@localhost   ## yum -y install mailx sendmail
   }
   notification_email_from warning@localhost  ## 设置邮件发送地址
   smtp_server 127.0.0.1        ## 设置邮件的smtp server地址
   smtp_connect_timeout 30    # 设置连接smtp sever超时时间
   router_id LVS_DEVEL_shuishui  # 表示运行keepalived服务器标识,发邮件时显示在邮件主题中的信息
}

######################
#  VRRPD配置
######################
vrrp_script chk_haproxy {
        script "killall -0 haproxy"    #服务探测,返回0说明服务是正常的
        interval 1    #每隔1秒探测一次
        weight 21      #haproxy上线,权重加2;下线,权重减2
}
#
vrrp_instance HAProxy_HA {        #双主实例1   # VRRPD 配置标识  HAProxy_HA是实例名称
    state MASTER            #ha1(192.168.30.71)为主,ha2(192.168.30.72)为备  #指定Keepalvied角色 MASTER表示此主机为主服务器 BACKUP则是表示为备用服务器
    interface eth0          # 指定 HA 监测网络的接口
    nopreempt
    virtual_router_id 80    #   # 虚拟路由标识,标识为数字,同一个VRRP实例使用唯一的标识,即可表示在同一个vrrp_instance下 MASTER_ID = BACKUP_ID #好像不是这样的 实例1的VRID为88
    garp_master_delay 1
    priority 100            #主(192.168.30.71)的优先级为100,从的(192.168.30.72)优先级为99 # 定义节点优先级,数字越大表示节点的优先级越高,同一个VRRP_instance下,MASTE_PRIORITY > BACKUP_PRIORITY 
    advert_int 2          # 设定MASTER与BACKUP主机质检同步检查的时间间隔,单位为秒
    nopreempt 
    authentication {     # 设定节点间通信验证类型和密码,验证类型主要有PASS和AH两种
        auth_type PASS   # 同一个vrrp_instance,MASTER验证密码和BACKUP保持一致
        auth_pass 123456
    }
#
    notify_master "/etc/keepalived/notify.py master"
    notify_backup "/etc/keepalived/notify.py backup"
    notify_fault "/etc/keepalived/notify.py  fault"
    
    track_script {        #脚本追踪
        chk_haproxy
    }
    virtual_ipaddress {
        192.168.30.88/16 dev eth0    #实例1的VIP # 设置虚拟IP地址 (VIP),又叫做漂移IP地址
    }
#    track_interface {
#        eth0
#    }
#

}
 


backup Keepalved

! Configuration File for keepalived
# cat /etc/keepalived/keepalived.conf
global_defs {
   notification_email {    #通知邮件地址
     root@localhost
     evan@localhost
   }
   notification_email_from warning@localhost
   smtp_server 127.0.0.1        #邮件服务器地址
   smtp_connect_timeout 30
   router_id LVS_DEVEL_shuishui
}
#
vrrp_script chk_haproxy {
        script "killall -0 haproxy"    #服务探测,返回0说明服务是正常的
        interval 1    #每隔1秒探测一次
        weight 21      #haproxy上线,权重加2;下线,权重减2
}
#
vrrp_instance HAProxy_HA {        #双主实例1
    state MASTER            #ha1(192.168.30.71)为主,ha2(192.168.30.72)为备
    interface eth0
    #nopreempt
    virtual_router_id 80    #  好像不是这样的 实例1的VRID为88
    garp_master_delay 1
    priority 90            #主(192.168.30.71)的优先级为100,从的(192.168.30.72)优先级为90
    advert_int 2
    nopreempt 
    authentication {
        auth_type PASS
        auth_pass 123456
    }
#
    notify_master "/etc/keepalived/notify.py master"
    notify_backup "/etc/keepalived/notify.py backup"
    notify_fault "/etc/keepalived/notify.py  fault"
    
    track_script {        #脚本追踪
        chk_haproxy
    }
    virtual_ipaddress {
        192.168.30.88/16 dev eth0    #实例1的VIP
    }
#    track_interface {
#        eth0
#    }
#

}


#mail

问题及解决回顾

keepalived 配置完获取不到vip

Keepalived virtual router id冲突问题 bogus VRRP packet received one or more VIP associated with VRID mismatch actual

参考

Keepalived安装与配置 https://my.oschina.net/luciamoore/blog/607034