MySQL MHA配置

zping發表於2016-03-23

 MySQL環境:

     master:192.168.202.129:3306

     slave:192.168.202.129:3307,192.168.202.129:3307,192.168.202.130:3306,192.168.202.130:3307,192.168.202.130:3308

     MariaDB-10.0.13

     MHA環境:

     manager:192.168.202.129

     node:192.168.202.130(3306埠監聽的例項作為備用主庫),192.168.202.129

     下載地址:http://code.google.com/p/mysql-master-ha/ (這個需要FQ),我在百度網盤裡共享了一份:http://pan.baidu.com/s/1pJ0VkSz

     一 MySQL安裝準備:

     1 建立MySQL安裝目錄:mkdir -p /usr/local/mysql

     2 建立mysql使用者:

     

groupadd mysql
useradd -g mysql mysql

    3 下載依賴包:

    

yum  install make apr* autoconf automake curl curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat*  cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel  libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel  libjpeg* libpng* php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison

    4 下載cmake:yum install cmake -y

    5 開始編譯:

    

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1

    6 結束之後,輸入下面的命令:make && make install

    上面的過程結束之後就安裝好了MySQL。下面是配置過程:

   二 編譯安裝MySQL:

   1 修改環境變數:vi /etc/profile,新增下面的語句:

   

export PATH=$PATH:/usr/local/mysql/bin

   2 source /etc/profile載入環境變數

   3 將/usr/local/mysql/support_files下的my-default.cnf複製到/etc下:cp /usr/local/mysql/support_files/my-default.cnf /etc/my.cnf,修改這個檔案加入下面的內容:

   

複製程式碼
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /home/mysql/mydata/log/mysqld_multi.log


[mysqld1]
socket = /home/mysql/mydata/data1/socket/mysqld.sock
port = 3306
pid-file = /home/mysql/mydata/data1/mysqld.pid
datadir = /home/mysql/mydata/data1

log_bin=/home/mysql/mydata/data1/binlog/mysql-bin
server-id = 1

[mysqld2]
socket = /home/mysql/mydata/data2/socket/mysqld.sock
port = 3307
pid-file = /home/mysql/mydata/data2/mysqld.pid
datadir = /home/mysql/mydata/data2

log_bin=/home/mysql/mydata/data2/binlog/mysql-bin
server-id = 2
relay_log = /home/mysql/mydata/data2/relay_log/mysql-relay-bin
log_slave_updates = 1
read_only = 1

[mysqld3]
socket = /home/mysql/mydata/data3/socket/mysqld.sock
port = 3308
pid-file = /home/mysql/mydata/data3/mysqld.pid
datadir = /home/mysql/mydata/data3

log_bin=/home/mysql/mydata/data3/binlog/mysql-bin
server-id = 3
relay_log = /home/mysql/mydata/data3/relay_log/mysql-relay-bin
log_slave_updates = 1
read_only = 1
複製程式碼

     上面的路徑都需要用mysql使用者建立,這裡不再贅述。

     4 下面就可以初始化資料庫了:

     

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/mydata/data1

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/mydata/data2

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/mydata/data3

    這樣就把一個伺服器上所有的資料庫都建立好了,在130伺服器上也是如法炮製,不過在修改my.cnf的時候要注意一點就是修改server-id,從4以後開始,不要和129伺服器的相同。

    下面就可以啟動資料庫了,命令很簡單:

    

mysqld_multi --defaults-extra-file=/etc/my.cnf start 1,2,3

    這就將三個資料庫啟動好了,可以用下面的語句檢查:

    

mysqld_multi --defaults-extra-file=/etc/my.cnf report

MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running

    

     三 主從配置

     1 主庫建立複製使用者:

     

在192.168.202.129上:
$mysql -uroot -P3306 -p127.0.0.1

grant replication slave, replication client on *.* to repl@'192.168.202.%' identified by 'repl'; -- 這裡限制在區域網內

    2 從庫配置:

    

複製程式碼
在192.168.202.129上:
$mysql -uroot -P3307 -p127.0.0.1
change master to master_host='192.168.202.129', MASTER_PORT=3306, master_user='repl', master_password='repl', master_log_file='mysql-bin.000001', master_log_pos=0;
start slave;

