如果对数据库的读和写都在同一个数据库中,对其压力太大,而且不能保证其安全性和高可用等
简单来说就是在主服务器上写,在从上面读
常见的方案
实验
#准备四台虚拟机10(master),11(slave),12(slave),13(Amoeba) #Amoeba基于jbk开发 chmod +x jbx-6u31-linux-x64.bin #在13中给jbk权限,保证前提 ./jbk... mv jbk /usr/local/jbk #给jbk位置方便配置变量 vim /etc/profile #配置jbk变量和amoeba变量 export JAVA_HOME=/usr/local/jbk export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$PATH:$JAVE_HOME/lib:$JAVE_HOME/jre/bin:$HOME/bin export AMOEBA_HOME=/usr/local/amoeba export PATH=$PATH:$AMOEBA_HOME/bin jave -version #查看Java是否报错和版本 mkdir /usr/local/amoeba #安装配置amoeba tar xf amoeba... -C /usr/local/amoeba chmod -R 775 /usr/local/amoeba #10,11,12配置Amoeba的访问授权 MariaDB[(nome)]>grant on **.* to 'test'@'192.168.200.%' identified by '123123'; flush privileges; cp /usr/local/amoeba/conf/amoeba.xml{,.bak} #编译Amoeba配置文件 vim /usr/local/amoeba/conf/amoeba.xml <property name="user">amoeba</property> <property name="password">123456</property> <property name="defaultPool">master</property> <property name="writePool">master</property> <property name="readPool">slaves</property> cp /usr/local/amoeba/conf/dbServers.xml{,.bak} #编译dbServers配置文件 vim /usr/local/amoeba/conf/dbServers.xml #启动Amoeba默认端口8066:13号 nohup /usr/local/amoeba/bin/amoeba start & #在一台新机器上启动mariadb连接13 mysql -uamoeba -p123456 -h192.168.200.13 -P8066 #在Mysql主服务器上创建一个表,会自动同步到各个从服务器上,然后关掉各个从服务器上的Slave功能,在分别插入语句测试。 #在10中创建一个库,在新机器上查看11,12的库
<!-- mysql port --> <property name="port">3306</property> <!-- mysql schema --> <property name="schema">test</property> <!-- mysql user --> <property name="user">test</property> <!-- mysql password --> <property name="password">123.com</property> <dbServer name="master" parent="abstractServer"> <factoryConfig> <property name="ipAddress">192.168.200.111</property> </factoryConfig> </dbServer> <dbServer name="slave1" parent="abstractServer"> <factoryConfig> <property name="ipAddress">192.168.200.112</property> </factoryConfig> </dbServer> <dbServer name="slave2" parent="abstractServer"> <factoryConfig> <property name="ipAddress">192.168.200.113</property> </factoryConfig> </dbServer> <dbServer name="slaves" virtual="true"> <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool"> <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA--> <property name="loadbalance">1</property> <!-- Separated by commas,such as: server1,server2,server1 --> <property name="poolNames">slave1,slave2</property> </poolConfig> </dbServer>