当前位置:Gxlcms > 数据库问题 > qihoo 360 Atlas Mysql HA方案

qihoo 360 Atlas Mysql HA方案

时间:2021-07-01 10:21:17 帮助过:12人阅读



wget https://github.com/Qihoo360/Atlas/releases/download/sharding-1.0.1/Atlas-sharding_1.0.1-el6.x86_64.rpm


rpm -ivh Atlas-2.2.el6.x86_64_2.rpm
Preparing...                ########################################### [100%]
   1:Atlas                  ########################################### [100%]
[root@dev04 downloads]# ls


rpm包安装后,修改/usr/local/test.cnf


[mysql-proxy]
#带#号的为非必需的配置项目
#管理接口的用户名
admin-username = root
#管理接口的密码
admin-password = 123456
#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 10.1.1.102:3306
#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
proxy-read-only-backend-addresses = 10.1.1.107:3306@1,10.1.1.108:3306@1
#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!
pwds = repluser:Zm3rwtutc2Qa8s/oWZlMvQ==
#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
daemon = true
#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
keepalive = true
#工作线程数,对Atlas的性能有很大影响,可根据情况适当设置
event-threads = 8
#日志级别,分为message、warning、critical、error、debug五个级别
log-level = message
#日志存放的路径
log-path = /usr/local/mysql-proxy/log
#SQL日志的开关,可设置为OFF、ON、REALTIME,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘,默认为OFF
#sql-log = OFF

#慢日志输出设置。当设置了该参数时,则日志只输出执行时间超过sql-log-slow(单位:ms)的日志记录。不设置该参数则输出全部日志。
#sql-log-slow = 10

#实例名称,用于同一台机器上多个Atlas实例间的区分
#instance = test

#Atlas监听的工作接口IP和端口
proxy-address = 0.0.0.0:1234

#Atlas监听的管理接口IP和端口
admin-address = 0.0.0.0:2345
#分表设置,此例中person为库名,mt为表名,id为分表字段,3为子表数量,可设置多项,以逗号分隔,若不分表则不需要设置该项
#tables = person.mt.id.3

#默认字符集,设置该项后客户端不再需要执行SET NAMES语句
#charset = utf8

#允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
#client-ips = 127.0.0.1, 192.168.1

#Atlas前面挂接的LVS的物理网卡的IP(注意不是虚IP),若有LVS且设置了client-ips则此项必须设置,否则可以不设置
#lvs-ips = 192.168.1.1


运行Atlas

进入/usr/local/mysql-proxy/bin目录,执行下面的命令启动、重启或停止Atlas。

(1). sudo ./mysql-proxyd test start,启动Atlas。

(2). sudo ./mysql-proxyd test restart,重启Atlas。

(3). sudo ./mysql-proxyd test stop,停止Atlas。

注意:

(1). 运行文件是:mysql-proxyd(不是mysql-proxy)。

(2). test是conf目录下配置文件的名字,也是配置文件里instance项的名字,三者需要统一。

(3). 可以使用ps -ef | grep mysql-proxy查看Atlas是否已经启动或停止。

执行命令:mysql -h127.0.0.1 -P1234 -u用户名 -p密码,如果能连上则证明Atlas初步测试正常,可以再尝试发几条SQL语句看看执行结果是否正确。

进入Atlas的管理界面的命令:mysql -h127.0.0.1 -P2345 -uuser -ppwd,进入后执行:select * from help;查看管理DB的各类命令。


管理控制台:

mysql -uroot -p123456 -h10.1.1.108 -P2345
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> select * from help;
+----------------------------+---------------------------------------------------------+
| command                    | description                                             |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help         | shows this help                                         |
| SELECT * FROM backends     | lists the backends and their state                      |
| SET OFFLINE $backend_id    | offline backend server, $backend_id is backend_ndx‘s id |
| SET ONLINE $backend_id     | online backend server, ...                              |
| ADD MASTER $backend        | example: "add master 127.0.0.1:3306", ...               |
| ADD SLAVE $backend         | example: "add slave 127.0.0.1:3306", ...                |
| REMOVE BACKEND $backend_id | example: "remove backend 1", ...                        |
| ADD CLIENT $client         | example: "add client 192.168.1.2", ...                  |
| REMOVE CLIENT $client      | example: "remove client 192.168.1.2", ...               |
| SAVE CONFIG                | save the backends to config file                        |
+----------------------------+---------------------------------------------------------+
10 rows in set (0.01 sec)

mysql> select * from backends;
+-------------+-----------------+-------+------+
| backend_ndx | address         | state | type |
+-------------+-----------------+-------+------+
|           1 | 10.1.1.102:3306 | up    | rw   |
|           2 | 10.1.1.107:3306 | up    | ro   |
|           3 | 10.1.1.108:3306 | up    | ro   |
+-------------+-----------------+-------+------+
3 rows in set (0.01 sec)

Slave HA 测试

登陆一个slave机器(107)

mysql> stop slave;

然后使用 mysql -urepluser -preplpass -h10.1.1.108 -P1234 登陆后进行插入

再执行查询,应该是轮训查询两个slave服务器(107和108),由于107关掉了slave同步,所以

结果会显示不同步,再次查询会显示同步(108),这说明负载均衡生效。 


更多参考见 https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md


qihoo 360 Atlas Mysql HA方案

标签:atlas

人气教程排行