设为首页 收藏本站
查看: 469|回复: 0

[经验分享] centos7mysql5.6.30单机多实例配置主主复制

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-1 09:18:06 | 显示全部楼层 |阅读模式
1.在原来单实例的基础上修改配置/usr/my.cnf
[mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
user=root

[mysqld3306]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/localhost.localdomain.pid
datadir=/var/lib/mysql/
user=root
character_set_server=utf8
lower_case_table_names=1
max_connections=300
server-id=1
binlog-do-db=test
log-bin=master-bin
log-bin-index=master-bin.index
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
auto-increment-increment = 2           
auto-increment-offset = 1              

[mysqld3307]
port=3307
socket=/home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock
pid-file=/home/fuyouling/mutl_mysql/mysql_3307/mysql/localhost.localdomain.pid
datadir=/home/fuyouling/mutl_mysql/mysql_3307/mysql/
user=root
character_set_server=utf8
lower_case_table_names=1
max_connections=300
server_id=2
log-bin=master-bin
log-bin-index=master-bin.index
replicate-do-db=test
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
auto-increment-increment = 2
auto-increment-offset = 2

2.在3306服务器建立复制账户
mysqld_multi --defaults-extra-file=/usr/my.cnf start 3306 #开启3306服务
mysql -uroot -p123456 -S /var/lib/mysql/mysql.sock        #登录mysql

mysql>grant replication slave,replication client on *.* to repl1@'localhost' identified by 'repl1'; #在主服务器上建立复制用户
mysql>flush privileges;  #刷新权限

3.在3307服务器上建立复制账户
mysqld_multi --defaults-extra-file=/usr/my.cnf start 3307 #开启3307服务
mysql -uroot -p654321 -S /home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock #登录mysql

mysql>grant replication slave,replication client on *.* to repl2@'localhost' identified by 'repl2'; #在主服务器上建立复制用户
mysql>flush privileges;  #刷新权限

4.在3306服务器上建立slave 连接master的信息
Change Master to Master_host='127.0.0.1',Master_port=3307,Master_user='repl2',Master_Password='repl2';

5.在3307从服务器上建立slave 连接master的信息
Change Master to Master_host='127.0.0.1',Master_port=3306,Master_user='repl1',Master_Password='repl1';

6.在3306上检查主从信息:
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000003 |      120 | test         |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 127.0.0.1
                  Master_User: repl2
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 120
               Relay_Log_File: slave-relay-bin.000008
                Relay_Log_Pos: 284
        Relay_Master_Log_File: master-bin.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: 120
              Relay_Log_Space: 621
              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
                  Master_UUID: 04793bcc-3e99-11e6-ab0c-000c29569f32
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           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
1 row in set (0.00 sec)

7.在3307上检查主从信息
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000003 |      120 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 127.0.0.1
                  Master_User: repl1
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 120
               Relay_Log_File: slave-relay-bin.000007
                Relay_Log_Pos: 284
        Relay_Master_Log_File: master-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: test
          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: 120
              Relay_Log_Space: 621
              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
                  Master_UUID: be707b89-20cf-11e6-a8d0-000c29569f32
             Master_Info_File: /home/fuyouling/mutl_mysql/mysql_3307/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           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
1 row in set (0.00 sec)

8.测试
(1)
在3306上新建表test_table4
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test_table1    |
| test_table2    |
| test_table3    |
+----------------+
3 rows in set (0.00 sec)

mysql> create table test_table4(id int,str varchar(100));
Query OK, 0 rows affected (0.03 sec)

登录3307上查看
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test_table1    |
| test_table2    |
| test_table3    |
| test_table4    |
+----------------+
4 rows in set (0.00 sec)

(2)
在3307上创建新表test_table5
mysql> create table test_table5(id int,str varchar(100));
Query OK, 0 rows affected (0.05 sec)

在3306上查看
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test_table1    |
| test_table2    |
| test_table3    |
| test_table4    |
| test_table5    |
+----------------+
5 rows in set (0.00 sec)

备注:这个其实是主主复制下的主动-主动模式。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-237733-1-1.html 上篇帖子: Mysql索引与键 下篇帖子: mysql5.6 的--dump-slave参数的用法 单机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表