LVS+Heartbeat 高可用集群方案操作步骤详解(5)

启动heartbeat服务的时候, 就会自带启动ipvsadm 和 ldirectord, 因为在/etc/ha.d/haresources文件里配置了!
需要知道的是: 只有当前提供lvs转发服务(即拥有VIP资源)的一方 才能在启动heartbeat的时候, 自带启动ipvsadm 和 ldirectord!
 
1) 先启动HA主节点的heartbeat
[root@ha-master ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.
 
[root@ha-master ~]# ps -ef|grep heartbeat
root    20886    1  0 15:41 ?        00:00:00 heartbeat: master control process
root    20891 20886  0 15:41 ?        00:00:00 heartbeat: FIFO reader       
root    20892 20886  0 15:41 ?        00:00:00 heartbeat: write: bcast eth0 
root    20893 20886  0 15:41 ?        00:00:00 heartbeat: read: bcast eth0 
root    20894 20886  0 15:41 ?        00:00:00 heartbeat: write: ucast eth0 
root    20895 20886  0 15:41 ?        00:00:00 heartbeat: read: ucast eth0 
root    20896 20886  0 15:41 ?        00:00:00 heartbeat: write: ping_group group1
root    20897 20886  0 15:41 ?        00:00:00 heartbeat: read: ping_group group1
root    20917 20886  0 15:41 ?        00:00:00 /usr/lib64/heartbeat/ipfail
root    20938 17616  0 15:41 pts/0    00:00:00 grep heartbeat
 
heartbeat服务端口默认是694.
[root@ha-master ~]# lsof -i:694
COMMAND    PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
heartbeat 20892 root    7u  IPv4  42238      0t0  UDP *:ha-cluster
heartbeat 20893 root    7u  IPv4  42238      0t0  UDP *:ha-cluster
heartbeat 20894 root    7u  IPv4  42244      0t0  UDP *:ha-cluster
heartbeat 20895 root    7u  IPv4  42244      0t0  UDP *:ha-cluster
 
发现ldirectord服务被自带启动了, 说明master节点是当前提供lvs转发服务的一方
[root@ha-master ~]# ps -ef|grep ldirectord
root    21336    1  0 15:41 ?        00:00:00 /usr/bin/perl -w /usr/sbin/ldirectord start
root    21365 17616  0 15:42 pts/0    00:00:00 grep ldirectord
 
[root@ha-master ~]# /etc/init.d/ldirectord status
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 21336
 
查看master节点,发现master节点当前占有vip资源  (首次启动heartbeat服务后, 需要稍微等待一段时间, vip资源才会出来. 后续再重启或切换时, vip资源就会迅速出现了)
[root@ha-master ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:ac:50:9b brd ff:ff:ff:ff:ff:ff
    inet 172.16.60.206/24 brd 172.16.60.255 scope global eth0
    inet 172.16.60.111/24 brd 172.16.60.255 scope global secondary eth0
    inet6 fe80::250:56ff:feac:509b/64 scope link
      valid_lft forever preferred_lft forever
 
master节点当前提供了lvs转发功能, 可以查看到转发效果
[root@ha-master ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
TCP  172.16.60.111:80 wlc persistent 600
  -> 172.16.60.204:80            Route  1      0          0       
  -> 172.16.60.205:80            Route  1      0          0 
 
查看master节点的heartbeat日志
[root@ha-master ~]# tail -f /var/log/ha-log
ip-request-resp(default)[21041]:        2018/12/25_15:41:48 received ip-request-resp IPaddr::172.16.60.111 OK yes
ResourceManager(default)[21064]:        2018/12/25_15:41:48 info: Acquiring resource group: ha-master IPaddr::172.16.60.111 ipvsadm ldirectord
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_172.16.60.111)[21092]: 2018/12/25_15:41:48 INFO:  Resource is stopped
ResourceManager(default)[21064]:        2018/12/25_15:41:48 info: Running /etc/ha.d/resource.d/IPaddr 172.16.60.111 start
IPaddr(IPaddr_172.16.60.111)[21188]:    2018/12/25_15:41:48 INFO: Adding inet address 172.16.60.111/24 with broadcast address 172.16.60.255 to device eth0
IPaddr(IPaddr_172.16.60.111)[21188]:    2018/12/25_15:41:48 INFO: Bringing device eth0 up
IPaddr(IPaddr_172.16.60.111)[21188]:    2018/12/25_15:41:48 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-172.16.60.111 eth0 172.16.60.111 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_172.16.60.111)[21174]: 2018/12/25_15:41:48 INFO:  Success
ResourceManager(default)[21064]:        2018/12/25_15:41:48 info: Running /etc/init.d/ipvsadm  start
ResourceManager(default)[21064]:        2018/12/25_15:41:48 info: Running /etc/init.d/ldirectord  start
 
2) 接着启动HA备份节点的heartbeat
[root@ha-slave ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.
 
[root@ha-slave ha.d]# ps -ef|grep heartbeat
root    21703    1  0 15:41 ?        00:00:00 heartbeat: master control process
root    21708 21703  0 15:41 ?        00:00:00 heartbeat: FIFO reader       
root    21709 21703  0 15:41 ?        00:00:00 heartbeat: write: bcast eth0 
root    21710 21703  0 15:41 ?        00:00:00 heartbeat: read: bcast eth0 
root    21711 21703  0 15:41 ?        00:00:00 heartbeat: write: ucast eth0 
root    21712 21703  0 15:41 ?        00:00:00 heartbeat: read: ucast eth0 
root    21713 21703  0 15:41 ?        00:00:00 heartbeat: write: ping_group group1
root    21714 21703  0 15:41 ?        00:00:00 heartbeat: read: ping_group group1
root    21734 21703  0 15:41 ?        00:00:00 /usr/lib64/heartbeat/ipfail
root    21769 19163  0 15:42 pts/0    00:00:00 grep heartbeat
 
[root@ha-slave ha.d]# lsof -i:694
COMMAND    PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
heartbeat 21709 root    7u  IPv4 105186      0t0  UDP *:ha-cluster
heartbeat 21710 root    7u  IPv4 105186      0t0  UDP *:ha-cluster
heartbeat 21711 root    7u  IPv4 105192      0t0  UDP *:ha-cluster
heartbeat 21712 root    7u  IPv4 105192      0t0  UDP *:ha-cluster
 
发现ldirectord服务没有被heartbeat自带启动 (因为当前备份节点没有提供lvs转发功能, 即没有接管vip资源)
[root@ha-slave ha.d]# /etc/init.d/ldirectord status
ldirectord is stopped for /etc/ha.d/ldirectord.cf
 
[root@ha-slave ha.d]# ps -ef|grep ldirectord     
root    21822 19163  0 15:55 pts/0    00:00:00 grep ldirectord
 
发现ipvsadm服务也没有被heartbeat自带启动  (因为当前备份节点没有提供lvs转发功能, 即没有接管vip资源)
[root@ha-slave ha.d]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:ac:05:b5 brd ff:ff:ff:ff:ff:ff
    inet 172.16.60.207/24 brd 172.16.60.255 scope global eth0
    inet6 fe80::250:56ff:feac:5b5/64 scope link
      valid_lft forever preferred_lft forever
[root@ha-slave ha.d]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
 
查看HA备份节点的heartbeat日志
[root@ha-slave ha.d]# tail -f /var/log/ha-log 
Dec 25 15:41:37 ha-slave heartbeat: [21734]: info: Starting "/usr/lib64/heartbeat/ipfail" as uid 0  gid 0 (pid 21734)
Dec 25 15:41:38 ha-slave heartbeat: [21703]: info: Status update for node ha-master: status active
harc(default)[21737]:  2018/12/25_15:41:38 info: Running /etc/ha.d//rc.d/status status
Dec 25 15:41:42 ha-slave ipfail: [21734]: info: Status update: Node ha-master now has status active
Dec 25 15:41:44 ha-slave ipfail: [21734]: info: Asking other side for ping node count.
Dec 25 15:41:47 ha-slave ipfail: [21734]: info: No giveup timer to abort.
Dec 25 15:41:48 ha-slave heartbeat: [21703]: info: remote resource transition completed.
Dec 25 15:41:48 ha-slave heartbeat: [21703]: info: remote resource transition completed.
Dec 25 15:41:48 ha-slave heartbeat: [21703]: info: Initial resource acquisition complete (T_RESOURCES(us))
Dec 25 15:41:48 ha-slave heartbeat: [21754]: info: No local resources [/usr/share/heartbeat/Resourc
 
访问使用vip地址访问, 即:
访问, 结果为"this is test page of realserver01:172.16.60.204" 或者 "this is test page of realserver02:172.16.60.205"
访问, 结果为"Test HA Page"
 
温馨提示:
下面是两个常用的ipvsadm 关于查看lvs状态的命令
======================================
查看lvs的连接状态命令
[root@ha-master ~]# ipvsadm  -l  --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port              Conns  InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  172.16.60.111:http                0        0        0        0        0
  -> 172.16.60.204:http                0        0        0        0        0
  -> 172.16.60.205:http                0        0        0        0        0
 
说明:
Conns    (connections scheduled)  已经转发过的连接数
InPkts  (incoming packets)      入包个数
OutPkts  (outgoing packets)      出包个数
InBytes  (incoming bytes)        入流量(字节) 
OutBytes (outgoing bytes)        出流量(字节)
 
======================================
查看lvs的速率
[root@ha-master ~]# ipvsadm  -l  --rate
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port                CPS    InPPS  OutPPS    InBPS  OutBPS
  -> RemoteAddress:Port
TCP  172.16.60.111:http                0        0        0        0        0
  -> 172.16.60.204:http                0        0        0        0        0
  -> 172.16.60.205:http                0        0        0        0        0
 
说明:
CPS      (current connection rate)  每秒连接数
InPPS    (current in packet rate)    每秒的入包个数
OutPPS  (current out packet rate)  每秒的出包个数
InBPS    (current in byte rate)      每秒入流量(字节)
OutBPS  (current out byte rate)    每秒入流量(字节)
 
======================================
上面的两台HA节点均只有一个网卡设备eth0,  如果有两块网卡, 比如还有一个eth1, 则可以将这个eth1作为heartbeat交叉线直连的设备,
即HA主备两台机器之间使用一根串口直连线缆eth1进行连接.
比如:
HA主节点  172.16.60.206(eth0), 10.0.11.21(eth1, heartbeat交叉线直连)
HA备节点  172.16.60.207(eth0), 10.0.11.22(eth1, heartbeat交叉线直连)
 
这样比起只有一个eth0, 只需要在ha.cf文件中多加下面一行 (其他的操作配置都不用变!)
ping_group group1 10.0.11.21 10.0.11.22      //多加这一行
ping_group group1 172.16.60.204 172.16.60.205

7) 故障转移切换测试

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a3c81ffb78ffb50266c1d4bc239d78e0.html