国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
利用NetScaler和自行編寫(xiě)的健康檢查腳本,完美解決多臺(tái)MySQL Slave數(shù)據(jù)庫(kù)的...

Citrix NetScaler是一款不錯(cuò)的4-7層硬件負(fù)載均衡交換機(jī),市場(chǎng)占有率僅次于F5 BIG-IP,位居第二。NetScaler 8.0是美國(guó)思杰系統(tǒng)有限公司(Citrix Systems, Inc)正式推出的最新版本NetScaler產(chǎn)品系列。

  從我的實(shí)際測(cè)試來(lái)看,NetScaler 8.0在七層負(fù)載均衡方面,性能和功能都要比F5 BIG-IP強(qiáng)。

  NetScaler 8.0的負(fù)載均衡監(jiān)控中,可以對(duì)MySQL數(shù)據(jù)庫(kù)進(jìn)行健康檢查,而F5 BIG-IP目前只支持對(duì)Oracle和Microsoft SQL Server數(shù)據(jù)庫(kù)的健康檢查。

  



  但是,NetScaler 8.0自帶的MySQL健康檢查腳本(nsmysql.pl)并不完善,它只能檢查一條SQL語(yǔ)句執(zhí)行是否出錯(cuò),并不能檢查MySQL主從結(jié)構(gòu)中的MySQL Slave數(shù)據(jù)庫(kù)同步是否正常、表有無(wú)損壞、同步延遲是否過(guò)大、是否出現(xiàn)錯(cuò)誤、非sleeping狀態(tài)的連程數(shù)是否過(guò)高等情況。于是,我根據(jù)自己的需要,為NetScaler 8.0寫(xiě)了一個(gè)MySQL Slave數(shù)據(jù)庫(kù)負(fù)載均衡健康檢查腳本(nsmysql-slave.pl),實(shí)現(xiàn)了上述需求。

  有了“nsmysql-slave.pl”做健康檢查,利用NetScaler的VIP(虛擬IP),就可以完美實(shí)現(xiàn)多臺(tái)MySQL Slave數(shù)據(jù)庫(kù)的負(fù)載均衡了。當(dāng)一臺(tái)MySQL Slave數(shù)據(jù)庫(kù)出現(xiàn)不同步、表?yè)p壞、同步延遲過(guò)大(本腳本中默認(rèn)設(shè)置的落后MySQL主庫(kù)180秒視為延遲,可根據(jù)具體應(yīng)用修改)、連程數(shù)太高(本腳本中默認(rèn)設(shè)置的是大于100視為連程數(shù)太高,可根據(jù)具體應(yīng)用修改)等情況,“nsmysql-slave.pl”就會(huì)自動(dòng)將其檢查出來(lái),并告知NetScaler,NetScaler會(huì)將該數(shù)據(jù)庫(kù)標(biāo)識(shí)為宕機(jī),從而不將用戶的查詢請(qǐng)求傳送到這臺(tái)發(fā)生故障的數(shù)據(jù)庫(kù)上。故障一旦修復(fù),“nsmysql-slave.pl”會(huì)自動(dòng)告知NetScaler,該數(shù)據(jù)庫(kù)已經(jīng)可以使用。

  “nsmysql-slave.pl”源代碼如下:  

  1. #!/usr/bin/perl -w   
  2. ################################################################   
  3. ##   
  4. ## MySQL Slave Server Monitoring Script for NetScaler 8.x   
  5. ## Written by Zhang Yan (blog.s135.com) on May 28, 2008   
  6. ##   
  7. ################################################################   
  8. ## This is a netscaler supplied script.    
  9.   
  10. ## This script is used to do MySQL slave server monitoring   
  11. ## using KAS feature.   
  12. ## The mandatory arguments are:   
  13. ##      1. Database to which the user is going to connect   
  14. ##      2. User name   
  15. ## The optional arguments are:   
  16. ##      1. password:  This is the password that will be used to   
  17. ##                    login into the server. If no password is   
  18. ##                    given a blank password is used.   
  19. ##      2. SQL query   
  20. ## Example:   
  21. ##              set monitor ...  -scriptArgs "database=test;user=user1;password=password;   
  22. ##                                                                              query=show slave status"   
  23.   
  24.   
  25. use strict;   
  26. use DBI;   
  27. use Netscaler::KAS;   
  28.   
  29. ## This function is a handler for performing MYSQL probe in KAS mode   
  30. sub mysql_probe   
  31. {   
  32.         ## There must be at least 3 arguments to this function.   
  33.         ##      1. First argument is the IP that has to be probed.   
  34.         ##      2. Second argument is the port to connect to.   
  35.         ##      3. Arguments to be used during probing.   
  36.         if(scalar(@_) < 3)   
  37.         {   
  38.                 return (1,"Arguments not given");   
  39.         }   
  40.   
  41.         ## Parse the argument given, to get database,user name,password,SQL query.   
  42.         ## If parsing fails, it is monitoring probe failure.   
  43.         $_[2]=~/database=([^;]+);user=([^;]+)(;password=([^;]+))?(;query=([^;]+))?/    
  44.                 or return (1,"Invalid argument format");   
  45.   
  46.         (my $database,my $username,my $password,my $sql_query)=($1,$2,$4,$6);   
  47.   
  48.         ## If no password is given, try blank password   
  49.         if(!defined($password))   
  50.         {   
  51.                 $password="";   
  52.         }   
  53.   
  54.         ## Try to connect to the server   
  55.         my $db_handle = DBI->connect("dbi:mysql:database=$database:host=$_[0]:$_[1]",$username,$password)   
  56.                 or return (1,"Connection to database failed - $!");   
  57.   
  58.         ## Check MySQL Slave Server   
  59.         my $slave_info = $db_handle->prepare("show slave status");   
  60.         $slave_info->execute()   
  61.                 or return (1,"Execution of SQL query failed");   
  62.         my $slave_ref = $slave_info->fetchrow_hashref()   
  63.                 or return (1,"Fetchrow of SQL query failed");   
  64.   
  65.         my $threads_info = $db_handle->prepare("show global status like "Threads_connected"");   
  66.         $threads_info->execute()   
  67.                 or return (1,"Execution of SQL query failed");   
  68.         my $threads_ref = $threads_info->fetchrow_hashref()   
  69.                 or return (1,"Fetchrow of SQL query failed");   
  70.   
  71.         if (exists $slave_ref->{Slave_SQL_Running} and $slave_ref->{Slave_SQL_Running} eq "No")   
  72.         {   
  73.             return (1,"Slave IO thread has stopped");   
  74.         }   
  75.         elsif (exists $slave_ref->{Slave_IO_Running} and $slave_ref->{Slave_IO_Running} eq "No")   
  76.         {   
  77.             return (1,"Slave IO thread has stopped");   
  78.         }   
  79.         elsif (exists $slave_ref->{Last_Error} and $slave_ref->{Last_Error} ne "")   
  80.         {   
  81.             return (1,"Has some error information");   
  82.         }   
  83.         elsif (exists $slave_ref->{Seconds_Behind_Master} and $slave_ref->{Seconds_Behind_Master} > 180)   
  84.         {   
  85.             return (1,"The seconds behind master more than 180");   
  86.         }       
  87.         elsif (exists $threads_ref->{Value} and $threads_ref->{Value} > 100)   
  88.         {   
  89.             return (1,"The number of threads that are not sleeping more than 100");   
  90.         }   
  91.         else  
  92.         {   
  93.             ## If no query is given then it is probe success , else try executing the query   
  94.             if(!defined($sql_query))   
  95.             {   
  96.                     $db_handle->disconnect();   
  97.                     return 0;   
  98.             }   
  99.   
  100.             ## Problem during query execution, report failure   
  101.             my $statement = $db_handle->prepare($sql_query)   
  102.                     or return (1,"Preparation of SQL query failed");   
  103.   
  104.             $statement->execute()   
  105.                     or return (1,"Execution of SQL query failed");   
  106.         }   
  107.   
  108.         ## Probe Succeeded.   
  109.         $db_handle->disconnect();   
  110.   
  111.         return 0;   
  112. }   
  113.   
  114. ## Register MS SQL probe handler, to the KAS module.   
  115. probe(&mysql_probe);  

  腳本壓縮包下載:



  健康檢查腳本寫(xiě)完了,現(xiàn)在開(kāi)始配置NetScaler 8.0:

  1、使用SecureCRT等SSH客戶端工具登錄到NetScaler,然后執(zhí)行以下命令:
  


