OneProxy :: 实现拖延了几个月的功能,动态增加用户避免重起中间件!

OneProxy里有众多的配置项,使用”oneproxy –help-all”查看命令行选项已经有108个了,绝大部份已经可以在管理端口动态进行配置,但这并不包括新增一个用户到OneProxy里(缺少这个功能曾让几个用户有点小伤心),现在请你升级到6.0.0版本吧。

以如下配置文件为例,起初只配置了一个用户,并实现了读写分离。如下所示:

proxy-user-list  = test/1378F6CC3A8E8A43CA388193FBED5405982FBBD3@test

也就是说只有test用户能连接到OneProxy,当我们需要新增用户时,仍需要更改配置新增用户,参数文件如下所示:

proxy-user-list.1  = test/1378F6CC3A8E8A43CA388193FBED5405982FBBD3@test
proxy-user-list.2  = test2/1378F6CC3A8E8A43CA388193FBED5405982FBBD3@test

在6.0.0新版本里无须重起OneProxy,可以先在MySQL的主节点中创建新用户,如下所示:

create user 'test2'@'%' identified by 'test';
grant all on test.* to 'test2'@'%';
flush privileges;

在验证MySQL的连接没有问题后,可以登录到管理端口,进行动态用户添加。如下所示:

mysql> passwd 'test';
+------+------------------------------------------+
| TEXT | PASSWORD                                 |
+------+------------------------------------------+
| test | 1378F6CC3A8E8A43CA388193FBED5405982FBBD3 |
+------+------------------------------------------+
1 row in set (0.00 sec)

mysql> add user 'test2/1378F6CC3A8E8A43CA388193FBED5405982FBBD3@test';
Query OK, 0 rows affected (0.00 sec)

接下来就可以测试用test2来连接OneProxy了,如下所示:

[root@rh4srv1 oneproxy]# mysql -u test2 -ptest -h127.0.0.1 -P3307
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 109
Server version: 5.6.31 OneProxy-Enterprise-6.0.0 (OneXSoft)

Copyright (c) 2000, 2016, 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> show tables;
+----------------+
| Tables_in_test |
+----------------+
| my_hash_0      |
| my_hash_2      |
| my_hash_4      |
+----------------+
3 rows in set (0.00 sec)

当然动态配置,并不能自动更新配置文件,还需要手工修改配置文件,将新增用户添加到配置文件中以实现持久化配置。在这个过程中无须重起OneProxy,减少了对应用的影响。