$mysql -uroot -P3308 -p127.0.0.1
change master to master_host='192.168.202.129', MASTER_PORT=3306, master_user='repl', master_password='repl', master_log_file='mysql-bin.000001', master_log_pos=0;
start slave;
在192.168.202.130上:
$mysql -uroot -P3306 -p127.0.0.1
change master to master_host='192.168.202.129', MASTER_PORT=3306, master_user='repl', master_password='repl', master_log_file='mysql-bin.000001', master_log_pos=0;
start slave;
$mysql -uroot -P3307 -p127.0.0.1
change master to master_host='192.168.202.129', MASTER_PORT=3306, master_user='repl', master_password='repl', master_log_file='mysql-bin.000001', master_log_pos=0;
start slave;
$mysql -uroot -P3308 -p127.0.0.1
change master to master_host='192.168.202.129', MASTER_PORT=3306, master_user='repl', master_password='repl', master_log_file='mysql-bin.000001', master_log_pos=0;
start slave;
複製程式碼

     這樣子就配置結束了。

     3 配置好了以後主庫上會有slave過來的程式:

     mysql>show processlist;

     

     有幾個slave,這裡就會有多少個程式。

     4 

# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

 

     三 MHA配置

     1 依賴安裝:

     在node節點上,執行下面的命令:

     

# yum install perl-DBD-MySQL

    在manager節點上:

    

# yum install perl-DBD-MySQL
# yum install perl-Config-Tiny
# yum install perl-Log-Dispatch
# yum install perl-Parallel-ForkManager
# yum install -y rrdtool perl-rrdtool rrdtool-devel perl-Params-Validate

    2 rpm包安裝:

    manager節點:

    

# rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm
# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

   node節點:

   

# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

    3 配置

    

mkdir -p /etc/masterha/
mkdir -p /var/log/masterha/app1/

    將下面的內容寫進/etc/masterha/app1.cnf:

複製程式碼
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log
user=admin
password=admin
ssh_user=root
repl_user=repl
repl_password=repl
ping_interval=1
shutdown_script=""
master_ip_online_change_script=""
report_script=""


[server1]
hostname=192.168.126.129
port=3306
candidate_master=1
master_binlog_dir="/home/mysql/mydata/data1/binlog"


[server2]
hostname=192.168.126.130
port=3306
candidate_master=1
master_binlog_dir="/home/mysql/mydata/data1/binlog"

[server3]
hostname=192.168.126.130
port=3307

[server4]
hostname=192.168.126.130
port=3308

[server5]
hostname=192.168.126.129
port=3307

[server6]
hostname=192.168.126.129
port=3308
複製程式碼

    4 配置ssh免祕鑰:

# ssh-keygen -t rsa
# cd ~/.ssh
# cat id_rsa.pub >> authorized_keys
# chmod 600 authorized_keys

    將id_rsa.pub的內容貼上到另一臺伺服器的~/.ssh/authorized_keys裡(保證兩個機器互相信任)。

    5 測試一下ssh: 

masterha_check_ssh --conf=/etc/masterha/app1.cnf

    下面的結果出來就對了:

    

複製程式碼
Sat Oct 18 14:04:43 2014 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Oct 18 14:04:43 2014 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sat Oct 18 14:04:43 2014 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sat Oct 18 14:04:43 2014 - [info] Starting SSH connection tests..
Sat Oct 18 14:06:29 2014 - [debug]
Sat Oct 18 14:04:46 2014 - [debug]  Connecting via SSH from root@192.168.126.129(192.168.126.129:22) to root@192.168.126.129(192.168.126.129:22)..
Sat Oct 18 14:05:07 2014 - [debug]   ok.
Sat Oct 18 14:05:07 2014 - [debug]  Connecting via SSH from root@192.168.126.129(192.168.126.129:22) to root@192.168.126.130(192.168.126.130:22)..
Sat Oct 18 14:05:28 2014 - [debug]   ok.
Sat Oct 18 14:05:28 2014 - [debug]  Connecting via SSH from root@192.168.126.129(192.168.126.129:22) to root@192.168.126.130(192.168.126.130:22)..
Sat Oct 18 14:05:49 2014 - [debug]   ok.
Sat Oct 18 14:05:49 2014 - [debug]  Connecting via SSH from root@192.168.126.129(192.168.126.129:22) to root@192.168.126.130(192.168.126.130:22)..
Sat Oct 18 14:06:10 2014 - [debug]   ok.
Sat Oct 18 14:06:10 2014 - [debug]  Connecting via SSH from root@192.168.126.129(192.168.126.129:22) to root@192.168.126.129(192.168.126.129:22)..
Sat Oct 18 14:06:29 2014 - [debug]
Sat Oct 18 14:04:45 2014 - [debug]  Connecting via SSH from root@192.168.126.130(192.168.126.130:22) to root@192.168.126.129(192.168.126.129:22)..
Sat Oct 18 14:05:06 2014 - [debug]   ok.
Sat Oct 18 14:05:06 2014 - [debug]  Connecting via SSH from root@192.168.126.130(192.168.126.130:22) to root@192.168.126.130(192.168.126.130:22)..
Sat Oct 18 14:05:27 2014 - [debug]   ok.
Sat Oct 18 14:05:27 2014 - [debug]  Connecting via SSH from root@192.168.126.130(192.168.126.130:22) to root@192.168.126.130(192.168.126.130:22)..
Sat Oct 18 14:05:48 2014 - [debug]   ok.
Sat Oct 18 14:05:48 2014 - [debug]  Connecting via SSH from root@192.168.126.130(192.168.126.130:22) to root@192.168.126.129(192.168.126.129:22)..
Sat Oct 18 14:06:09 2014 - [debug]   ok.
Sat Oct 18 14:06:09 2014 - [debug]  Connecting via SSH from root@192.168.126.130(192.168.126.130:22) to root@192.168.126.129(192.168.126.129:22)..
Sat Oct 18 14:06:31 2014 - [info] All SSH connection tests passed successfully.
複製程式碼

    6 測試一下複製:

    

