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

The installation and configuration method of mysql+keepalived

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to install and configure mysql+keepalived". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to install and configure mysql+keepalived.

Note: keepalived needs to be installed on every server

Environment introduction:

Master_mysql: 10.20.20.51

Slave_mysql: 10.20.20.61

Virtual_ip: 10.20.20.201

Note: turn off the firewall, selinux

First, install keepalived

Download address:

1. Http://www.keepalived.org/software/keepalived-1.1.20.tar.gz

3. Install the C compiler

Yum install popt-devel openssl-devel popt-devel

Yum install gcc gcc-c++ autoconf automake

4. Compile and install

[root@node1 ~] # tar zxvf keepalived-1.2.13.tar.gz

[root@node1 keepalived-1.2.13] # cd keepalived-1.2.13

[root@node1 keepalived-1.2.13] # / configure-- prefix=/usr/local/keepalived-- disable-fwmark

[root@node1 keepalived-1.2.13] # make

[root@node1 keepalived-1.2.13] # make install

[root@node1 keepalived-1.2.13] # cp / usr/local/keepalived/sbin/keepalived / usr/sbin/

[root@node1 keepalived-1.2.13] # cp / usr/local/keepalived/etc/sysconfig/keepalived / etc/sysconfig/

[root@node1 keepalived-1.2.13] # cp / usr/local/keepalived/etc/rc.d/init.d/keepalived / etc/init.d/

[root@node1 keepalived-1.2.13] # cd / etc/init.d/

[root@node1 init.d] # chkconfig-- add keepalived

[root@node1 init.d] # chkconfig keepalived on

[root@node1 init.d] # mkdir-p / etc/keepalived

5. Configure the keepalived file

1) keepalived configuration file of the main library

Vim / etc/keepalived/keepalived.conf

Global_defs {

Router_id Hadb_1

}

Vrrp_sync_group VGM {

Group {

VI_HA

}

}

Vrrp_script chk_mysql {

Script "

Interval 1

}

# vvrp_instance define #

Vrrp_instance VI_HA {

State MASTER

Interface eth0

Virtual_router_id 54

Priority 100

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass hamysql

}

Virtual_ipaddress {

10.20.20.201

}

Track_script {

Chk_mysql

}

}

2) configuration file of the keepalived of the slave library

Vim / etc/keepalived/keepalived.conf

Global_defs {

Router_id Hadb_1

}

Vrrp_sync_group VGM {

Group {

VI_HA

}

}

Vrrp_script chk_mysql {

Script "

Interval 1

}

# vvrp_instance define #

Vrrp_instance VI_HA {

State BACKUP

Interface eth0

Virtual_router_id 54

Priority 50

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass hamysql

}

Virtual_ipaddress {

10.20.20.201

}

Track_script {

Chk_mysql

}

}

6. Start the keepalived service

Service keepalived start

Configure AB replication of mysql (mutual AB replication)

1 、 1. Master library configuration (master server)

# vi / etc/my.cnf

[mysqld]

Log-bin=mysql-bin / / [must] enable binary logging

Server-id=51 / / [required] the server has a unique ID. The default is 1. Generally, the last segment of IP is taken.

two。 Modify the slave server slave:

# vi / etc/my.cnf

[mysqld]

Log-bin=mysql-bin / / [must] enable binary logging

Server-id=61 / / [required] the server has a unique ID. The default is 1. Generally, the last segment of IP is taken.

3. Restart the mysql of two servers

/ etc/init.d/mysql restart

4. Establish an account on the master server and authorize slave:

10.20.20.51:

Mysql > GRANT REPLICATION SLAVE ON *. * to 'repler'@'%' identified by' 123.com'

10.20.20.61:

Mysql > GRANT REPLICATION SLAVE ON *. * to 'repler'@'%' identified by' 123.com'

5. Log in to the mysql of the master server and query the status of master

Mysql > show master status

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |

+-+

| | mysql-bin.000004 | 308 |

+-+

6. Configure slave server Slave:

10.20.20.61:

Mysql > change master to master_host='10.20.20.51',master_user='repler',master_password='123.com'

Master_log_file='mysql-bin.000004',master_log_pos=308

10.20.20.51:

Mysql > change master to master_host='10.20.20.61',master_user='repler',master_password='123.com'

Master_log_file='mysql-bin.000004',master_log_pos=308

7. Start the copy function from the server

Mysql > start slave

8. Check the status of replication from the server:

Mysql > show slave status\ G

At this point, I believe you have a deeper understanding of the "method of installation and configuration of mysql+keepalived". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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