Atlas安装部署---读写分离

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

上海阿丽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值