Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)相关的知识,希望对你有一定的参考价值。
一、环境准备:
操作系统:CentOS Linux release 7.5.1804 (Core)
mysql版本:mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
主库:172.16.8.247
从库:172.16.8.249
主机名:
172.16.8.247 qas-zabbix-node01
172.16.8.249 qas-zabbix-node02
二、mysql5.7安装
主库:172.16.8.247
从库:172.16.8.249
数据安装参考:
一、Centos7.5安装mysql5.7.24二进制包方式部署
三、mysql主从复制配置
1、启用GTID和二进制日志:(主库)
grep -n ^[a-Z] /app/mysql5.7/etc/my.cnf
2:daemonize = on
3:user = mysql
4:port = 3306
5:basedir = /app/mysql5.7
6:datadir = /app/mysql5.7/data
7:socket = /tmp/mysql.sock
8:bind-address = 0.0.0.0
9:pid-file = /app/mysql5.7/tmp/mysqld.pid
10:character-set-server = utf8
11:collation-server = utf8_general_ci
12:max_connections = 2408
13:log-error = /app/mysql5.7/logs/mysqld.log
15:gtid_mode = ON
16:server_id = 247
17:log-bin = mysql-bin
18:enforce_gtid_consistency = ON
修改配置文件需要重启动mysql数据库
systemctl restart mysqld
2、创建主从复制账号(主库)
创建一个同步用户,slave与master进行同步
mysql -uroot -p
grant replication slave on *.* to ‘repl‘@‘172.16.8.%‘ identified by ‘[email protected]‘;
3、启用GTID和二进制日志:(从库)
grep -n ^[a-Z] /app/mysql5.7/etc/my.cnf
2:daemonize = on
3:user = mysql
4:port = 3306
5:basedir = /app/mysql5.7
6:datadir = /app/mysql5.7/data
7:socket = /tmp/mysql.sock
8:bind-address = 0.0.0.0
9:pid-file = /app/mysql5.7/tmp/mysqld.pid
10:character-set-server = utf8
11:collation-server = utf8_general_ci
12:max_connections = 2408
13:log-error = /app/mysql5.7/logs/mysqld.log
15:gtid_mode = ON
16:server_id = 249
17:log-bin = mysql-bin
18:log_slave_updates = ON
19:enforce_gtid_consistency = ON
20:slave-parallel-type = LOGICAL_CLOCK
21:slave-parallel-workers = 8
22:master-info-repository = TABLE
23:relay-log-info-repository = TABLE
4、配置复制连接(从库)
CHANGE MASTER TO MASTER_HOST=‘172.16.8.247‘, MASTER_USER=‘repl‘, MASTER_PASSWORD=‘[email protected]‘, MASTER_AUTO_POSITION=1;
5、查看复制状态:(从库)
mysql> show slave statusG;
Empty set (0.00 sec)
ERROR:
No query specified
mysql> CHANGE MASTER TO MASTER_HOST=‘172.16.8.247‘, MASTER_USER=‘repl‘, MASTER_PASSWORD=‘[email protected]‘, MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> show slave statusG;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 172.16.8.247
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: qas-zabbix-node02-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 0
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
6、启动复制线程(从库)
mysql> start slave;
Query OK, 0 rows affected (0.02 sec)
mysql> show slave statusG;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.8.247
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 194
Relay_Log_File: qas-zabbix-node02-relay-bin.000003
Relay_Log_Pos: 407
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 194
Relay_Log_Space: 1131
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 247
Master_UUID: a7fef663-f05e-11e8-b1f5-08002728f0e4
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: a7fef663-f05e-11e8-b1f5-08002728f0e4:1
Executed_Gtid_Set: a7fef663-f05e-11e8-b1f5-08002728f0e4:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
四、测试结果
(主库)
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| qas |
| sys |
| test |
| zabbix |
+--------------------+
(备库)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| qas |
| sys |
| test |
| zabbix |
+--------------------+
mysql> select user,host from mysql.user;
+---------------+------------+
| user | host |
+---------------+------------+
| root | 172.16.0.% |
| repl | 172.16.8.% |
| zabbix | 172.16.8.% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| zabbix | localhost |
+---------------+------------+
以上是关于Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)的主要内容,如果未能解决你的问题,请参考以下文章
Centos7.5安装mysql5.7.24二进制包方式部署(keepalived+主从复制)