[文章作者:张宴 本文版本:v1.1 最后修改:2008.07.17 转载请注明出自:http://blog.zyan.cc]

  Citrix NetScaler是一款不错的4-7层硬件负载均衡交换机,市场占有率仅次于F5 BIG-IP,位居第二。NetScaler 8.0是美国思杰系统有限公司(Citrix Systems, Inc)正式推出的最新版本NetScaler产品系列。

  从我的实际测试来看,NetScaler 8.0在七层负载均衡方面,性能和功能都要比F5 BIG-IP强。

  NetScaler 8.0的负载均衡监控中,可以对MySQL数据库进行健康检查,而F5 BIG-IP目前只支持对Oracle和Microsoft SQL Server数据库的健康检查。

  点击在新窗口中浏览此图片

  但是,NetScaler 8.0自带的MySQL健康检查脚本(nsmysql.pl)并不完善,它只能检查一条SQL语句执行是否出错,并不能检查MySQL主从结构中的MySQL Slave数据库同步是否正常、表有无损坏、同步延迟是否过大、是否出现错误、非sleeping状态的连程数是否过高等情况。于是,我根据自己的需要,为NetScaler 8.0写了一个MySQL Slave数据库负载均衡健康检查脚本(nsmysql-slave.pl),实现了上述需求。

  有了“nsmysql-slave.pl”做健康检查,利用NetScaler的VIP(虚拟IP),就可以完美实现多台MySQL Slave数据库的负载均衡了。当一台MySQL Slave数据库出现不同步、表损坏、同步延迟过大(本脚本中默认设置的落后MySQL主库600秒视为延迟,可根据具体应用修改)、活动连程数太高(本脚本中默认设置的是大于200视为连程数太高,可根据具体应用修改)等情况,“nsmysql-slave.pl”就会自动将其检查出来,并告知NetScaler,NetScaler会将该数据库标识为宕机,从而不将用户的查询请求传送到这台发生故障的数据库上。故障一旦修复,“nsmysql-slave.pl”会自动告知NetScaler,该数据库已经可以使用。

  “nsmysql-slave.pl”源代码如下:    脚本压缩包下载:



  健康检查脚本写完了,现在开始配置NetScaler 8.0:

  1、使用SecureCRT等SSH客户端工具登录到NetScaler,然后执行以下命令:
  点击在新窗口中浏览此图片
shell
cd /nsconfig/monitors/
vi nsmysql-slave.pl

  将“nsmysql-slave.pl”的源代码粘贴到其中,然后保存退出,再执行以下命令:
chmod +x nsmysql-slave.pl



  2、检查一下从NetScaler上是否能够连接MySQL Slave数据库:
mysql -u 用户名 -p -h 192.168.1.31 -P 3306

  Enter password:(在此输入MySQL登录密码)

  ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client


  如果你的MySQL Slave服务器版本高于4.0,就会出现以上错误。这是因为MySQL 4.1及其以上版本的密码验证算法与MySQL 4.0及其以下版本不同,而NetScaler 8.0上的MySQL客户端默认版本为4.0.25,因此,4.0.25版本的MySQL客户端连接4.1、5.X、6.X版本的MySQL服务器就会出错。

  解决办法1:升级NetScaler 8.0上的MySQL客户端,但最好不要这么做,因为NetScaler与底层的FreeBSD系统和应用软件嵌入很密切的,不要轻易替换成非官方版本,以免导致不兼容、不稳定等情况。

  解决方法2:在各台MySQL Slave服务器上新建一个名为“netscaler”的超级管理员帐号,将密码改为使用旧加密算法进行加密的密码。如果从安全考虑,可将以下语句中的%换成NetScaler的Subnet IP。
  Server version: 5.1.24-rc MySQL Community Server (GPL)
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql>

GRANT ALL PRIVILEGES ON *.* TO 'netscaler'@'%' IDENTIFIED BY OLD_PASSWORD('12345678');
FLUSH PRIVILEGES;



  3、各台MySQL Slave数据库必须添加允许NetScaler的Subnet IP访问的帐号,因为在同一网段,不能开启源IP支持,MySQL服务器上看到的将是NetScaler的Subnet IP:

  例如:【Web服务器(192.168.1.21)】──→【NetScaler VIP(192.168.1.5)】- - - →【NetScaler Subnet IP(192.168.1.2)】──→【MySQL Slave服务器(192.168.1.31)】
  MySQL Slave服务器看到的是IP地址是192.168.1.2,就需要添加NetScaler的Subnet IP访问的帐号('apache'@'192.168.1.2'):
  Server version: 5.1.24-rc MySQL Community Server (GPL)
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql>

GRANT ALL PRIVILEGES ON *.* TO 'apache'@'192.168.1.2' IDENTIFIED BY '12345678';
FLUSH PRIVILEGES;




  4、从Web管理界面登录NetScaler 8.0,进入Configuration页面(需要安装Java Runtime Environment,版本在JRE 1.4.x+以上):
  点击在新窗口中浏览此图片



  5、点击【Load Balancing】──【Monitors】栏的“add”按钮,添加一个名为“mysql_slave”的MySQL健康检查:

  点击在新窗口中浏览此图片

  ①、Interval:正常情况下,10秒钟检查一次;
  ②、Response Timeout:每次检查的超时时间为8秒,必须小于Interval;
  ③、Down Time:宕机状态下,每5秒钟检查一次;
  ④、Retries:重试5次后仍然检查失败,标记服务器为宕机;
  ⑤、Type:选择MySQL;
  ⑥、Script Name:点击其后的“Browse...”按钮,选择我编写的MySQL Slave健康检查脚本“nsmysql-slave.pl”;
  ⑦、Dispatcher IP和Dispatcher Port必须填“127.0.0.1”和“3013”,不要改变;
  ⑧、User Name输入刚才创建的帐号“netscaler“,password输入创建帐号时设定的“12345678”。

  点击在新窗口中浏览此图片



  6、点击【Load Balancing】──【Service Groups】栏的“add”按钮,添加一个名为“pool_mysql”的MySQL服务器池:

  ①、添加真实MySQL Slave服务器到“pool_mysql”服务器池,协议选择TCP:
  点击在新窗口中浏览此图片

  ②、健康检查方式选择第5步中创建的“mysql_slave”:
  点击在新窗口中浏览此图片



  7、点击【Load Balancing】──【Virtual Servers】栏的“add”按钮,添加一个名为“vs_mysql_slave”的VIP(虚拟IP):

  ①、添加“pool_mysql”服务器池到名为“vs_mysql_slave”的VIP(192.168.1.5:3306),协议选择TCP:
  点击在新窗口中浏览此图片

  ②、负载均衡方式选择Least Connection(最小连接数):
  点击在新窗口中浏览此图片



  8、Web服务器要访问MySQL Slave,只需访问NetScaler的VIP──192.168.1.5的3306端口即可。至此,已经完美解决多台MySQL Slave数据库的负载均衡问题。



技术大类 » 系统架构与硬件 | 评论(36) | 引用(0) | 阅读(54963)
xujie777 Email
2012-5-18 16:43
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
潇潇易水
2012-5-19 16:35
请问张老师,如果没有这种硬件负载设备,通过Nginx也可以通过这个脚本做到吗?
xujie123
2012-5-21 11:20
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
xujie555
2012-5-21 13:44
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 15:08
coach outlet online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website.coach factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
coach88888888 Email
2012-8-13 17:49
If you desire to go to Coach Factory Outlet, but have no idea in which to go, you can research online. It is no doubt that there is drastically information and details about it for the reference.Coach Factory Online are loved by many people, when you walk in the street, you could see many people take coach styles.hat experts claim Coach Outlet Online shopping is in the changes they are available in.Coach Outlet will send you a coupon in the post to use in their upon only after you type a achieve. The Coach bags are customarily somewhat many than the ones in the stores.
sdsd
2012-11-28 14:07
NADFGEWR
2012-11-28 15:52
GAWERW
2013-1-29 17:27
买轴承就到:www.jkzhoucheng.cn
GHAWE
2013-1-29 17:36
买轴承就到:www.jkzhoucheng.cn
GWRWE
2013-3-5 13:40
买轴承就到:www.jkzhoucheng.cn
HAWERW
2013-3-7 14:46
买轴承就到:www.jkzhoucheng.cn
sdsd
2013-4-7 17:09
买轴承就到:www.jkzhoucheng.cn
jon Email Homepage
2013-9-14 12:29
再次感谢!我会按照正确的步骤。<a href="http://www.myfreecreditreportx.com/credit-report-one-time-fee">credit report one time fee</a>
kelly Email Homepage
2014-6-2 20:21
Great article! I have actually frequently thought about this very subject. You've certainly put a remarkable quantity of thought and study into developing this considerable blog post. You provided and suggested lots of facets I had ruled out. Well done. Do you intend on writing a follow-up? Kelly, Waist Training: Is It Right for You? blogger
adasdsadasd
2015-3-2 19:15
sadasdサタンサタン<a href=\"http://www.dsadsaadad.com\">akon</a>サタ<br/>ンのは滴をwangnima撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー撒くアーサー
分页: 2/2 第一页 上页 1 2 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]