91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MHA故障轉移可以幫助我們解決什么問題

發布時間:2020-05-25 16:39:47 來源:網絡 閱讀:207 作者:三月 欄目:MySQL數據庫

下面一起來了解下MHA故障轉移可以幫助我們解決什么問題,相信大家看完肯定會受益匪淺,文字在精不在多,希望MHA故障轉移可以幫助我們解決什么問題這篇短內容是你想要的。

MHA是一套Mysql故障切換方案,來保障數據庫的高可用性,它的功能是能在0-30s之內實現主Mysql故障轉移(failover),MHA故障轉移可以很好的幫我們解決從庫數據的一致性問題,同時最大化挽回故障發生后數據的一致性。
操作系統版本:Red Hat Enterprise Linux Server release 6.9 (Santiago)
192.168.1.11    master
192.168.1.12    slave01
192.168.1.13    slave02
192.168.1.14    manager

下面開始安裝:
1.準備安裝包,FTP到/usr/local/

1.1解壓安裝包

tar zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

重命名

mv mysql-5.6.39-linux-glibc2.12-x86_64 mysql

1.2 安裝 輔助軟件  yum -y install perl perl-devel

2.添加用戶

groupadd mysql

useradd -r -g mysql mysql

3.修改目錄權限

chown -R mysql.mysql /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql

4.初始化數據庫

/usr/local/mysql/scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

5.注冊服務

cp /usr/local/mysql//support-files/mysql.server/etc/rc.d/init.d/mysql

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

chkconfig --add mysql

chkconfig mysql on

6.啟動服務

service mysql start

7、ssh無密碼登錄

#主機:master執行命令

