Deploy amoeba on CentOS 7 for MySQL master-slave synchronization, read/write separation, load balancing high availability cluster

Source: Internet
Author: User
Tags mysql client

Experiment Description

This experiment requires four hosts to install MySQL, a deployment amoeba, a primary database server, two from the database server, also need a host to do client access testing, the end of this experiment can realize the primary database server and from the database server synchronization between data, read and write separation (client read from the server data, The data that is written is stored on the primary server, and the primary server is then synchronized to the slave server for load balancing.

Experimental topology

Experimental environment

Experiment Step one, Master Sync time 1, master install NTP
yum install ntp -y
2. Modify the NTP configuration file
vim /etc/ntp.conf
#空白处插入如下内容server 127.127.10.0        //本地是时钟源//fudge 127.127.10.0 stratum 8     //设置时间层级为8(限制在15内)
3. Turn on NTPD service, turn off firewall and security features
systemctl start ntpd.service systemctl stop firewalld.service setenforce 0
4. Two databases also install NTP from the server
yum install ntp ntpdate -y
5. Turn on NTPD service, turn off firewall and security function, and synchronize time
systemctl start ntpd.service systemctl stop firewalld.service setenforce 0/usr/sbin/ntpdate 192.168.10.157    //进行时间同步,此处是MasterIP地址
Second, the master-slave three servers install MySQL at the same time, the specific process can refer to my previous blog, where the installation process omitted three, master-slave database server configuration 1, edit Master master configuration file
vim /etc/my.cnf
server-id       = 11      log-bin=master-bin      //主服务器日志文件//log-slave-updates=true       //从服务器更新二进制日志//
Restart database
systemctl restart mysqld.service
2. Enter MySQL database
mysql
GRANT REPLICATION SLAVE ON *.* TO ‘myslave‘@‘192.168.10.%‘ IDENTIFIED BY ‘123456‘;   //为从数据库服务器同步创建用户FLUSH PRIVILEGES;     //立即生效show master status;          //查看主数据库服务器状态+-------------------+----------+--------------+------------------+| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |+-------------------+----------+--------------+------------------+| master-bin.000001 |      569 |              |                  |+-------------------+----------+--------------+------------------+1 row in set (0.00 sec)

3. Edit the master configuration file from the server database
server-id       = 22     //两台从服务器id一样relay-log=relay-log-bin         //从主服务器上同步日志文件记录到本地//relay-log-index=slave-relay-bin.index       //定义relay-log的位置和名称//
4. Enter the database
mysql
change master to master_host=‘192.168.10.159‘,master_user=‘myslave‘,master_password=‘123456‘,master_log_file=‘master-bin.000001‘,master_log_pos=569;   //向主服务器同步数据start slave;   //开启同步show slave status\G;     //查看状态,这里需要两个yes才可同步,缺一不可

5. Verify Master-Slave synchronization
#主服务器上新建数据库create database xxy;#从服务器上查看show databases;

Master

Slave1

Slave2

Iv. Amoeba Server Configuration 1, turn off firewall and security features
systemctl stop firewalld.servicesetenforce 0
2. Copy the JDK package to the/usr/local directory and execute the
cp jdk-6u14-linux-x64.bin /usr/local/./jdk-6u14-linux-x64.bin#一直回车,直到需要输入的时候输入yes再回车
3. Rename the Unpacked JDK folder
mv jdk1.6.0_14/ jdk1.6
4. Edit/etc/profire, add jdk, JRE, amoeba environment variables
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/libexport PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/binexport AMOEBA_HOME=/usr/local/amoebaexport PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile   //重新加载环境变量立即生效
5. Create the Amoeba folder in the/usr/local directory
mkdir /usr/local/amoeba
6. Extract the amoeba package to the folder you just created and add permissions
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/chmod -R 755 /usr/local/amoeba/
7. Running Amoeba
/usr/local/amoeba/bin/amoeba#显示amoeba start|stop说明安装成功

8. Add permissions on three MySQL servers open to amoeba access
grant all on *.* to [email protected]‘192.168.10.%‘ identified by ‘123.com‘;
9, back to the amoeba server, modify the amoeba configuration file
vim /usr/local/amoeba/conf/amoeba.xml---30行-- <property name="user">amoeba</property>----32行--------- <property name="password">123456</property>---117-去掉注释- <property name="defaultPool">master</property> <property name="writePool">master</property> <property name="readPool">slaves</property>


vi conf/dbServers.xml--26-29--去掉注释-- <property name="user">test</property> <property name="password">123.com</property>-----42-主服务器地址---<dbServer name="master"  parent="abstractServer"> <property name="ipAddress">192.168.10.161</property>--52-从服务器主机名-<dbServer name="slave1"  parent="abstractServer">--55-从服务器地址- <property name="ipAddress">192.168.10.162</property> --复制再添加--<dbServer name="slave2"  parent="abstractServer"> <property name="ipAddress">192.168.10.165</property> <dbServer name="slaves" virtual="true"> <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">--末尾--<property name="poolNames">slave1,slave2</property> </poolConfig>


10. Open Amoeba
/usr/local/amoeba/bin/amoeba start& netstat -anpt | grep java

V. Test client Host Configuration 1, install the MySQL client and log in
yum install -y mysqlmysql -u amoeba -p123456 -h 192.168.10.157 -P8066

Vi. Test 1, the client can see the XXY database created earlier

2. Verifying load Balancing
#从服务器关闭同步stop slave;#主服务器添加内容insert into zang values(‘1‘,‘zhang‘,‘this_is_master‘);#从服务器则不会同步添加的内容#在两台从上分别添加如下内容Slave1:use xxy;insert into zang values(‘2‘,‘zhang‘,‘this_is_slave1‘);Slave2:use xxy;insert into zang values(‘3‘,‘zhang‘,‘this_is_slave2‘);#在客户端上测试----第一次会向从服务器1读数据-第二次会各从2读取select * from zang;

Master

Slave1

Slave2

Client

3. Verify read/write separation
#在通过客户端连接数据库后写入的数据只有主会记录,然后同步给从-从服务器不会记录,从而实现了读写分离。#在客户端写入如下一条记录insert into zang values(‘5‘,‘zhang‘,‘write_test‘);#从服务器看不到新插入的数据,因为同步没有开启,只有主服务器上有数据。select * from zang;

Client

Master

Slave1

Slave2

Deploy amoeba on CentOS 7 for MySQL master-slave synchronization, read and write separation, load balancing high availability clusters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.