一、环境说明
monitor节点:10.10.2.10
master节点: 10.10.2.72
slave1节点: 10.10.2.73(候选master)
slave2节点: 10.10.2.74
二、配置root免密码登录
1、所有节点执行:
ssh-keygen -t rsa (生成密钥)
2、4台节点公钥的内容统一存到authorized_keys 文件中,分发到4个节点root的/root/.ssh/目录下,权限600;
三、数据库主从配置跳过,下面主要记录主从半同步配置
1、主库
mysql> install plugin rpl_semi_sync_master soname'semisync_master.so'; mysql> set global rpl_semi_sync_master_enabled=1; mysql> set global rpl_semi_sync_master_timeout=3000;
PS:3s超时,半同步复制是如果从服务端没有开启的话,主服务端第一次会延迟3秒中之后提交,
之后主服务端会降低延迟不再等待从服务端。从服务端开启之后在追赶上主服务端让后在实现半同步。
验证是否打开了semisync功能:
mysql> show global status like 'rpl%';
让mysql在重启时自动加载该功能,在/etc/my.cnf中加入:
rpl_semi_sync_master_enabled=1 rpl_semi_sync_master_timeout=1000
2、从库
mysql> install plugin rpl_semi_sync_slave soname'semisync_slave.so'; mysql> set global rpl_semi_sync_slave_enabled=1;
验证是否打开了semisync功能:
mysql> show global status like 'rpl%';
让mysql在重启时自动加载该功能,在/etc/my.cnf中加入:
rpl_semi_sync_slave_enabled=1
四、设置的复制权限帐号(管理节点、主库、候选主库)
GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.10' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.72' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.73' IDENTIFIED BY '123456'; FLUSH PRIVILEGES;
五、MHA安装配置
1、安装
数据库节点:
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles -y rpm -ivh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53-0.el6.noarch.rpm
管理节点:
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles -y rpm -ivh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53-0.el6.noarch.rpm yum -y install perl-Time-HiRes rpm -ivh http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.53-0.el6.noarch.rpm
2、配置(所有节点一样)
mkdir /var/log/masterha/app1 -p #创建work目录 yum -y install mysql #安装命令
撰写配置文件:
[server default] manager_workdir=/var/log/masterha/app1 manager_log=/var/log/masterha/app1/manager.log user=mha_rep //mysql的管理用户名 必要的时候要执行 stop slave ,change master reset slave 等命令。 password=123456 //mysql的管理员密码 ssh_user=root //使用root账号ssh登录 repl_user=mha_rep //mysql复制账号 repl_password=123456 //mysql复制账号密码 ping_interval=1 //ping间隔,这里设置一次ping不通即failover shutdown_script="" //强制关机脚本,这里设为空 #master_ip_failover_script="/usr/local/bin/master_ip_failover" //主从故障切换脚本 #master_ip_online_change_script="" #report_script="" [server1] hostname=10.10.2.72 candidate_master=1 port=13306 master_binlog_dir=/data/mysql/auth/db/ [server2] hostname=10.10.2.73 candidate_master=1 port=13306 master_binlog_dir=/data/mysql/auth/db/ [server3] hostname=10.10.2.74 no_master=1 port=13306
六、测试
1、测试ssh是否正常
[root@db_lvs_master ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf Sat Nov 30 15:49:36 2013 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Nov 30 15:49:36 2013 - [info] Reading application default configurations from /etc/masterha/app1.cnf.. Sat Nov 30 15:49:36 2013 - [info] Reading server configurations from /etc/masterha/app1.cnf.. Sat Nov 30 15:49:36 2013 - [info] Starting SSH connection tests.. Sat Nov 30 15:49:37 2013 - [debug] Sat Nov 30 15:49:36 2013 - [debug] Connecting via SSH from [email protected](10.10.2.72:22) to [email protected](10.10.2.73:22).. Sat Nov 30 15:49:36 2013 - [debug] ok. Sat Nov 30 15:49:36 2013 - [debug] Connecting via SSH from [email protected](10.10.2.72:22) to [email protected](10.10.2.74:22).. Sat Nov 30 15:49:37 2013 - [debug] ok. Sat Nov 30 15:49:37 2013 - [debug] Sat Nov 30 15:49:37 2013 - [debug] Connecting via SSH from [email protected](10.10.2.73:22) to [email protected](10.10.2.72:22).. Sat Nov 30 15:49:37 2013 - [debug] ok. Sat Nov 30 15:49:37 2013 - [debug] Connecting via SSH from [email protected](10.10.2.73:22) to [email protected](10.10.2.74:22).. Sat Nov 30 15:49:37 2013 - [debug] ok. Sat Nov 30 15:49:38 2013 - [debug] Sat Nov 30 15:49:37 2013 - [debug] Connecting via SSH from [email protected](10.10.2.74:22) to [email protected](10.10.2.72:22).. Sat Nov 30 15:49:37 2013 - [debug] ok. Sat Nov 30 15:49:37 2013 - [debug] Connecting via SSH from [email protected](10.10.2.74:22) to [email protected](10.10.2.73:22).. Sat Nov 30 15:49:38 2013 - [debug] ok. Sat Nov 30 15:49:38 2013 - [info] All SSH connection tests passed successfully.
2、测试复制是否正常
[root@db_lvs_master ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf Sat Nov 30 15:50:15 2013 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Nov 30 15:50:15 2013 - [info] Reading application default configurations from /etc/masterha/app1.cnf.. Sat Nov 30 15:50:15 2013 - [info] Reading server configurations from /etc/masterha/app1.cnf.. Sat Nov 30 15:50:15 2013 - [info] MHA::MasterMonitor version 0.53. Sat Nov 30 15:50:15 2013 - [info] Dead Servers: Sat Nov 30 15:50:15 2013 - [info] Alive Servers: Sat Nov 30 15:50:15 2013 - [info] 10.10.2.72(10.10.2.72:13306) Sat Nov 30 15:50:15 2013 - [info] 10.10.2.73(10.10.2.73:13306) Sat Nov 30 15:50:15 2013 - [info] 10.10.2.74(10.10.2.74:13306) Sat Nov 30 15:50:15 2013 - [info] Alive Slaves: Sat Nov 30 15:50:15 2013 - [info] 10.10.2.73(10.10.2.73:13306) Version=5.5.15-log (oldest major version between slaves) log-bin:enabled Sat Nov 30 15:50:15 2013 - [info] Replicating from 10.10.2.72(10.10.2.72:13306) Sat Nov 30 15:50:15 2013 - [info] Primary candidate for the new Master (candidate_master is set) Sat Nov 30 15:50:15 2013 - [info] 10.10.2.74(10.10.2.74:13306) Version=5.5.15-log (oldest major version between slaves) log-bin:enabled Sat Nov 30 15:50:15 2013 - [info] Replicating from 10.10.2.72(10.10.2.72:13306) Sat Nov 30 15:50:15 2013 - [info] Not candidate for the new Master (no_master is set) Sat Nov 30 15:50:15 2013 - [info] Current Alive Master: 10.10.2.72(10.10.2.72:13306) Sat Nov 30 15:50:15 2013 - [info] Checking slave configurations.. Sat Nov 30 15:50:15 2013 - [info] read_only=1 is not set on slave 10.10.2.73(10.10.2.73:13306). Sat Nov 30 15:50:15 2013 - [warning] relay_log_purge=0 is not set on slave 10.10.2.73(10.10.2.73:13306). Sat Nov 30 15:50:15 2013 - [info] read_only=1 is not set on slave 10.10.2.74(10.10.2.74:13306). Sat Nov 30 15:50:15 2013 - [warning] relay_log_purge=0 is not set on slave 10.10.2.74(10.10.2.74:13306). Sat Nov 30 15:50:15 2013 - [info] Checking replication filtering settings.. Sat Nov 30 15:50:15 2013 - [info] binlog_do_db= , binlog_ignore_db= information_schema,mysql,performance_schema,test Sat Nov 30 15:50:15 2013 - [info] Replication filtering check ok. Sat Nov 30 15:50:15 2013 - [info] Starting SSH connection tests.. Sat Nov 30 15:50:17 2013 - [info] All SSH connection tests passed successfully. Sat Nov 30 15:50:17 2013 - [info] Checking MHA Node version.. Sat Nov 30 15:50:17 2013 - [info] Version check ok. Sat Nov 30 15:50:17 2013 - [info] Checking SSH publickey authentication settings on the current master.. Sat Nov 30 15:50:17 2013 - [info] HealthCheck: SSH to 10.10.2.72 is reachable. Sat Nov 30 15:50:17 2013 - [info] Master MHA Node version is 0.53. Sat Nov 30 15:50:17 2013 - [info] Checking recovery script configurations on the current master.. Sat Nov 30 15:50:17 2013 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysql/auth/db/ --output_file=/var/tmp/save_binary_logs_test --manager_version=0.53 --start_file=mysql-bin.000012 Sat Nov 30 15:50:17 2013 - [info] Connecting to [email protected](10.10.2.72).. Creating /var/tmp if not exists.. ok. Checking output directory is accessible or not.. ok. Binlog found at /data/mysql/auth/db/, up to mysql-bin.000012 Sat Nov 30 15:50:18 2013 - [info] Master setting check done. Sat Nov 30 15:50:18 2013 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers.. Sat Nov 30 15:50:18 2013 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=mha_rep --slave_host=10.10.2.73 --slave_ip=10.10.2.73 --slave_port=13306 --workdir=/var/tmp --target_version=5.5.15-log --manager_version=0.53 --relay_log_info=/data/mysql/auth/db/relay-log.info --relay_dir=/data/mysql/auth/db/ --slave_pass=xxx Sat Nov 30 15:50:18 2013 - [info] Connecting to [email protected](10.10.2.73:22).. Checking slave recovery environment settings.. Opening /data/mysql/auth/db/relay-log.info ... ok. Relay log found at /data/mysql/auth/db, up to mysqld-relay-bin.000012 Temporary relay log file is /data/mysql/auth/db/mysqld-relay-bin.000012 Testing mysql connection and privileges.. done. Testing mysqlbinlog output.. done. Cleaning up test file(s).. done. Sat Nov 30 15:50:18 2013 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=mha_rep --slave_host=10.10.2.74 --slave_ip=10.10.2.74 --slave_port=13306 --workdir=/var/tmp --target_version=5.5.15-log --manager_version=0.53 --relay_log_info=/data/mysql/auth/db/relay-log.info --relay_dir=/data/mysql/auth/db/ --slave_pass=xxx Sat Nov 30 15:50:18 2013 - [info] Connecting to [email protected](10.10.2.74:22).. Checking slave recovery environment settings.. Opening /data/mysql/auth/db/relay-log.info ... ok. Relay log found at /data/mysql/auth/db, up to mysqld-relay-bin.000012 Temporary relay log file is /data/mysql/auth/db/mysqld-relay-bin.000012 Testing mysql connection and privileges.. done. Testing mysqlbinlog output.. done. Cleaning up test file(s).. done. Sat Nov 30 15:50:18 2013 - [info] Slaves settings check done. Sat Nov 30 15:50:18 2013 - [info] 10.10.2.72 (current master) +--10.10.2.73 +--10.10.2.74 Sat Nov 30 15:50:18 2013 - [info] Checking replication health on 10.10.2.73.. Sat Nov 30 15:50:18 2013 - [info] ok. Sat Nov 30 15:50:18 2013 - [info] Checking replication health on 10.10.2.74.. Sat Nov 30 15:50:18 2013 - [info] ok. Sat Nov 30 15:50:18 2013 - [warning] master_ip_failover_script is not defined. Sat Nov 30 15:50:18 2013 - [warning] shutdown_script is not defined. Sat Nov 30 15:50:18 2013 - [info] Got exit code 0 (Not master dead). MySQL Replication Health is OK.
七、启动管理节点进程:
nohup masterha_manager --conf=/etc/masterha/app1.cnf --ignore_fail_on_start --ignore_last_failover > /tmp/mha_manager.log < /dev/null 2>&1 &
查看状态:
[root@db_lvs_master ~]# masterha_check_status --conf=/etc/masterha/app1.cnf app1 (pid:19135) is running(0:PING_OK), master:10.10.2.72
本文出自 “�潘吭宋�男” 博客,谢绝转载!