yuanqiao 发表于 2018-12-29 10:56:28

Keepalived单主模式

  1、配置selinux ,iptables ,同步时间

[*]  各节点时间必须同步:
  ntpdate TIME_SERVER_IP (如果没有ntpdate,安装ntp包,或者直接安装ntpdate包)
  vim /etc/chrony.conf

  server TIME_SERVER_IP iburst
  #server 0.centos.pool.ntp.org iburst
  #server 1.centos.pool.ntp.org iburst
  #server 2.centos.pool.ntp.org iburst
  #server 3.centos.pool.ntp.org iburst
  systemctl restart chronyd


[*]  确保iptables及selinux不会成为阻碍。
[*]  各节点之间可通过主机名互相通信(对KA并非必须):建议使用/etc/hosts文件实现(DNS服务如果有问题,还不如hosts文件好用)
[*]  确保各节点的用于集群服务的接口支持MULTICAST通信:多播或叫组播,使用D类地址(224-239)。(多播地址最好不要使用默认的,手动修改一下。因为如果好多个集群服务都是用默认的,虽然有认证机制,但是也会互相发送信息,虽然因为认证机制丢弃掉了,但也影响性能,也会产生无用的日志。)
  2、在ka1上
  #vim keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
   root@localhost(提醒是发送邮件地址)
   }
   notification_email_from keepalived@localhost(邮件来源)
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id proxy1
   vrrp_mcast_group4 224.1.1.1(组播地址与备用ka服务器相同)
}
vrrp_instance VI_1 {
    state MASTER
    interface eth1(提供服务的网卡名称)
    virtual_router_id 66(与备用ka服务器的相同,即表明在同一网段)
    priority 100(抢占虚拟IP的优先级)
    advert_int 1
    authentication {
      auth_type PASS (认证方式:PASS为简单字符串密码,推荐使用;AH为IPSEC方式,不推荐使用)
      auth_pass 123456
    }
    virtual_ipaddress {
      172.18.0.200/16 (注意掩码,默认为32)
    }
}  3在ka2上
  #vim keepalived.conf

! Configuration File for keepalived
global_defs {
   notification_email {
   root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id proxy2 (不能与主ka相同)
   vrrp_mcast_group4 224.1.1.1
}
vrrp_instance VI_1 {
    state BACKUP(备用模式)
    interface eth1
    virtual_router_id 66
    priority 80(抢占IP优先级)
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 123456
    }
    virtual_ipaddress {
      172.18.0.200/16
    }
}  vrrp_instance{
  state MASTER|BACKUP:当前节点在此虚拟路由器上的初始状态;只能有一个是MASTER,余下的都应该为BACKUP
  interface IFACE_NAME:绑定为当前虚拟路由器使用的物理接口
  virtual_router_id VRID:当前虚拟路由器惟一标识,范围是0-255
  priority 100:当前物理节点在此虚拟路由器中的优先级;范围1-254
  advert_int 1:vrrp通告的时间间隔,默认1s
  }
  启用ka的日志
  vim /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -S 3"  vim /etc/rsyslog.conf
local3.*   /var/log/keepalived.log


页: [1]
查看完整版本: Keepalived单主模式