在mysql的复制,当主服务崩溃了,利用mha实现主服务自动切换,并能使其他从服务切换到新的主机。下面是部署步骤
(1)准备三机器:主服务 192.168.8.120,备主 192.168.8.121 ,从服务和管理节点 192.168.8.122
(2)修改各台主机名 如 管理节点192.168.8.122 cat /etc/hosts
[root@centos3 mha]# more /etc/hosts
127.0.0.1 localhost
192.168.8.120 centos1
192.168.8.121 centos2
192.168.8.122 centos3 (3)数据节点
安装mha4mysql-node-0.53.tar.gz
mha4mysql-manager-0.53.tar.gz,由于mha4mysql-node 依赖 perl-DBD-MySQL, mha4mysql-manager依赖
perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager 。所以现在这些依赖包。实验使用yum 安装。
对三台mariadb数据节点只需安装
mha4mysql-node-0.53.tar.gz ,本文没有写mariadb的安装以及复制。
[root@centos1mha]# rpm -ivh
http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
[root@centos1mha]#
yum -y install perl-DBD-MySQL ncftp
[root@centos1mha]# tar -zxf
mha4mysql-node-0.53.tar.gz
[root@centos1mha]# cd mha4mysql-node-0.53
[root@centos1mha]# perl Makefile.PL
[root@centos1mha]#
make && make install
(4)管理节点
[root@sh-gs-dbmg0227 ~]# rpm -ivh
http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm //这个是centos5.x 如果是6.x rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@centos3 mha]# yum -y install perl-DBD-MySQL ncftp [root@centos3 mha]# tar -zxf mha4mysql-node-0.53.tar.gz
[root@centos3 mha]# cd mha4mysql-node-0.53 [root@centos3 mha]#
perl Makefile.PL
[root@centos3 mha]#
make && make install [root@centos3 mha]#
yum -y install perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles
[root@centos3 mha]# tar -zxf mha4mysql-manager-0.53.tar.gz [root@centos3 mha]# perl Makefile.PL
如果在该过程中出现下面错误
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: inc
/usr/local/lib/perl5 /usr/local/share/perl5
/usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at inc/Module/Install/Can.pm line 6.
解决方法:
yum install perl-CPAN
[root@centos3 mha]#
make && make install [root@centos3 mha]# mkdir /etc/masterha [root@centos3 mha]# mkdir -p /master/app1
[root@centos3 mha]# mkdir -p /scripts[root@centos3 mha]# cp samples/conf/* /etc/masterha/
[root@centos3
mha]# cp samples/scripts/* /scripts
配置管理节点 [root@centos3 mha]# more
/etc/masterha/masterha_default.cnf
[server default]
user=root
password=123456
ssh_user=root
repl_user=repl
repl_password=qwert
master_binlog_dir= /app/mysql
remote_workdir=/app/mha
secondary_check_script= masterha_secondary_check -s
192.168.12.234 -s
192.168.12.232
ping_interval=1
master_ip_failover_script=/scripts/master_ip_failover
#shutdown_script=/scripts/power_manager
report_script= /scripts/send_report
master_ip_online_change_script= /scripts/master_ip_online_change
[root@centos3
mha]# more
/etc/masterha/app1.cnf [server default]
manager_workdir=/app/mha
manager_log=/app/mha/manager.log[server1]
hostname=192.168.8.120
candidate_master=1[server2]
hostname=192.168.8.121
candidate_master=1[server3]
hostname=192.168.8.122
no_master=1
(5)在mysql 添加用户,复制设置 mysql 主节点
grant replication slave on *.* to 'repl'@'192.168.8.%' identified by 'qwert';
grant all on *.* to 'root'@'192.168.8.122' identified by '123456'; 备主节点
grant replication slave on *.* to 'repl'@'192.168.8.%' identified by 'qwert';
grant all on *.* to 'root'@'192.168.8122' identified by '123456'; set read_only=1
set relay_log_purge=0 从节点
grant all on *.* to 'root'@'192.168.8.122' identified by '123456'; set read_only=1
set relay_log_purge=0 (6)配置ssh
[[root@centos3~# ssh-keygen -t rsa [root@centos3 ~]# ssh-copy-id -i
.ssh/id_rsa.pub root@192.168.8.120
[root@centos3~]#
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.8.121 [root@centos1 ~]# ssh-keygen -t rsa [root@centos1 ~]# ssh-copy-id -i
.ssh/id_rsa.pub root@192.168.8.121 [root@centos1 ~]# ssh-copy-id -i
.ssh/id_rsa.pub root@192.168.8.122 [root@centos2 ~]# ssh-keygen -t rsa
[root@centos2 ~]# ssh-copy-id -i
.ssh/id_rsa.pub root@192.168.8.120
[root@centos2 ~]#
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.8.122 (7)测试ssh
[root@centos3 mha]# masterha_check_ssh
--global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf
Sat Aug 10 06:15:39 2013 - [info] Reading default configuratoins
from /etc/masterha/masterha_default.cnf..
Sat Aug 10 06:15:39 2013 - [info] Reading application default
configurations from /etc/masterha/app1.cnf..
Sat Aug 10 06:15:39 2013 - [info] Reading server configurations
from /etc/masterha/app1.cnf..
Sat Aug 10 06:15:39 2013 - [info] Starting SSH connection
tests..
Sat Aug 10 06:15:42 2013 - [debug]
Sat Aug 10 06:15:39 2013 - [debug] Connecting via SSH from root@192.168.8.120(192.168.8.120:22) to root@192.168.8.121(192.168.8.121:22)..
Sat Aug 10 06:15:41 2013 - [debug] ok.
Sat Aug 10 06:15:41 2013 - [debug] Connecting via SSH from root@192.168.8.120(192.168.8.120:22) to root@192.168.8.122(192.168.8.122:22)..
Sat Aug 10 06:15:42 2013 - [debug] ok.
Sat Aug 10 06:15:43 2013 - [debug]
Sat Aug 10 06:15:40 2013 - [debug] Connecting via SSH from root@192.168.8.121(192.168.8.121:22) to
root@192.168.8.120(192.168.8.120:22)..
Sat Aug 10 06:15:41 2013 - [debug] ok.
Sat Aug 10 06:15:41 2013 - [debug] Connecting via SSH from root@192.168.8.121(192.168.8.121:22) to root@192.168.8.122(192.168.8.122:22)..
Sat Aug 10 06:15:43 2013 - [debug] ok.
Sat Aug 10 06:15:44 2013 - [debug]
Sat Aug 10 06:15:40 2013 - [debug] Connecting via SSH from root@192.168.8.122(192.168.8.122:22) to root@192.168.8.120(192.168.8.120:22)..
Sat Aug 10 06:15:42 2013 - [debug] ok.
Sat Aug 10 06:15:42 2013 - [debug] Connecting via
SSH from root@192.168.8.122(192.168.8.122:22) to root@192.168.8.121(192.168.8.121:22)..
Sat Aug 10 06:15:44 2013 - [debug] ok.
Sat Aug 10 06:15:44 2013 - [info] All SSH connection tests passed successfully. (8)测试复制
[root@centos3 mha]# masterha_check_repl --global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf
Sat Aug 10 06:26:13 2013 - [info] Reading default configuratoins
from /etc/masterha/masterha_default.cnf..
Sat Aug 10 06:26:13 2013 - [info] Reading application default
configurations from /etc/masterha/app1.cnf..
Sat Aug 10 06:26:13 2013 - [info] Reading server configurations
from /etc/masterha/app1.cnf..
Sat Aug 10 06:26:13 2013 - [info] MHA::MasterMonitor version 0.53.
Sat Aug 10 06:26:13 2013 - [info] Dead Servers:
Sat Aug 10 06:26:13 2013 - [info] Alive Servers:
Sat Aug 10 06:26:13 2013 - [info]
192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:26:13 2013 - [info]
192.168.8.121(192.168.8.121:3306)
Sat Aug 10 06:26:13 2013 - [info]
192.168.8.122(192.168.8.122:3306)
Sat Aug 10 06:26:13 2013 - [info] Alive Slaves:
Sat Aug 10 06:26:13 2013 - [info]
192.168.8.121(192.168.8.121:3306)
Version=5.5.29-log (oldest major version between slaves) log-bin:enabled
Sat Aug 10 06:26:13 2013 - [info]
Replicating from 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:26:13 2013 - [info]
Primary candidate for the new Master (candidate_master is set)
Sat Aug 10 06:26:13 2013 - [info]
192.168.8.122(192.168.8.122:3306)
Version=5.5.29-log (oldest major version between slaves) log-bin:enabled
Sat Aug 10 06:26:13 2013 - [info]
Replicating from 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:26:13 2013 - [info]
Not candidate for the new Master (no_master is set)
Sat Aug 10 06:26:13 2013 - [info] Current Alive Master: 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:26:13 2013 - [info] Checking slave configurations..
Sat Aug 10 06:26:13 2013 - [info] Checking replication filtering settings..
Sat Aug 10 06:26:13 2013 - [info] binlog_do_db= ,
binlog_ignore_db=
Sat Aug 10 06:26:13 2013 - [info] Replication filtering check ok.
Sat Aug 10 06:26:13 2013 - [info] Starting SSH connection tests..
Sat Aug 10 06:26:17 2013 - [info] All SSH connection tests passed successfully.
Sat Aug 10 06:26:17 2013 - [info] Checking MHA Node version..
Sat Aug 10 06:26:18 2013 - [info] Version check ok.
Sat Aug 10 06:26:18 2013 - [info] Checking SSH publickey authentication settings on the current master..
Sat Aug 10 06:26:18 2013 - [info] HealthCheck: SSH to
192.168.8.120 is reachable.
Sat Aug 10 06:26:18 2013 - [info] Master MHA Node version is 0.53.
Sat Aug 10 06:26:18 2013 - [info] Checking recovery script configurations on the current master..
Sat Aug 10 06:26:18 2013 - [info] Executing command:
save_binary_logs --command=test --start_pos=4 --binlog_dir=/app/mysql
--output_file=/app/mha/save_binary_logs_test --manager_version=0.53 --start_file=mysql-bin.000010
Sat Aug 10 06:26:18 2013 - [info] Connecting to
root@192.168.8.120(192.168.8.120)..
Creating /app/mha if not exists.. ok.
Checking output directory is accessible or not.. ok.
Binlog found at /app/mysql, up to mysql-bin.000010
Sat Aug 10 06:26:18 2013 - [info] Master setting check done.
Sat Aug 10 06:26:18 2013 - [info] Checking SSH publickey authentication and checking recovery script configurations on all
alive slave servers..
Sat Aug 10 06:26:18 2013 - [info] Executing command :
apply_diff_relay_logs --command=test --slave_user=root --slave_host=192.168.8.121 --slave_ip=192.168.8.121 --slave_port=3306 --workdir=/app/mha --target_version=5.5.29-log --manager_version=0.53
--relay_log_info=/app/mysql/relay-log.info --relay_dir=/app/mysql/ --slave_pass=xxx
Sat Aug 10 06:26:18 2013 - [info] Connecting to
root@192.168.8.121(192.168.8.121:22)..
Checking slave recovery environment settings..
Opening
/app/mysql/relay-log.info ... ok.
Relay log
found at /app/mysql, up to mysql-relay-bin.000004
Temporary
relay log file is /app/mysql/mysql-relay-bin.000004
Testing
mysql connection and privileges.. done.
Testing
mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Sat Aug 10 06:26:19 2013 - [info] Executing command :
apply_diff_relay_logs --command=test --slave_user=root --slave_host=192.168.8.122 --slave_ip=192.168.8.122 --slave_port=3306 --workdir=/app/mha --target_version=5.5.29-log --manager_version=0.53
--relay_log_info=/app/mysql/relay-log.info --relay_dir=/app/mysql/ --slave_pass=xxx
Sat Aug 10 06:26:19 2013 -
[info] Connecting to
root@192.168.8.122(192.168.8.122:22)..
Checking slave recovery environment settings..
Opening
/app/mysql/relay-log.info ... ok.
Relay log
found at /app/mysql, up to mysql-relay-bin.000004
Temporary
relay log file is /app/mysql/mysql-relay-bin.000004
Testing
mysql connection and privileges.. done.
Testing
mysqlbinlog output.. done.
Cleaning up
test file(s).. done.
Sat Aug 10 06:26:20 2013 - [info] Slaves settings check done.
Sat Aug 10 06:26:20 2013 - [info]
192.168.8.120 (current master)
+--192.168.8.121
+--192.168.8.122Sat Aug 10 06:26:20 2013 - [info] Checking replication health on 192.168.8.121..
Sat Aug 10 06:26:20 2013 - [info] ok.
Sat Aug 10 06:26:20 2013 - [info] Checking replication health on 192.168.8.122..
Sat Aug 10 06:26:20 2013 - [info] ok.
Sat Aug 10 06:26:20 2013 - [info] Checking master_ip_failover_script status:
Sat Aug 10 06:26:20 2013 - [info]
/scripts/master_ip_failover --command=status --ssh_user=root
--orig_master_host=192.168.8.120 --orig_master_ip=192.168.8.120 --orig_master_port=3306
Sat Aug 10 06:26:20 2013 - [info] OK.
Sat Aug 10 06:26:20 2013 - [warning] shutdown_script is not defined.
Sat Aug 10 06:26:20 2013 - [info] Got exit code 0 (Not master
dead).MySQL Replication Health is OK.
(9)启动management
[root@centos3 mysql]# nohup masterha_manager --global-conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf
Sat Aug 10 06:29:36 2013 - [info] MHA::MasterMonitor version 0.53.
Sat Aug 10 06:29:37 2013 - [info] Dead Servers:
Sat Aug 10 06:29:37 2013 - [info] Alive Servers:
Sat Aug 10 06:29:37 2013 - [info]
192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:29:37 2013 - [info]
192.168.8.121(192.168.8.121:3306)
Sat Aug 10 06:29:37 2013 -
[info]
192.168.8.122(192.168.8.122:3306)
Sat Aug 10 06:29:37 2013 - [info] Alive Slaves:
Sat Aug 10 06:29:37 2013 - [info]
192.168.8.121(192.168.8.121:3306)
Version=5.5.29-log (oldest major version between slaves) log-bin:enabled
Sat Aug 10 06:29:37 2013 - [info]
Replicating from 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:29:37 2013 - [info]
Primary candidate for the new Master (candidate_master is set)
Sat Aug 10 06:29:37 2013 - [info]
192.168.8.122(192.168.8.122:3306)
Version=5.5.29-log (oldest major version between slaves) log-bin:enabled
Sat Aug 10 06:29:37 2013 - [info]
Replicating from 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:29:37 2013 - [info]
Not candidate for the new Master (no_master is set)
Sat Aug 10 06:29:37 2013 - [info] Current Alive Master: 192.168.8.120(192.168.8.120:3306)
Sat Aug 10 06:29:37 2013 - [info] Checking slave configurations..
Sat Aug 10 06:29:37 2013 - [info] Checking replication filtering settings..
Sat Aug 10 06:29:37 2013 - [info] binlog_do_db= , binlog_ignore_db=
Sat Aug 10 06:29:37 2013 - [info] Replication filtering check ok.
Sat Aug 10 06:29:37 2013 - [info] Starting SSH connection tests..
Sat Aug 10 06:29:40 2013 - [info] All SSH connection tests passed successfully.
Sat Aug 10 06:29:40 2013 - [info] Checking MHA Node version..
Sat Aug 10 06:29:41 2013 - [info] Version check ok.
Sat Aug 10 06:29:41 2013 - [info] Checking SSH publickey authentication settings on the current master..
Sat Aug
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务