手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Keepalived+HAProxy 高可用负载均衡

[日期:2013-09-20] 来源:Linux社区  作者:davehe [字体:大 中 小]

测试

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查看各节点状态

http://10.1.6.173:8888/status

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款