在主机Master搭建时间同步服务器NTP(20.0.0.11)
[root@ns1 ~]# yum -y install ntp
[root@ns1 ~]# vi /etc/ntp.conf
server 127.127.1.0 ##最后面添加这两行
fudge 127.127.1.0 stratum 8
[root@ns1 ~]# systemctl restart ntpd
[root@ns1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
在从服务器上配置NTP同步(20.0.0.12)
[root@localhost ~]# yum -y install ntpdate
[root@localhost ~]# ntpdate 20.0.0.11
14 Sep 21:44:44 ntpdate[20913]: step time server 20.0.0.11 offset 3.058116 sec
[root@localhost ~]# crontab -e ##添加计划任务
*/2 * * * * /usr/sbin/ntpdate 20.0.0.11 >> /var/log/ntpdate.log
[root@localhost ~]# touch /var/log/ntpdate.log
[root@localhost ~]# systemctl restart crond
[root@localhost ~]# systemctl enable crond
[root@localhost ~]# tail -f /var/log/ntpdate.log ##动态查看更新日志文件
14 Sep 21:48:08 ntpdate[20944]: adjust time server 20.0.0.11 offset -0.000003 sec
14 Sep 21:50:07 ntpdate[20950]: adjust time server 20.0.0.11 offset 0.000017 sec
......
在从服务器上配置NTP同步(20.0.0.13)
[root@ceshi ~]# yum -y install ntpdate
[root@ceshi ~]# ntpdate 20.0.0.11
14 Sep 21:58:27 ntpdate[29326]: step time server 20.0.0.11 offset 1.631892 sec
[root@ceshi ~]# crontab -e
*/2 * * * * /usr/sbin/ntpdate 20.0.0.11 >> /var/log/ntpdate.log
[root@ceshi ~]# touch /var/log/ntpdate.log
[root@ceshi ~]# systemctl restart crond
[root@ceshi ~]# systemctl enable crond
[root@ceshi ~]# tail -f /var/log/ntpdate.log
14 Sep 22:04:07 ntpdate[29345]: adjust time server 20.0.0.11 offset -0.000026 sec
......
安装过程见之前相关博客
Master主服务器配置 20.0.0.11
[root@ns1 ~]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 11 ##改成11
log_bin = master-bin ##后面两行添加
log-slave-updates = true
[root@ns1 ~]# systemctl restart mysqld
[root@ns1 ~]# mysql -u root -p
Enter password:
mysql> grant replication slave on *.* to 'myslave'@'20.0.0.%' identified by 'abc123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 | 599 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
salve1从服务器配置 20.0.0.12
[root@localhost mysql]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 22
relay-log = relay-log-bin
relay-log-index = slave-relay-bin.index
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -uroot -p
Enter password:
mysql> change master to master_host='20.0.0.11',master_user='myslave',master_password='abc123',master_log_file='master-bin.000001',master_log_pos=599;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 20.0.0.11
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000002
Read_Master_Log_Pos: 154
Relay_Log_File: relay-log-bin.000003
Relay_Log_Pos: 369
Relay_Master_Log_File: master-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: 154
Relay_Log_Space: 741
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: 11
Master_UUID: 6926c052-f679-11ea-8dad-000c29c74d51
Master_Info_File: /usr/local/mysql/data/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:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
salve2从服务器配置 20.0.0.13
[root@ceshi ~]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 22
relay-log = relay-log-bin
relay-log-index = slave-relay-bin.index
[root@ceshi ~]# systemctl restart mysqld
[root@ceshi ~]# mysql -uroot -p
Enter password:
mysql> change master to master_host='20.0.0.11',master_user='myslave',master_password='abc123',master_log_file='master-bin.000001',master_log_pos=599;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 20.0.0.11
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000002
Read_Master_Log_Pos: 154
Relay_Log_File: relay-log-bin.000003
Relay_Log_Pos: 369
Relay_Master_Log_File: master-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: 154
Relay_Log_Space: 741
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: 11
Master_UUID: 6926c052-f679-11ea-8dad-000c29c74d51
Master_Info_File: /usr/local/mysql/data/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:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
登录master服务器20.0.0.11
mysql> create database a; ##测试,创建新的a数据库
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| a |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
登录salve1服务器20.0.0.12
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| a |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
说明新建的a数据库同步成功
登录salve2服务器20.0.0.13
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| a |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
说明新建的a数据库同步成功