mysql讀寫分離

搭建一個主從複製服務器:192.168.200.111(master) 192.168.200.112 (slave1)192.168.200.113(slave2)java

AMOEBA服務器:192.168.200.114mysql

關閉防火牆linux

[root@localhost ~]# systemctl stop firewalldsql

[root@localhost ~]# setenforce 0vim

[root@localhost ~]# iptables -F
上傳jdk-6u14-linux-x64.bin包
[root@localhost ~]# chmod +x jdk-6u14-linux-x64.bin
[root@localhost ~]# ./jdk-6u14-linux-x64.bin
[root@localhost ~]# mv jdk1.6.0_14/ /usr/local/java
[root@localhost ~]# vim /etc/profile
添加五行:
export JAVA_HOME=/usr/local/java
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
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mkdir /usr/local/amoeba
[root@localhost ~]# tar fx amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
[root@localhost ~]# chmod -R 755 /usr/local/amoeba/
[root@localhost ~]# /usr/local/amoeba/bin/amoeba
amoeba start|stop //出現此行用法說明,證實配置無誤。
若是出現一下信息表示錯誤:
The stack size specified is too small, Specify at least 160k
Could not create the Java virtual machine.
解決方法:
[root@localhost ~]# vim /usr/local/amoeba/bin/amoeba
修改58行:
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k" --> DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"服務器

[root@localhost ~]# cd /usr/local/amoeba/conf
[root@localhost conf ]# cp amoeba.xml amoeba.xml.bak
[root@localhost conf ]# vim amoeba.xml
修改以下幾行:
30 <property name="user">amoeba</property>
32 <property name="password">123456</property>
115 <property name="defaultPool">master</property>
117 <property name="writePool">master</property>
118 <property name="readPool">slaves</property>
[root@localhost conf ]# vim dbServers.xml
20 <property name="port">3306</property>
26 <property name="user">admin</property>
28 <property name="password">123</property>
43 <dbServer name="master" parent="abstractServer">
46 <property name="ipAddress">192.168.200.111</property
50 <dbServer name="slave1" parent="abstractServer">
53 <property name="ipAddress">192.168.200.112</property>
57 <dbServer name="slave2" parent="abstractServer">
58 <factoryConfig>
59 <!-- mysql ip -->
60 <property name="ipAddress">192.168.200.113</property>
61 </factoryConfig>
62 </dbServer>
64 <dbServer name="slaves" virtual="true">
70 <property name="poolNames">slave1,slave2</property>
[root@localhost conf ]# nohup /usr/local/amoeba/bin/amoeba start &
[root@localhost ~]# netstat -anpt | grep java
tcp6 0 0 127.0.0.1:36539 :::* LISTEN 20222/java
tcp6 0 0 :::8066 :::* LISTEN 20222/java負載均衡

客戶端:192.168.200.115tcp

       此時三臺mysql服務器是主從備份的,在mysql-master中建立db_test庫及該庫下的test表,
而後能夠在mysql-slave1和mysql-slave2上能夠查看該庫和表。
       在mysql-slave1和mysql-slave2上中止主從備份。
       在master、slave一、slave2上添加不一樣的表內容。
       在客戶機上進行讀測試時,發現它以輪詢的方式讀取到slave1和slave2的不一樣的內容,進行
寫測試時,它會將寫的內容寫到master中。
       至此,能夠驗證amoeba實現了mysql的讀寫分離,寫入數據僅會寫入到mysql_master中,
而讀取數據時,則以輪詢的方式從slave1,slave2兩臺服務器上讀取數據,實現負載均衡。測試

相關文章
相關標籤/搜索