Experiment 1 (MySQL master-slave asynchronous replication backup case) environment from a main two
MySQL-master 192.168.200.111
MySQL-slave1 192.168.200.112
MySQL-slave2 192.168.200.113
All servers turn off the firewall
All servers installed yum -y install mariadb mariadb-server
Start mariadb systemctl // start mariadb
Establish time synchronization environment, installation configuration NTP time synchronization server on the primary server
主:yum -y install ntpdate
vim /etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 startum 8
systemctl start ntpd
Modify the configuration file: vim /etc/my.cnf
[mysqld]
server_id=1
log-bin=mysql-binlog
log-slave-updates=true
systemctl restart mariadb
Log in mysql database
To the authorization from the server
MariaDB [(none)]> grant replication slave on *.* to 'slave'@'192.168.200.%' identified by '123123';
MariaDB [(none)]> flush privileges;
Configuring from the server
yum -y install ntpdate
ntpdate
[mysqld]
server-id = 2 # is not the same as the master server from the server-id! , Two from the server-id can not be the same
relay-log = relay-log- bin ## open relay log
relay-log-index = slave- relay-bin.index
systemctl restart mariadb
mysql # MySQL Login
MariaDB [(none)]> change master to master_host='192.168.200.111',master_user='slave',master_password='123123',master_log_file='mysql-binlog.000001',master_log_pos=245;
MariaDB [(none)]> start slave; # Turn on the main replication from
MariaDB [(none)]> show slave status\G;
Test, create a database on 111 to see if written from the server
two. Amoeba achieve MySQL separate read and write
lab environment:
192.168.200.111 MySQL-master
192.168.200.112 MySQL-slave1
192.168.200.113 MySQL-slave2
192.168.200.114 Amoeba
192.168.200.115 Client
MySQL database to achieve the main see above written from a copy method
1. Installing Java environment on Amoeba (recommended installation jdk1.5, or 1.6, is not recommended to install the 1.7 version)
Packages need to have
amoeba-mysql-binary-2.2.0.tar.gz
jdk-6u14-linux-x64.bin
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
All the way to space, enter yes, press Enter to complete
etc. jdk1.6.0_14 / /usr/local/jdk1.6
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export AMOEBA_HOME=/usr/local/amoeba/
export PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile
java -version
View version 1.6 is not
If not rm -rf / usr / bin / java
Installation configuration Amoeba
mkdir /usr/local/amoeba
tar xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
3. Configure amoeba implement mysql-slave1, mysql-slave2 read load balancing
Authorization of amoeba in the three MySQL server
MariaDB [(none)]> grant all on *.* to 'admin'@'192.168.200.%' identified by '123123';
cd /usr/local/amoeba/conf/
MariaDB [(none)]> flush privileges;
Amoeba.xml edit the configuration profile is provided separate read and write
cp amoeba.xml amoeba.xml.bak
vim amoeba.xml
11 <property name = "port"> 8066 </ property> // default port 8066, without modification
30 <property name = "user"> amoeba </ property> // set a user, client access later use
32 <property name = "password"> 123123 </ property> // Set Password
115 <property name = "defaultPool"> master </ property> // default server pool
117 <property name = "writePool"> master </ property> // write server pool
118 <property name = "readPool"> slaves </ property> // read the server pool
There are some comments above <! - ->, he deleted
DbServer.xml edit the configuration file, IP address, set the login and password for the MySQL server users, MySQL server nodes, load-balancing algorithm
cp dbServers.xml dbServers.xml.bak
vim dbServers.xml
20 <property name = "port"> 3306 </ property> // Set MySQL port, the default is 3306
26 <property name = "user"> username admin </ property> // set the access server uses MySQL
29 <property name = "password"> 123123 </ property> // set a password to access the MySQL server used
45 <dbServer name = "master" parent = "abstractServer"> // Set the IP address and MySQL server
48 <property name = "ipAddress"> 192.168.200.111 </ property> // IP address of the primary server MySQL
52 <dbServer name="slave1" parent="abstractServer">
55 <property name = "ipAddress"> 192.168.200.112 </ property> // slave1 IP address from the server
58 <dbServer name="slave2" parent="abstractServer">
61 <property name = "ipAddress"> 192.168.200.113 </ property> // slave 2 IP address from the server
Because there is no slave2 configuration, so the copy slave1 configuration, add and modify
65 <dbServer name = "slaves" virtual = "true"> // server pool
71 <property name = "poolNames"> slave1, slave2 </ property> // previously defined node name server
4. Start amoeba
/usr/local/amoeba/bin/amoeba start &
netstat -lnpt | grep 8066
5. Test
At this point the three main MySQL server from a backup
Create a test table under db_test library and the library mysql-master
MariaDB [(none)]> create database db_test;
MariaDB [db_test]> create table test(id int(10),name varchar(20));
See the library 112 and 113
show databases;
On stopping the primary server 112 and 113 from the backup
MariaDB [(none)]> stop slave;
Add the contents of table 111
MariaDB [db_test]> insert into test values('1','master');
Prior to the synchronization table on the server, it can be directly inserted in the other content from the server manually
On slave1:
MariaDB [(none)]> insert into db_test.test values('2','slave1');
On slave2:
MariaDB [(none)]> insert into db_test.test values('3','slave2');
Read test on the client 115:
yum -y install mariadb
mysql -uamoeba -p123123 -h 192.168.200.114 -P8066
(1) read test
(2) written test:
MySQL [(none)]> insert into db_test.test values('4','clieent');
Check whether to write on the master server:
Completion of the experiment