Linux技术区

Linux服务篇之mysql主从复制

2017-09-19  本文已影响235人  数据革命

概念

主从复制配置

[root@server ~]# ntpdate 172.16.0.1
[root@server ~]# yum install mariadb-server -y
[root@server ~]# vim /etc/my.cnf.d/server.cnf 
# this is only for the mysqld standalone daemon
[mysqld]
server-id = 1                   <<<<< ID号最好是唯一
log-bin = master-log            <<<<< 开启二进制日志
skip_name_resolve = ON
[root@server ~]# vim /etc/my.cnf.d/server.cnf 
 [server]

# this is only for the mysqld standalone daemon
[mysqld]
server-id = 2
relay-log = relay-log
skip_name-resolve = ON
[root@server ~]# systemctl  start mariadb.service
[root@server ~]# ss -nutl
Netid State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
udp   UNCONN     0      0                *:43362                        *:*                  
udp   UNCONN     0      0                *:68                           *:*                  
udp   UNCONN     0      0               :::28989                       :::*                  
tcp   LISTEN     0      50               *:3306                         *:*                  
tcp   LISTEN     0      128              *:22                           *:*                  
tcp   LISTEN     0      100      127.0.0.1:25                           *:*                  
tcp   LISTEN     0      128             :::22                          :::*                  
tcp   LISTEN     0      100            ::1:25                          :::*   
[root@server ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000003 |      245 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'lilin'@'172.16.251.190' IDENTIFIED BY 'li56412820';
MariaDB [(none)]> FLUSH PRIVILEGES;
[root@form ~]# systemctl start mariadb.service
[root@form ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='172.16.252.133' , MASTER_USER='lilin',MASTER_PASSWORD='li5641282' , MASTER_LOG_FILE='master-log.000003' , MASTER_LOG_POS=678;
[root@form ~]# cd /var/lib/mysql/
[root@form mysql]# ls
aria_log.00000001  ib_logfile0  mysql               relay-log.000001  test
aria_log_control   ib_logfile1  mysql.sock          relay-log.index
ibdata1            master.info  performance_schema  relay-log.info
[root@form mysql]# cat master.info 
18
master-log.000003
678
172.16.252.133
lilin
li5641282
3306
60
0





0
1800.000

0
[root@form mysql]# cat relay-log.info 
./relay-log.000001
4
master-log.000003
678
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 172.16.252.133
                  Master_User: lilin
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-log.000003
          Read_Master_Log_Pos: 678
               Relay_Log_File: relay-log.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: master-log.000003
             Slave_IO_Running: No                       <<<<<复制NO为没有启动
            Slave_SQL_Running: No                       <<<<<重放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: 678
              Relay_Log_Space: 245
              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
1 row in set (0.00 sec)
mysql> START SLAVE
上一篇 下一篇

猜你喜欢

热点阅读