ab520025520025 发表于 2018-12-30 13:39:51

keepalived+nginx 学习笔记

  from http://www.youyou13.com
  环境:
  master   192.168.1.100
  backup192.168.1.101
  虚拟ip192.168.1.103
  1.安装keepalived
  我安装完的目录是 /usr/local/keepalive/
  2.配置
  keepalived.conf
  master-------------------------------------------------------------------------------------------
  ! Configuration File for keepalived
  global_defs {
   notification_email {
   linlin@8788.cn
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
  vrrp_instance VI_1 {
    state MASTER
  interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.1.100                (master)
    priority 100                               (主机要比从机优先级高,不然不能在恢复时夺取角色)
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass youyou13.com
  }
    virtual_ipaddress {
      192.168.1.103               (虚拟ip)
    }
}
  backup-----------------------------------------------------------------------------------------
  ! Configuration File for keepalived
  global_defs {
   notification_email {
   linlin@8788.cn
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
  vrrp_instance VI_1 {
    state MASTER(BACKUP)
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.1.101                  (从机)
    priority 50         (主机要比从机优先级高,不然不能在恢复时夺取角色)
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass youyou13.com
  }
    virtual_ipaddress {
      192.168.1.103            (虚拟ip)
    }
}
  启动----------------------------------------------------
  keepalived -D -f /usr/local/keepalive/etc/keepalived/keepalived.conf
  测试----------------------------------------------------
  1.访问192.168.1.103成功(这时候是master在负责虚拟ip)
  2.关闭master keepalived
  3.访问192.168.1.103成功(这时候是backup在负责虚拟ip)
  日志分析------------------
  从服务器的日志:
  May2 17:59:13 server Keepalived: Starting Keepalived v1.1.19 (05/02,2012)
May2 17:59:13 server Keepalived_vrrp: Registering Kernel netlink reflector
May2 17:59:13 server Keepalived_vrrp: Registering Kernel netlink command channel
May2 17:59:13 server Keepalived_vrrp: Registering gratutious ARP shared channel
May2 17:59:13 server Keepalived_vrrp: Opening file '/usr/local/keepalive/etc/keepalived/keepalived.conf'.
May2 17:59:13 server Keepalived_vrrp: Configuration is using : 62366 Bytes
May2 17:59:13 server Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May2 17:59:13 server Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
May2 17:59:13 server Keepalived_vrrp: VRRP sockpool:
May2 17:59:13 server Keepalived: Starting VRRP child process, pid=30233
(当主机宕机时的日志)
May2 18:01:54 server Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
r Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
May2 18:01:55 server Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
May2 18:01:55 server Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.103
May2 18:01:55 server avahi-daemon: Registering new address record for 192.168.1.103 on eth0.
May2 18:02:00 server Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.103
May2 18:02:13 server avahi-daemon: Invalid query packet.
(当主机恢复运用时)
May3 13:28:17 server Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
May3 13:28:17 server Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
May3 13:28:17 server Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
May3 13:28:17 server avahi-daemon: Withdrawing address record for 192.168.1.103 on eth0



页: [1]
查看完整版本: keepalived+nginx 学习笔记