masterha_check_repl --conf=/etc/masterha/app1.cnf
複製程式碼
Sat Oct 18 14:12:45 2014 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Oct 18 14:12:45 2014 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sat Oct 18 14:12:45 2014 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sat Oct 18 14:12:45 2014 - [info] MHA::MasterMonitor version 0.56.
Sat Oct 18 14:12:46 2014 - [info] GTID failover mode = 0
Sat Oct 18 14:12:46 2014 - [info] Dead Servers:
Sat Oct 18 14:12:46 2014 - [info] Alive Servers:
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3306)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3307)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3308)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.129(192.168.126.129:3307)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.129(192.168.126.129:3308)
Sat Oct 18 14:12:46 2014 - [info] Alive Slaves:
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3306)  Version=10.0.13-MariaDB-log (oldest major version between slaves) log-bin:enabled
Sat Oct 18 14:12:46 2014 - [info]     Replicating from 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info]     Primary candidate for the new Master (candidate_master is set)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3307)  Version=10.0.13-MariaDB-log (oldest major version between slaves) log-bin:enabled
Sat Oct 18 14:12:46 2014 - [info]     Replicating from 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.130(192.168.126.130:3308)  Version=10.0.13-MariaDB-log (oldest major version between slaves) log-bin:enabled
Sat Oct 18 14:12:46 2014 - [info]     Replicating from 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.129(192.168.126.129:3307)  Version=10.0.13-MariaDB-log (oldest major version between slaves) log-bin:enabled
Sat Oct 18 14:12:46 2014 - [info]     Replicating from 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info]   192.168.126.129(192.168.126.129:3308)  Version=10.0.13-MariaDB-log (oldest major version between slaves) log-bin:enabled
Sat Oct 18 14:12:46 2014 - [info]     Replicating from 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info] Current Alive Master: 192.168.126.129(192.168.126.129:3306)
Sat Oct 18 14:12:46 2014 - [info] Checking slave configurations..
Sat Oct 18 14:12:46 2014 - [info]  read_only=1 is not set on slave 192.168.126.130(192.168.126.130:3306).
Sat Oct 18 14:12:46 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.126.130(192.168.126.130:3306).
Sat Oct 18 14:12:46 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.126.130(192.168.126.130:3307).
Sat Oct 18 14:12:46 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.126.130(192.168.126.130:3308).
Sat Oct 18 14:12:46 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.126.129(192.168.126.129:3307).
Sat Oct 18 14:12:46 2014 - [warning]  relay_log_purge=0 is not set on slave 192.168.126.129(192.168.126.129:3308).
Sat Oct 18 14:12:46 2014 - [info] Checking replication filtering settings..
Sat Oct 18 14:12:46 2014 - [info]  binlog_do_db= , binlog_ignore_db=
Sat Oct 18 14:12:46 2014 - [info]  Replication filtering check ok.
Sat Oct 18 14:12:46 2014 - [info] GTID (with auto-pos) is not supported
Sat Oct 18 14:12:46 2014 - [info] Checking MHA Node version..
Sat Oct 18 14:13:40 2014 - [info]  Version check ok.
Sat Oct 18 14:13:40 2014 - [info] Checking SSH publickey authentication settings on the current master..
Sat Oct 18 14:13:45 2014 - [warning] HealthCheck: Got timeout on checking SSH connection to 192.168.126.129! at /usr/share/perl5/vendor_perl/MHA/HealthCheck.pm line 342.
Sat Oct 18 14:13:45 2014 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Sat Oct 18 14:13:45 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='admin' --slave_host=192.168.126.130 --slave_ip=192.168.126.130 --slave_port=3306 --workdir=/var/tmp --target_version=10.0.13-MariaDB-log --manager_version=0.56 --relay_log_info=/home/mysql/mydata/data1/relay-log.info  --relay_dir=/home/mysql/mydata/data1/  --slave_pass=xxx
Sat Oct 18 14:13:45 2014 - [info]   Connecting to root@192.168.126.130(192.168.126.130:22)..
  Checking slave recovery environment settings..
    Opening /home/mysql/mydata/data1/relay-log.info ... ok.
    Relay log found at /home/mysql/mydata/data1, up to mysqld-relay-bin.000002
    Temporary relay log file is /home/mysql/mydata/data1/mysqld-relay-bin.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Sat Oct 18 14:13:56 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='admin' --slave_host=192.168.126.130 --slave_ip=192.168.126.130 --slave_port=3307 --workdir=/var/tmp --target_version=10.0.13-MariaDB-log --manager_version=0.56 --relay_log_info=/home/mysql/mydata/data2/relay-log.info  --relay_dir=/home/mysql/mydata/data2/  --slave_pass=xxx
