手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

基于SSL加密的MySQL主从复制

[日期:2012-05-12] 来源:Linux社区  作者:grass51 [字体:大 中 小]
五、记录主服务器的二进制日志文件以及事件,并且创建基于ssl复制的用户
ps:这里主从服务器的数据当前都是一致的,如果从服务器是新添加的,则需要将主服务器的最后的一个二进制日志之前的所有数据导入从服务器,具体步骤见:
MySQL的主从复制的场景二       http://www.linuxidc.com/Linux/2012-05/60211.htm


Master:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000075 |      107 |              |                  |
+------------------+----------+--------------+------------------+

mysql> grant replication client,replication slave on *.* to sslrepl@172.16.4.112 identified by '135246' require ssl;
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


六、启动从服务的从服务线程
Slave:
mysql> change master to \
    -> master_host='172.16.4.111',
    -> master_user='sslrepl',
    -> master_password='135246',
    -> master_log_file='mysql-bin.000075',
    -> master_log_pos=107,
    -> master_ssl=1,
    -> master_ssl_ca='/usr/local/mysql/ssl/cacert.pem',
    -> master_ssl_cert='/usr/local/mysql/ssl/mysql.crt',
    -> master_ssl_key='/usr/local/mysql/ssl/mysql.key';
Query OK, 0 rows affected (0.17 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 172.16.4.111
                  Master_User: sslrepl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000075
          Read_Master_Log_Pos: 608
               Relay_Log_File: relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000075
             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: 608
              Relay_Log_Space: 107
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: Yes
           Master_SSL_CA_File: /usr/local/mysql/ssl/cacert.pem
           Master_SSL_CA_Path: /usr/local/mysql/ssl
              Master_SSL_Cert: /usr/local/mysql/ssl/mysql.crt
            Master_SSL_Cipher:
               Master_SSL_Key: /usr/local/mysql/ssl/mysql.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: 1

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: 172.16.4.111
                  Master_User: sslrepl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000075
          Read_Master_Log_Pos: 608
               Relay_Log_File: relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000075
             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: 608
              Relay_Log_Space: 403
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: Yes
           Master_SSL_CA_File: /usr/local/mysql/ssl/cacert.pem
           Master_SSL_CA_Path: /usr/local/mysql/ssl
              Master_SSL_Cert: /usr/local/mysql/ssl/mysql.crt
            Master_SSL_Cipher:
               Master_SSL_Key: /usr/local/mysql/ssl/mysql.key
        Seconds_Behind_Master: 2132
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


输出信息为
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Master_SSL_Allowed: Yes
说明,基于ssl的配置已经成功

linux
相关资讯       MySQL数据库教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款