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

MySQL dual master configuration

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

Share

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

Preparation environment: the server operating system is RHEL6.4 x86x64, which minimizes the installation. Host An and host B both turn off the firewall and SELINUX. The IP addresses are 192.168.131.129 and 192.168.131.130 respectively. MySQL version 5.6.26, which is a general binary package.

1. Install MySQL

1. Host An operation

# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

# mv mysql-5.6.26-linux-glibc2.5-x86_64 / usr/local/mysql

# useradd-M-s / sbin/nologin mysql

# chown-R root:root / usr/local/mysql/*

# chown-R mysql:mysql / usr/local/mysql/data/

# yum-y install libaio

# cd / usr/local/mysql/scripts/

#. / mysql_install_db-datadir=/usr/local/mysql/data/-user=mysql-basedir=/usr/local/mysql/

# cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld

# echo 'export PATH=$PATH:/usr/local/mysql/bin' > > / etc/profile

# source / etc/profile

# vim / etc/my.cnf

[mysqld]

Datadir=/usr/local/mysql/data

Socket=/tmp/mysql.sock

User=mysql

Symbolic-links=0

[mysqld_safe]

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

# service mysqld start

# chkconfig mysqld on

# ss-tunlp | grep 3306

# mysqladmin-uroot password '123456' # set the database password

two。 Host B operation (ibid.)

Second, configure double masters

1. Host An operation

# vim / etc/my.cnf

Server-id=20

Log-bin=mysql-bin

Log-bin-index=mysql-bin.index

Replicate-ignore-db=test

Binlog-ignore-db=mysql

Binlog-ignore-db=information_schema

Auto-increment-increment=2

Auto-increment-offset=1

# service mysqld restart

# mysql-uroot-p123456

Mysql > flush tables with read lock

Open a remote terminal window and do the following

# mysqldump-uroot-p123456-B test > test.sql

Return to the previous terminal window and do the following

Mysql > unlock tables

Mysql > grant replication slave on *. * to 'wdd'@'192.168.131.130' identified by' 123456'

Mysql > flush privileges

# scp test.sql 192.168.131.130:/root

2. Host B operation

# vim / etc/my.cnf

Server-id = 21

Log-bin=mysql-bin

Log-bin-index= mysql-bin.index

Replicate-do-db=test

Binlog-ignore-db=mysql

Binlog-ignore-db=information_schema

Auto-increment-increment=2

Auto-increment-offset=2

# service mysqld restart

# mysql-uroot-p123456

< test.sql # mysql -uroot -p123456 mysql>

Grant replication slave on *. * to 'wdd'@'192.168.131.129' identified by' 123456'

Mysql > flush privileges

3. Host An and host B do the following respectively

Host A

① # mysql-uroot-p123456

Mysql > SHOW MASTER STATUS

Mysql > change master to

Master_host='192.168.131.130'

Master_user='wdd'

Master_password='123456'

Master_log_file=' mysql-bin.000002'

Master_log_pos=420

Mysql > start slave

Mysql > show slave status\ G

② # mysql-uroot-p123456

Mysql > show master status

Mysql > change master to

Master_host='192.168.131.129'

Master_user='wdd'

Master_password='123456'

Master_log_file='mysql-bin.000002'

Master_log_pos=689

Mysql > start slave

Mysql > show slave status\ G

III. Testing

1. Host A does some operations.

Mysql > use test

Mysql > create table info (

-> id int (10) not null auto_increment primary key

-> name char (20))

Mysql > show tables

2. Host B carries on the operation

Mysql > use test

Mysql > show tables

Mysql > create table person (

-> id int (20) unsigned not null auto_increment primary key

-> name char (20))

Mysql > show tables

3. Carry out operation inspection on host A

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