Sat Oct 18 14:13:56 2014 - [info]   Connecting to root@192.168.126.130(192.168.126.130:22)..
  Checking slave recovery environment settings..
    Opening /home/mysql/mydata/data2/relay-log.info ... ok.
    Relay log found at /home/mysql/mydata/data2/relay_log, up to mysql-relay-bin.000002
    Temporary relay log file is /home/mysql/mydata/data2/relay_log/mysql-relay-bin.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Sat Oct 18 14:14:21 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='admin' --slave_host=192.168.126.130 --slave_ip=192.168.126.130 --slave_port=3308 --workdir=/var/tmp --target_version=10.0.13-MariaDB-log --manager_version=0.56 --relay_log_info=/home/mysql/mydata/data3/relay-log.info  --relay_dir=/home/mysql/mydata/data3/  --slave_pass=xxx
Sat Oct 18 14:14:21 2014 - [info]   Connecting to root@192.168.126.130(192.168.126.130:22)..
  Checking slave recovery environment settings..
    Opening /home/mysql/mydata/data3/relay-log.info ... ok.
    Relay log found at /home/mysql/mydata/data3/relay_log, up to mysql-relay-bin.000002
    Temporary relay log file is /home/mysql/mydata/data3/relay_log/mysql-relay-bin.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Sat Oct 18 14:14:47 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='admin' --slave_host=192.168.126.129 --slave_ip=192.168.126.129 --slave_port=3307 --workdir=/var/tmp --target_version=10.0.13-MariaDB-log --manager_version=0.56 --relay_log_info=/home/mysql/mydata/data2/relay-log.info  --relay_dir=/home/mysql/mydata/data2/  --slave_pass=xxx
Sat Oct 18 14:14:47 2014 - [info]   Connecting to root@192.168.126.129(192.168.126.129:22)..
  Checking slave recovery environment settings..
    Opening /home/mysql/mydata/data2/relay-log.info ... ok.
    Relay log found at /home/mysql/mydata/data2/relay_log, up to mysql-relay-bin.000002
    Temporary relay log file is /home/mysql/mydata/data2/relay_log/mysql-relay-bin.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Sat Oct 18 14:14:58 2014 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='admin' --slave_host=192.168.126.129 --slave_ip=192.168.126.129 --slave_port=3308 --workdir=/var/tmp --target_version=10.0.13-MariaDB-log --manager_version=0.56 --relay_log_info=/home/mysql/mydata/data3/relay-log.info  --relay_dir=/home/mysql/mydata/data3/  --slave_pass=xxx
Sat Oct 18 14:14:58 2014 - [info]   Connecting to root@192.168.126.129(192.168.126.129:22)..
  Checking slave recovery environment settings..
    Opening /home/mysql/mydata/data3/relay-log.info ... ok.
    Relay log found at /home/mysql/mydata/data3/relay_log, up to mysql-relay-bin.000002
    Temporary relay log file is /home/mysql/mydata/data3/relay_log/mysql-relay-bin.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Sat Oct 18 14:15:10 2014 - [info] Slaves settings check done.
