Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize High availability by combining MySQL Master and Master with each other in Openstack

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to achieve high availability with the combination of MySQL master and master and backup in Openstack, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Lab environment server test1 (master) 192.168.106.156 server test2 (master) 192.168.106.158 Mysql version: 5.1.73 VM System OS:CentOS 6 X64

1 install and configure mysql master, master and backup 1. Install Mysql: you need to turn off the firewall and SELINUX, and install the same version of mysql database on both machines.

Yum install mysql-server

two。 Create a synchronization user:

Here test1 and test2 are master and slave to each other, so each has to establish a synchronous user. Execute on test1 and test2 respectively:

Mysql > GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *. * TO sync@'%' IDENTIFIED BY '123456 * MySQL > flush privileges

3. Modify the configuration file:

3.1 configuration file for mysql on test1:

[mysqld] # log-bin=mysql-binserver-id=156log_bin = / var/lib/mysql/mysql-binlogbinlog-ignore-db=mysqlbinlog-ignore-db=information_schemareplicate-ignore-db=mysql,information_schemalog-slave-updatessync_binlog=1auto_increment_offset=1auto_increment_increment=2

3.2 configuration file for mysql on test2:

[mysqld] # log-bin=mysql-binserver-id=158auto_increment_offset=2auto_increment_increment=2log-slave-updatessync_binlog=1log_bin = / var/lib/mysql/mysql-binlogbinlog-ignore-db=mysqlbinlog-ignore-db=information_schemareplicate-ignore-db=mysql,information_schema

4. Then, restart the mysql server separately.

Service mysqld restart

5. Check the status of the primary server on test1 and test2 respectively:

On test1: mysql > flush tables with read lock;Query OK, 0 rows affected (0.00 sec) mysql > show master status\ Graph * 1. Row * * File: mysql-binlog.000001 Position: 106Binlog_Ignore_DB: mysql,information_schema1 row in set (0.00 sec) mysql > mysql > unlock tables On test2: mysql > stop slave;mysql > flush tables with read lock Query OK, 0 rows affected (0.00 sec) mysql > show master status\ gateway * 1. Row * * File: mysql-binlog.000001 Position: 106Binlog_Ignore_DB: mysql,information_schema1 row in set (0.00 sec) mysql > unlock tables

Note: the purpose of locking the table here is to prevent new data from entering the production environment, so that the synchronization location can be located from the server. Remember to unlock after the initial synchronization is complete.

6. Specify the synchronization location with the change master statement on test1 and test2, respectively:

6.1 test1:mysql > change master to master_host='192.168.106.158', master_user='sync', master_password='123456', master_log_file='mysql-binlog.000001', master_log_pos=106;Query OK, 0 rows affected (0.12 sec) mysql > start slave Query OK, 0 rows affected (0.00 sec) 6.2 test2:mysql > change master to master_host='192.168.106.156', master_user='sync', master_password='123456', master_log_file='mysql-binlog.000001', master_log_pos=106;mysql > start slave;Query OK, 0 rows affected (0.00 sec)

View the slave server status on test1 and test2 respectively:

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.106.158 Master_User: repli Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-binlog.000001 Read_Master_Log_Pos: 106 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 254 Relay_Master_Log_File: mysql-binlog.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: mysql Information_schema... ...

Check the values of the above two items. If Slave_IO_Running: Yes Slave_SQL_Running: Yes is Yes, the status is normal.

8. Test: two-way test, create database db1 on test1 and view information from test2; similarly, after creating database db2 on test2, view information from test1.

Install and configure keepalived to achieve MySQL double main high availability 1. Install keepalived

Yum install keepalived

two。 Configure keepalived