[root@master ~]# ssh-keygen -t rsa
[root@master ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@manager
[root@master ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01
[root@master ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02
#主機:slave01執行命令

[root@slave01 ~]# ssh-keygen -t rsa
[root@slave01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@manager
[root@slave01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master
[root@slave01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02
#主機: slave02執行命令

[root@slave02 ~]# ssh-keygen -t rsa
[root@slave02 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@manager
[root@slave02 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master
[root@slave02 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01
#主機:manager執行命令

[root@manager ~]# ssh-keygen -t rsa
[root@manager ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master
[root@manager ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01
[root@manager ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02

8.配置Mysql云服務器

#master配置文件/usr/local/mysql/etc/my.cnf 配置如下:
basedir = /usr/local//mysql
datadir = /data/mysql
port = 3306
server_id = 241
socket = /tmp/mysql.sock
log-bin=mysql-bin
log-slave-updates
expire_logs_days = 10
#slave01配置文件/usr/local/mysql/etc/my.cnf 配置如下:

basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 242
socket = /tmp/mysql.sock
log-bin=mysql-bin
log-slave-updates
expire_logs_days = 10
#slave02配置文件/usr/local/mysql/etc/my.cnf 配置如下:

basedir = /usr/local//mysql
datadir = /data/mysql
port = 3306
server_id = 243
socket = /tmp/mysql.sock
log-bin=mysql-bin
log-slave-updates
expire_logs_days = 10
read_only = 1

9.配置master、slave01和slave02之間的主從復制
在MySQL5.6 的主從配置中,master端同樣要開啟兩個重要的選項,server-id和log-bin,并且選項server-id在全局架構中并且唯一,不能被其它主機使用,這里采用主機ip地址的最后一位充當server-id的值;slave端要開啟relay-log;

#主機: master執行命令

[root@master ~]# egrep "log-bin|server_id" /usr/local/lnmp/mysql/etc/my.cnf
server_id = 11
log-bin=mysql-bin
#主機: slave01執行命令

[root@slave01 ~]# egrep "log-bin|server_id" /usr/local/lnmp/mysql/etc/my.cnf
server_id = 12
log-bin=mysql-bin
#主機: slave02執行命令

[root@slave02 ~]# egrep "log-bin|server_id" /usr/local/lnmp/mysql/etc/my.cnf
server_id = 13
log-bin=mysql-bin

10.在master、slave01上創建主從同步的賬號。slave01是備用master,這個也需要建立授權用戶。

[root@master ~]# mysql -uroot -p123456 -e "grant replication slave on . to 'backup'@'192.168.1.%' identified by 'backup';flush privileges;"
[root@slave01 ~]# mysql -uroot -p123456 -e "grant replication slave on . to 'backup'@'192.168.1.%' identified by 'backup';flush privileges;"

11.在master上執行命令,查看master狀態信息

[root@master ~]# mysql -uroot -p123456 -e 'show master status;'
Warning: Using a password on the command line interface can be insecure.
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 |      118 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+

12.在slave01和slave02上執行主從同步

#slave01配置主從

[root@slave01 ~]# mysql -uroot -p123456
mysql>    change master to
->    master_host='192.168.1.11',master_user='backup',master_password='backup',master_port=3306,master_log_file='mysql-bin.000004',master_log_pos=118;
Query OK, 0 rows affected, 2 warnings (0.56 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)

mysql> show slave status\G;
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.11
Master_User: backup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 118
Relay_Log_File: slave01-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 118
Relay_Log_Space: 458
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 11
Master_UUID: cb4af7bc-d600-11e5-8101-26c537b62ad9
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

#slave02配置主從

[root@slave02 ~]# mysql -uroot -p123456
mysql>    change master to
->    master_host='192.168.1.11',master_user='backup',master_password='backup',master_port=3306,master_log_file='mysql-bin.000004',master_log_pos=118;
Query OK, 0 rows affected, 2 warnings (0.56 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)
mysql> show slave status\G;
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.11
Master_User: backup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 118
Relay_Log_File: slave01-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 118
Relay_Log_Space: 458
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 11
Master_UUID: cb4af7bc-d600-11e5-8101-26c537b62ad9
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

13.開始MHA的建設
13.1、創建賬號,每臺數據庫(master、slave01、slave02)上都要創建賬號,在這里以其中master為例.。

[root@master ~]# mysql -uroot -p123456 -e "grant all privileges on . to 'mha_rep'@'192.168.1.%' identified by '123456';flush privileges;"
mysql> select host,user from user;
+---------------+---------+
| host          | user    |
+---------------+---------+
| 192.168.1.% | backup  |
| 192.168.1.% | mha_rep |
| localhost     | root    |
+---------------+---------+
3 rows in set (0.00 sec)

13.2、在3臺主機上(master、slave01和slave02)上分別安裝mha4mysql-node包,這里以master為例,其它主機同理。

[root@master ~]# yum install perl-DBD-MySQL -y
[root@master ~]# rpm -ivh https://downloads.mariadb.com/files/MHA/mha4mysql-node-0.54-0.el6.noarch.rpm

13.3、在manager上安裝mha4mysql-manager和mha4mysql-node包

[root@manager ~]# yum install perl cpan  perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Net-Telnet -y
[root@manager ~]# rpm -ivh https://downloads.mariadb.com/files/MHA/mha4mysql-node-0.54-0.el6.noarch.rpm
[root@manager ~]# wget https://downloads.mariadb.com/files/MHA/mha4mysql-manager-0.56.tar.gz
[root@manager ~]# tar zvxf mha4mysql-manager-0.56.tar.gz
[root@manager ~]# cd mha4mysql-manager-0.56
[root@manager ~]# perl Makefile.PL
[root@manager mha4mysql-manager-0.56]# make && make install
[root@manager mha4mysql-manager-0.56]# mkdir -p /usr/local/mha/scripts
[root@manager mha4mysql-manager-0.56]# cp samples/conf/app1.cnf /usr/local/mha/mha.cnf
[root@manager mha4mysql-manager-0.56]# cp samples/scripts/* /usr/local/mha/scripts/

13.4、修改manager端mha的配置文件,如下

[root@manager ~]# cat /usr/local/mha/mha.cnf
[server default]
user=mha_rep                                    #MHA管理mysql的用戶名
password=123456                                 #MHA管理mysql的密碼
manager_workdir=/usr/local/mha                  #MHA的工作目錄
manager_log=/usr/local/mha/manager.log          #MHA的日志路徑
ssh_user=root                                   #免秘鑰登陸的用戶名
repl_user=backup                                #主從復制賬號,用來在主從之間同步數據
repl_password=backup
ping_interval=1                                 #ping間隔時間,用來檢查master是否正常

[server1]
hostname=192.168.1.11
port=3306
master_binlog_dir=/data/mysql/
candidate_master=1

[server2]
hostname=192.168.1.12
port=3306
master_binlog_dir=/data/mysql/
candidate_master=1

[server3]
hostname=192.168.1.13
port=3306
master_binlog_dir=/data/mysql/
no_master=1

13.5、檢查ssh是否暢通
[root@manager mha4mysql-manager-0.56]# masterha_check_ssh --conf=/usr/local/mha/mha.cnf
Can't locate Params/Validate.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/share/perl5/vendor_perl/Log/Dispatch.pm line 9.
BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/Log/Dispatch.pm line 9.
Compilation failed in require at /usr/local/share/perl5/MHA/SSHCheck.pm line 29.
BEGIN failed--compilation aborted at /usr/local/share/perl5/MHA/SSHCheck.pm line 29.
Compilation failed in require at /usr/local/bin/masterha_check_ssh line 25.
BEGIN failed--compilation aborted at /usr/local/bin/masterha_check_ssh line 25.

通過安裝包解決此問題
[root@manager mha4mysql-manager-0.56]# yum install perl-Params-Validate
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package perl-Params-Validate.x86_64 0:0.92-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
Package                                          Arch                               Version                                  Repository                          Size

Installing:
perl-Params-Validate                             x86_64                             0.92-3.el6                               Server                              75 k

Transaction Summary

Install       1 Package(s)

Total download size: 75 k
Installed size: 175 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 5 pre-existing rpmdb problem(s), 'yum check' output follows:
perl-Log-Dispatch-2.27-1.el6.noarch has missing requires of perl(MIME::Lite)
perl-Log-Dispatch-2.27-1.el6.noarch has missing requires of perl(Mail::Send)
perl-Log-Dispatch-2.27-1.el6.noarch has missing requires of perl(Mail::Sender)
perl-Log-Dispatch-2.27-1.el6.noarch has missing requires of perl(Mail::Sendmail)
perl-Log-Dispatch-2.27-1.el6.noarch has missing requires of perl(Params::Validate)
Installing : perl-Params-Validate-0.92-3.el6.x86_64                                                                                                              1/1
Verifying  : perl-Params-Validate-0.92-3.el6.x86_64                                                                                                              1/1

Installed:
perl-Params-Validate.x86_64 0:0.92-3.el6

Complete!

[root@manager ~]# masterha_check_ssh --conf=/usr/local/mha/mha.cnf
Thu May 17 18:42:22 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 17 18:42:22 2018 - [info] Reading application default configurations from /usr/local/mha/mha.cnf..
Thu May 17 18:42:22 2018 - [info] Reading server configurations from /usr/local/mha/mha.cnf..
Thu May 17 18:42:22 2018 - [info] Starting SSH connection tests..
Thu May 17 18:42:25 2018 - [debug]
Thu May 17 18:42:22 2018 - [debug]  Connecting via SSH from root@192.168.1.11(192.168.1.11:22) to root@192.168.1.12(192.168.1.12:22)..
Thu May 17 18:42:24 2018 - [debug]   ok.
Thu May 17 18:42:24 2018 - [debug]  Connecting via SSH from root@192.168.1.11(192.168.1.11:22) to root@192.168.1.13(192.168.1.13:22)..
Thu May 17 18:42:25 2018 - [debug]   ok.
Thu May 17 18:42:26 2018 - [debug]
Thu May 17 18:42:23 2018 - [debug]  Connecting via SSH from root@192.168.1.12(192.168.1.12:22) to root@192.168.1.11(192.168.1.11:22)..
Thu May 17 18:42:24 2018 - [debug]   ok.
Thu May 17 18:42:24 2018 - [debug]  Connecting via SSH from root@192.168.1.12(192.168.1.12:22) to root@192.168.1.13(192.168.1.13:22)..
Thu May 17 18:42:26 2018 - [debug]   ok.
Thu May 17 18:42:26 2018 - [debug]
Thu May 17 18:42:23 2018 - [debug]  Connecting via SSH from root@192.168.1.13(192.168.1.13:22) to root@192.168.1.11(192.168.1.11:22)..
Thu May 17 18:42:25 2018 - [debug]   ok.
Thu May 17 18:42:25 2018 - [debug]  Connecting via SSH from root@192.168.1.13(192.168.1.13:22) to root@192.168.1.12(192.168.1.12:22)..
Thu May 17 18:42:26 2018 - [debug]   ok.
Thu May 17 18:42:26 2018 - [info] All SSH connection tests passed successfully.

13.6、masterha_check_repl工具檢查mysql主從復制是否成功
[root@manager mha]# masterha_check_repl --conf=/usr/local/mha/mha.cnf
Tue May 15 09:46:42 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue May 15 09:46:42 2018 - [info] Reading application default configurations from /usr/local/mha/mha.cnf..
Tue May 15 09:46:42 2018 - [info] Reading server configurations from /usr/local/mha/mha.cnf..
Tue May 15 09:46:42 2018 - [info] MHA::MasterMonitor version 0.56.
Tue May 15 09:46:42 2018 - [info] Dead Servers:
Tue May 15 09:46:42 2018 - [info] Alive Servers:
Tue May 15 09:46:42 2018 - [info]   192.168.1.11(192.168.1.11:3306)
Tue May 15 09:46:42 2018 - [info]   192.168.1.12(192.168.1.12:3306)
Tue May 15 09:46:42 2018 - [info]   192.168.1.13(192.168.1.13:3306)
Tue May 15 09:46:42 2018 - [info] Alive Slaves:
Tue May 15 09:46:42 2018 - [info]   192.168.1.12(192.168.1.12:3306)  Version=5.6.39-log (oldest major version between slaves) log-bin:enabled
Tue May 15 09:46:42 2018 - [info]     Replicating from 192.168.1.11(192.168.1.11:3306)
Tue May 15 09:46:42 2018 - [info]     Primary candidate for the new Master (candidate_master is set)
Tue May 15 09:46:42 2018 - [info]   192.168.1.13(192.168.1.13:3306)  Version=5.6.39-log (oldest major version between slaves) log-bin:enabled
Tue May 15 09:46:42 2018 - [info]     Replicating from 192.168.1.11(192.168.1.11:3306)
Tue May 15 09:46:42 2018 - [info]     Not candidate for the new Master (no_master is set)
Tue May 15 09:46:42 2018 - [info] Current Alive Master: 192.168.1.11(192.168.1.11:3306)
Tue May 15 09:46:42 2018 - [info] Checking slave configurations..
Tue May 15 09:46:42 2018 - [info]  read_only=1 is not set on slave 192.168.1.12(192.168.1.12:3306).
Tue May 15 09:46:42 2018 - [warning]  relay_log_purge=0 is not set on slave 192.168.1.12(192.168.1.12:3306).
Tue May 15 09:46:42 2018 - [warning]  relay_log_purge=0 is not set on slave 192.168.1.13(192.168.1.13:3306).
Tue May 15 09:46:42 2018 - [info] Checking replication filtering settings..
Tue May 15 09:46:42 2018 - [info]  binlog_do_db= , binlog_ignore_db=
Tue May 15 09:46:42 2018 - [info]  Replication filtering check ok.
Tue May 15 09:46:42 2018 - [info] Starting SSH connection tests..
Tue May 15 09:46:46 2018 - [info] All SSH connection tests passed successfully.
Tue May 15 09:46:46 2018 - [info] Checking MHA Node version..
Tue May 15 09:46:47 2018 - [info]  Version check ok.
Tue May 15 09:46:47 2018 - [info] Checking SSH publickey authentication settings on the current master..
Tue May 15 09:46:48 2018 - [info] HealthCheck: SSH to 192.168.1.11 is reachable.
Tue May 15 09:46:49 2018 - [info] Master MHA Node version is 0.54.
Tue May 15 09:46:49 2018 - [info] Checking recovery script configurations on the current master..
Tue May 15 09:46:49 2018 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysql/ --output_file=/var/tmp/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.000004
Tue May 15 09:46:49 2018 - [info]   Connecting to root@192.168.1.11(192.168.1.11)..
Creating /var/tmp if not exists..    ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/, up to mysql-bin.000004
Tue May 15 09:46:49 2018 - [info] Master setting check done.
Tue May 15 09:46:49 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue May 15 09:46:49 2018 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha_rep' --slave_host=192.168.1.12 --slave_ip=192.168.1.12 --slave_port=3306 --workdir=/var/tmp --target_version=5.6.39-log --manager_version=0.56 --relay_log_info=/data/mysql/relay-log.info  --relay_dir=/data/mysql/  --slave_pass=xxx
Tue May 15 09:46:49 2018 - [info]   Connecting to root@192.168.1.12(192.168.1.12:22)..
Checking slave recovery environment settings..
Opening /data/mysql/relay-log.info ... ok.
Relay log found at /data/mysql, up to slave01-relay-bin.000002
Temporary relay log file is /data/mysql/slave01-relay-bin.000002
Testing mysql connection and privileges..Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'mha_rep'@'slave01' (using password: YES)
mysql command failed with rc 1:0!
at /usr/bin/apply_diff_relay_logs line 367
main::check() called at /usr/bin/apply_diff_relay_logs line 486
eval {...} called at /usr/bin/apply_diff_relay_logs line 466
main::main() called at /usr/bin/apply_diff_relay_logs line 112
Tue May 15 09:46:50 2018 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln201] Slaves settings check failed!
Tue May 15 09:46:50 2018 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln390] Slave configuration failed.
Tue May 15 09:46:50 2018 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln401] Error happend on checking configurations.  at /usr/local/bin/masterha_check_repl line 48
Tue May 15 09:46:50 2018 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln500] Error happened on monitoring servers.
Tue May 15 09:46:50 2018 - [info] Got exit code 1 (Not master dead).

MySQL Replication Health is NOT OK!

解決方法:
[root@master bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+---------+-------------+
| user    | host        |
+---------+-------------+
| root    | 127.0.0.1   |
| backup  | 192.168.1.% |
| mha_rep | 192.168.1.% |
| root    | ::1         |
|         | localhost   |
| mha_rep | localhost   |
| root    | localhost   |
|         | master      |
| root    | master      |
+---------+-------------+
9 rows in set (0.03 sec)

mysql> grant all privileges on . to mha_rep@'192.168.1.12' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on . to mha_rep@'192.168.1.13' identified by '123456';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all privileges on . to mha_rep@'192.168.1.11' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql>

再次運行監測腳本masterha_check_repl --conf=/usr/local/mha/mha.cnf后報錯;
Can't exec "mysqlbinlog": No such file or directory at /usr/local/share/perl5/MHA/BinlogManager.pm line 99.
mysqlbinlog version not found!

缺少軟連接,我們在三個庫中都創建一下軟連接;
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog
再次檢測通過;

14.mha實驗模擬

1、在每次做mha實驗的時候,我們都最好先執行如下命令做檢測

[root@manager ~]# masterha_check_ssh --conf=/usr/local/mha/mha.cnf
[root@manager ~]# masterha_check_repl --conf=/usr/local/mha/mha.cnf
#確定兩條命令的返回結果都是無異常的,然后啟動mha服務

2、在manager端啟動mha服務并時刻監控日志文件的輸出變化

[root@manager ~]# nohup masterha_manager --conf=/usr/local/mha/mha.cnf > /tmp/mha_manager.log 2>&1 &
[root@manager ~]# ps -ef |grep masterha |grep -v 'grep'

3、測試master宕機后,時候會自動切換
#測試前查看slave01,slave02的主從同步情況
#slave01

[root@slave01 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#slave02

[root@slave02 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

#停止master的mysql服務

[root@master ~]# service mysql stop
Shutting down MySQL.....                                   [  OK  ]

#我們查看slave02的主從同步信息

[root@slave02 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Master_Host|Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Master_Host: 192.168.1.12  #表明已經轉移新的ip
Slave_IO_Running: Yes            #主從正常
Slave_SQL_Running: Yes
4、恢復master服務
#刪除故障轉移文件

[root@manager mha]# rm -rf /usr/local/mha/mha.failover.complete
#重啟mysql服務

[root@master ~]# service mysqld start

#在manager的日子文件中找到主從同步的sql語句

[root@manager mha]# grep MASTER_HOST /usr/local/mha/manager.log
Tue May 15 10:08:54 2018 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.1.12', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=2294, MASTER_USER='backup', MASTER_PASSWORD='xxx';
#在master上啟動主從同步,密碼為backup

mysql> change master to
->        master_host='192.168.1.12'',master_user='backup',master_password='backup',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=2294;
Query OK, 0 rows affected, 2 warnings (0.75 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)
#在master和slave02上執行,檢查主從同步是否都正常,這里以master為例,slave02同理

[root@master ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Master_Host|Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Master_Host: 192.168.1.12
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
5、再次啟動MHA的manager服務,并停止slave01

[root@manager ~]# nohup masterha_manager --conf=/usr/local/mha/mha.cnf > /tmp/mha_manager.log 2>&1 &
#關閉slave01的mysql服務

[root@slave01 ~]# service mysqld stop
Shutting down MySQL... SUCCESS
[root@manager mha]# tail -f /usr/local/mha/manager.log

#在slave02上查看主從同步情況

[root@slave02 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Master_Host|Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Master_Host: 192.168.1.12
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
6、恢復slave01服務
#刪除故障轉移文件

[root@manager mha]# rm -rf /usr/local/mha/mha.failover.complete
#重啟mysql服務

[root@slave01 ~]# service mysqld start
Starting MySQL ... SUCCESS!
#在manager的日子文件中找到主從同步的sql語句

[root@manager mha]# grep MASTER_HOST /usr/local/mha/manager.log
Tue May 15 10:25:51 2018 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.1.11', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=120, MASTER_USER='backup', MASTER_PASSWORD='xxx';
#在slave01上啟動主從同步,密碼為backup

mysql>  change master to
->        master_host='192.168.1.11',master_user='backup',master_password='backup',master_port=3306,master_log_file='mysql-bin.000005',master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.61 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)
#在slave01和slave02上執行,檢查主從同步是否都正常,這里以slave01為例,slave02同理。

[root@slave01 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Master_Host|Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Master_Host: 192.168.1.11
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
7、再次啟動MHA的manager服務

[root@manager ~]# nohup masterha_manager --conf=/usr/local/mha/mha.cnf > /tmp/mha_manager.log 2>&1 &

15.通過vip實現mysql的高可用
1、修改/usr/local/mha/mha.cnf

[root@manager mha]# more cat /usr/local/mha/mha.cnf
cat: No such file or directory
::::::::::::::
/usr/local/mha/mha.cnf
::::::::::::::

[server default]
user=mha_rep
password=123456
manager_workdir=/usr/local/mha
manager_log=/usr/local/mha/manager.log
master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover  #定制perl腳本
ssh_user=root
repl_user=backup
repl_password=backup
ping_interval=1

[server1]
hostname=192.168.1.11
port=3306
master_binlog_dir=/data/mysql/
candidate_master=1

[server2]
hostname=192.168.1.12
port=3306
master_binlog_dir=/data/mysql/
candidate_master=1

[server3]
hostname=192.168.1.13
port=3306
master_binlog_dir=/data/mysql/
no_master=1

2、修改腳本/usr/local/mha/scripts/master_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 = '192.168.1.240';
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" ) {

    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" ) {

    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";
    exit 0;
}
else {
    &usage();
    exit 1;
}

}
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";
}

3、模擬故障進行切換

#停止master的mysql服務

[root@master ~]# service mysqld stop
Shutting down MySQL... SUCCESS!
#查看slave02的同步信息

[root@slave02 ~]# mysql -uroot -p123456 -e 'show slave status\G' |egrep 'Master_Host|Slave_IO_Running:|Slave_SQL_Running:'
Warning: Using a password on the command line interface can be insecure.
Master_Host: 192.168.1.12
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#查看slave01的IP信息

eth0      Link encap:Ethernet  HWaddr 00:0C:29:EB:86:1F  
inet addr:192.168.1.12  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feeb:861f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:59533 errors:0 dropped:0 overruns:0 frame:0
TX packets:27157 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63732835 (60.7 MiB)  TX bytes:4660626 (4.4 MiB)

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:01:46:B7  
inet addr:192.168.1.240  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                    
4、恢復master服務與上面恢復方法一樣。

PS:配置文件中請勿添加注釋,要不然會有意想不到的問題,如:
mha.cnf 配置文件中,我們上面添加了#定制perl腳本,就會在啟動MHA時候報錯,ps -ef 查看mha進程,發現不在。查看日志文件如下報錯;

tail: /tmp/mha_manager.log:
nohup: ignoring input
Thu May 17 15:14:46 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 17 15:14:46 2018 - [info] Reading application default configurations from /usr/local/mha/mha.cnf..
Thu May 17 15:14:46 2018 - [info] Reading server configurations from /usr/local/mha/mha.cnf..

Use of uninitialized value $command in string eq at /usr/local/mha/scripts/master_ip_failover line 29.

16.日常維護命令

1.檢查狀態

masterha_check_status --conf=/usr/local/mha/mha.cnf
2.停止
masterha_stop masterha_check_status --conf=/usr/local/mha/mha.cnf

看完MHA故障轉移可以幫助我們解決什么問題這篇文章后,很多讀者朋友肯定會想要了解更多的相關內容,如需獲取更多的行業信息,可以關注我們的行業資訊欄目。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

和静县| 吴桥县| 东明县| 道真| 新疆| 乾安县| 长宁区| 曲沃县| 元朗区| 松溪县| 平武县| 青岛市| 修文县| 文化| 桃源县| 富平县| 玉环县| 渝中区| 遂川县| 阳谷县| 垦利县| 和平县| 潮州市| 浠水县| 连州市| 南靖县| 怀集县| 太仆寺旗| 中超| 葵青区| 镇康县| 项城市| 新干县| 达孜县| 亳州市| 阜康市| 清流县| 科尔| 章丘市| 泸西县| 双江|