您好,登錄后才能下訂單哦!
1,環境準備:
DB:mysql-5.7.16
MHA:mha4mysql-manager-0.56.tar.gz、mha4mysql-node-0.56.tar.gz、daemontools-0.76.tar.gz
role ip monitor 10.99.121.206 master 10.99.121.209 slave 10.99.121.210 slave 10.99.121.213
主從:
在主上(10.99.121.206)創建復制用戶與監控用戶
GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'%' IDENTIFIED BY '123qwe'; grant all privileges on *.* to 'monitor'@'%' identified by '123qwe';
在從上(10.99.121.210、10.99.121.213)配置
change master to master_host='10.99.121.209', master_port=3306, master_user='repluser', master_password='123qwe', master_log_file='binlog.000002', master_log_pos=1009; set global read_only=on;
2,在所有的node上安裝perl依賴、mha-node
master slave install epel and perl-DBD-MySQL rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install perl-DBD-MySQL -y yum install -y perl-devel yum install -y perl-CPAN master slave install MHA node tar xf mha4mysql-node-0.56.tar.gz cd mha4mysql-node-0.56 perl Makefile.PL make && make install
安裝完成后會在/usr/local/bin目錄下生成以下腳本文件:
apply_diff_relay_logs //識別差異的中繼日志事件并將其差異的事件應用于其他的slave
filter_mysqlbinlog //去除不必要的ROLLBACK事件(MHA已不再使用這個工具)
purge_relay_logs //清除中繼日志(不會阻塞SQL線程)
save_binary_logs //保存和復制master的二進制日志
3,安裝MHA Manager,在MHA Manager的主機也是需要安裝MHA Node,MHA Manger也依賴于perl模塊
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install perl-DBD-MySQL -y yum install -y perl-devel perl-CPAN yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes -y tar xf mha4mysql-node-0.56.tar.gz cd mha4mysql-node-0.56 perl Makefile.PL make && make install tar xf mha4mysql-manager-0.56.tar.gz cd mha4mysql-manager-0.56 perl Makefile.PL make && make install cd /apps/mha4mysql-manager-0.56/samples/scripts cp * /usr/local/bin/
4,配置SSH登錄無密碼驗證
所有服務器上生成:
ssh-keygen -t rsa
登陸10.99.121.206:
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.209 ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.210 ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.213
登陸10.99.121.209
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.210 ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.213
登陸10.99.121.210
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.209 ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.213
登陸10.99.121.213
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.209 ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.99.121.210
5,配置MHA(登陸10.99.121.206)
(1)創建MHA的工作目錄,并且創建相關配置文件(在軟件包解壓后的目錄里面有樣例配置文件)
mkdir -p /etc/masterha cp mha4mysql-manager-0.56/samples/conf/app1.cnf /etc/masterha/
修改app1.cnf配置文件,修改后的文件內容如下
[server default] manager_workdir=/var/log/masterha/app1 manager_log=/var/log/masterha/app1/manager.log master_binlog_dir=/data/mysql/mysql_data master_ip_failover_script= /usr/local/bin/master_ip_failover ster_ip_online_change_script= /usr/local/bin/master_ip_online_change password=123qwe user=monitor ping_interval=1 remote_workdir=/tmp repl_password=123qwe repl_user=repluser report_script=/usr/local/bin/send_report secondary_check_script= /usr/local/bin/masterha_secondary_check -s lenovo2 -s lenovo1 --user=repluser --master_host=lenovo1 --master_ip=10.99.121.209 --master_port=3306 shutdown_script="" ssh_user=root [server1] hostname=10.99.121.209 port=3306 [server2] hostname=10.99.121.210 port=3306 candidate_master=1 check_repl_delay=0 [server3] hostname=10.99.121.213 port=3306
(2)設置relay log的清除方式(在每個slave節點上)
mysql -uroot -pLenovo123#@! -e "set global relay_log_purge=0" mysql -uroot -pLenovo123#@! -e "set global relay_log_purge=0"
6,檢查SSH配置(10.99.121.206 Monitor 監控節點上操作),如下
[root@lenovo16 masterha]# masterha_check_ssh --conf=/etc/masterha/app1.cnf Thu May 25 16:55:19 2017 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Thu May 25 16:55:19 2017 - [info] Reading application default configuration from /etc/masterha/app1.cnf.. Thu May 25 16:55:19 2017 - [info] Reading server configuration from /etc/masterha/app1.cnf.. Thu May 25 16:55:19 2017 - [info] Starting SSH connection tests.. Thu May 25 16:55:20 2017 - [debug] Thu May 25 16:55:19 2017 - [debug] Connecting via SSH from root@10.99.121.210(10.99.121.210:22) to root@10.99.121.209(10.99.121.209:22).. Thu May 25 16:55:20 2017 - [debug] ok. Thu May 25 16:55:20 2017 - [debug] Connecting via SSH from root@10.99.121.210(10.99.121.210:22) to root@10.99.121.213(10.99.121.213:22).. Thu May 25 16:55:20 2017 - [debug] ok. Thu May 25 16:55:20 2017 - [debug] Thu May 25 16:55:19 2017 - [debug] Connecting via SSH from root@10.99.121.209(10.99.121.209:22) to root@10.99.121.210(10.99.121.210:22).. Thu May 25 16:55:19 2017 - [debug] ok. Thu May 25 16:55:19 2017 - [debug] Connecting via SSH from root@10.99.121.209(10.99.121.209:22) to root@10.99.121.213(10.99.121.213:22).. Thu May 25 16:55:20 2017 - [debug] ok. Thu May 25 16:55:21 2017 - [debug] Thu May 25 16:55:20 2017 - [debug] Connecting via SSH from root@10.99.121.213(10.99.121.213:22) to root@10.99.121.209(10.99.121.209:22).. Thu May 25 16:55:20 2017 - [debug] ok. Thu May 25 16:55:20 2017 - [debug] Connecting via SSH from root@10.99.121.213(10.99.121.213:22) to root@10.99.121.210(10.99.121.210:22).. Thu May 25 16:55:21 2017 - [debug] ok. Thu May 25 16:55:21 2017 - [info] All SSH connection tests passed successfully.
7,檢查整個復制環境狀況(10.99.121.206 Monitor 監控節點上操作),如下
masterha_check_repl --conf=/etc/masterha/app1.cnf
如果遇到如下錯誤:
Thu May 25 16:58:30 2017 - [info] Connecting to root@10.99.121.210(10.99.121.210:22).. Can't exec "mysqlbinlog": No such file or directory at /usr/local/share/perl5/MHA/BinlogManager.pm line 106. mysqlbinlog version command failed with rc 1:0, please verify PATH, LD_LIBRARY_PATH, and client options at /usr/local/bin/apply_diff_relay_logs line 493
那在所有mysql數據庫上執行:
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
8,開啟MHA Manager監控(10.99.121.206 Monitor 監控節點上操作)如下
[root@lenovo16 apps]# masterha_check_status --conf=/etc/masterha/app1.cnf app1 is stopped(2:NOT_RUNNING). [root@lenovo16 apps]# nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 & [1] 18587 [root@lenovo16 apps]# masterha_check_status --conf=/etc/masterha/app1.cnf app1 monitoring program is now on initialization phase(10:INITIALIZING_MONITOR). Wait for a while and try checking again. [root@lenovo16 apps]# masterha_check_status --conf=/etc/masterha/app1.cnf app1 (pid:18587) is running(0:PING_OK), master:10.99.121.209
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz tar -zxvf daemontools-0.76.tar.gz cd admin/daemontools-0.76/ package/install
在src/conf-cc最后加上-include /usr/include/errno.h
[root@lenovo16 apps]# package/install
最后會在admin/daemontools-0.76先建立command目錄并存放相關命令,有什么命令我們可以這樣查看:
[root@lenovo16 apps]# ls /apps/admin/daemontools-0.76/command envdir fghack pgrphack setlock softlimit svc svscan svstat tai64nlocal envuidgid multilog readproctitle setuidgid supervise svok svscanboot tai64n
同時在/usr/local/bin下對上面這些命令建立了軟連接方便我們執行
另外創建監控/services目錄,并在/etc/inittab下也有變化:
SV:123456:respawn:/command/svscanboot
它使用init的方式來守護自己
[root@lenovo16 apps]# mkdir -p /service/masterha_app1 [root@lenovo16 apps]# vim /service/masterha_app1/run #!bin/bash exec masterha_manager --conf=/etc/mha/app1.cnf --wait_on_monitor_error=60 --wait_on_failover_error=60 >> /var/log/masterha/app1/app1.log 2>&1 [root@lenovo16 apps]#chmod 755 /service/masterha_app1/run ##啟動monitoring svc -u /service/masterha_app1 ##停止monitoring svc -d /service/masterha_app1
在此我們先不使用這種方式啟動。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。