shell
cd /nsconfig/monitors/
vi nsmysql-slave.pl


  將“nsmysql-slave.pl”的源代碼粘貼到其中,然后保存退出,再執(zhí)行以下命令:

chmod +x nsmysql-slave.pl




  2、檢查一下從NetScaler上是否能夠連接MySQL Slave數(shù)據(jù)庫(kù):

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服務(wù)器版本高于4.0,就會(huì)出現(xiàn)以上錯(cuò)誤。這是因?yàn)镸ySQL 4.1及其以上版本的密碼驗(yàn)證算法與MySQL 4.0及其以下版本不同,而NetScaler 8.0上的MySQL客戶端默認(rèn)版本為4.0.25,因此,4.0.25版本的MySQL客戶端連接4.1、5.X、6.X版本的MySQL服務(wù)器就會(huì)出錯(cuò)。

  解決辦法1:升級(jí)NetScaler 8.0上的MySQL客戶端,但最好不要這么做,因?yàn)镹etScaler與底層的FreeBSD系統(tǒng)和應(yīng)用軟件嵌入很密切的,不要輕易替換成非官方版本,以免導(dǎo)致不兼容、不穩(wěn)定等情況。

  解決方法2:在各臺(tái)MySQL Slave服務(wù)器上新建一個(gè)名為“netscaler”的超級(jí)管理員賬號(hào),將密碼改為使用舊加密算法進(jìn)行加密的密碼。如果從安全考慮,可將以下語(yǔ)句中的%換成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、各臺(tái)MySQL Slave數(shù)據(jù)庫(kù)必須添加允許NetScaler的Subnet IP訪問(wèn)的賬號(hào),因?yàn)樵谕痪W(wǎng)段,不能開(kāi)啟源IP支持,MySQL服務(wù)器上看到的將是NetScaler的Subnet IP:

  例如:【W(wǎng)eb服務(wù)器(192.168.1.21)】──→【NetScaler VIP(192.168.1.5)】- - - →【NetScaler Subnet IP(192.168.1.2)】──→【MySQL Slave服務(wù)器(192.168.1.31)】
  MySQL Slave服務(wù)器看到的是IP地址是192.168.1.2,就需要添加NetScaler的Subnet IP訪問(wèn)的賬號(hào)("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,進(jìn)入Configuration頁(yè)面(需要安裝Java Runtime Environment,版本在JRE 1.4.x+以上):
  





  5、點(diǎn)擊【Load Balancing】──【Monitors】欄的“add”按鈕,添加一個(gè)名為“mysql_slave”的MySQL健康檢查:

  



  ①、Interval:正常情況下,10秒鐘檢查一次;
  ②、Response Timeout:每次檢查的超時(shí)時(shí)間為8秒,必須小于Interval;
 ?、邸own Time:宕機(jī)狀態(tài)下,每5秒鐘檢查一次;
  ④、Retries:重試5次后仍然檢查失敗,標(biāo)記服務(wù)器為宕機(jī);
  ⑤、Type:選擇MySQL;
  ⑥、Script Name:點(diǎn)擊其后的“Browse...”按鈕,選擇我編寫(xiě)的MySQL Slave健康檢查腳本“nsmysql-slave.pl”;
  ⑦、Dispatcher IP和Dispatcher Port必須填“127.0.0.1”和“3013”,不要改變;
 ?、唷ser Name輸入剛才創(chuàng)建的賬號(hào)“netscaler“,password輸入創(chuàng)建賬號(hào)時(shí)設(shè)定的“12345678”。

  




  6、點(diǎn)擊【Load Balancing】──【Service Groups】欄的“add”按鈕,添加一個(gè)名為“pool_mysql”的MySQL服務(wù)器池:

 ?、佟⑻砑诱鎸?shí)MySQL Slave服務(wù)器到“pool_mysql”服務(wù)器池,協(xié)議選擇TCP:
  



 ?、?、健康檢查方式選擇第5步中創(chuàng)建的“mysql_slave”:
  




  7、點(diǎn)擊【Load Balancing】──【Virtual Servers】欄的“add”按鈕,添加一個(gè)名為“vs_mysql_slave”的VIP(虛擬IP):

 ?、?、添加“pool_mysql”服務(wù)器池到名為“vs_mysql_slave”的VIP(192.168.1.5:3306),協(xié)議選擇TCP:
  



 ?、?、負(fù)載均衡方式選擇Least Connection(最小連接數(shù)):
  




  8、Web服務(wù)器要訪問(wèn)MySQL Slave,只需訪問(wèn)NetScaler的VIP──192.168.1.5的3306端口即可。至此,已經(jīng)完美解決多臺(tái)MySQL Slave數(shù)據(jù)庫(kù)的負(fù)載均衡問(wèn)題。

