MYSQL主从复制
yum install ntp -y
时间同步服务
master
vim /etc/ntp.conf
server 127.127.1.0
fudge  127.127.1.0 stratum 8
systemctl start ntpd

slave
yum install ntp ntpdate -y
systemctl start ntpd
ntpdate 192.168.1.151

yum -y install mariadb mariadb-server
systemctl stop firewalld

systemctl start mariadb
mster主服务器配置
yum -y install libaio-devel     #安装liaio 支持I/O
vim /etc/my.cnf
server-id = 1
log-bin=master-bin
log-slave-updates=true
mysql -p1
mysql> grant replication slave on *.* to 'myslave'@'192.168.1.%' identified by '123';
mysql>  flush privileges;

slave1从服务器配置
yum -y install libaio-devel
vim /etc/my.cnf
server-id = 2
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index

slave1从服务器配置
yum -y install libaio-devel
vim /etc/my.cnf
server-id = 3
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index

mysql> change master to master_host='192.168.1.101',master_user='myslave',
master_password='123',master_log_file='master-bin.000003',master_log_pos=472;
mysql> start slave;
mysql> stop slave;
mysql> show slave status\G


关于 Slave_IO_Running: NO 的错误其实有很多原因,在这先说一种

环境:Centos6.7 , MySQL-5.6.25
首先我只安装了一台linux 又克隆了两台,一主两从 , 关键点就在于我是克隆的,才导致了报Slave_IO_Running: NO
原因一:
原因:mysql 有个uuid , 然而uuid 是唯一标识的,所以我克隆过来的uuid是一样的,只需要修改一下uuid 就ok了,找到auto.cnf 文件修改uuid
auto.cnf文件一般在  ./var/lib/mysql/auto.cnf , 如果没有那就用linux 查询命令找:find / -name auto.cnf
vim /usr/local/mysql/data/auto.cnf
mv /usr/local/mysql/data/auto.cnf /usr/local/mysql/data/auto.cnf.bak

amoeba服务
首先安装JDK
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
mv jdk1.6.0_14/ /usr/local/jdk1.6

export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin

source /etc/profile

MYSQL读写分离
mkdir /usr/local/amoeba/
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod 755 /usr/local/amoeba/

Master Slave1 Slave2中开放权限给amoeba访问
grant all on *.* to test@'192.168.1.%' identified by 'test';

vim /usr/local/amoeba/conf/amoeba.xml
30行    <property name="user">amoeba</property>
<property name="password">123456</property>

115行 <property name="defaultPool">master</property>
<property name="writePool">master</property>
<property name="readPool">slaves</property

vim /usr/local/amoeba/conf/dbServers.xml
26行 <property name="user">test</property>
       <property name="password">test</property>


46行开始到最后
<dbServer name="master"  parent="abstractServer">
               <factoryConfig>
                       <!-- mysql ip -->
                       <property name="ipAddress">192.168.1.151</property>
               </factoryConfig>
       </dbServer>


<dbServer name="slave1"  parent="abstractServer">
               <factoryConfig>
                       <!-- mysql ip -->
                       <property name="ipAddress">192.168.1.152</property>
               </factoryConfig>
       </dbServer>

       <dbServer name="slave2"  parent="abstractServer">
               <factoryConfig>
                       <!-- mysql ip -->
                       <property name="ipAddress">192.168.1.153</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>

最后客户端

/usr/local/amoeba/bin/amoeba start
mysql -u amoeba -p123456 -h 192.168.1.10 -P8066


如果是mariadb的情况下要这么改
               <property name="defaultPool">slaves</property>
               <property name="writePool">master</property>
               <property name="readPool">slaves</property>