mysql主从备份案例—读写分离(异步主从)

徘徊边缘 提交于 2019-12-01 10:07:18

主备配置

主:MySQL 192.168.200.115

从:MySQL 192.168.200.116

从:MySQL 192.168.200.113

 

 

主:  yum -y install ntp

cp -p /etc/ntp.conf /etc/ntp.conf/origin

vim /etc/ntp.conf--------------------------

server 127.127.1.0

fudge 127.127.1.0 startum 8-------------------

/etc/init.d/ntpd start

chkconfig ntpd on

从:yum -y install ntpdate

ntpdate 192.168.200.115

------------------------------------------------------------------------------------------------------------------

主:

vim /etc/my.cnf---------------------------

server-id = 1
log-bin=mysql-bin
log-slave-updates=true-------------------------------

重启 /etc/init.d/mysqld restart

进入mysql

 

grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123123';

flush privileges;

-------------------------------------------------------------------------------------------

show master staus;

从:

vim /etc/my.cnf

server-id = 2
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index

重启 mysql

进入mysql

>stop slave;

>change master to master_host='192.168.200.115',master_user='myslave',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=477;

>start slave;

>show slave status;

--------------------------------------------------------------第二台同上,改一下my.cnf就好

到此,做完

==================================================================

再开一台amoeba

rz 传jdk1.6   和  amoeba-mysql-binary-2.2.0.tar.gz

chmod +x jdk...............

./jdk................

mv jdk....../ /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/lib
export AMOEBA_HOME=/usr/local/amoeba/
export PATH=$PATH:$AMOEBA_HOME/bin

-------------------------------------------------------------------

rm rf /usr/local/java

source /etc/profile

java -version

 

mkdir  /usr/local/amoeba

tar xf amoeba................ -C /usr/local/amoeba/

chmod -R 755 /usr/local/amoeba/

/usr/local/amoeba/bin/amoeba

------------------------------------------------------------------------

在另外三台Mysql 授权

 grant all on *.* to 'admin'@'192.168.200.%' identified by '123123';

flush privileges;

--------------------------------------------------------------------------------------

amoeba机上

cd /usr/local/amoeba/conf

vim amoeba.xml------------------------------------------------------------------

                                        <property name="user">amoeba</property>
                                        <property name="password">123456</property>
             <property name="LRUMapSize">1500</property>
                        <property name="defaultPool">master</property>

                    <property name="writePool">master</property>  
                      <property name="readPool">slaves</property>

--------------------------------------------------------------------------------------------------------

vim dbServers.xml-------------------------------------------------------------------------------------

 <property name="user">admin</property>
                        <!--  mysql password -->
                        <property name="password">123</property>
 
 <dbServer name="master"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.200.115</property>
                </factoryConfig>
        </dbServer>
        <dbServer name="slave1"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.200.116</property>
                </factoryConfig>
        </dbServer>
<dbServer name="slave2"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.200.113</property>
                </factoryConfig>
        </dbServer>
<dbServer name="slaves" virtual="true">
 <property name="poolNames">slave1,slave2</property>
-----------------------------------------------------------------------------------------------------------------
/usr/local/amoeba/bin/amoeba start &

jobs

netstat -anpt|grep java

=======================================================结束

测试

在mysql 里创建库表

不断查看另外两台从mysql 对主的获取库表信息

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!