chancey 2008-5-30 17:08
replication 的 master 跟 slave 可以不是一種存儲(chǔ)引擎?
張宴 回復(fù)于 2008-5-30 17:25
MySQL主從庫(kù)可以是不同的存儲(chǔ)引擎。

MySQL主從庫(kù)可以是不同的版本,但MySQL從庫(kù)的版本不能小于MySQL主庫(kù)的版本。

InnoDB存儲(chǔ)引擎是行鎖,不會(huì)存在大量鎖表情況,對(duì)寫(xiě)操作有利,用于主庫(kù);MyISAM存儲(chǔ)引擎雖然是表鎖,但select查詢速度在PHP+MySQL網(wǎng)站應(yīng)用中要比InnoDB快5~20倍,用于MySQL Slave只讀數(shù)據(jù)庫(kù)。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
利用oneproxy部署mysql數(shù)據(jù)庫(kù)的讀寫(xiě)分離
Mysql雙機(jī)互備熱備,自動(dòng)切換
mysql如何使用延遲復(fù)制拯救你的誤操作(及sql
讀寫(xiě)分離
生產(chǎn)環(huán)境下shell腳本:Mysql數(shù)據(jù)庫(kù)備份和Mysql主從同步監(jiān)控
MySQL高可用系列之MHA(二)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服