標籤:password val arch from style col tor app1 ignore
先說一下大概原理
虛擬機器A ip為10.0.3.92 作為master
虛擬機器B ip為10.0.3.102 作為slave1
虛擬機器C ip為10.0.3.103 作為slave2
虛擬機器D ip為10.0.3.104 作為manager
首先配置一主兩從環境,A為主,BC為從
然後配置所有虛擬機器兩兩之間ssh免密登入(ssh怎麼免密登入,自己百度,或者搜尋我部落格裡的文章吧,也有記錄怎麼配置ssh免密登入的)
D中建立設定檔
D中檢測ssh配置以及主從配置是否成功,這兩個非常關鍵
如果上面都沒有問題,那麼我們試著把master伺服器停掉之後,manager會把主庫自動切換到B
下面來說一下具體部署步驟
重要的事情先說,那就是,防火牆和selinux必須關閉,如果不想關閉,那你就慢慢折騰該通過哪個連接埠之類的吧
下一個MHA壓縮包,裡面有我們需要用到的檔案
http://www.yougemysqldba.com/discuz/viewthread.php?tid=491&extra=page%3D1
我下載的是第二個rhel56.zip,因為我的是6.5的系統
虛擬機器A
首先安裝mysql,mysql-server (我的系統是centos6.5,聽說centos7上部署MHA還需要做其他額外的工作),然後自然而然是開啟服務並修改密碼
配置/etc/my.cnf,添加在mysqld裡面,內容如下
server-id=1 log-bin=master-log relay-log=relay-logskip_name_resolveinnodb_file_per_table
解壓我們下載的那個壓縮包,在虛擬機器A上,我們只需要安裝mha4mysql-node-0.54-0.el6.noarch.rpm,怎麼安裝?百度啊,安裝時提示缺少依賴關係依賴包?百度啊
進入mysql,執行以下命令
建立一個repluser使用者,專門用來同步
mysql> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000004 | 106 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
這樣子的話說明master端配置好了
虛擬機器B以及虛擬機器C:
當然這兩台虛擬機器也需要安裝node那個rpm檔案包
設定檔/etc/my.cnf,當然也是放在mysqld下面了
symbolic-links=0
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_bin
default-storage-engine=INNODB
max_allowed-packet=32M
sql_mode=NO_AUTO_VALUE_ON_ZERO
server-id=2 #虛擬機器C只需要把這裡改為3
relay-log=relay-log
log-bin=master-log
read_only=1
relay_log_purge=0
skip_name_resolve
innodb_file_per_table
前面多出的幾行是設定中文編碼
進入資料庫
change master 設定
change master to master_host=‘10.0.3.92‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-log.000004‘,MASTER_LOG_POS=106;
現在start slave查看slave狀態,主要查看下面兩個參數是否為yes,如果是就表示正常
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
虛擬機器D:
安裝下載的壓縮包裡面的所有rpm檔案
配置
[[email protected] ~]# cat /etc/masterha_default.cnf
[server default]
user=root #聽說這個是資料庫的使用者名稱,需要在四台虛擬機器上都建立這個使用者,並且授權為可遠程登入,反正我是直接用的root使用者,並且密碼統一為123456
password=123456 #這個是上面使用者對應的密碼
manager_workdir=/data/masterha/app1
manager_log=/data/masterha/app1/manager.log
remote_workdir=/data/masterha/app1
ssh_user=root #ssh登入的使用者名稱,配置ssh時也是配置該使用者
repl_user=repluser #配置主從時設定的使用者
repl_password=replpass #主從使用者密碼
ping_interval=1
[server1]
hostname=10.0.3.92
[server2]
hostname=10.0.3.102
[server3]
hostname=10.0.3.103
[[email protected] ~]#
[[email protected] ~]# masterha_
masterha_check_repl masterha_check_status masterha_manager masterha_master_switch masterha_stop
masterha_check_ssh masterha_conf_host masterha_master_monitor masterha_secondary_check
[[email protected] ~]# masterha_check_ssh --conf=/etc/masterha_default.cnf 檢測ssh配置
Thu Nov 9 01:12:32 2017 - [info] Reading default configuratoins from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Reading application default configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Reading server configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:32 2017 - [info] Starting SSH connection tests..
Thu Nov 9 01:12:33 2017 - [debug]
Thu Nov 9 01:12:32 2017 - [debug] Connecting via SSH from [email protected](10.0.3.92:22) to [email protected](10.0.3.102:22)..
Thu Nov 9 01:12:32 2017 - [debug] ok.
Thu Nov 9 01:12:32 2017 - [debug] Connecting via SSH from [email protected](10.0.3.92:22) to [email protected](10.0.3.103:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug]
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from [email protected](10.0.3.102:22) to [email protected](10.0.3.92:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from [email protected](10.0.3.102:22) to [email protected](10.0.3.103:22)..
Thu Nov 9 01:12:33 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug]
Thu Nov 9 01:12:33 2017 - [debug] Connecting via SSH from [email protected](10.0.3.103:22) to [email protected](10.0.3.92:22)..
Thu Nov 9 01:12:34 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [debug] Connecting via SSH from [email protected](10.0.3.103:22) to [email protected](10.0.3.102:22)..
Thu Nov 9 01:12:34 2017 - [debug] ok.
Thu Nov 9 01:12:34 2017 - [info] All SSH connection tests passed successfully.
[[email protected] ~]#
[[email protected] ~]# masterha_check_repl --conf=/etc/masterha_default.cnf #檢測主從複製,正常情況下mysql replication health is ok,這裡因為我是在實驗完成後停掉master伺服器了,才導致的not ok。剛開始的時候我這裡一直是not ok,然後我就各種查錯,最後發現是防火牆不知道什麼時候又開啟了。。。這裡我建議在D上嘗試串連另外三台虛擬機器的資料庫,分別用root登入以及主從複製使用者登入,如果不報錯,檢測主從複製這裡應該就沒有問題了
Thu Nov 9 01:12:59 2017 - [info] Reading default configuratoins from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] Reading application default configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] Reading server configurations from /etc/masterha_default.cnf..
Thu Nov 9 01:12:59 2017 - [info] MHA::MasterMonitor version 0.55.
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln604] There are 2 non-slave servers! MHA manages at most one non-slave server. Check configurations.
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations. at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line 300
Thu Nov 9 01:13:00 2017 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
Thu Nov 9 01:13:00 2017 - [info] Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!
現在我們試著把master伺服器停掉,然後我們看一下虛擬機器C的狀態
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.3.102 #可以看到這裡自動把master從10.0.3.92 切換到10.0.3.102了
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-log.000010
Read_Master_Log_Pos: 600
Relay_Log_File: relay-log.000005
Relay_Log_Pos: 252
Relay_Master_Log_File: master-log.000010
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: 600
Relay_Log_Space: 1286
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:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
大概就是這麼簡單,但是第一次配置時還是很容易出現這樣或那樣的問題的,慢慢琢磨吧
什麼,我寫得亂七八糟的,你看不懂?
好吧,給一個參考連結給你http://www.178linux.com/87554
MySQL之高可用MHA部署