MySQL下高可用毛病轉移計劃MHA的超等安排教程。本站提示廣大學習愛好者:(MySQL下高可用毛病轉移計劃MHA的超等安排教程)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL下高可用毛病轉移計劃MHA的超等安排教程正文
MHA引見
MHA是一名日本MySQL年夜牛用Perl寫的一套MySQL毛病切換計劃,來包管數據庫體系的高可用.在宕機的時光內(平日10—30秒內),完成毛病切換,安排MHA,可防止主從分歧性成績,勤儉購置新辦事器的費用,不影響辦事器機能,易裝置,不轉變現有安排。
還支撐在線切換,從以後運轉master切換到一個新的master下面,只須要很短的時光(0.5-2秒內),此時僅僅壅塞寫操作,其實不影響讀操作,便於主機硬件保護。
在有高可用,數據分歧性請求的體系上,MHA 供給了有效的功效,簡直無連續的知足保護須要。
長處:
1.master主動監控和毛病轉移
在以後已存在的主從復制情況中,MHA可以監控master主機毛病,而且毛病主動轉移。
即便有一些slave沒有接收新的relay log events,MHA也會從最新的slave主動辨認差別的relay log events,並apply差別的event到其他slaves。是以一切的slave都是分歧的。MHA秒級別毛病轉移(9-12秒監測到主機毛病,任選7秒鐘封閉電源主機防止腦裂,接上去apply差別relay logs,注冊到新的master,平日須要時光10-30秒即total downtime)。別的,在設置裝備擺設文件裡可以設置裝備擺設一個slave優先成為master。由於MHA修復了slave之間的分歧性,dba就不消行止理分歧性成績。
當遷徙新的master以後,並行恢復其他slave。即便有不計其數的slave,也不會影響恢復master時光,slave也很快完成。
DeNA公司在150+主從情況頂用MHA。當個中一個master瓦解,MHA4秒完成毛病轉移,這是自動/主動集群處理計劃沒法完成的。
2.互動(手動)master毛病轉移
MHA可以用來只做毛病轉移,而不監測master,MHA只作為毛病轉移的交互。
3.非交互式毛病轉移
非交互式的毛病轉移也供給(不監控master,主動毛病轉移)。這個特征很有效,特殊是你曾經裝置了其他軟件監控master。好比,用Pacemaker(Heartbeat)監測master毛病和vip接收,用MHA毛病轉移和slave晉升。
4.在線切換master到分歧主機
在許多情形下,有需要將master轉移到其他主機上(如調換raid掌握器,晉升master機械硬件等等)。這其實不是master瓦解,然則籌劃保護必需去做。籌劃保護招致downtime,必需盡量快的恢復。疾速的master切換和優雅的壅塞寫操作是必須的,MHA供給了這類方法。優雅的master切換, 0.5-2秒內壅塞寫操作。在許多情形下0.5-2秒的downtime是可以接收的,而且即便不在籌劃保護窗口。這意味著當須要改換更快機械,進級高版本時,dba可以很輕易采用舉措。
5.master crash不會招致主從數據紛歧致性
當master crash後,MHA主動辨認slave間relay logevents的分歧,然後運用與分歧的slave,終究一切slave都同步。聯合經由過程半同步一路應用,簡直沒有任何數據喪失。
其他高可用計劃
6.MHA安排不影響以後情況設置
MHA最主要的一個設計理念就是盡量應用簡略。應用與5.0+以上主從情況,其他HA計劃須要轉變mysql安排設置,MHA不會讓dba做這些安排設置裝備擺設,同步和半同步情況都可以用。啟動/停滯/進級/升級/裝置/卸載 MHA都不消轉變mysql主從(如啟動/停滯)。
當你須要進級MHA到新版本時,不須要停滯mysql,僅僅更新HMA版本,然後從新啟動MHAmanger便可。
MHA 支撐包括5.0/5/1/5.5(應當也支撐5.6,翻譯文檔時MHA開辟者沒更新關於5.6版本)。有些HA計劃請求特定的mysql版本(如mysqlcluster,mysql with global transaction id 等),並且你能夠不想僅僅為了MasterHA而遷徙運用。許多情形下,公司曾經安排了很多傳統的mysql運用,開辟或dba不想花太多時光遷徙到分歧的存儲引擎或新的特征(newer bleeding edge distributions 不曉得這個能否該這麼翻譯)。
7.不增長辦事器費用
MHA 包括MHA Manager和MHA node。MHA node運轉在每台mysql辦事器上,Manager可以零丁安排一台機械,監控100+以上master,總辦事器數目不會有太年夜增長。須要留意的是Manager也能夠運轉在slaves中的一台機械上。
8.機能無影響
當監控master,MHA只是幾秒鐘(默許3秒)發送ping包,不發送年夜的查詢。主從復制機能不受影響
9.實用任何存儲引擎
Mysql不只僅實用於事務平安的innodb引擎,在主從中實用的引擎,MHA都可以實用。即便用遺留情況的mysiam引擎,不停止遷徙,也能夠用MHA。
裝置設置裝備擺設辦法
1、示例情況引見
2、辦事器解釋
三台辦事器都裝置mysql,將manager作為治理節點
3、設置裝備擺設等價性
manager:
ssh-keyger -t rsa ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh 192.168.216.50 date ssh 192.168.216.51 date ssh 192.168.216.52 date
master:
ssh-keyger -t rsa ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh 192.168.216.50 date ssh 192.168.216.51 date ssh 192.168.216.52 date
slave:
ssh-keyger -t rsa ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh-coyp-id -i /root/.ssh/id_rsa.pub [email protected] ssh 192.168.216.50 date ssh 192.168.216.51 date ssh 192.168.216.52 date
4、裝置mysql
groupadd mysql useradd -g mysql -s /bin/nologin -M mysql mkdir -pv /data/mysql tar -zxvf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.16-linux-glibc2.5-x86_64 /usr/local/mysql cd /usr/local/mysql/script ./ mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadair=/data/mysql
創立mysql設置裝備擺設文件
vim /usr/local/mysql/my.cnf
[mysql] # CLIENT # port = 3306 socket = /tmp/mysql.sock [mysqld] # GENERAL # user = mysql default-storage-engine = InnoDB socket = /tmp/mysql.sock pid-file = /data/mysql/mysql.pid # MyISAM # key-buffer-size = 32M myisam-recover = FORCE,BACKUP # SAFETY # max-allowed-packet = 16M max-connect-errors = 1000000 # DATA STORAGE # datadir = /data/mysql/ # BINARY LOGGING # server_id = 1 #分歧辦事器紛歧樣 log-bin = /data/mysql/mysql-bin expire-logs-days = 14 sync-binlog = 1 # CACHES AND LIMITS # tmp-table-size = 32M max-heap-table-size = 32M query-cache-type = 0 query-cache-size = 0 max-connections = 500 thread-cache-size = 50 open-files-limit = 65535 table-definition-cache = 1024 table-open-cache = 2048 # INNODB # innodb-flush-method = O_DIRECT innodb-log-files-in-group = 2 innodb-log-file-size = 64M innodb-flush-log-at-trx-commit = 1 innodb-file-per-table = 1 innodb-buffer-pool-size = 592M # LOGGING # log-error = /data/mysql/mysql-error.log log-queries-not-using-indexes = 1 slow-query-log = 1 slow-query-log-file = /data/mysql/mysql-slow.log
5、設置裝備擺設權限
manager:
grant all privileges on *.* to root@'127.0.0.1' identified by 'root'; grant all privileges on *.* to root@'localhost' identified by 'root'; grant all privileges on *.* to root@'192.168.216.50' identified by 'root'; grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
master:
grant all privileges on *.* to root@'127.0.0.1' identified by 'root'; grant all privileges on *.* to root@'localhost' identified by 'root'; grant all privileges on *.* to root@'192.168.216.50' identified by 'root'; grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
slave:
grant all privileges on *.* to root@'127.0.0.1' identified by 'root'; grant all privileges on *.* to root@'localhost' identified by 'root'; grant all privileges on *.* to root@'192.168.216.50' identified by 'root'; grant all privileges on *.* to root@'192.168.216.51' identified by 'root'; grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave'; grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
6、裝置依附包
治理辦事器manager須要裝置以下全體
perl-Config-Tiny perl-Params-Validate perl-Parallel-ForkManager perl-Log-Dispatch |- perl-MIME-Lite-3.027-2.el6.noarch.rpm |- perl-MIME-Types-1.28-2.el6.noarch.rpm |- perl-Email-Date-Format-1.002-5.el6.noarch.rpm |- perl-MailTools-2.04-4.el6.noarch.rpm |- perl-TimeDate-1.16-11.1.el6.noarch.rpm |- perl-Data-ShowTable-3.3-3.4.noarch.rpm |- perl-Mail-Sender-0.8.22-21.1.noarch.rpm |- perl-IO-Socket-SSL-1.31-2.el6.noarch.rpm |- perl-Net-LibIDN-0.12-3.el6.x86_64.rpm |- perl-Net-SSLeay-1.35-9.el6.x86_64.rpm |-perl-Win32API-Registry |- perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm
rpm -ivh ncftp-debuginfo-3.2.3-1.3.x86_64.rpm rpm -ivh perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm rpm -ivh perl-Params-Validate-0.91-2.4.x86_64.rpm rpm -ivh perl-Config-Tiny-2.12-7.1.el6.noarch.rpm rpm -ivh perl-MIME-Types-1.28-2.el6.noarch.rpm rpm -ivh perl-Email-Date-Format-1.002-5.el6.noarch.rpm rpm -ivh perl-TimeDate-1.16-11.1.el6.noarch.rpm rpm -ivh perl-Data-ShowTable-3.3-3.4.noarch.rpm rpm -ivh perl-MailTools-2.04-4.el6.noarch.rpm rpm -ivh perl-MIME-Lite-3.027-2.el6.noarch.rpm rpm -ivh perl-Net-LibIDN-0.12-3.el6.x86_64.rpm rpm -ivh perl-Net-SSLeay-1.35-9.el6.x86_64.rpm rpm -ivh perl-IO-Socket-SSL-1.31-2.el6.noarch.rpm rpm -ivh perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm rpm -ivh perl-Mail-Sender-0.8.22-21.1.noarch.rpm rpm -ivh perl-Log-Dispatch-2.22-7.3.noarch.rpm
假如安perl-DBD-MySQL-4.013-3.el6.x86_64.rpm在檢討rep是報錯則須要手動編譯裝置
tar -zxvf DBD-mysql-4.027.tar.gz cd DBD-mysql-4.0.27 perl Makefile.PL make && make install
節點辦事器裝置
rpm -ivh ncftp-debuginfo-3.2.3-1.3.x86_64.rpm rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
7、創立軟銜接
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
導出mysql庫搜刮途徑
vim /etc/ld.so.conf.d/mysql-x86_64.conf /usr/local/mysql/lib ldconfig
8、在一切辦事器上裝置mha4mysql-node-0.54.tar.gz
tar -zxvf mha4mysql-node-0.54.tar.gz cd mha4mysql-node-0.54 perl Makefile.PL make && make install
9、在治理辦事上裝置 mha4mysql-manager-0.54.tar.gz
tar -zxvf mha4mysql-manager-0.54.tar.gz cd mha4mysql-manager-0.54 perl Makefile.PL make && make install mkdir -pv /etc/masterha mkdir -pv /masterha/app1 cp samples/conf/* /etc/masterha cp samples/scripts/* /usr/local/bin
vim /etc/masterha/app1.cnf
[server default] manager_workdir=/masterha/app1 manager_log=/masterha/app1/manager.log user=root password=root ssh_user=root repl_user=slave repl_password=slave shutdown_script="" #master_ip_failover_script="/usr/local/bin/masterha_ip_failover" master_ip_online_change_script="/usr/local/bin/masterha_ip_failover " report_script="" [server1] hostname=192.168.216.50 master_binlog_dir="/data/mysql/" candidate_master=1 [server2] hostname=192.168.216.51 master_binlog_dir="/data/mysql/" candidate_master=1 [server3] hostname=192.168.216.52 master_binlog_dir="/data/mysql/" candidate_master=1
10、測試ssh銜接
masterha_check_ssh –conf=/etc/masterha/app1.cnf
11、測試replication
masterha_check_repl –conf=/etc/masterha/app1.cnf
12、開啟治理節點過程
masterha_manager –conf=/etc/masterha/app1.cnf
13、測試毛病轉移
封閉主庫mysql,檢查從庫的的狀況能否將同步ip切換到新的主庫
14、設置毛病轉移的ip
vim /etc/masterha/app1.cnf
master_ip_failover_script="/usr/local/bin/masterha_ip_failover " master_ip_online_change_script="/usr/local/bin/masterha_ip_failover "
編纂毛病轉移劇本,將vip設置成192.168.216.100
vim /usr/local/bin/masterha_ip_failover
#!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use Getopt::Long; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port ); # my $vip = '172.16.21.119/24'; # Virtual IP my $vip = '192.168.216.100/24'; # Virtual IP my $key = "1"; my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip"; my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down"; GetOptions( 'command=s' => \$command, 'ssh_user=s' => \$ssh_user, 'orig_master_host=s' => \$orig_master_host, 'orig_master_ip=s' => \$orig_master_ip, 'orig_master_port=i' => \$orig_master_port, 'new_master_host=s' => \$new_master_host, 'new_master_ip=s' => \$new_master_ip, 'new_master_port=i' => \$new_master_port, ); exit &main(); sub main { print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n"; if ( $command eq "stop" || $command eq "stopssh" ) { # $orig_master_host, $orig_master_ip, $orig_master_port are passed. # If you manage master ip address at global catalog database, # invalidate orig_master_ip here. my $exit_code = 1; eval { print "Disabling the VIP on old master: $orig_master_host \n"; &stop_vip(); $exit_code = 0; }; if ($@) { warn "Got Error: $@\n"; exit $exit_code; } exit $exit_code; } elsif ( $command eq "start" ) { # all arguments are passed. # If you manage master ip address at global catalog database, # activate new_master_ip here. # You can also grant write access (create user, set read_only=0, etc) here. my $exit_code = 10; eval { print "Enabling the VIP – $vip on the new master – $new_master_host \n"; &start_vip(); $exit_code = 0; }; if ($@) { warn $@; exit $exit_code; } exit $exit_code; } elsif ( $command eq "status" ) { print "Checking the Status of the script.. OK \n"; `ssh $ssh_user\@cluster1 \" $ssh_start_vip \"`; exit 0; } else { &usage(); exit 1; } } # A simple system call that enable the VIP on the new master sub start_vip() { `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`; } # A simple system call that disable the VIP on the old_master sub stop_vip() { `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`; } sub usage { print "Usage: master_ip_failover –command=start|stop|stopssh|status –orig_master_host=host –orig_master_ip=ip –orig_master_port=port –new_master_host=host –new_master_ip=ip –new_master_port=port\n"; }
測試劇本
/usr/local/bin/masterha_ip_failover –command=status –ssh_user=root –orig_master_host=192.168.216.51 –orig_master_ip=192.168.216.51 –orig_master_port=3306
虛擬ip要手動啟動,在主庫毛病後會主動轉移。
/usr/local/bin/masterha_ip_failover –command=start –ssh_user=root –orig_master_host=192.168.216.51 –orig_master_ip=192.168.216.51 –orig_master_port=3306 –new_master_host=192.168.216.51
測試ip毛病轉移:
封閉主庫mysql,檢查vip能否轉移的新的主庫上。