Sat Oct 18 14:15:10 2014 - [info]
192.168.126.129(192.168.126.129:3306) (current master)
 +--192.168.126.130(192.168.126.130:3306)
 +--192.168.126.130(192.168.126.130:3307)
 +--192.168.126.130(192.168.126.130:3308)
 +--192.168.126.129(192.168.126.129:3307)
 +--192.168.126.129(192.168.126.129:3308)

Sat Oct 18 14:15:10 2014 - [info] Checking replication health on 192.168.126.130..
Sat Oct 18 14:15:10 2014 - [info]  ok.
Sat Oct 18 14:15:10 2014 - [info] Checking replication health on 192.168.126.130..
Sat Oct 18 14:15:10 2014 - [info]  ok.
Sat Oct 18 14:15:10 2014 - [info] Checking replication health on 192.168.126.130..
Sat Oct 18 14:15:10 2014 - [info]  ok.
Sat Oct 18 14:15:10 2014 - [info] Checking replication health on 192.168.126.129..
Sat Oct 18 14:15:10 2014 - [info]  ok.
Sat Oct 18 14:15:10 2014 - [info] Checking replication health on 192.168.126.129..
Sat Oct 18 14:15:10 2014 - [info]  ok.
Sat Oct 18 14:15:10 2014 - [warning] master_ip_failover_script is not defined.
Sat Oct 18 14:15:10 2014 - [warning] shutdown_script is not defined.
Sat Oct 18 14:15:10 2014 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.
複製程式碼

    這樣就OK了。

    7 開啟masterha_manager

 # nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log  2>&1 &

   看一下狀態:

# masterha_check_status --conf=/etc/masterha/app1.cnf 

app1 (pid:5161) is running(0:PING_OK), master:192.168.126.129

   這個時候也可以檢測一下日誌,可以新開一個terminal:

   tail -f /var/log/masterha/app1/manager.log

   8 測試一下斷掉129的3306以後能不能切換到130的3306:

[root@bogon ~]# mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1

   但是這之前確保沒有這個檔案 /var/log/masterha/app1/app1.failover.complete

   關掉例項之後就會發現剛才tail的日誌不停的重新整理,摘Failover Report出來:

  

複製程式碼
----- Failover Report -----

app1: MySQL Master failover 192.168.126.129(192.168.126.129:3306) to 192.168.126.130(192.168.126.130:3306) succeeded

Master 192.168.126.129(192.168.126.129:3306) is down!

Check MHA Manager logs at bogon:/var/log/masterha/app1/manager.log for details.

Started automated(non-interactive) failover.
The latest slave 192.168.126.130(192.168.126.130:3306) has all relay logs for recovery.
Selected 192.168.126.130(192.168.126.130:3306) as a new master.
192.168.126.130(192.168.126.130:3306): OK: Applying all logs succeeded.
192.168.126.130(192.168.126.130:3307): This host has the latest relay log events.
192.168.126.130(192.168.126.130:3308): This host has the latest relay log events.
192.168.126.129(192.168.126.129:3307): This host has the latest relay log events.
192.168.126.129(192.168.126.129:3308): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.126.130(192.168.126.130:3308): OK: Applying all logs succeeded. Slave started, replicating from 192.168.126.130(192.168.126.130:3306)
192.168.126.130(192.168.126.130:3307): OK: Applying all logs succeeded. Slave started, replicating from 192.168.126.130(192.168.126.130:3306)
192.168.126.129(192.168.126.129:3307): OK: Applying all logs succeeded. Slave started, replicating from 192.168.126.130(192.168.126.130:3306)
192.168.126.129(192.168.126.129:3308): OK: Applying all logs succeeded. Slave started, replicating from 192.168.126.130(192.168.126.130:3306)
192.168.126.130(192.168.126.130:3306): Resetting slave info succeeded.
Master failover to 192.168.126.130(192.168.126.130:3306) completed successfully.
複製程式碼

    9 下面看看是不是已經切過來了,登陸到130的3306上看一下processlist:

    

    確實是四個,再看看129的3307的slave status:

    

    已經切換到了130的3306上。

    再看看130的3307上:

    

    這個配置起來不是很複雜,我覺得基本所有的開源專案安裝配置都不難,關鍵都是在引數的配置上,下面是我參考的文件,有自己的也有別人的:

    http://ylw6006.blog.51cto.com/470441/890360/

    http://www.jb51.net/LINUXjishu/128753.html

    http://www.cnblogs.com/wingsless/p/4002806.html

    http://www.cnblogs.com/wingsless/p/4002806.html

相關文章