1、安装依赖包
tar zxf libffi-3.0.11-rc2.tar.gz
cd libffi-3.0.11-rc2
mkdir /usr/local/libffi
./configure --prefix=/usr/local/libffi/
make
make install
xz -d glib-2.32.4.tar.xz
tar xf glib-2.32.4.tar
cd glib-2.32.4
mkdir /usr/local/glib
./configure --prefix=/usr/local/glib/ LIBFFI_CFLAGS="/usr/local/libffi/lib -lm -ldl" LIBFFI_LIBS="/usr/local/libffi/lib/libffi.la"
make
make install
cp /usr/local/glib/lib/glib-2.0/include/glibconfig.h /usr/local/glib/include/glib-2.0/
2、安装atlas
unzip Atlas-master.zip
cd Atlas-master
./configure LDFLAGS="-L/home/mariadb/product/10.1/mariadb-1/lib -ldl -lcrypto" \
LUA_CFLAGS="/usr/local/lua/bin/lua -I/usr/local/lua/include" LUA_LIBS="/usr/local/lua/lib/liblua.a" \
--prefix=/usr/local/atlas --with-lua --with-mysql=/home/mariadb/product/10.1/mariadb-1 \
GLIB_CFLAGS="/usr/local/glib/bin/gdbus -I/usr/local/glib/include/glib-2.0" \
GLIB_LIBS="/usr/local/glib/lib/libglib-2.0.la" \
GMODULE_CFLAGS="/usr/local/glib/bin/gdbus -I/usr/local/glib/include/glib-2.0" \
GMODULE_LIBS="/usr/local/glib/lib/libgmodule-2.0.la" \
GTHREAD_CFLAGS="/usr/local/glib/bin/gdbus -I/usr/local/glib/include/glib-2.0" \
GTHREAD_LIBS="/usr/local/glib/lib/libgthread-2.0.la"
make
make install
说明:安装atlas要求glib2.32及以上版本,而glib2.32则需要安装libffi3.0及以上版本。由于两上版本分别为2.28、2.8,所以重新安装。
3、配置
授权
mysql> grant all privileges on test.* to proxy@'%' identified by '123456';
加密密码
/usr/local/atlas/bin/encrypt 123456
/iZxz+0GRoA=
配置文件
vi /usr/local/atlas/conf/aone.cnf
[mysql-proxy]
admin-username = admin
admin-password = 123456
pwds = proxy:/iZxz+0GRoA=
<pre name="code" class="html">proxy-backend-addresses = 10.128.11.90:3308
proxy-read-only-backend-addresses =10.128.11.90:3309
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/atlas/log
sql-log = OFF
sql-log-slow = 10
instance = aone
proxy-address = 0.0.0.0:3316
admin-address = 0.0.0.0:3315
charset = utf8
#tables
#client-ips
#lvs-ips
说明:
1)配置文件名与参数instance保持一致,即同为aone
2)安装不是在/usr/local/mysql-proxy,则修改启动文件/usr/lcoal/atlas/bin/mysql-proxyd为自己的安装目录即可,proxydir=/usr/local/atlas
3)主从在一台服务器上,端口分别为3308、3309
4、启动
/usr/local/atlas/bin/mysql-proxyd aone start
5、连接,验证读写分离
mysql -uroot -p123456 --protocol=tcp -P3309
MariaDB[(none)]> stop slave;
mysql -uproxy -p123456 --protocol=tcp -P3316
MySQL [(none)]> use test
MySQL [test]> select * from tb1;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 1 | b |
| 2 | c |
| 3 | d |
| 4 | e |
| 5 | f |
+------+------+
MySQL [test]> insert into tb1 values(6,'g');
Query OK, 1 row affected (0.00 sec)
MySQL [test]> select * from tb1;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 1 | b |
| 2 | c |
| 3 | d |
| 4 | e |
| 5 | f |
+------+------+
mysql -uroot -p123456 --protocol=tcp -P3308
MariaDB[(none)]> select * from test.tb1;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 1 | b |
| 2 | c |
| 3 | d |
| 4 | e |
| 5 | f |
| 6 | g |
+------+------+
mysql -uroot -p123456 --protocol=tcp -P3309
MariaDB[(none)]> select * from test.tb1;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 1 | b |
| 2 | c |
| 3 | d |
| 4 | e |
| 5 | f |
+------+------+
6、查看atlas日志
2016-04-22 09:23:08: (message) proxy listening on port 0.0.0.0:3316
2016-04-22 09:23:08: (message) added read/write backend: 10.128.11.90:3308
2016-04-22 09:23:08: (message) added read-only backend: 10.128.11.90:3309
2016-04-22 09:23:08: (message) chassis-event-thread.c:235: starting 8 threads
2016-04-22 09:25:16: (message) chassis-unix-daemon.c:138: [angel] we try to keep PID=27479 alive
2016-04-22 09:25:16: (message) mysql-proxy 0.8.2 started - instance: aone
2016-04-22 09:25:16: (message) proxy listening on port 0.0.0.0:3316
2016-04-22 09:25:16: (message) added read/write backend: 10.128.11.90:3308
2016-04-22 09:25:16: (message) added read-only backend: 10.128.11.90:3309
2016-04-22 09:25:16: (message) chassis-event-thread.c:235: starting 8 threads
7、连接管理口
mysql -uadmin -p123456 --protocol=tcp -P3315
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 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", ... |
| SELECT * FROM clients | lists the clients |
| ADD CLIENT $client | example: "add client 192.168.1.2", ... |
| REMOVE CLIENT $client | example: "remove client 192.168.1.2", ... |
| SELECT * FROM pwds | lists the pwds |
| ADD PWD $pwd | example: "add pwd user:raw_password", ... |
| ADD ENPWD $pwd | example: "add enpwd user:encrypted_password", ... |
| REMOVE PWD $pwd | example: "remove pwd user", ... |
| SAVE CONFIG | save the backends to config file |
| SELECT VERSION | display the version of Atlas |
+----------------------------+---------------------------------------------------------+
MySQL [(none)]> SELECT VERSION ;
+---------+
| version |
+---------+
| 2.2.2 |
+---------+
MySQL [(none)]> select * from backends;
+-------------+-------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+-------------------+-------+------+
| 1 | 10.128.11.90:3308 | up | rw |
| 2 | 10.128.11.90:3309 | up | ro |
+-------------+-------------------+-------+------+
参考:http://www.mamicode.com/info-detail-556437.html