atlas------------360改写的mysql-proxy


atlas读写分离: 更充分的利用硬件资源: 生产建议单独机器,这里暂时放到从库manager节点 rpm -ivh Atlas-2.2.1.el6.x86_64.rpm (兼容6系统的包) (一般配合mha来用) 配置: cd /usr/local/mysql-proxy/conf mv test.cnf test.cnf.bak vi test.cnf [mysql-proxy] admin-username = user admin-password = pwd proxy-backend-addresses = vip:3306(主库所在) proxy-read-only-backend-addresses = 读库1:3306,读库2:3306 pwds = dafu:3yb5jEku5h4=,mha:O2jBXONX098= daemon = true keepalive = true event-threads = 8 log-level = message log-path = /usr/local/mysql-proxy/log sql-log=ON proxy-address = 0.0.0.0:33060 admin-address = 0.0.0.0:2345 charset=utf8

【注意】配置文件pwds=那一行

用户名是授权的可以用远程登录的用户名

密码是经过加密后的密码

加密后的密码需要在/usr/local/mysql-proxy/bin/ 下的程序 encrypt中获得

例如 我用户 dafu 的密码是123456

那么我需要执行 ./encrypt 123456

得到的结果就是加密后的密码 在配置文件中就填这个密码 (前面的/不用)

启动atlas /usr/local/mysql-proxy/bin/mysql-proxyd test(配置文件前缀) start ps -ef |grep proxy

测试读写分离的功能: 测试读操作:

mysql -umha -pmha -h 从库manager所在ip -P 33060

mysql>select @@server_id; 会发现轮询读操作。 测试写操作: mysql> begin;select @@server_id;commit; 用事务测试读写落点。 注意: DDL建议不要再Atlas触发,最好是到主库触发(Online DDL或者PT-OSC)。 DML建议begin; DML; commit;

Atlas 的管理操作 [root@db03 conf]# mysql -uuser -ppwd -h 10.0.0.53 -P2345

db03 [(none)]>select * from help;

4.1 查看所有节点 db03 [(none)]>SELECT * FROM backends;

+-------------+----------------+-------+------+

| backend_ndx | address | state | type |

+-------------+----------------+-------+------+

| 1 | 10.0.0.55:3306 | up | rw |

| 2 | 10.0.0.52:3306 | up | ro |

| 3 | 10.0.0.53:3306 | up | ro |

+-------------+----------------+-------+------+

3 rows in set (0.00 sec)

4.2 节点的上线和下线 db03 [(none)]>SET OFFLINE 1;

+-------------+----------------+---------+------+

| backend_ndx | address | state | type |

+-------------+----------------+---------+------+

| 1 | 10.0.0.55:3306 | offline | rw |

+-------------+----------------+---------+------+

1 row in set (0.01 sec)

db03 [(none)]>SELECT * FROM backends;

+-------------+----------------+---------+------+

| backend_ndx | address | state | type |

+-------------+----------------+---------+------+

| 1 | 10.0.0.55:3306 | offline | rw |

| 2 | 10.0.0.52:3306 | up | ro |

| 3 | 10.0.0.53:3306 | up | ro |

+-------------+----------------+---------+------+

db03 [(none)]>SET ONLINE 1;

+-------------+----------------+---------+------+

| backend_ndx | address | state | type |

+-------------+----------------+---------+------+

| 1 | 10.0.0.55:3306 | unknown | rw |

+-------------+----------------+---------+------+

4.3 删除和添加节点 db03 [(none)]>REMOVE BACKEND 3; db03 [(none)]>ADD SLAVE 10.0.0.53:3306; 从库用的比较多。(以上操作都是临时性的) 4.4 用户管理 主库[(none)]>grant all on . to oldliu@'%' identified by '123'; 从库阿特拉斯所在[(none)]>SELECT * FROM pwds;查看用户 从库阿特拉斯所在[(none)]>add pwd oldliu:123; (将主库授权的用户放到阿特拉斯) 密码加密: /usr/local/mysql-proxy/bin/encrypt 密码 add enpwd oldliu:3yb5jEku5h4= 4.5 持久化配置文件 从库阿特拉斯所在[(none)]>save config;