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

HAProxy + Keepalived实现MySQL的高可用负载均衡

[日期:2013-10-29] 来源:Linux社区  作者:jinyan2049 [字体:大 中 小]

6、查看vip是否起来

[root@vm-105-23~]#ipaddr

1:lo:<LOOPBACK,UP,LOWER_UP>mtu16436qdiscnoqueuestateUNKNOWN

link/loopback00:00:00:00:00:00brd00:00:00:00:00:00

inet127.0.0.1/8scopehostlo

inet6::1/128scopehost

valid_lftforeverpreferred_lftforever

2:eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000

link/ether52:54:00:6c:d5:95brdff:ff:ff:ff:ff:ff

inet10.10.105.23/24brd10.10.105.255scopeglobaleth0

inet10.10.105.30/32scopeglobaleth0

inet6fe80::5054:ff:fe6c:d595/64scopelink

valid_lftforeverpreferred_lftforever

 

7、因为我们知道crontab的颗粒细化度只有1分钟,不能细化到秒,所以我们编写haproxy循环检测脚本,并且放入后台运行

cd/home/ops/scripts

nohupshcheckhapid.sh&

vicheckhapid.sh

#!/bin/bash

whiletrue

do

HA=`ps-ef|grephaproxy|grep-vgrep|wc-l`

if[$HA-eq0];

then

/etc/init.d/haproxystart

echo"">/dev/null

sleep2

if[$HA-eq0];

then

/etc/init.d/keepalivedstop

fi

fi

sleep2

done

 

8、高可用测试

在10.10.105.23上执行ipaddr|grepeth0

[root@vm-105-23~]#ipaddr|grepeth0

eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000

inet10.10.105.23/24brd10.10.105.255scopeglobaleth0

inet10.10.105.30/32scopeglobaleth0

关闭haproxy再打开一个终端继续执行ipaddr|grepeth0,观测

可以发现当无法迅速启动haproxy进程之后,循环脚本会杀死keepalived进程,实现vip的迁移

10.10.105.30迅速转移到10.10.105.24这台备机上!

 

9、MySQL测试

程序在读写分离之后,所有的select语句可以直接通过访问10.10.105.303306来进行工作,后端的mysql服务器可以实现并发读操作

[root@vm-105-23scripts]#mysqlslap-h10.10.105.30--concurrency=100--iterations=1--create-schema='ultrax'--query='select*frompre_home_share;'--number-of-queries=10--debug-info-ubbs-piz3n3s0ft

Benchmark

Averagenumberofsecondstorunallqueries:1.028seconds

Minimumnumberofsecondstorunallqueries:1.028seconds

Maximumnumberofsecondstorunallqueries:1.028seconds

Numberofclientsrunningqueries:100

Averagenumberofqueriesperclient:0

 

Usertime0.02,Systemtime0.08

Maximumresidentsetsize6996,Integralresidentsetsize0

Non-physicalpagefaults1584,Physicalpagefaults0,Swaps0

Blocksin0out0,Messagesin0out0,Signals0

Voluntarycontextswitches1280,Involuntarycontextswitches91

 

10、效果

可以访问http://10.10.105.23/korea

用户名admin

密码12345

linux
相关资讯       keepalived  HAProxy 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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