Keepalived+HAProxy 高可用负载均衡(4)

2个节点开启keepalived(主节点会获得vip,自动拉起haproxy),xinetd

root@10.1.6.203:~# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:26:b9:36:0f:81 brd ff:ff:ff:ff:ff:ff
inet 211.151.105.186/26 brd 211.151.105.191 scope global eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:26:b9:36:0f:83 brd ff:ff:ff:ff:ff:ff
inet 10.1.6.203/24 brd 10.1.6.255 scope global eth1
inet 10.1.6.173/32 scope global eth1
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 00:26:b9:36:0f:85 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 00:26:b9:36:0f:87 brd ff:ff:ff:ff:ff:ff
root@10.1.6.203:~# netstat -tunlp | grep ha
tcp 0 0 10.1.6.173:3366 0.0.0.0:* LISTEN 1042/haproxy
tcp 0 0 10.1.6.203:8888 0.0.0.0:* LISTEN 1042/haproxy
udp 0 0 0.0.0.0:56562 0.0.0.0:* 1042/haproxy
root@10.1.6.203:~# netstat -tunlp | grep xine
tcp 0 0 10.1.6.203:9222 0.0.0.0:* LISTEN 30897/xinetd
root@10.1.6.203:~# ps -ef | grep haproxy
root 1042 1 0 Sep17 ? 00:00:00 /usr/local/sbin/haproxy -f /etc/haproxy/haproxy.cfg

测试:

通过vip10.1.6.173 3366访问cluster数据库(注意账户dave权限需要加3个ip10.1.6.203,10.1.6.205,10.1.6.173)

root@10.1.6.203:mgm# MySQL -udave -p -h 10.1.6.173 -P 3366
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1344316
Server version: 5.5.22-ndb-7.2.6-gpl-log MySQL Cluster Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| dave |
| test |
+--------------------+
3 rows in set (0.01 sec)

mysql>

手动分别使keepalive,haproxy,数据库挂掉.vip10.1.6.173会自动漂到10.1.6.205从上,并不影响vip的访问

通过vip,haproxy查看各节点状态

:8888/status

Keepalived+HAProxy 高可用负载均衡

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

转载注明出处:http://www.heiqu.com/d143f336eaed53ad1e8f130a48d628bf.html