[文章作者:张宴 本文版本: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) | 阅读(79096)
chancey
2008-5-30 17:08
replication 的 master 跟 slave 可以不是一种存储引擎?
张宴 回复于 2008-5-30 17:25
MySQL主从库可以是不同的存储引擎。

MySQL主从库可以是不同的版本,但MySQL从库的版本不能小于MySQL主库的版本。

InnoDB存储引擎是行锁,不会存在大量锁表情况,对写操作有利,用于主库;MyISAM存储引擎虽然是表锁,但select查询速度在PHP+MySQL网站应用中要比InnoDB快5~20倍,用于MySQL Slave只读数据库。
dd_macle
2008-5-30 20:58
现在每天都来关注你的博客,你写的文章真是非常详细,支持!!
johnzw
2008-6-4 10:52
你这个想法是可以的,但是我还是感觉有点怪。你这样写了以后,那么如果mysql服务器之间出现问题了话,谁会知道?netscaler 可以发现这个问题,然后把问题服务器cut掉,然后呢?你们监控netscaler的见面吗? mysql之间做同步应该有一个脚本或守护在跑吧,一旦出现问题会及时发送警报给监控的。

“但是,NetScaler 8.0自带的MySQL健康检查脚本(nsmysql.pl)并不完善,它只能检查一条SQL语句执行是否出错,并不能检查MySQL主从结构中的MySQL Slave数据库同步是否正常、表有无损坏、同步延迟是否过大、是否出现错误、非sleeping状态的连程数是否过高等情况。”

你的意思是当多台mysql slave库提供读操作时,有可能因为同步异常问题导致前台读取的数据有误?
这个不太理解,这应该是基本的数据库原理。我不知道这种错误是否会真实存在,没有解决方案?
张宴 Email Homepage
2008-6-5 09:38
引用
johnzw
你的意思是当多台mysql slave库提供读操作时,有可能因为同步异常问题导致前台读取的数据有误?
这个不太理解,这应该是基本的数据库原理。我不知道这种错误是否会真实存在,没有解决方案?

数据库同步出错、MyISAM某张表坏、update同步锁表导致select查询被大量阻塞的问题,在实际应用中经常存在,为了保证前台读取的数据正常,不影响用户正常访问,利用nsmysql-slave.pl的健康检查解决了这个问题。

至于数据库发生故障,报警给监控人员,则由我目前正在编写的另一套专用监控系统来负责。目前已经实现邮件报警、MSN机器人报警。手机短信报警接口积极写完。

点击在新窗口中浏览此图片
http://zyan.cc/attachment/200806/monitor01.png


点击在新窗口中浏览此图片
http://zyan.cc/attachment/200806/monitor02.png
metoo
2008-6-11 13:20
bigip 从9.3以后的版本里,也内置有mysql的客户端。可以通过脚本方式来检查mysql 服务器的状态。mysql 服务器的负载均横F5也已经有过案例了。我对这句话比较感兴趣:

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

能否找时间聊聊?你到www.adntech.com上就能找到我。我请客吃饭一顿。。。
wangyi Email
2008-6-26 15:09
我不赞同博主的观点。
我在用过NetScaler 跟 BIGIP后,认为各有特色。
先看低端平台
从4层性能上来说,BIGIP是要强于Netscaler的(除了最低端的bigip只有cpu,没有np。)
7层的性能,bigip的某些型号实际处理能力只有1G,打开bigip低端型号的机箱,你能看到其前端交换板与后端7层处理板之间是一个GE的光纤,因此其理论最大值为1G。
4层性能netscaler完全没的比,与bigip差距太大。
7层性能对于netscaler来说,与其4层相差不大,因为都是同一个处理器,你打开netsclaer的机箱,观察其主板从Interface到处理器之间的电路,能明显看出来其4、7层处理芯片是同一个。因此netscaler的大多数型号7层处理能力也不会比bigip强。
当然不排除netscaler的某些新的信号改变了硬件架构。
在实际应用中,总是4层7层的处理都有的,因此从架构上来说,bigip要优于netsclaer。

对于高端平台
高端平台上,单port的4层处理上,各个厂家的处理并没有显著差距,毕竟都是boardcom的44G芯片一颗,要比较也是看谁舍得多用几颗芯片。同理对f5而言纯7层处理是需要cpu来做的,而大多数可以靠np完成,还有一些4层芯片即可处理。
这样做成一个层次化的处理芯片群组,比单纯的双核、多核或者多CPU的架构要先进,不同的芯片在处理不同的数据时,其效率是不一样的
因此,netsclaer 利用通用cpu来处理的话,在7层处理上更加灵活一些,但bigip并不比netsclaer差,唯一的区别就是一部分用np一部分用cpu处理,两相比较,就要根据应用来决定哪款产品更合适了。
总结就是,两个产品各有特色,但f5的bigip更胜一筹,因为毕竟大多数网络及应用都是4、7层都要处理的。
huifeideluotuo
2008-6-26 18:55
有2个疑点要请问楼主

1,你的DB--MASTER和DB--BACKUP是如何保证高可用性的,也是用数据同步吗?
2,从库采用MYISAM引擎,我这里经常碰到数据表损坏的情况,而且修复起来比较麻烦,不知道楼主如何解决?
victor Email
2009-1-4 15:25
F5 bigip低端的1500和中端的3400,以及netscaler的ns 7000,还有notel的alteon我都用过,citrix的厂商以及你都说它的七层负载能力比F5强,可以把测试结果发出来看看否?

另外,据我所知,F5的很多功能都是由license控制的,比如cache之类的功能,不知道你们的设备是否购买了那台设备所有支持的功能
DSF
2009-6-21 18:11
fwer
2009-6-21 18:22
海龙
2010-5-24 11:32
不错..zan
nadella
2011-1-9 22:44
dresses Email Homepage
2011-7-26 10:19
Here are a variety of the empire <a href="http://www.romancearound.com/">dresses</a>, I want to introduce yourself. The first shoulder chiffon <a href="http://www.romancearound.com/bridesmaid-dresses-c-197.html">bridesmaid dresses</a> empire style wedding will <a href="http://www.romancearound.com/wedding-dresses-trumpet-wedding-dresses-c-180_253.html">trumpet wedding dresses</a>.This Tia cowries, dressed in her wedding day.Chiffon of the empire the best clothes, because they are the size of the drum as complete motion from the wind the site makes it easy to create a plan impression.One romantic flowers floating above shoulder function and help catch the eyes of the cut of the chest and neck problems, so that more comprehensive coverage of physical illusion bust.Clothing do not like big long torso, short legs, or pear-shaped<a href="http://www.romancearound.com/bridesmaid-dresses-ankle-length-bridesmaid-dresses-c-197_198.html">ankle length bridesmaid dresses</a> figure.special is also suitable for pregnant brides since the mobility as a dress can accommodate more Many of the abdomen.
niseon
2011-7-26 11:52
我想问一下Mysql Backup(InnoDB)这个是如何实现的?
coach factory outlet Email Homepage
2012-5-17 11:33
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 11:33
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 11:34
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 11:34
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 16:43
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 16:43
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
分页: 1/3 第一页 1 2 3 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]