[文章作者:张宴 本文版本: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数据库的负载均衡问题。






技术大类 » 系统架构与硬件 | 评论(56) | 引用(0) | 阅读(79403)
shz Email
2022-7-3 22:16
Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.  Digital real estate business
shx Email
2022-7-3 22:17
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!  Digital real estate business
shz Email
2022-7-3 22:20
Hello! I just wish to give an enormous thumbs up for the nice info you've got right here on this post. I will probably be coming back to your weblog for more soon!  Digital real estate business
shx Email
2022-7-3 22:20
This article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article.  Digital real estate business
shx Email
2022-7-3 22:24
Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!  Digital real estate business
shz Email
2022-7-3 22:25
I must say, I thought this was a pretty interesting read when it comes to this topic. Liked the material. . . . .  Digital real estate business
shx Email
2022-7-3 22:27
Great survey. I'm sure you're getting a great response.  Digital real estate business
Chris79 Email
2022-7-26 15:50
The information you give us in this article is very helpful. fnf I enjoyed reading your post, it helped me to know a lot more. Let's keep doing this!! Thanks!!
Hibbah Email
2022-8-29 13:30
It is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post.  플레이포커
Hibbah Email
2022-8-30 21:15
He does RG three-D Coaching that's a three Dimensional Coaching motivating humans from inner and stimulating the cappotential to set and gain goals. Getting you from in which you're now to in which you need to be is proper on the coronary heart of RG three-D coaching.  Rajeev Gupta chairman of regional council of BMA
Hibbah Email
2022-8-31 20:26
I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information?  Fluyezcambios
Hibbah Email
2022-9-1 15:44
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.  simply buzzes
Heurekan Email
2022-12-29 03:49
Like I said many times, if you believe in angelic numerology, you believe in the meaning of numbers.
Hughes Homepage
2023-4-17 17:54
most realistic sex doll is More in line with what men might find more attractive when they're alone
메이저사이트 Email Homepage
2023-8-21 16:38
The loading speed of this website is really fast. I'm curious what unique method you're using. I am very happy to have visited such an excellent website. 메이저사이트
SexyPGGAME Email Homepage
2024-2-9 15:55
slot777 A new gaming website that meets every gambling lifestyle.
分页: 3/3 第一页 上页 1 2 3 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]