使用Atlas实现MySQL读写分离+MySQL-(Master-Slave)配置

参考博文:

MySQL-(Master-Slave)配置  本人按照博友北在北方的配置已成功  我使用的是 mysql5.6.27版本。

使用Atlas实现MySQL读写分离  

数据切分——Atlas读写分离Mysql集群的搭建

[转] MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 博文中的数据迁移(主从复制)挺好

 配置中 又进一步对mysql5.6的日志进行了了解 :mysql日志详细解析

 

1.安装

         注意:只能安装在64位的Linux操作系统上,CentOS官方建议rpm安装方式

         获取地址:https://github.com/Qihoo360/Atlas/releases

         目前最新的版本为:

          Atlas-2.2.1.el5.x86_64.rpm                      CentOS 5.*  版本

          Atlas-2.2.1.el6.x86_64.rpm                      CentOS 6.*  版本

安装命令:

         [root@jhq0229 src]# rpm -i Atlas-2.2.1.el6.x86_64.rpm

         

         安装位置:

         /usr/local/mysql-proxy

         配置文件:

         /usr/local/mysql-proxy/conf/test.cnf

2、编写简单Atlas的启动脚本:

[root@jhq0229 ~]# vim /etc/init.d/atlas

#!/bin/sh
#
#atlas:    Atlas Daemon
#
# chkconfig:    - 90 25
# description:  Atlas Daemon
#
# Source function library.
start()
{
        echo -n $"Starting atlas: "
        /usr/local/mysql-proxy/bin/mysql-proxyd test start
        echo 
}
stop()
{
        echo -n $"Shutting down atlas: "
        /usr/local/mysql-proxy/bin/mysql-proxyd test stop
        echo
}
ATLAS="/usr/local/mysql-proxy/bin/mysql-proxyd"
[ -f $ATLAS ] || exit 1
# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 1
                start
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                exit 1
esac
exit 0
授权并加入开机启动
[root@jhq0229 ~]# chmod +x /etc/init.d/atlas
[root@jhq0229 ~]# chkconfig atlas on

启动atlas服务
[root@jhq0229 ~]# service atlas start

 3、注意事项

3.1 主master上的 mysql 重新启动

主master上的 mysql 每重新启动一次  配置在master 上的 “在master上查看 binary log文件名和 position”就会发生改变:如下

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000005 |      276 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
重新启动mysql服务后:
mysql> show master status;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    3
Current database: mysql

+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 |      120 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.08 sec)

这就会导致 从slave上的配置失效,从而导致主-从无法同步:所以每次重新启动 主(master)上的mysql服务都需要修改 从(slave)上的配置。目前只能这么做具体需要怎么改 再研究。

mysql> change master to master_host='192.168.29.128',master_user='repl',master_password='123456',master_port=3306,master_log_file='mysql-bin.000006',master_log_pos=120,master_connect_retry=10;
Query OK, 0 rows affected, 2 warnings (0.30 sec)

 3.2 从slave上的 mysql 重新启动

 从slave上的 mysql 重新启动  会导致 主从配置失效无法完成写同步功能,所以需要重启 mysql服务后 ,重新启动 slave ;

posted @ 2015-10-12 16:03  wuling129  阅读(344)  评论(0编辑  收藏  举报