iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >Keepalived+Mysql如何配置主主复制
  • 238
分享到

Keepalived+Mysql如何配置主主复制

2024-04-02 19:04:59 238人浏览 独家记忆
摘要

小编给大家分享一下Keepalived+Mysql如何配置主主复制,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!安装环境:Hos

小编给大家分享一下Keepalived+Mysql如何配置主主复制,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

安装环境:

HostnameIPvirtual IP
D2-TYmysql51192.168.12.51192.168.12.50
D2-TYMYsql52192.168.12.52

软件包:
keepalived-1.3.5.tar.gz
mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz

节点51部署
(1)环境确认
[root@D2-TYMYSQL51 ~]# cat /etc/Centos-release
CentOS Linux release 7.2.1511 (Core)
[root@D2-TYMYSQL51 ~]# hostnamectl status
   Static hostname: D2-TYMYSQL51
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 4ff908d829c546f8a037b61638b50e43
           Boot ID: 43cbb3326cd646f9aaa40b63c77384b5
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
[root@D2-TYMYSQL51 ~]# cat /etc/hosts
192.168.  D2-
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.12.51  D2-TYMYSQL51
[root@D2-TYMYSQL51 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
[root@D2-TYMYSQL51 ~]# getenforce
Disabled


(2)安装数据库
参考Http://blog.itpub.net/28536251/viewspace-2138854/安装Mysql,注意目录的位置。
[root@D2-TYMYSQL51 ~]# ps -ef | grep mysql
root     31799     1  0 11:16 pts/0    00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/D2-TYMYSQL51.pid
mysql    32214 31799 37 11:16 pts/0    00:00:10 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/opt/mysql/data/D2-TYMYSQL51.pid
root     32754 30568  0 11:17 pts/0    00:00:00 grep --color=auto mysql

[root@D2-TYMYSQL51 ~]# rm -fr /opt/mysql/data/auto.cnf
[root@D2-TYMYSQL51 ~]# /etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!


(3)主从配置
[root@D2-TYMYSQL51 ~]# vim /etc/my.cnf
[root@D2-TYMYSQL51 ~]# cat /etc/my.cnf
[mysqld]
server-id = 1251
character-set-server=utf8

binlog_fORMat=mixed
log-bin=/opt/mysql/log/binlog
binlog-ignore-db=mysql,information_schema
auto-increment-increment=2
auto-increment-offset=1
slave-skip-errors=all

relay-log-index = /opt/mysql/log/relaylog
relay-log-info-file = /opt/mysql/log/relaylog
relay-log = /opt/mysql/log/relaylog

slow-query-log
long_query_time=3
log-output=TABLE
expire_logs_days = 7

basedir=/opt/mysql
datadir=/opt/mysql/data

event_scheduler=1

innodb_file_per_table=1
innodb_log_file_size=536870912
innodb_buffer_pool_size=1073741824
max_binlog_size=1073741824

log_bin_trust_function_creators=1
innodb_stats_on_metadata=0

max_connect_errors = 1000000
max_connections = 5000

skip_name_resolve = 1
symbolic-links=0


[mysql]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[root@D2-TYMYSQL51 ~]# /etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!

[root@D2-TYMYSQL51 ~]# /opt/mysql/bin/mysql -uroot -p123456
Warning: Using a passWord on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.22-log Source distribution

Copyright (c) 2000, 2014, oracle and/or its affiliates. All rights reserved.

Oracle is a reGIStered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show master status;
+---------------+----------+--------------+--------------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+---------------+----------+--------------+--------------------------+-------------------+
| binlog.000003 |      120 |              | mysql,information_schema |                   |
+---------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

mysql> grant replication slave on *.* to 'replication'@'192.168.12.%' identified by 'replication';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'root'@'192.168.12.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'192.168.12.%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec)

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


