MySQL master-slave replication and separation of read and write

One. Configure master-slave replication
1. Configure ntp server
Install ntp
[[email protected] ~]# yum -y install ntp

Insert picture description here


modify ntp configuration file
[[email protected] ~]# vim /etc/ntp.conf

Insert picture description here


Insert picture description here


start service settings automatically start

Insert picture description here


synchronization with other servers Time

Insert picture description here


2. Install mysql
slightly. . . . . . . .

3. Modify the main mysql configuration file
Modify the configuration file
[[email protected] ~]# vim /etc/my.cnf

Insert picture description here
Insert picture description here


Insert picture description here
Insert picture description here


2. Restart the MySQL service to load the configuration file

Insert picture description here


3. Modify the mysql main configuration file
centso2 and centos3 (the same)

Insert picture description here


Insert picture description here


Restart the MySQL service to load the configuration file

Insert picture description here


4. Configure the master-slave replication
Create the master-slave replication account
[[email protected] ~]# mysql -uroot [email protected]
mysql> grant replication slave on . to'slave'@'192.168.100.%' identified by'[email protected]';

Insert picture description here


mysql> select user,host from mysql.user;

Insert picture description here

View the master MySQL status
mysql> show master status;

Insert picture description here


configure the replication accounts
centso2 and centso3 from the MySQL database (the same)

[[email protected] ~]# mysql -uroot [email protected]

Insert picture description here


Insert picture description here


Start the slave database replication process
mysql> start slave;

Insert picture description here

View the status of replication from MySQL
mysql> show slave status\G;

Insert picture description here

Verification: the main server creates benet

Insert picture description here


Insert picture description here


View from server

Insert picture description here


Insert picture description here

two. Configure read-write separation
Write hosts file
[[email protected] ~]# vim /etc/hosts

Insert picture description here


copy to other servers

Insert picture description here


1. Install jdk and amoeba,
decompress jdk,

Insert picture description here


Insert picture description here


move jdk location,

Insert picture description here


create amoba configuration file

Insert picture description here


[[email protected] ~]# tar zxvf /mnt/ amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/

Insert picture description here

2. Configure the environment variable

Insert picture description here


export JAVA_HOME=/usr/local/java
export CLASSPATH= C L A S S P A T H: CLASSPATH: C L A S S P A T H:JAVA_HOME/lib: J A V A H O M E / j r e / l i b e x p o r t P A T H = JAVA_HOME/jre/lib export PATH= J A V AH​O M E / j r e / l i b e x p o r t P A T H=JAVA_HOME/lib/: J A V A H O M E / j r e / b i n: JAVA_HOME/jre/bin: J A V AH​O M E / j r e / b i n:PATH: H O M E / b i n / e x p o r t A M O E B A = / u s r / l o c a l / a m o e b a e x p o r t P A T H = HOME/bin/ export AMOEBA=/usr/local/amoeba export PATH= H O M E / b i n / e x p o r t A M O E B A=/ u s r / l o c a l / a m o e b a e x p o r t P A T H=PATH:AMOEBA/bin

Insert picture description here


Insert picture description here


view jdk version

Insert picture description here


3. Configure read-write separation
Create amoeba to access MySQL is a database read-write separation account
[[email protected] ~]# mysql -uroot [email protected]

Insert picture description here


view the slave server

Insert picture description here

Modify the amoeba configuration file settings to log in to the amoeba account

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here

Modify the configuration file to add a read-write node.

Insert picture description here


Insert picture description here


Insert picture description here


Insert picture description here


Start amoeba

Insert picture description here


4. Configure the MySQL client
centso5:
install the MySQL client

Insert picture description here


Log in to amoeba

Insert picture description here


Insert picture description here


Insert picture description here


centos2 to view the

Insert picture description here


read-write separation

Insert picture description here


Insert picture description here


MySQL [(none)]> select * from xsh.student;

Insert picture description here

stop from the server service

Insert picture description here

Verification:

Insert picture description here


view on the main server and start slave

Insert picture description here


server services, the client can view
mysql> start slave;

Insert picture description here


Insert picture description here