2.1 test1 192.168.106.156# vi / etc/keepalived/keepalived.conf! Configuration File for keepalived global_defs {notification_email {admin@tcloudsoft.com zhuzy@tcloudsoft.com} notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_instance HA_1 {state BACKUP # test1 and test2 are both configured as BACKUP interface eth0 # to specify the network interface virtual_router_ for HA detection Id 80 # Virtual Route identity The same master / slave priority 100 # defines priority, and test2 setting 90 advert_int 1 # sets the time interval of synchronization check between test1 and test2. Nopreempt # does not preempt mode. Authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {# virtual IP can be set only on high priority machines. Multiple virtual IP can be set, one for each line, 192.168.106.200 IP for 24 dev eth0 # MySQL external service. That is, VIP} virtual_server 192.168.106.200 3306 {delay_loop 2 # query real server status every 2 seconds lb_algo wrr # lvs algorithm lb_kinf DR # LVS mode (Direct Route) persistence_timeout 50 protocol TCP real_server 192.168.106.156 3306 {# monitor this machine IP weight 1 notify_down / etc/keepalived/mysql.sh TCP_CHECK {connect_timeout 10 # 10 second No response timeout bingto 192.168.106.200 nb_get_retry 3 delay_before_retry 3 connect_port 3306}}

2.2 keepalived detection script, when one of the MySQL services fails down fails, the implementation automatically switches to the normal MySQL server to continue to provide services.

Vi / etc/keepalived/mysql.sh#!/bin/bashpkill keepalived2.3 test2 192.168.106.158# vi / etc/keepalived/keepalived.conf! Configuration File for keepalived global_defs {notification_email {root@tcloudsoft.com zhuzy@tcloudsoft.com} notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_instance HA_1 {state BACKUP # test1 and test2 are both configured as BACKUP interface eth0 # to specify the network interface virtual_router_id for HA detection 80 # Virtual routing identity The same master / slave priority 90 # defines priority, test2 setting 90 advert_int 1 # sets the time interval of synchronization check between test1 and test2 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {# sets virtual IP, you can set multiple One 192.168.106.200 IP for external service of 24 dev eth0 # MySQL per line That is, VIP}} virtual_server 192.168.106.200 3306 {delay_loop 2 lb_algo wrr lb_kinf DR persistence_timeout 50 protocol TCP real_server 192.168.106.158 3306 {# listening on local IP weight 1 notify_down / etc/keepalived/mysql.sh TCP_CHECK {connect_timeout 10 bingto 192.168.106.200 nb _ get_retry 3 delay_before_retry 3 connect_port 3306}

3. Authorize the root user rights of VIP to authorize remote hosts to log in to MySQL through VIP and test the data replication function

Mysql > grant all on *. * to root@'192.168.6.44' identified by '123456 is MySQL > grant all on *. * to root@'192.168.106.200' identified by' 123456 is MySQL > flush privileges

4. To test the high availability feature of keepalived in OpenStack, you need to complete the third part of the setup before testing. 4.1 remote host login logs in to MySQL through VIP 192.168.106.200 to check the MySQL connection status

Mysql > show variables like 'hostname%';+-+-+ | Variable_name | Value | +-+-+ | hostname | test1 | +-+-+ 1 row in set (0.00 sec)

4.2 failure test, stop the MySQL service of test1 and check again to see if it is transferred to the test2 server

Mysql > show variables like 'hostname%'

The method of realizing VIP handover with three OpenStack VM single network card and multiple IP. Using the port_security_enabled attribute, port_security_enabled is a Ml2 extension driver added after the kilo version, which may be changed for the entire network or for a port, which defaults to true.

Neutron port-listneutron port-update-no-security-groups 413b58fe-44c0-4df2-b588-332d5b6030e9neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9-port_security_enabled=False

two。 Use allowed-address-pairs to extend the port properties to allow traffic to manually specify the port's mac_address and ip address pairs.

Neutron port-listneutron port-show 413b58fe-44c0-4df2-b588-332d5b6030e9neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9-- allowed-address-pairs type=dict list=true ip_address=192.168.106.200neutron port-update 413b58fe-44c0-4df2-b588-332d5b6030e9-- allowed-address-pairs action=clear shares here on how to achieve high availability of MySQL master / master / backup combination in Openstack. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report