mysql> change master to master_host='192.168.12.52',master_user='replication',master_password='replication',master_log_file='binlog.000003',master_log_pos=637;
Query OK, 0 rows affected, 2 warnings (0.00 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: 192.168.12.52
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000004
          Read_Master_Log_Pos: 120
               Relay_Log_File: relaylog.000005
                Relay_Log_Pos: 280
        Relay_Master_Log_File: binlog.000004
             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: 606
              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: 1252
                  Master_UUID: e3b13736-7258-11e5-b726-005056a70ab8
             Master_Info_File: /opt/mysql/data/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)


(4)主从测试
主库:
mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> use test;
Database changed
mysql> create table usr(number int(10),name varchar(255));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into usr values(01,'aa');
Query OK, 1 row affected (0.00 sec)

从库:
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 |
+----------------+
| usr            |
+----------------+
1 row in set (0.00 sec)

mysql> select * from usr;
+--------+------+
| number | name |
+--------+------+
|      1 | aa   |
+--------+------+
1 row in set (0.00 sec)

确认同步正常后删除测试数据库
mysql> drop database test;
Query OK, 1 row affected (0.00 sec)


(5)安装keepalived
[root@D2-TYMYSQL51 ~]# yum install -y pcre-devel openssl-devel popt-devel GCc
[root@D2-TYMYSQL51 ~]# tar -xvzf keepalived-1.3.5.tar.gz
[root@D2-TYMYSQL51 ~]# cd keepalived-1.3.5/
[root@D2-TYMYSQL51 keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived
[root@D2-TYMYSQL51 keepalived-1.3.5]# make && make install
[root@D2-TYMYSQL51 keepalived-1.3.5]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/       
[root@D2-TYMYSQL51 keepalived-1.3.5]# mkdir /etc/keepalived
[root@D2-TYMYSQL51 keepalived-1.3.5]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@D2-TYMYSQL51 keepalived-1.3.5]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@D2-TYMYSQL51 keepalived-1.3.5]# vim /etc/keepalived/keepalived.conf
[root@D2-TYMYSQL51 keepalived-1.3.5]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id mysql01
}

vrrp_instance mysql01 {
    state BACKUP
    interface eno16777984
    virtual_router_id 50
    priority 100
    advert_int 5
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.12.50
    }
}

