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

Building mysql MM (double hosts) and keepalived on linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

1. Master / standby IP and VIP planning:

Master1 10.1.1.14 VIP 10.1.1.16

Master2 10.1.1.15 VIP 10.1.1.16

II. Mysql MM configuration

1. Modify the my.cnf of master1

# vi / etc/my.cnf

[mysqld]

Basedir = / usr/local/mysql/

Datadir=/usr/local/mysql/data

Log-error=/usr/local/mysql/mysqld.log

Port = 3306

Socket=/usr/local/mysql/mysql.sock

Pid-file=/usr/local/mysql/mysql.pid

Expire-logs-days=10

# binlog-do-db=db1

# binlog-ignore-db=db2

Server-id = 1

Log-bin = binlog

Relay_log = relay-bin

Log_slave_updates = 1

Auto_increment_increment=2

Auto_increment_offset=1

two。 Modify the my.cnf of master2

# vim / etc/my.cnf

[mysqld]

Basedir = / usr/local/mysql/

Datadir=/usr/local/mysql/data

Log-error=/usr/local/mysql/mysqld.log

Port = 3306

Socket=/usr/local/mysql/mysql.sock

Pid-file=/usr/local/mysql/mysql.pid

Expire-logs-days=10

# binlog-do-db=db1

# binlog-ignore-db=db2

Server-id=2

Relay_log=relay-bin

Log_bin = binlog

Log_slave_updates = 1

Auto_increment_increment=2

Auto_increment_offset=2

3. Create a master1 replication account

Grant replication slave,replication client on *. * to 'repl'@'10.1.1.15' identified by' repl'

4. Create a master2 replication account

Grant replication slave,replication client on *. * to 'repl'@'10.1.1.14' identified by' repl'

5. Configure master for master1

Show master status

Change master to master_host='10.1.1.15',master_user='repl',master_password='repl',master_log_file='binlog.000005',master_log_pos=154

6. Configure master for master2

Show master status

Change master to master_host='10.1.1.14',master_user='repl',master_password='repl',master_log_file='binlog.000001',master_log_pos=154

7. Start slave

Master1:

Start slave

Master2:

Start slave

III. Keepalived configuration

1. Edit the keepalived configuration file for master1

# vi / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

# configure alarm notification mailboxes. You can configure multiple mailboxes

Notification_email {

Root@localhost

}

# configure email destination address

Notification_email_from mysql@xiaomi.com

# configure the smtp server address, which must exist

Smtp_server 10.1.1.11

# configure the timeout for connecting to the smtp server

Smtp_connect_timeout 30

# set the identity of the running Keepalived instance, which will be displayed in the message header

Router_id mysql_ha

}

# Monitoring script

Vrrp_script chk_mysql {

Script "/ etc/keepalived/check_mysql.sh"

Interval 2

Weight 2

}

# configure a VRRP instance with any name

Vrrp_instance mysql-ha {

# configure Keepalived role, MASTER is the host, BACKUP is the standby, and both are set to BACKUP

State BACKUP

# configure the network interface for keepalived monitoring

Interface eth0

# Virtual routing ID, which is a number (1-255mm), and the ID of the host in a VRRP instance must be the same

Virtual_router_id 66

# Server priority. The higher the number, the higher the priority. In an instance, the priority of the primary server is higher than that of the standby server.

Priority 50

# configure the time interval for synchronization check between master and slave servers (seconds)

Advert_int 1

# configure server preemption mode, which is configured in non-preemption mode (you only need to configure master1)

Nopreempt

# configure authentication type and password

Authentication {

# two types of verification {PASS | HA}

Auth_type PASS

# specify the authentication password. The password of the master / slave server in an instance should be the same.

Auth_pass centos

}

Track_script {

# specify the service to perform monitoring

Chk_mysql

}

# configure virtual IP. You can specify more than one, each on a line

Virtual_ipaddress {

10.1.1.16

}

}

two。 Edit the master1 heartbeat detection script:

# vi / etc/keepalived/check_mysql.sh

#! / bin/bash

# This scripts is check for Mysql Slave status

Counter=$ (netstat-na | grep "LISTEN" | grep "3311" | wc-l)

If ["${counter}"-eq 0]; then

Service keepalived stop

Killall keepalived

Fi

Ping 10.1.1.14-W1-C1 & > / dev/null

If [$?-ne 0]

Then

Systemctl stop keepalived

Killall keepalived

Fi

3. Edit the keepalived configuration file for master2

# vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

# configure alarm notification mailboxes. You can configure multiple mailboxes

Notification_email {

Root@localhost

}

# configure email destination address

Notification_email_from mysql@xiaomi.com

# configure the smtp server address, which must exist

Smtp_server 10.1.1.11

# configure the timeout for connecting to the smtp server

Smtp_connect_timeout 30

# set the identity of the running Keepalived instance, which will be displayed in the message header

Router_id mysql_ha

}

# Monitor copy

Vrrp_script chk_mysql {

Script "/ etc/keepalived/check_mysql.sh"

Interval 2

Weight 2

}

# configure a VRRP instance with any name

Vrrp_instance mysql-ha {

# configure Keepalived role, MASTER is the host, BACKUP is the standby, and both are set to BACKUP

State BACKUP

# configure the network interface for keepalived monitoring

Interface eth0

# Virtual routing ID, which is a number (1-255mm), and the ID of the host in a VRRP instance must be the same

Virtual_router_id 66

# Server priority. The higher the number, the higher the priority. In an instance, the priority of the primary server is higher than that of the standby server.

Priority 49

# configure the time interval for synchronization check between master and slave servers (seconds)

Advert_int 1

# configure server preemption mode, which is configured in non-preemption mode (you only need to configure master1)

# nopreempt

# configure authentication type and password

Authentication {

# two types of verification {PASS | HA}

Auth_type PASS

# specify the authentication password. The password of the master / slave server in an instance should be the same.

Auth_pass centos

}

Track_script {

# specify the service to perform monitoring

Chk_mysql

}

# configure virtual IP. You can specify more than one, each on a line

Virtual_ipaddress {

10.1.1.16

}

}

4. Edit the master2 detection script

# vim / etc/keepalived/check_mysql.sh

#! / bin/bash

# This scripts is check for Mysql Slave status

Counter=$ (netstat-na | grep "LISTEN" | grep "3306" | wc-l)

If ["${counter}"-eq 0]; then

Systemctl stop keepalived

Killall keepalived

Fi

Ping 10.1.1.15-W1-C1 & > / dev/null

If [$?-ne 0]

Then

Service keepalived stop

Killall keepalived

Fi

5.vip drift detection

1) enable keepalived and mysql on both master1 and master2

# service keepalived start

# service mysqld start

2) check the ip address on master1

Ip addr

3) Log in to mysql on 10.1.1.16

Mysql-uusername-ppassword-h20.1.1.16-P3311

4) stop the mysql service on master1

Service mysqld stop

5) observe the ip address on master1 and master2

Ip addr

6) continue to run the mysql command in session in 3) to see what happened

Mysql > use information_schema

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

Database

Wechat

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

12
Report