Use amoeba to configure mysql master-slave synchronization read-write separation

Use amoeba to configure mysql master-slave synchronization read-write separation

Experimental environment:
Three manually compiled and installed mysql, one master and two slave
masters: 192.168.88.100
slave 1: 192.168.88.103
slave 2: 192.168.88.104
Front server: 192.168.88.101

-----Do it on the main server 192.168.88.100---------------Configure the NTP server---------- //Set up the ntp service on the main server , which provides time synchronization

yum install -y ntp

vi /etc/ntp.conf

restrict 192.168.88.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 8 //Set the level of the time server to level 8 and the top level to 0

service ntpd start
service firewalld stop
setenforce 0

Configure the MYSQL of the master server:
vi /etc/my.cnf //Configure under [mysqld]

server_id = 11
log_bin=master_bin //this is the binary log file that records operations on the master
log_slave_updates=true //allows synchronization from the server

service mysqld restart

mysql -u root -p

GRANT REPLICATION SLAVE ON . TO 'myslave'@'192.168.88.%' IDENTIFIED BY '123456'; //Authorize all databases for all slave servers

FLUSH PRIVILEGES;
show master status; //Note the value of the Position column (mine is 603) and the value of File

Use amoeba to configure mysql master-slave synchronization read-write separation![]

--------The following configures ntp services from servers 192.168.88.103 and 192.168.88.104 and from mysql-------------------

service firewalld stop
setenforce 0

yum install -y ntpdate
ntpdate 192.168.88.100

Use amoeba to configure mysql master-slave synchronization read-write separation![]
When offset appears, the synchronization is successful. offset value

echo ' /30 * /usr/sbin/ntpdate 192.168.88.100' >> /var/spool/cron/root //Scheduled tasks to synchronize with the master server every 30 minutes
crontab -l

Then configure mysql on the slave server:
vi /etc/my.cnf //
server_id = 22 under [mysqld] //Note here that the id value cannot be the same as the master's id, and the id of the two slave mysql cannot be the same
relay_log=relay- log-bin
relay_log_index=slave-relay-bin.index

service mysqld restart
------- Note the value of master_log pos=, use show master status on the master; check it out, note - and ----

mysql -u root
change master to master_host='192.168.88.100',master_user='myslave',master_password='123456',master_log_file='master_bin.000001',master_log_pos=900; //Track the binary file of the main mysql server
start slave ;
show slave status \G //The following two options need to be Yes

……
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
……

Use amoeba to configure mysql master-slave synchronization read-write separation

Then verify master-slave synchronization:
------Create a new library on the master server and verify synchronization------------
mysql -u root -p

create database hello;
show databases; //The master server creates the database, view it on the slave server, and the slave server will also synchronize from time to time

----------------------------------Configure mysql read-write separation ---------

-----Configuration on frontend server (192.168.88.101)------------

service firewalld stop
setenforce 0

yum install -y ntpdate
ntpdate 192.168.88.100

echo ' /30 * /usr/sbin/ntpdate 192.168.88.100' >> /var/spool/cron/root
crontab -l
-----------Install JDK------- // amoeba is developed based on java, so the installation requires java environment

tar xf jdk-8u144-linux-x64.tar.gz
cp -rv jdk1.8.0_144/ /usr/local/java

vi /etc/profile //Set environment variables

export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export PATH=$PATH:/usr/local/java/bin
export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib

source /etc/profile

#java -version

java version "1.8.0_144" //The above appears, the java environment is successfully built
...

--------------安装amoeba------https://sourceforge.net/projects/amoeba/files/--

unzip amoeba-mysql-3.0.5-RC-distribution.zip -d /usr/local/
mv /usr/local/amoeba-mysql-3.0.5-RC/ /usr/local/amoeba
chmod -R 755 /usr/local/amoeba/

vi /usr/local/amoeba/jvm.properties

JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss196k -XX:PermSize=16m -XX:MaxPermSize=96m" //Modify 32 lines to the following parameters
JVM_OPTIONS="-server -Xms1024m -Xmx1024m -Xss256k"

------Make amoeba management script-------
vi /etc/init.d/amoeba

#!/bin/bash
#chkconfig: 35 62 62
#
export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
NAME=Amoeba
AMOEBA_BIN=/usr/local/amoeba/bin/launcher
SHUTDOWN_BIN=/usr/local/amoeba/bin/shutdown
PIDFILE=/usr/local/amoeba/Amoeba-MySQL.pid
SCRIPTNAME=/etc/init.d/amoeba

case "$1" in
start)
echo -n "Starting $NAME... "
$AMOEBA_BIN
echo " done"
;;
stop)
echo -n "Stoping $NAME... "
$SHUTDOWN_BIN
echo " done"
;;
restart)
$SHUTDOWN_BIN
sleep 1
$AMOEBA_BIN
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}"
exit 1
;;
esac

chmod +x /etc/init.d/amoeba
chkconfig --add amoeba

service amoeba start
netstat -anpt | grep 8066 //default listening on port 8066

----------------Authorize amoeba in three mysql databases respectively -------

GRANT ALL ON . TO test@'192.168.88.%' IDENTIFIED BY '123.com';

FLUSH PRIVILEGES;

--------On the front-end server----

cd /usr/local/amoeba

vi conf/amoeba.xml
---Line 28-----Set the user name and password used by the client to connect to the amoeba front-end server----
<property name="user">amoeba</property>
---- 30 lines ---------
<property name="password">123456</property>
------------------------- ------------The above configuration is used for client connection username and password-------------

---83-Remove the comment-At the same time, change the default server1 to master, and change the default servers to slaves
<property name="defaultPool">master</property>
<property name="writePool">master</property>
<property name="readPool">slaves</property>

vi conf / dbServers.xml

--26-29--Remove comments--
<property name="user">test</property>

<property name="password">123.com</property>

------主服务器地址---
43 <dbServer name="master" parent="abstractServer">
46 <property name="ipAddress">192.168.80.181</property>

--50-Slave server hostname-
<dbServer name="slave1" parent="abstractServer">
--53-Slave server address-
<property name="ipAddress">192.168.80.182</property>

----Copy related code---
<dbServer name="slave1" parent="abstractServer">
<factoryConfig>

192.168.88.103 192.168.88.104 --- Modify the following two lines--- --end-- slave1,slave2 -----------------------Notice---------------------- test t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) -------------The data written after connecting to the database through the client is only recorded by the master, and then synchronized to the slave - the slave server does not Will record, thus realizing the separation of read and write. ---- insert into zhang values('4','zhang','write_test'); -----You cannot see the newly inserted data on the client amoeba--because synchronization is not enabled----- Only the master server can see the data. select * from zhang; -----After the client starts synchronization, the data on the master server will be synchronized to each slave server, but the data added by the slave server will not be synchronized, only stored locally--- select * from zhang; //Viewing on the client side, you will see the data synchronized from the master and the data added by yourself, but you can't see other things added by yourself.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324747701&siteId=291194637