virtual_server 192.168.12.50 3306 {
    delay_loop 2
    lb_alGo wrr
    lb_kind DR
    persistence_timeout 60
    protocol tcp

    real_server 192.168.12.51 3306 {
        weight 3
        notify_down /usr/local/keepalived.sh
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

[root@D2-TYMYSQL51 keepalived-1.3.5]# vim /usr/local/keepalived.sh
[root@D2-TYMYSQL51 keepalived-1.3.5]# cat /usr/local/keepalived.sh
#!/bin/bash
pkill keepalived
[root@D2-TYMYSQL51 keepalived-1.3.5]# chmod +x /usr/local/keepalived.sh
[root@D2-TYMYSQL51 keepalived-1.3.5]# /usr/local/keepalived/sbin/keepalived -D -d -S 0
[root@D2-TYMYSQL51 keepalived-1.3.5]# ps -ef | grep keepalived
root     17727     1  0 16:07 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     17728 17727  0 16:07 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     17729 17727  0 16:07 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     17745 10101  0 16:08 pts/0    00:00:00 grep --color=auto keepalived

节点52部署
(1)环境确认
[root@D2-TYMYSQL52 ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
[root@D2-TYMYSQL52 ~]# hostnamectl status
   Static hostname: D2-TYMYSQL52
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 4ff908d829c546f8a037b61638b50e43
           Boot ID: 458ee453a718418daf05dea5cac4788b
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
[root@D2-TYMYSQL52 ~]# cat /etc/hosts
192.168.  D2-
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.12.52  D2-TYMYSQL52
[root@D2-TYMYSQL52 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
[root@D2-TYMYSQL52 ~]# getenforce
Disabled


(2)数据库安装
参考http://blog.itpub.net/28536251/viewspace-2138854/安装Mysql,注意目录的位置。
[root@D2-TYMYSQL52 ~]# ps -ef | grep mysql
root       728 30967  0 11:28 pts/0    00:00:00 grep --color=auto mysql
root     32212     1  0 11:28 pts/0    00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/D2-TYMYSQL52.pid
mysql    32627 32212 33 11:28 pts/0    00:00:10 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/opt/mysql/data/D2-TYMYSQL52.pid


(3)主从配置
[root@D2-TYMYSQL52 ~]# vim /etc/my.cnf
[root@D2-TYMYSQL52 ~]# cat /etc/my.cnf
[mysqld]
server-id = 1252
character-set-server=utf8

binlog_format=mixed
log-bin=/opt/mysql/log/binlog
binlog-ignore-db=mysql,information_schema
auto-increment-increment=2
auto-increment-offset=2
slave-skip-errors=all

relay-log-index = /opt/mysql/log/relaylog
relay-log-info-file = /opt/mysql/log/relaylog
relay-log = /opt/mysql/log/relaylog

slow-query-log
long_query_time=3
log-output=TABLE
expire_logs_days = 7

basedir=/opt/mysql
datadir=/opt/mysql/data

event_scheduler=1

innodb_file_per_table=1
innodb_log_file_size=536870912
innodb_buffer_pool_size=1073741824
max_binlog_size=1073741824

log_bin_trust_function_creators=1
innodb_stats_on_metadata=0

max_connect_errors = 1000000
max_connections = 5000

skip_name_resolve = 1
symbolic-links=0


[mysql]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


[root@D2-TYMYSQL52 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!


[root@D2-TYMYSQL52 ~]#  /opt/mysql/bin/mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.22-log Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> grant replication slave on *.* to 'replication'@'192.168.12.%' identified by 'replication';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'root'@'192.168.12.%' identified by '123456';
Query OK, 0 rows affected (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 |
+---------------+----------+--------------+--------------------------+-------------------+
| binlog.000003 |      637 |              | mysql,information_schema |                   |
+---------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)


mysql> change master to master_host='192.168.12.51',master_user='replication',master_password='replication',master_log_file='binlog.000003',master_log_pos=120;
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: 192.168.12.51
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000004
          Read_Master_Log_Pos: 120
               Relay_Log_File: relaylog.000004
                Relay_Log_Pos: 280
        Relay_Master_Log_File: binlog.000004
             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: 1351
              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: 1251
                  Master_UUID: baf1f004-3471-11e7-ae2b-0050568a1967
             Master_Info_File: /opt/mysql/data/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.01 sec)


(4)主从测试
主库:
mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> use test;
Database changed

mysql> create table usr(number int(10),name varchar(255));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into usr values(01,'aa');
Query OK, 1 row affected (0.00 sec)

从库:
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 |
+----------------+
| usr            |
+----------------+
1 row in set (0.00 sec)

mysql> select * from usr;
+--------+------+
| number | name |
+--------+------+
|      1 | aa   |
+--------+------+
1 row in set (0.00 sec)

确认同步正常后删除测试数据库:
mysql> drop database test;
Query OK, 1 row affected (0.00 sec)


(5)安装keepalived
[root@D2-TYMYSQL52 ~]# yum install -y pcre-devel openssl-devel popt-devel gcc
[root@D2-TYMYSQL52 ~]# tar -xvzf keepalived-1.3.5.tar.gz
[root@D2-TYMYSQL52 ~]# cd keepalived-1.3.5/
[root@D2-TYMYSQL52 keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived
[root@D2-TYMYSQL52 keepalived-1.3.5]# make && make install
[root@D2-TYMYSQL52 keepalived-1.3.5]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/       
[root@D2-TYMYSQL52 keepalived-1.3.5]# mkdir /etc/keepalived
[root@D2-TYMYSQL52 keepalived-1.3.5]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@D2-TYMYSQL52 keepalived-1.3.5]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@D2-TYMYSQL52 keepalived-1.3.5]# vim /etc/keepalived/keepalived.conf
[root@D2-TYMYSQL52 keepalived-1.3.5]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id mysql01
}

vrrp_instance mysql01 {
    state BACKUP
    interface eno16777984
    virtual_router_id 50
    priority 50
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.12.50
    }
}

virtual_server 192.168.12.50 3306 {
    delay_loop 2
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP

    real_server 192.168.12.52 3306 {
        weight 3
        notify_down /usr/local/keepalived.sh
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

[root@D2-TYMYSQL52 keepalived-1.3.5]# vim /usr/local/keepalived.sh
[root@D2-TYMYSQL52 keepalived-1.3.5]# cat /usr/local/keepalived.sh
#!/bin/bash
pkill keepalived
[root@D2-TYMYSQL52 keepalived-1.3.5]# chmod +x /usr/local/keepalived.sh
[root@D2-TYMYSQL52 keepalived-1.3.5]# /usr/local/keepalived/sbin/keepalived -D -d -S 0
[root@D2-TYMYSQL52 keepalived-1.3.5]# ps -ef | grep keepalived
root     16652     1  0 16:10 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     16653 16652  0 16:10 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     16654 16652  0 16:10 ?        00:00:00 /usr/local/keepalived/sbin/keepalived -D -d -S 0
root     16660 11645  0 16:10 pts/0    00:00:00 grep --color=auto keepalived


(6)故障转移测试:
51节点:
[root@D2-TYMYSQL51 keepalived-1.3.5]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777984:  mtu 1500 qdisc MQ state UP qlen 1000
    link/ether 00:50:56:8a:19:67 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.51/24 brd 192.168.12.255 scope global eno16777984
       valid_lft forever preferred_lft forever
    inet 192.168.12.50/32 scope global eno16777984
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe8a:1967/64 scope link
       valid_lft forever preferred_lft forever

客户端发起连接:
[root@D2-EDUMSDB45 ~]# mysql -h 192.168.12.50 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1866
Server version: 5.6.22-log Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>


关闭51节点的mysql:
[root@D2-TYMYSQL51 keepalived-1.3.5]# /etc/init.d/mysqld stop
Shutting down MySQL............ SUCCESS!


查看52节点:
[root@D2-TYMYSQL52 keepalived-1.3.5]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777984:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:8a:35:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.52/24 brd 192.168.12.255 scope global eno16777984
       valid_lft forever preferred_lft forever
    inet 192.168.12.50/32 scope global eno16777984
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe8a:359c/64 scope link
       valid_lft forever preferred_lft forever


45节点进行操作:
mysql> use mysql
No connection. Trying to reconnect...
Connection id:    1289
Current database: *** NONE ***

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

以上是“Keepalived+Mysql如何配置主主复制”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网数据库频道!

您可能感兴趣的文档:

--结束END--

本文标题: Keepalived+Mysql如何配置主主复制

本文链接: https://www.lsjlt.com/news/63238.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Keepalived+Mysql如何配置主主复制
    小编给大家分享一下Keepalived+Mysql如何配置主主复制,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!安装环境:Hos...
    99+
    2024-04-02
  • 如何理解基于keepalived的MySQL主主复制
    这篇文章将为大家详细讲解有关如何理解基于keepalived的MySQL主主复制,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。 ...
    99+
    2024-04-02
  • mysql的主从复制如何配置
    这篇文章给大家分享的是有关mysql的主从复制如何配置的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。数据库复制对于系统高可用、高性能的提升扮演者很重要的角色。1 主库配置1.1 ...
    99+
    2024-04-02
  • mysql中如何配置主从复制
    这篇文章主要介绍了mysql中如何配置主从复制,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。对于现在的系统来说,在业务复杂的系统中,数据库往...
    99+
    2024-04-02
  • Mysql - 配置Mysql主从复制-keepalived高可用-读写分离集群
    目录 高可用: 为什么需要高可用呢? 高可用的主要作用: keepalived是什么?它用在哪里? 什么是VRRP协议,它的作用是什么? 搭建一个基于keepalived的高可用Mysql主从复制读写分离集群 一、项目中的IP地址配置表:...
    99+
    2023-09-18
    数据库
  • mysql如何实现双主复制配置
    这篇文章主要介绍了mysql如何实现双主复制配置,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。  两台...
    99+
    2024-04-02
  • MySQL配置SSL主从复制
    MySQL5.6 创建SSL文件方法 官方文档:https://dev.mysql.com/doc/refman/5.6/en/creating-ssl-files-using-openssl.html#c...
    99+
    2024-04-02
  • MySQL主主复制+Keepalived打造高可用MySQL集群的步骤
    这篇文章主要介绍“MySQL主主复制+Keepalived打造高可用MySQL集群的步骤”,在日常操作中,相信很多人在MySQL主主复制+Keepalived打造高可用MySQL集群的步骤问题上存在疑惑,小...
    99+
    2024-04-02
  • Mysql中怎么配置主主复制架构
    这期内容当中小编将会给大家带来有关Mysql中怎么配置主主复制架构,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。 MySQL主主复制结构区别于主从复制结构。在主主复制结...
    99+
    2024-04-02
  • MariaDB中如何配置主从复制
    在MariaDB中配置主从复制,需要完成以下步骤: 在主服务器上配置主数据库 编辑主服务器上的my.cnf文件,添加或修改以下...
    99+
    2024-03-15
    MariaDB
  • Linux下MySQL主从复制的配置
    本篇内容主要讲解“Linux下MySQL主从复制的配置”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下MySQL主从复制的配置”吧! MySQL...
    99+
    2024-04-02
  • MySQL配置主从复制的方法
    今天小编给大家分享一下MySQL配置主从复制的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。一、检测通信查看主库(mas...
    99+
    2023-07-02
  • keepalived中mysql主从配置的方法是什么
    在keepalived中配置MySQL主从复制,可以通过以下步骤实现: 在主服务器和从服务器上安装MySQL,并进行配置; 配置主...
    99+
    2024-05-10
    keepalived mysql
  • Mysql5.6.22双向复制+KeepAlived如何配置mysql的高可用
    小编给大家分享一下Mysql5.6.22双向复制+KeepAlived如何配置mysql的高可用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!1. 基础安装环境  ,采...
    99+
    2024-04-02
  • keepalived Mysql双主热备配置的示例分析
    这篇文章主要介绍keepalived Mysql双主热备配置的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! 基于keepalived双主热备:...
    99+
    2024-04-02
  • MySQL 配置主从复制实践分享
    目录一、检测通信二、master配置1. 开启二进制日志2. 创建一个用于主从库通信用的账号3. 获取binlog的日志文件名和position三、slave配置1. 配置全局唯一的...
    99+
    2024-04-02
  • keepalived怎么配置redis主从切换
    本篇内容介绍了“keepalived怎么配置redis主从切换”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!IP规划:主节点:10.0.37...
    99+
    2023-06-05
  • Mysql双主如何配置
    这篇“Mysql双主如何配置”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Mysql双主如何配置”文章吧。前言特点:在双主配...
    99+
    2023-07-02
  • 半同步与异步的MySQL主从复制如何配置
    这篇文章主要介绍了半同步与异步的MySQL主从复制如何配置,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。一、MySQL主从复制原理这里我以M...
    99+
    2024-04-02
  • MySQL主从配置及haproxy和keepalived搭建过程解析
    目录docker 小知识创建harpoxy、Keepalive 的容器下载MySQLMySQL主主配置172.17.0.2 MySQL 配置172.17.0.2的配置执行sql命令M...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作