拓扑结构
master51
|
|
______________________________________________________
| | | | |
slave52 slave53 slave54 slave55 mgm56
备用主 备用主 Manager
一、配置所有数据节点主机之间可以互相以ssh密钥对方式认证登陆
1.1 在每一台数据库服务器创建密钥对,然后把公钥拷贝给其他4台数据库服务器
51主机:
[root@db108 ~]# ssh-keygen 创建密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pb0sJunRZ/2CoUkfd8oYm2u6WjAUWePVr4VjPTTUp7o root@db108
The key's randomart image is:
+---[RSA 2048]----+
| .oo .. ... |
| .o o . o o|
| . . . = o.|
| . + + * |
| o S .. = . |
| =..+o+ . |
| +.=+=@.+ |
| . =o+B E. |
| o.o+.. .. |
+----[SHA256]-----+
[root@db108 ~]#
[root@db108 ~]# ssh-copy-id [email protected] //同样拷贝公钥给其他4台数据库服务器
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.36.107 (192.168.36.107)' can't be established.
ECDSA key fingerprint is SHA256:hFHvPGRC70RSaXhsXSOCMWqB7y13GxmCR5mznQTG6u8.
ECDSA key fingerprint is MD5:ca:73:1b:97:ea:e5:10:4f:b1:37:a4:c8:5f:6b:3b:da.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@db108 ~]#
1.2 配置manager56主机 无密码ssh登录 所有数据节点主机
[root@db108 ~]# ssh-keygen //创建密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pb0sJunRZ/2CoUkfd8oYm2u6WjAUWePVr4VjPTTUp7o root@db108
The key's randomart image is:
+---[RSA 2048]----+
| .oo .. ... |
| .o o . o o|
| . . . = o.|
| . + + * |
| o S .. = . |
| =..+o+ . |
| +.=+=@.+ |
| . =o+B E. |
| o.o+.. .. |
+----[SHA256]-----+
[root@db108 ~]#
[root@db108 ~]# ssh-copy-id [email protected] //同样拷贝公钥给其他4台数据库服务器
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.36.107 (192.168.36.107)' can't be established.
ECDSA key fingerprint is SHA256:hFHvPGRC70RSaXhsXSOCMWqB7y13GxmCR5mznQTG6u8.
ECDSA key fingerprint is MD5:ca:73:1b:97:ea:e5:10:4f:b1:37:a4:c8:5f:6b:3b:da.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@db108 ~]#
二、安装软件包
2.1 在所有主机上安装perl软件包
[root@db108 share]# ls perl-*.rpm
perl-Config-Tiny-2.14-7.el7.noarch.rpm
perl-Mail-Sender-0.8.23-1.el7.noarch.rpm
perl-MIME-Types-1.38-2.el7.noarch.rpm
perl-Email-Date-Format-1.002-15.el7.noarch.rpm
perl-Mail-Sendmail-0.79-21.el7.art.noarch.rpm
perl-Parallel-ForkManager-1.18-2.el7.noarch.rpm
perl-Log-Dispatch-2.41-1.el7.1.noarch.rpm
perl-MIME-Lite-3.030-1.el7.noarch.rpm
[root@db108 share]# yum -y install perl-*.rpm
2.2 在所有数据节点主机上安装mha_node软件包
[root@db108 share]# yum -y install perl-DBD-mysql perl-DBI
[root@db108 share]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
2.3 在管理主机上安装mha_node包和mha_manager包
[root@db108 share]# yum -y install perl-DBD-mysql perl-DBI
[root@db108 share]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
]# yum -y install perl-ExtUtils-* perl-CPAN-*
]#tar -zxf mha4mysql-manager-0.56.tar.gz
]#cd mha4mysql-manager-0.56
[root@host114 mha4mysql-manager-0.56]# perl Makefile.PL
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- DBI ...loaded. (1.627)
- DBD::mysql ...loaded. (4.023)
- Time::HiRes ...loaded. (1.9725)
- Config::Tiny ...loaded. (2.14)
- Log::Dispatch ...loaded. (2.41)
- Parallel::ForkManager ...loaded. (1.18)
- MHA::NodeConst ...loaded. (0.56)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Writing Makefile for mha4mysql::manager
Writing MYMETA.yml and MYMETA.json
[root@host114 mha4mysql-manager-0.56]# make
[root@host114 mha4mysql-manager-0.56]# make install
三、配置主从同步,要求如下:
51 主库 开半同步复制
52 从库(备用主库) 开半同步复制
53 从库(备用主库) 开半同步复制
54 从库 不做备用主库所以不用开半同步复制
55 从库 不做备用主库所以不用开半同步复制
56 管理主机
3.1、master51配置:
vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=51
log-bin=master51
binlog-format="mixed"
:wq
[root@db107 ~]# systemctl restart mysqld
[root@db107 ~]# ls /var/lib/mysql/master51.*
/var/lib/mysql/master51.000001 /var/lib/mysql/master51.index
[root@db107 ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to repluser@"%" identified by "123456";
Query OK, 0 rows affected, 1 warning (10.04 sec)
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.15 sec)
mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| master51.000001 | 441 | | | |
+-----------------+----------+--------------+------------------+-------------------+
mysql> quit;
3.2、备用master52的配置
vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=52
log-bin=master52
binlog-format="mixed"
]# systemctl restart mysqld
[root@db108 ~]# ls /var/lib/mysql/master52.*
/var/lib/mysql/master52.000001 /var/lib/mysql/master52.index
[root@db108 ~]# mysql -uroot -p123456
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.13 sec)
mysql> change master to
-> master_host="192.168.36.107",
-> master_user="repluser",
-> master_password="123456",
-> master_log_file="master51.000001",
-> master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
[root@db108 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i YES
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db108 ~]#
3.3、备用master53的配置
]# vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=53
log-bin=master53
binlog-format="mixed"
:wq
[root@db109 ~]# systemctl restart mysqld
[root@db109 ~]# ls /var/lib/mysql/master53.*
/var/lib/mysql/master53.000001 /var/lib/mysql/master53.index
[root@db109 ~]#
[root@db109 ~]# mysql -uroot -p123456
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.14 sec)
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql>
[root@db109 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db109 ~]#
3.4、配置从服务器54
[root@db111 ~]# vim /etc/my.cnf
[mysqld]
server_id=54
:wq
[root@db111 ~]# systemctl restart mysqld
[root@db111 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@db111 ~]#
[root@db111 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db111 ~]#
3.5、配置从服务器55
[root@db111 ~]# vim /etc/my.cnf
[mysqld]
server_id=55
:wq
[root@db111 ~]# systemctl restart mysqld
[root@db111 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@db111 ~]#
[root@db111 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db111 ~]#
3.6、在客户端测试主从同步配置
3.6.1 在主库51上添加访问数据的授权用户
[root@db107 ~]# mysql -uroot -p123456
mysql> grant all on gamedb.* to admin@"%" identified by "123456";
3.6.2 在客户端主机连接主库51 建库表记录
mysql> create database gamedb;
Query OK, 1 row affected (0.01 sec)
mysql> create table gamedb.t1 (id int);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.15 sec)
mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.05 sec)
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
2 rows in set (0.00 sec)
mysql>
3.6.3 在客户端使用授权用户连接从库52-55,也能看到同样的库表及记录
[root@host114 ~]# mysql -h从库IP地址 -uadmin -p123456
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
四、编辑管理主机主配置文件
]# cp mha4mysql-manager-0.56/bin/* /usr/local/bin/
]#mkdir /etc/mha_manager/
[root@host114 mha4mysql-manager-0.56]# cp samples/conf/app1.cnf /etc/mha_manager/
]#vim /etc/mha_manager/app1.cnf
[server default]
manager_workdir=/etc/mha_manager
manager_log=/etc/mha_manager/manager.log
master_ip_failover_script=/usr/local/bin/master_ip_failover
ssh_user=root
ssh_port=22
repl_user=repluser
repl_password=123456
user=root
password=123456
[server1]
hostname=192.168.36.107
port=3306
[server2]
hostname=192.168.36.108
port=3306
candidate_master=1
[server3]
hostname=192.168.36.109
port=3306
candidate_master=1
[server4]
hostname=192.168.36.111
port=3306
no_master=1
[server5]
hostname=192.168.36.113
port=3306
no_master=1
:wq
[root@host114 ~]# masterha_check_ssh --conf /etc/mha_manager/app1.cnf
Thu May 3 06:36:36 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 06:36:36 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 06:36:36 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
Thu May 3 06:36:36 2018 - [info] Starting SSH connection tests..
Thu May 3 06:36:45 2018 - [debug]
Thu May 3 06:36:38 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:41 2018 - [debug] ok.
Thu May 3 06:36:41 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:44 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:37 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:40 2018 - [debug] ok.
Thu May 3 06:36:40 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:45 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:37 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:41 2018 - [debug] ok.
Thu May 3 06:36:41 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:44 2018 - [debug] ok.
Thu May 3 06:36:44 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:36 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:42 2018 - [debug] ok.
Thu May 3 06:36:42 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:36 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:38 2018 - [debug] ok.
Thu May 3 06:36:38 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:42 2018 - [debug] ok.
Thu May 3 06:36:42 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [info] All SSH connection tests passed successfully.
[root@host114 ~]#
**检查主从同步时把app1.cnf文件中的此配置项#master_ip_failover_script=/usr/local/bin/master_ip_failover注释掉,不然检查失败。
[root@host114 mhasoft]# masterha_check_repl --conf /etc/mha_manager/app1.cnf
Thu May 3 07:02:46 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 07:02:46 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:02:46 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:02:46 2018 - [info] MHA::MasterMonitor version 0.56.
Thu May 3 07:02:47 2018 - [info] GTID failover mode = 0
Thu May 3 07:02:47 2018 - [info] Dead Servers:
Thu May 3 07:02:47 2018 - [info] Alive Servers:
Thu May 3 07:02:47 2018 - [info] 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.108(192.168.36.108:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.109(192.168.36.109:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.111(192.168.36.111:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.113(192.168.36.113:3306)
Thu May 3 07:02:47 2018 - [info] Alive Slaves:
Thu May 3 07:02:47 2018 - [info] 192.168.36.108(192.168.36.108:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.109(192.168.36.109:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.111(192.168.36.111:3306) Version=5.7.17 (oldest major version between slaves) log-bin:disabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Not candidate for the new Master (no_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.113(192.168.36.113:3306) Version=5.7.17 (oldest major version between slaves) log-bin:disabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Not candidate for the new Master (no_master is set)
Thu May 3 07:02:47 2018 - [info] Current Alive Master: 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Checking slave configurations..
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.108(192.168.36.108:3306).
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.109(192.168.36.109:3306).
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.111(192.168.36.111:3306).
Thu May 3 07:02:47 2018 - [warning] relay_log_purge=0 is not set on slave 192.168.36.111(192.168.36.111:3306).
Thu May 3 07:02:47 2018 - [warning] log-bin is not set on slave 192.168.36.111(192.168.36.111:3306). This host cannot be a master.
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.113(192.168.36.113:3306).
Thu May 3 07:02:47 2018 - [warning] relay_log_purge=0 is not set on slave 192.168.36.113(192.168.36.113:3306).
Thu May 3 07:02:47 2018 - [warning] log-bin is not set on slave 192.168.36.113(192.168.36.113:3306). This host cannot be a master.
Thu May 3 07:02:47 2018 - [info] Checking replication filtering settings..
Thu May 3 07:02:47 2018 - [info] binlog_do_db= , binlog_ignore_db=
Thu May 3 07:02:47 2018 - [info] Replication filtering check ok.
Thu May 3 07:02:48 2018 - [info] GTID (with auto-pos) is not supported
Thu May 3 07:02:48 2018 - [info] Starting SSH connection tests..
Thu May 3 07:02:55 2018 - [info] All SSH connection tests passed successfully.
Thu May 3 07:02:55 2018 - [info] Checking MHA Node version..
Thu May 3 07:02:57 2018 - [info] Version check ok.
Thu May 3 07:02:57 2018 - [info] Checking SSH publickey authentication settings on the current master..
Thu May 3 07:02:57 2018 - [info] HealthCheck: SSH to 192.168.36.107 is reachable.
Thu May 3 07:02:58 2018 - [info] Master MHA Node version is 0.56.
Thu May 3 07:02:58 2018 - [info] Checking recovery script configurations on 192.168.36.107(192.168.36.107:3306)..
Thu May 3 07:02:58 2018 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.56 --start_file=master51.000001
Thu May 3 07:02:58 2018 - [info] Connecting to [email protected](192.168.36.107:22)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /var/lib/mysql, up to master51.000001
Thu May 3 07:02:58 2018 - [info] Binlog setting check done.
Thu May 3 07:02:58 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Thu May 3 07:02:58 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.108 --slave_ip=192.168.36.108 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:02:58 2018 - [info] Connecting to [email protected](192.168.36.108:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db108-relay-bin.000003
Temporary relay log file is /var/lib/mysql/db108-relay-bin.000003
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:02:59 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.109 --slave_ip=192.168.36.109 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:02:59 2018 - [info] Connecting to [email protected](192.168.36.109:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db109-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db109-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:00 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.111 --slave_ip=192.168.36.111 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17 --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:03:00 2018 - [info] Connecting to [email protected](192.168.36.111:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db111-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db111-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:00 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.113 --slave_ip=192.168.36.113 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17 --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:03:00 2018 - [info] Connecting to [email protected](192.168.36.113:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db113-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db113-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:01 2018 - [info] Slaves settings check done.
Thu May 3 07:03:01 2018 - [info]
192.168.36.107(192.168.36.107:3306) (current master)
+--192.168.36.108(192.168.36.108:3306)
+--192.168.36.109(192.168.36.109:3306)
+--192.168.36.111(192.168.36.111:3306)
+--192.168.36.113(192.168.36.113:3306)
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.108..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.109..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.111..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.113..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [warning] master_ip_failover_script is not defined.
Thu May 3 07:03:01 2018 - [warning] shutdown_script is not defined.
Thu May 3 07:03:01 2018 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
[root@host114 mhasoft]#
没有在后台运行 ,占用当前终端执行
[root@host114 mhasoft]# masterha_manager --conf=/etc/mha_manager/app1.cnf --remove_dead_master_conf --ignore_last_failover
Thu May 3 07:07:15 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 07:07:15 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:07:15 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
再开新终端查看状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:3097) is running(0:PING_OK), master:192.168.36.107
[root@host114 ~]#
停止服务,
[root@host114 ~]# masterha_stop --conf=/etc/mha_manager/app1.cnf
Stopped app1 successfully.
查看状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 is stopped(2:NOT_RUNNING).
[root@host114 ~]#
测试高可用配置
1.1 拷贝故障转移脚本到系统目录下/usr/local/bin/
[root@host114 ~]# cp mha4mysql-manager-0.56/samples/scripts/master_ip_failover /usr/local/bin/
vim /usr/local/bin/scripts/master_ip_failover 在脚本中添加如下代码
$new_master_password
);
my $vip = '192.168.36.250/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";
GetOptions(
:wq
在主库服务器 上手动绑定VIP地址(mha_manager服务不负责部署 只负责故障转移,所以服务启动之前,主库的VIP地址要手动配置)
[root@db107 ~]# ifconfig ens33:1 192.168.36.250/24
去掉app1.cnf文件master_ip_failover_script 项的注释,启动服务
[root@host114 ~]# grep master_ip_failover_script /etc/mha_manager/app1.cnf
master_ip_failover_script=/usr/local/bin/master_ip_failover
[root@host114 ~]# masterha_manager --conf=/etc/mha_manager/app1.cnf --remove_dead_master_conf --ignore_last_failover
Fri May 4 02:23:42 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri May 4 02:23:42 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Fri May 4 02:23:42 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
查看服务状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:21284) is running(0:PING_OK), master:192.168.36.107
[root@host114 ~]#
[root@host114 ~]# ls /etc/mha_manager/
app1.cnf app1.master_status.health manager.log
[root@host114 ~]#
PING vip地址
[root@host114 ~]# ping -c 2 192.168.36.250
PING 192.168.36.250 (192.168.36.250) 56(84) bytes of data.
64 bytes from 192.168.36.250: icmp_seq=1 ttl=64 time=1.35 ms
64 bytes from 192.168.36.250: icmp_seq=2 ttl=64 time=0.549 ms
客户端连接访问vip地址,访问数据库服务器
[root@host114 ~]# mysql -h192.168.36.250 -uadmin -p123456
mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| db107 |
+------------+
1 row in set (0.00 sec)
mysql>
在拿这vip地址的主库上 执行关机命令 ]# shutdown -h now
在管理主机上查看日志内容
]# tail -f /etc/mha_manager/
.....
.....
192.168.36.108(192.168.36.108:3306): Resetting slave info succeeded.
Master failover to 192.168.36.108(192.168.36.108:3306) completed successfully. //提示vip地址部署在了那台数据库服务器上了
查看状态信息
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:23314) is running(0:PING_OK), master:192.168.36.108 //显示主库那一台
[root@host114 ~]#
在对应的数据库服务器上查看vip地址
[root@db108 share]# ip addr show | grep 192.168.36.250
inet 192.168.36.250/24 brd 192.168.36.255 scope global secondary ens33:1
[root@db108 share]#
客户端连接VIP地址 访问数据库服务器
[root@host114 ~]# mysql -h192.168.36.250 -uadmin -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 83
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
| 1000 |
| 1000 |
| 1000 |
+------+
5 rows in set (0.02 sec)
[root@host114 ~]# ls /etc/mha_manager/
app1.cnf app1.failover.complete app1.master_status.health manager.log
[root@host114 ~]#
-------------------------------安装nginx
[root@bogon ~ ]# yum -y install gcc gcc-c++ pcre-devel zlib-devel
[root@bogon ~ ]# tar -zxf nginx-1.12.2.tar.gz
[root@bogon ~ ]# cd nginx-1.12.2
[root@bogon nginx-1.12.2]# ./configure --prefix=/usr/local/nginx
[root@bogon nginx-1.12.2]# make
[root@bogon nginx-1.12.2]# make install
[root@bogon nginx-1.12.2]# ls /usr/local/nginx/
conf html logs sbin
[root@bogon nginx-1.12.2]# /usr/local/nginx/sbin/nginx
[root@bogon nginx-1.12.2]# netstat -utnalp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15933/nginx: master
[root@bogon nginx-1.12.2]#
[root@bogon nginx-1.12.2]# echo "test web" > /usr/local/nginx/html/test.html
[root@bogon nginx-1.12.2]# yum -y install elinks
[root@bogon nginx-1.12.2]# elinks --dump http://localhost/test.html
test web
[root@bogon nginx-1.12.2]#
-------------------------------安装php-fpm
[root@bogon ~ ]# yum -y install php-common
[root@bogon ~ ]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm
[root@bogon lnmp]# systemctl start php-fpm
[root@bogon lnmp]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-04-12 00:53:51 EDT; 5s ago
Main PID: 16021 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/php-fpm.service
├─16021 php-fpm: master process (/etc/php-fpm.conf)
├─16022 php-fpm: pool www
├─16023 php-fpm: pool www
├─16024 php-fpm: pool www
├─16025 php-fpm: pool www
└─16026 php-fpm: pool www
Apr 12 00:53:51 bogon systemd[1]: Starting The PHP FastCGI Process Manager...
Apr 12 00:53:51 bogon systemd[1]: Started The PHP FastCGI Process Manager.
[root@bogon lnmp]# netstat -utnalp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16021/php-fpm: mast
[root@bogon lnmp]#
-------------------------修改nginx服务的主配置文件 把访问PHP文件的请求,发送给本机的9000端口
[root@bogon ~]# vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
70 include fastcgi_params;
71 }
:wq
[root@bogon lnmp]# /usr/local/nginx/sbin/nginx -s stop
[root@bogon lnmp]# /usr/local/nginx/sbin/nginx
-------------------------编写网页文件
[root@bogon lnmp]# vim /usr/local/nginx/html/test.php
<?php
echo "hello world!!!";
?>
:wq
[root@bogon lnmp]#
--------------------------客户端测试
[root@bogon lnmp]# elinks --dump http://localhost/test.php
hello world!!!
[root@bogon lnmp]#
--------------------------安装redis
[root@bogon ~ ]# tar -zxf redis-4.0.8.tar.gz
[root@bogon ~ ]# cd redis-4.0.8
[root@bogon redis-4.0.8]# make #源码目录有些好的Makefile文件,所以可以直接执行编译命令
[root@bogon redis-4.0.8]# mkdir -p /usr/local/redis/etc/
[root@bogon redis-4.0.8]# mkdir -p /usr/local/redis/bin
//编译后安装的文件拷贝到创建的目录下
[root@bogon redis-4.0.8]# cp src/redis-server /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp src/redis-cli /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp src/redis-benchmark /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp redis.conf /usr/local/redis/etc/
---------------------------修改主配置文件,让redis服务以守护进程的方式运行
[root@bogon redis-4.0.8]# sed -n "136p" /usr/local/redis/etc/redis.conf
daemonize no
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# sed -i "136s/no/yes/" /usr/local/redis/etc/redis.conf //把136行的no 修改为yes
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# sed -n "136p" /usr/local/redis/etc/redis.conf //显示修改成功
daemonize yes
[root@bogon redis-4.0.8]#
-----------------------------启动redis服务
[root@bogon redis-4.0.8]# netstat -utnalp | grep :6379
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
23233:C 12 Apr 04:47:01.974 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23233:C 12 Apr 04:47:01.974 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=23233, just started
23233:C 12 Apr 04:47:01.974 # Configuration loaded
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# netstat -utnalp | grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 23234/redis-server
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# /usr/local/redis/bin/redis-cli //本机登陆
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
[root@bogon redis-4.0.8]#
--------------------------安装php扩展php-redis
27 yum -y install autoconf
28 yum -y install automake
29 rpm -ivh ../php-devel-5.4.16-42.el7.x86_64.rpm
30 which phpize
31 /usr/bin/phpize
1 tar -zxf php-redis-2.2.4.tar.gz
2 ls
3 cd phpredis-2.2.4/
[root@bogon phpredis-2.2.4]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@bogon phpredis-2.2.4]# find / -name "php-config"
/usr/bin/php-config
[root@bogon phpredis-2.2.4]#
[root@bogon phpredis-2.2.4]# ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
[root@bogon phpredis-2.2.4]# make
[root@bogon phpredis-2.2.4]# make install
Installing shared extensions: /usr/lib64/php/modules/
[root@bogon phpredis-2.2.4]#
[root@bogon phpredis-2.2.4]# ls /usr/lib64/php/modules/
curl.so fileinfo.so json.so phar.so redis.so zip.so
[root@bogon phpredis-2.2.4]#
------------------加载redis模块
[root@bogon ~]# vim /etc/php.ini
731 ;extension_dir = "./"
731 extension_dir = "/usr/lib64/php/modules/"
732 extension = "redis.so"
----------------查看是否支持模块
[root@bogon ~]# php -m | grep -i redis
redis
[root@bogon ~]#
----------------编写网页测试文件
[root@bogon bin]# ./redis-server /usr/local/redis/etc/redis.conf
58195:C 13 Apr 01:02:28.760 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
58195:C 13 Apr 01:02:28.761 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=58195, just started
58195:C 13 Apr 01:02:28.761 # Configuration loaded
[root@bogon bin]#
[root@bogon bin]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit
[root@bogon bin]#
[root@bogon bin]# netstat -utnalp | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 58196/./redis-serve
tcp 0 0 127.0.0.1:37366 127.0.0.1:6379 TIME_WAIT -
[root@bogon bin]#
-------------------------------------------编写网页测试文件
[root@bogon bin]# cat /usr/local/nginx/html/redis.php
<?php
$redis = new redis();
$redis->connect('127.0.0.1',6379);
$redis->set('redistest','666666');
echo $redis->get('redistest');
?>
[root@bogon bin]#
[root@bogon bin]# elinks --dump http://localhost/redis.php
666666
[root@bogon bin]#
[root@bogon bin]# pwd
/usr/local/redis/bin
[root@bogon bin]# ./redis-cli #连接本机的redis服务
127.0.0.1:6379> get redistest #查看变量的值
"666666"
127.0.0.1:6379>
127.0.0.1:6379> quit
[root@bogon bin]#
[root@bogon bin]#
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth(“666”); #连接redis服务的密码
$redis->set('redistest','666666');
echo $redis->get('redistest');
?>
master51
|
|
______________________________________________________
| | | | |
slave52 slave53 slave54 slave55 mgm56
备用主 备用主 Manager
一、配置所有数据节点主机之间可以互相以ssh密钥对方式认证登陆
1.1 在每一台数据库服务器创建密钥对,然后把公钥拷贝给其他4台数据库服务器
51主机:
[root@db108 ~]# ssh-keygen 创建密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pb0sJunRZ/2CoUkfd8oYm2u6WjAUWePVr4VjPTTUp7o root@db108
The key's randomart image is:
+---[RSA 2048]----+
| .oo .. ... |
| .o o . o o|
| . . . = o.|
| . + + * |
| o S .. = . |
| =..+o+ . |
| +.=+=@.+ |
| . =o+B E. |
| o.o+.. .. |
+----[SHA256]-----+
[root@db108 ~]#
[root@db108 ~]# ssh-copy-id [email protected] //同样拷贝公钥给其他4台数据库服务器
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.36.107 (192.168.36.107)' can't be established.
ECDSA key fingerprint is SHA256:hFHvPGRC70RSaXhsXSOCMWqB7y13GxmCR5mznQTG6u8.
ECDSA key fingerprint is MD5:ca:73:1b:97:ea:e5:10:4f:b1:37:a4:c8:5f:6b:3b:da.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@db108 ~]#
1.2 配置manager56主机 无密码ssh登录 所有数据节点主机
[root@db108 ~]# ssh-keygen //创建密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pb0sJunRZ/2CoUkfd8oYm2u6WjAUWePVr4VjPTTUp7o root@db108
The key's randomart image is:
+---[RSA 2048]----+
| .oo .. ... |
| .o o . o o|
| . . . = o.|
| . + + * |
| o S .. = . |
| =..+o+ . |
| +.=+=@.+ |
| . =o+B E. |
| o.o+.. .. |
+----[SHA256]-----+
[root@db108 ~]#
[root@db108 ~]# ssh-copy-id [email protected] //同样拷贝公钥给其他4台数据库服务器
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.36.107 (192.168.36.107)' can't be established.
ECDSA key fingerprint is SHA256:hFHvPGRC70RSaXhsXSOCMWqB7y13GxmCR5mznQTG6u8.
ECDSA key fingerprint is MD5:ca:73:1b:97:ea:e5:10:4f:b1:37:a4:c8:5f:6b:3b:da.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@db108 ~]#
二、安装软件包
2.1 在所有主机上安装perl软件包
[root@db108 share]# ls perl-*.rpm
perl-Config-Tiny-2.14-7.el7.noarch.rpm
perl-Mail-Sender-0.8.23-1.el7.noarch.rpm
perl-MIME-Types-1.38-2.el7.noarch.rpm
perl-Email-Date-Format-1.002-15.el7.noarch.rpm
perl-Mail-Sendmail-0.79-21.el7.art.noarch.rpm
perl-Parallel-ForkManager-1.18-2.el7.noarch.rpm
perl-Log-Dispatch-2.41-1.el7.1.noarch.rpm
perl-MIME-Lite-3.030-1.el7.noarch.rpm
[root@db108 share]# yum -y install perl-*.rpm
2.2 在所有数据节点主机上安装mha_node软件包
[root@db108 share]# yum -y install perl-DBD-mysql perl-DBI
[root@db108 share]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
2.3 在管理主机上安装mha_node包和mha_manager包
[root@db108 share]# yum -y install perl-DBD-mysql perl-DBI
[root@db108 share]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
]# yum -y install perl-ExtUtils-* perl-CPAN-*
]#tar -zxf mha4mysql-manager-0.56.tar.gz
]#cd mha4mysql-manager-0.56
[root@host114 mha4mysql-manager-0.56]# perl Makefile.PL
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- DBI ...loaded. (1.627)
- DBD::mysql ...loaded. (4.023)
- Time::HiRes ...loaded. (1.9725)
- Config::Tiny ...loaded. (2.14)
- Log::Dispatch ...loaded. (2.41)
- Parallel::ForkManager ...loaded. (1.18)
- MHA::NodeConst ...loaded. (0.56)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Writing Makefile for mha4mysql::manager
Writing MYMETA.yml and MYMETA.json
[root@host114 mha4mysql-manager-0.56]# make
[root@host114 mha4mysql-manager-0.56]# make install
三、配置主从同步,要求如下:
51 主库 开半同步复制
52 从库(备用主库) 开半同步复制
53 从库(备用主库) 开半同步复制
54 从库 不做备用主库所以不用开半同步复制
55 从库 不做备用主库所以不用开半同步复制
56 管理主机
3.1、master51配置:
vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=51
log-bin=master51
binlog-format="mixed"
:wq
[root@db107 ~]# systemctl restart mysqld
[root@db107 ~]# ls /var/lib/mysql/master51.*
/var/lib/mysql/master51.000001 /var/lib/mysql/master51.index
[root@db107 ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to repluser@"%" identified by "123456";
Query OK, 0 rows affected, 1 warning (10.04 sec)
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.15 sec)
mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| master51.000001 | 441 | | | |
+-----------------+----------+--------------+------------------+-------------------+
mysql> quit;
3.2、备用master52的配置
vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=52
log-bin=master52
binlog-format="mixed"
]# systemctl restart mysqld
[root@db108 ~]# ls /var/lib/mysql/master52.*
/var/lib/mysql/master52.000001 /var/lib/mysql/master52.index
[root@db108 ~]# mysql -uroot -p123456
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.13 sec)
mysql> change master to
-> master_host="192.168.36.107",
-> master_user="repluser",
-> master_password="123456",
-> master_log_file="master51.000001",
-> master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
[root@db108 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i YES
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db108 ~]#
3.3、备用master53的配置
]# vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1
server_id=53
log-bin=master53
binlog-format="mixed"
:wq
[root@db109 ~]# systemctl restart mysqld
[root@db109 ~]# ls /var/lib/mysql/master53.*
/var/lib/mysql/master53.000001 /var/lib/mysql/master53.index
[root@db109 ~]#
[root@db109 ~]# mysql -uroot -p123456
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.14 sec)
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql>
[root@db109 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db109 ~]#
3.4、配置从服务器54
[root@db111 ~]# vim /etc/my.cnf
[mysqld]
server_id=54
:wq
[root@db111 ~]# systemctl restart mysqld
[root@db111 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@db111 ~]#
[root@db111 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db111 ~]#
3.5、配置从服务器55
[root@db111 ~]# vim /etc/my.cnf
[mysqld]
server_id=55
:wq
[root@db111 ~]# systemctl restart mysqld
[root@db111 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.107",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
[root@db111 ~]#
[root@db111 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@db111 ~]#
3.6、在客户端测试主从同步配置
3.6.1 在主库51上添加访问数据的授权用户
[root@db107 ~]# mysql -uroot -p123456
mysql> grant all on gamedb.* to admin@"%" identified by "123456";
3.6.2 在客户端主机连接主库51 建库表记录
mysql> create database gamedb;
Query OK, 1 row affected (0.01 sec)
mysql> create table gamedb.t1 (id int);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.15 sec)
mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.05 sec)
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
2 rows in set (0.00 sec)
mysql>
3.6.3 在客户端使用授权用户连接从库52-55,也能看到同样的库表及记录
[root@host114 ~]# mysql -h从库IP地址 -uadmin -p123456
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
四、编辑管理主机主配置文件
]# cp mha4mysql-manager-0.56/bin/* /usr/local/bin/
]#mkdir /etc/mha_manager/
[root@host114 mha4mysql-manager-0.56]# cp samples/conf/app1.cnf /etc/mha_manager/
]#vim /etc/mha_manager/app1.cnf
[server default]
manager_workdir=/etc/mha_manager
manager_log=/etc/mha_manager/manager.log
master_ip_failover_script=/usr/local/bin/master_ip_failover
ssh_user=root
ssh_port=22
repl_user=repluser
repl_password=123456
user=root
password=123456
[server1]
hostname=192.168.36.107
port=3306
[server2]
hostname=192.168.36.108
port=3306
candidate_master=1
[server3]
hostname=192.168.36.109
port=3306
candidate_master=1
[server4]
hostname=192.168.36.111
port=3306
no_master=1
[server5]
hostname=192.168.36.113
port=3306
no_master=1
:wq
[root@host114 ~]# masterha_check_ssh --conf /etc/mha_manager/app1.cnf
Thu May 3 06:36:36 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 06:36:36 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 06:36:36 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
Thu May 3 06:36:36 2018 - [info] Starting SSH connection tests..
Thu May 3 06:36:45 2018 - [debug]
Thu May 3 06:36:38 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:41 2018 - [debug] ok.
Thu May 3 06:36:41 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.113:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:44 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:37 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:40 2018 - [debug] ok.
Thu May 3 06:36:40 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.111:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:45 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:37 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:41 2018 - [debug] ok.
Thu May 3 06:36:41 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:44 2018 - [debug] ok.
Thu May 3 06:36:44 2018 - [debug] Connecting via SSH from [email protected](192.168.36.109:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:36 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.107:22)..
Thu May 3 06:36:39 2018 - [debug] ok.
Thu May 3 06:36:39 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:42 2018 - [debug] ok.
Thu May 3 06:36:42 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.108:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [debug]
Thu May 3 06:36:36 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.108:22)..
Thu May 3 06:36:38 2018 - [debug] ok.
Thu May 3 06:36:38 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.109:22)..
Thu May 3 06:36:42 2018 - [debug] ok.
Thu May 3 06:36:42 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.111:22)..
Thu May 3 06:36:43 2018 - [debug] ok.
Thu May 3 06:36:43 2018 - [debug] Connecting via SSH from [email protected](192.168.36.107:22) to [email protected](192.168.36.113:22)..
Thu May 3 06:36:46 2018 - [debug] ok.
Thu May 3 06:36:46 2018 - [info] All SSH connection tests passed successfully.
[root@host114 ~]#
**检查主从同步时把app1.cnf文件中的此配置项#master_ip_failover_script=/usr/local/bin/master_ip_failover注释掉,不然检查失败。
[root@host114 mhasoft]# masterha_check_repl --conf /etc/mha_manager/app1.cnf
Thu May 3 07:02:46 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 07:02:46 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:02:46 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:02:46 2018 - [info] MHA::MasterMonitor version 0.56.
Thu May 3 07:02:47 2018 - [info] GTID failover mode = 0
Thu May 3 07:02:47 2018 - [info] Dead Servers:
Thu May 3 07:02:47 2018 - [info] Alive Servers:
Thu May 3 07:02:47 2018 - [info] 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.108(192.168.36.108:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.109(192.168.36.109:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.111(192.168.36.111:3306)
Thu May 3 07:02:47 2018 - [info] 192.168.36.113(192.168.36.113:3306)
Thu May 3 07:02:47 2018 - [info] Alive Slaves:
Thu May 3 07:02:47 2018 - [info] 192.168.36.108(192.168.36.108:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.109(192.168.36.109:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.111(192.168.36.111:3306) Version=5.7.17 (oldest major version between slaves) log-bin:disabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Not candidate for the new Master (no_master is set)
Thu May 3 07:02:47 2018 - [info] 192.168.36.113(192.168.36.113:3306) Version=5.7.17 (oldest major version between slaves) log-bin:disabled
Thu May 3 07:02:47 2018 - [info] Replicating from 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Not candidate for the new Master (no_master is set)
Thu May 3 07:02:47 2018 - [info] Current Alive Master: 192.168.36.107(192.168.36.107:3306)
Thu May 3 07:02:47 2018 - [info] Checking slave configurations..
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.108(192.168.36.108:3306).
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.109(192.168.36.109:3306).
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.111(192.168.36.111:3306).
Thu May 3 07:02:47 2018 - [warning] relay_log_purge=0 is not set on slave 192.168.36.111(192.168.36.111:3306).
Thu May 3 07:02:47 2018 - [warning] log-bin is not set on slave 192.168.36.111(192.168.36.111:3306). This host cannot be a master.
Thu May 3 07:02:47 2018 - [info] read_only=1 is not set on slave 192.168.36.113(192.168.36.113:3306).
Thu May 3 07:02:47 2018 - [warning] relay_log_purge=0 is not set on slave 192.168.36.113(192.168.36.113:3306).
Thu May 3 07:02:47 2018 - [warning] log-bin is not set on slave 192.168.36.113(192.168.36.113:3306). This host cannot be a master.
Thu May 3 07:02:47 2018 - [info] Checking replication filtering settings..
Thu May 3 07:02:47 2018 - [info] binlog_do_db= , binlog_ignore_db=
Thu May 3 07:02:47 2018 - [info] Replication filtering check ok.
Thu May 3 07:02:48 2018 - [info] GTID (with auto-pos) is not supported
Thu May 3 07:02:48 2018 - [info] Starting SSH connection tests..
Thu May 3 07:02:55 2018 - [info] All SSH connection tests passed successfully.
Thu May 3 07:02:55 2018 - [info] Checking MHA Node version..
Thu May 3 07:02:57 2018 - [info] Version check ok.
Thu May 3 07:02:57 2018 - [info] Checking SSH publickey authentication settings on the current master..
Thu May 3 07:02:57 2018 - [info] HealthCheck: SSH to 192.168.36.107 is reachable.
Thu May 3 07:02:58 2018 - [info] Master MHA Node version is 0.56.
Thu May 3 07:02:58 2018 - [info] Checking recovery script configurations on 192.168.36.107(192.168.36.107:3306)..
Thu May 3 07:02:58 2018 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.56 --start_file=master51.000001
Thu May 3 07:02:58 2018 - [info] Connecting to [email protected](192.168.36.107:22)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /var/lib/mysql, up to master51.000001
Thu May 3 07:02:58 2018 - [info] Binlog setting check done.
Thu May 3 07:02:58 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Thu May 3 07:02:58 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.108 --slave_ip=192.168.36.108 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:02:58 2018 - [info] Connecting to [email protected](192.168.36.108:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db108-relay-bin.000003
Temporary relay log file is /var/lib/mysql/db108-relay-bin.000003
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:02:59 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.109 --slave_ip=192.168.36.109 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:02:59 2018 - [info] Connecting to [email protected](192.168.36.109:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db109-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db109-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:00 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.111 --slave_ip=192.168.36.111 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17 --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:03:00 2018 - [info] Connecting to [email protected](192.168.36.111:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db111-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db111-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:00 2018 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.36.113 --slave_ip=192.168.36.113 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17 --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Thu May 3 07:03:00 2018 - [info] Connecting to [email protected](192.168.36.113:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to db113-relay-bin.000002
Temporary relay log file is /var/lib/mysql/db113-relay-bin.000002
Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Thu May 3 07:03:01 2018 - [info] Slaves settings check done.
Thu May 3 07:03:01 2018 - [info]
192.168.36.107(192.168.36.107:3306) (current master)
+--192.168.36.108(192.168.36.108:3306)
+--192.168.36.109(192.168.36.109:3306)
+--192.168.36.111(192.168.36.111:3306)
+--192.168.36.113(192.168.36.113:3306)
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.108..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.109..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.111..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [info] Checking replication health on 192.168.36.113..
Thu May 3 07:03:01 2018 - [info] ok.
Thu May 3 07:03:01 2018 - [warning] master_ip_failover_script is not defined.
Thu May 3 07:03:01 2018 - [warning] shutdown_script is not defined.
Thu May 3 07:03:01 2018 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
[root@host114 mhasoft]#
没有在后台运行 ,占用当前终端执行
[root@host114 mhasoft]# masterha_manager --conf=/etc/mha_manager/app1.cnf --remove_dead_master_conf --ignore_last_failover
Thu May 3 07:07:15 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 3 07:07:15 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Thu May 3 07:07:15 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
再开新终端查看状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:3097) is running(0:PING_OK), master:192.168.36.107
[root@host114 ~]#
停止服务,
[root@host114 ~]# masterha_stop --conf=/etc/mha_manager/app1.cnf
Stopped app1 successfully.
查看状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 is stopped(2:NOT_RUNNING).
[root@host114 ~]#
测试高可用配置
1.1 拷贝故障转移脚本到系统目录下/usr/local/bin/
[root@host114 ~]# cp mha4mysql-manager-0.56/samples/scripts/master_ip_failover /usr/local/bin/
vim /usr/local/bin/scripts/master_ip_failover 在脚本中添加如下代码
$new_master_password
);
my $vip = '192.168.36.250/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";
GetOptions(
:wq
在主库服务器 上手动绑定VIP地址(mha_manager服务不负责部署 只负责故障转移,所以服务启动之前,主库的VIP地址要手动配置)
[root@db107 ~]# ifconfig ens33:1 192.168.36.250/24
去掉app1.cnf文件master_ip_failover_script 项的注释,启动服务
[root@host114 ~]# grep master_ip_failover_script /etc/mha_manager/app1.cnf
master_ip_failover_script=/usr/local/bin/master_ip_failover
[root@host114 ~]# masterha_manager --conf=/etc/mha_manager/app1.cnf --remove_dead_master_conf --ignore_last_failover
Fri May 4 02:23:42 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri May 4 02:23:42 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf..
Fri May 4 02:23:42 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..
查看服务状态
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:21284) is running(0:PING_OK), master:192.168.36.107
[root@host114 ~]#
[root@host114 ~]# ls /etc/mha_manager/
app1.cnf app1.master_status.health manager.log
[root@host114 ~]#
PING vip地址
[root@host114 ~]# ping -c 2 192.168.36.250
PING 192.168.36.250 (192.168.36.250) 56(84) bytes of data.
64 bytes from 192.168.36.250: icmp_seq=1 ttl=64 time=1.35 ms
64 bytes from 192.168.36.250: icmp_seq=2 ttl=64 time=0.549 ms
客户端连接访问vip地址,访问数据库服务器
[root@host114 ~]# mysql -h192.168.36.250 -uadmin -p123456
mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| db107 |
+------------+
1 row in set (0.00 sec)
mysql>
在拿这vip地址的主库上 执行关机命令 ]# shutdown -h now
在管理主机上查看日志内容
]# tail -f /etc/mha_manager/
.....
.....
192.168.36.108(192.168.36.108:3306): Resetting slave info succeeded.
Master failover to 192.168.36.108(192.168.36.108:3306) completed successfully. //提示vip地址部署在了那台数据库服务器上了
查看状态信息
[root@host114 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf
app1 (pid:23314) is running(0:PING_OK), master:192.168.36.108 //显示主库那一台
[root@host114 ~]#
在对应的数据库服务器上查看vip地址
[root@db108 share]# ip addr show | grep 192.168.36.250
inet 192.168.36.250/24 brd 192.168.36.255 scope global secondary ens33:1
[root@db108 share]#
客户端连接VIP地址 访问数据库服务器
[root@host114 ~]# mysql -h192.168.36.250 -uadmin -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 83
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
| 1000 |
| 1000 |
| 1000 |
+------+
5 rows in set (0.02 sec)
[root@host114 ~]# ls /etc/mha_manager/
app1.cnf app1.failover.complete app1.master_status.health manager.log
[root@host114 ~]#
-------------------------------安装nginx
[root@bogon ~ ]# yum -y install gcc gcc-c++ pcre-devel zlib-devel
[root@bogon ~ ]# tar -zxf nginx-1.12.2.tar.gz
[root@bogon ~ ]# cd nginx-1.12.2
[root@bogon nginx-1.12.2]# ./configure --prefix=/usr/local/nginx
[root@bogon nginx-1.12.2]# make
[root@bogon nginx-1.12.2]# make install
[root@bogon nginx-1.12.2]# ls /usr/local/nginx/
conf html logs sbin
[root@bogon nginx-1.12.2]# /usr/local/nginx/sbin/nginx
[root@bogon nginx-1.12.2]# netstat -utnalp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15933/nginx: master
[root@bogon nginx-1.12.2]#
[root@bogon nginx-1.12.2]# echo "test web" > /usr/local/nginx/html/test.html
[root@bogon nginx-1.12.2]# yum -y install elinks
[root@bogon nginx-1.12.2]# elinks --dump http://localhost/test.html
test web
[root@bogon nginx-1.12.2]#
-------------------------------安装php-fpm
[root@bogon ~ ]# yum -y install php-common
[root@bogon ~ ]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm
[root@bogon lnmp]# systemctl start php-fpm
[root@bogon lnmp]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-04-12 00:53:51 EDT; 5s ago
Main PID: 16021 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/php-fpm.service
├─16021 php-fpm: master process (/etc/php-fpm.conf)
├─16022 php-fpm: pool www
├─16023 php-fpm: pool www
├─16024 php-fpm: pool www
├─16025 php-fpm: pool www
└─16026 php-fpm: pool www
Apr 12 00:53:51 bogon systemd[1]: Starting The PHP FastCGI Process Manager...
Apr 12 00:53:51 bogon systemd[1]: Started The PHP FastCGI Process Manager.
[root@bogon lnmp]# netstat -utnalp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16021/php-fpm: mast
[root@bogon lnmp]#
-------------------------修改nginx服务的主配置文件 把访问PHP文件的请求,发送给本机的9000端口
[root@bogon ~]# vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
70 include fastcgi_params;
71 }
:wq
[root@bogon lnmp]# /usr/local/nginx/sbin/nginx -s stop
[root@bogon lnmp]# /usr/local/nginx/sbin/nginx
-------------------------编写网页文件
[root@bogon lnmp]# vim /usr/local/nginx/html/test.php
<?php
echo "hello world!!!";
?>
:wq
[root@bogon lnmp]#
--------------------------客户端测试
[root@bogon lnmp]# elinks --dump http://localhost/test.php
hello world!!!
[root@bogon lnmp]#
--------------------------安装redis
[root@bogon ~ ]# tar -zxf redis-4.0.8.tar.gz
[root@bogon ~ ]# cd redis-4.0.8
[root@bogon redis-4.0.8]# make #源码目录有些好的Makefile文件,所以可以直接执行编译命令
[root@bogon redis-4.0.8]# mkdir -p /usr/local/redis/etc/
[root@bogon redis-4.0.8]# mkdir -p /usr/local/redis/bin
//编译后安装的文件拷贝到创建的目录下
[root@bogon redis-4.0.8]# cp src/redis-server /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp src/redis-cli /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp src/redis-benchmark /usr/local/redis/bin/
[root@bogon redis-4.0.8]# cp redis.conf /usr/local/redis/etc/
---------------------------修改主配置文件,让redis服务以守护进程的方式运行
[root@bogon redis-4.0.8]# sed -n "136p" /usr/local/redis/etc/redis.conf
daemonize no
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# sed -i "136s/no/yes/" /usr/local/redis/etc/redis.conf //把136行的no 修改为yes
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# sed -n "136p" /usr/local/redis/etc/redis.conf //显示修改成功
daemonize yes
[root@bogon redis-4.0.8]#
-----------------------------启动redis服务
[root@bogon redis-4.0.8]# netstat -utnalp | grep :6379
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
23233:C 12 Apr 04:47:01.974 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23233:C 12 Apr 04:47:01.974 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=23233, just started
23233:C 12 Apr 04:47:01.974 # Configuration loaded
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# netstat -utnalp | grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 23234/redis-server
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]#
[root@bogon redis-4.0.8]# /usr/local/redis/bin/redis-cli //本机登陆
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
[root@bogon redis-4.0.8]#
--------------------------安装php扩展php-redis
27 yum -y install autoconf
28 yum -y install automake
29 rpm -ivh ../php-devel-5.4.16-42.el7.x86_64.rpm
30 which phpize
31 /usr/bin/phpize
1 tar -zxf php-redis-2.2.4.tar.gz
2 ls
3 cd phpredis-2.2.4/
[root@bogon phpredis-2.2.4]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@bogon phpredis-2.2.4]# find / -name "php-config"
/usr/bin/php-config
[root@bogon phpredis-2.2.4]#
[root@bogon phpredis-2.2.4]# ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
[root@bogon phpredis-2.2.4]# make
[root@bogon phpredis-2.2.4]# make install
Installing shared extensions: /usr/lib64/php/modules/
[root@bogon phpredis-2.2.4]#
[root@bogon phpredis-2.2.4]# ls /usr/lib64/php/modules/
curl.so fileinfo.so json.so phar.so redis.so zip.so
[root@bogon phpredis-2.2.4]#
------------------加载redis模块
[root@bogon ~]# vim /etc/php.ini
731 ;extension_dir = "./"
731 extension_dir = "/usr/lib64/php/modules/"
732 extension = "redis.so"
----------------查看是否支持模块
[root@bogon ~]# php -m | grep -i redis
redis
[root@bogon ~]#
----------------编写网页测试文件
[root@bogon bin]# ./redis-server /usr/local/redis/etc/redis.conf
58195:C 13 Apr 01:02:28.760 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
58195:C 13 Apr 01:02:28.761 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=58195, just started
58195:C 13 Apr 01:02:28.761 # Configuration loaded
[root@bogon bin]#
[root@bogon bin]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit
[root@bogon bin]#
[root@bogon bin]# netstat -utnalp | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 58196/./redis-serve
tcp 0 0 127.0.0.1:37366 127.0.0.1:6379 TIME_WAIT -
[root@bogon bin]#
-------------------------------------------编写网页测试文件
[root@bogon bin]# cat /usr/local/nginx/html/redis.php
<?php
$redis = new redis();
$redis->connect('127.0.0.1',6379);
$redis->set('redistest','666666');
echo $redis->get('redistest');
?>
[root@bogon bin]#
[root@bogon bin]# elinks --dump http://localhost/redis.php
666666
[root@bogon bin]#
[root@bogon bin]# pwd
/usr/local/redis/bin
[root@bogon bin]# ./redis-cli #连接本机的redis服务
127.0.0.1:6379> get redistest #查看变量的值
"666666"
127.0.0.1:6379>
127.0.0.1:6379> quit
[root@bogon bin]#
[root@bogon bin]#
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth(“666”); #连接redis服务的密码
$redis->set('redistest','666666');
echo $redis->get('redistest');
?>