美文网首页
主主复制

主主复制

作者: 尘曦的雨 | 来源:发表于2017-09-14 16:35 被阅读12次

    两个节点配置文件的设置

    [root@centos7 /]# cat etc/my.cnf.d/server.cnf 
    #
    # These groups are read by MariaDB server.
    # Use it for options that only the server (but not clients) should see
    #
    # See the examples of server my.cnf files in /usr/share/mysql/
    #
    
    # this is read by the standalone daemon and embedded servers
    [server]
    
    # this is only for the mysqld standalone daemon
    [mysqld]
    server-id = 1   #设定serverID的值
    log-bin = mysql.log  #启用二进制日志并以文件
    relay-log=chenxi.log #
    skip_name_resolve = ON #关闭名称解析功能
    auto_increment_offset=1
    auto_increment_increment=2
    # this is only for embedded server
    [embedded]
    
    # This group is only read by MariaDB-5.5 servers.
    # If you use the same .cnf file for MariaDB of different versions,
    # use this group for options that older servers don't understand
    [mysqld-5.5]
    
    # These two groups are only read by MariaDB servers, not by MySQL.
    # If you use the same .cnf file for MySQL and MariaDB,
    # you can put MariaDB-only options here
    [mariadb]
    
    [mariadb-5.5]
    

    节点二的设置

    [root@localhost ~]# cat /etc/my.cnf.d/server.cnf 
    #
    # These groups are read by MariaDB server.
    # Use it for options that only the server (but not clients) should see
    #
    # See the examples of server my.cnf files in /usr/share/mysql/
    #
    
    # this is read by the standalone daemon and embedded servers
    [server]
    server-id=2    #定义服务器ID
    log-bin = chenxi-log
    relay_log = relay-log
    skip_name_resolve = NO
    auto_increment_offset=2
    auto_increment_increment=2
    
    # this is only for the mysqld standalone daemon
    [mysqld]
    
    # this is only for embedded server
    [embedded]
    
    # This group is only read by MariaDB-5.5 servers.
    # If you use the same .cnf file for MariaDB of different versions,
    # use this group for options that older servers don't understand
    [mysqld-5.5]
    
    # These two groups are only read by MariaDB servers, not by MySQL.
    # If you use the same .cnf file for MySQL and MariaDB,
    # you can put MariaDB-only options here
    [mariadb]
    
    [mariadb-5.5]
    

    两个节点启动服务

    节点1 的设置
    [root@centos7 my.cnf.d]# 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)]>  GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluse'@'172.16.%.%' identified by 'replpass';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]>  flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]>  show master status; 
    +--------------+----------+--------------+------------------+
    | File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +--------------+----------+--------------+------------------+
    | mysql.000003 |      505 |              |                  |
    +--------------+----------+--------------+------------------+
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> change master to master_host='172.16.250.236' ,master_user='repluse',master_password='replpass',master_log_file='mysql.000003',master_log_pos=505;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 172.16.250.236
                      Master_User: repluse
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql.000003
              Read_Master_Log_Pos: 505
                   Relay_Log_File: chenxi.000002
                    Relay_Log_Pos: 525
            Relay_Master_Log_File: mysql.000003
                 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: 505
                  Relay_Log_Space: 810
                  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: 2
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> 
    节点2 的设置
    MariaDB [(none)]>  GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluse'@'172.16.%.%' identified by 'replpass';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> show grants for 'repluser'@'172.16.%.%';
    ERROR 1141 (42000): There is no such grant defined for user 'repluser' on host '172.16.%.%'
    MariaDB [(none)]> show grants for 'repluse'@'172.16.%.%';
    +-------------------------------------------------------------------------------------------------------------------------------------------------+
    | Grants for repluse@172.16.%.%                                                                                                                   |
    +-------------------------------------------------------------------------------------------------------------------------------------------------+
    | GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluse'@'172.16.%.%' IDENTIFIED BY PASSWORD '*D98280F03D0F78162EBDBB9C883FC01395DEA2BF' |
    +-------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    MariaDB [(none)]>  show master status; 
    +--------------+----------+--------------+------------------+
    | File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +--------------+----------+--------------+------------------+
    | mysql.000003 |      425 |              |                  |
    +--------------+----------+--------------+------------------+
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]>  show master status; 
    +--------------+----------+--------------+------------------+
    | File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +--------------+----------+--------------+------------------+
    | mysql.000003 |      505 |              |                  |
    +--------------+----------+--------------+------------------+
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> change master to master_host='172.16.251.203' ,master_user='repluse',master_password='replpass',master_log_file='mysql.000003',master_log_pos=505;
    Query OK, 0 rows affected (0.07 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.02 sec)
    
    MariaDB [(none)]> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 172.16.251.203
                      Master_User: repluse
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql.000003
              Read_Master_Log_Pos: 505
                   Relay_Log_File: chenxi.000002
                    Relay_Log_Pos: 525
            Relay_Master_Log_File: mysql.000003
                 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: 505
                  Relay_Log_Space: 810
                  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: 1
    1 row in set (0.00 sec)
    
    MariaDB [(none)]> 
    

    相关文章

      网友评论

          本文标题:主主复制

          本文链接:https://www.haomeiwen.com/subject/zozrsxtx.html