1.下载proxySQL,我用的是rpm安装
https://www.percona.com/downloads/proxysql/
2.安装ProxySQL
[root@qht134 home]# rpm -ivh proxysql-1.4.7-1.1.el6.x86_64.rpm
warning: proxysql-1.4.7-1.1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing... ########################################### [100%]
1:proxysql ########################################### [100%]
可能遇到的问题:
[root@qht131 home]# rpm -ivh proxysql-1.4.7-1.1.el6.x86_64.rpm
warning: proxysql-1.4.7-1.1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
error: Failed dependencies:
libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by proxysql-1.4.7-1.1.el6.x86_64
libcrypto.so.10(libcrypto.so.10)(64bit) is needed by proxysql-1.4.7-1.1.el6.x86_64
libssl.so.10(libssl.so.10)(64bit) is needed by proxysql-1.4.7-1.1.el6.x86_64
通过 yum安装libssl还是报错,最后yum install update更新了所有的内核包后居然可以安装正常了。
3.启动proxysql:
[root@qht134 home]# proxysql --help
High Performance Advanced Proxy for MySQL
USAGE: proxysql [OPTIONS]
OPTIONS:
-c, --config ARG Configuraton file
-D, --datadir ARG Datadir
-e, --exit-on-error Do not restart ProxySQL if crashes
-f, --foreground Run in foreground
-h, -help, --help, --usage Display usage instructions.
-M, --no-monitor Do not start Monitor Module
-n, --no-start Starts only the admin service
-r, --reuseport Use SO_REUSEPORT
-S, --admin-socket ARG Administration Unix Socket
-V, --version Print version
--idle-threads Create auxiliary threads to handle idle connections
--initial Rename/empty database file
--reload Merge config file into database file
--sqlite3-server Enable SQLite3 Server
[root@qht134 home]# ps -ef | grep proxysql
root 18815 1 0 23:16 ? 00:00:00 proxysql
root 18816 18815 0 23:16 ? 00:00:00 proxysql
root 18840 2865 0 23:17 pts/0 00:00:00 grep proxysql
[root@qht134 /]# service proxysql status
ProxySQL is running (18815).
proxysql安装好后就直接是启动的状态
那他的配置文件在哪里?
[root@qht134 /]# find -name 'proxy*'
./usr/bin/proxysql-status
./usr/bin/proxysql
./usr/bin/proxy
./usr/bin/proxysql_galera_checker
./usr/bin/proxysql_node_monitor
./usr/bin/proxysql-admin
./usr/share/doc/m2crypto-0.20.2/demo/x509/proxy_init.py
./usr/share/doc/m2crypto-0.20.2/demo/x509/proxy_info.py
./usr/share/doc/m2crypto-0.20.2/demo/x509/proxylib.py
./usr/share/doc/m2crypto-0.20.2/demo/x509/proxy_destroy.py
./usr/share/doc/proxysql-1.4.7
./usr/share/man/man8/proxymap.8.gz
./usr/libexec/sssd/proxy_child
./usr/libexec/postfix/proxymap
./usr/lib/python2.6/site-packages/nose/proxy.py
./usr/lib/python2.6/site-packages/nose/proxy.pyo
./usr/lib/python2.6/site-packages/nose/proxy.pyc
./usr/lib/python2.6/site-packages/scservices/dbus/proxy
./proc/sys/net/ipv4/neigh/default/proxy_qlen
./proc/sys/net/ipv4/neigh/default/proxy_delay
./proc/sys/net/ipv4/neigh/lo/proxy_qlen
./proc/sys/net/ipv4/neigh/lo/proxy_delay
./proc/sys/net/ipv4/neigh/eth3/proxy_qlen
./proc/sys/net/ipv4/neigh/eth3/proxy_delay
./proc/sys/net/ipv4/conf/all/proxy_arp
./proc/sys/net/ipv4/conf/all/proxy_arp_pvlan
./proc/sys/net/ipv4/conf/default/proxy_arp
./proc/sys/net/ipv4/conf/default/proxy_arp_pvlan
./proc/sys/net/ipv4/conf/lo/proxy_arp
./proc/sys/net/ipv4/conf/lo/proxy_arp_pvlan
./proc/sys/net/ipv4/conf/eth3/proxy_arp
./proc/sys/net/ipv4/conf/eth3/proxy_arp_pvlan
./proc/sys/net/ipv6/neigh/default/proxy_qlen
./proc/sys/net/ipv6/neigh/default/proxy_delay
./proc/sys/net/ipv6/neigh/eth3/proxy_qlen
./proc/sys/net/ipv6/neigh/eth3/proxy_delay
./proc/sys/net/ipv6/neigh/lo/proxy_qlen
./proc/sys/net/ipv6/neigh/lo/proxy_delay
./proc/sys/net/ipv6/conf/all/proxy_ndp
./proc/sys/net/ipv6/conf/default/proxy_ndp
./proc/sys/net/ipv6/conf/eth3/proxy_ndp
./proc/sys/net/ipv6/conf/lo/proxy_ndp
./var/run/proxysql
./var/spool/postfix/private/proxywrite
./var/spool/postfix/private/proxymap
./var/lib/proxysql
./var/lib/proxysql/proxysql.pid
./var/lib/proxysql/proxysql_stats.db
./var/lib/proxysql/proxysql.log
./var/lib/proxysql/proxysql.db
./etc/proxysql.cnf
./etc/proxysql-admin.cnf
./etc/logrotate.d/proxysql-logrotate
./etc/rc.d/init.d/proxysql
./home/proxysql-1.4.7-1.1.el6.x86_64.rpm
可以看到比较重要的文件,比如文件放在/etc/*.cnf,安装好的数据文件,以及log,pid都放在/var/lib/proxysql下面。
4.登陆proxysql,通过端口6032可以直接登入到proxysql来配置参数
[root@qht134 home]# mysql -uadmin -padmin -h 127.0.0.1 -P6032
mysql: [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.5.30 (ProxySQL Admin Module)
Copyright (c) 2000, 2018, 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 databases;
+-----+---------------+-------------------------------------+
| seq | name | file |
+-----+---------------+-------------------------------------+
| 0 | main | |
| 2 | disk | /var/lib/proxysql/proxysql.db |
| 3 | stats | |
| 4 | monitor | |
| 5 | stats_history | /var/lib/proxysql/proxysql_stats.db |
+-----+---------------+-------------------------------------+
5 rows in set (0.00 sec)
mysql> show tables;
+--------------------------------------------+
| tables |
+--------------------------------------------+
| global_variables |
| mysql_collations |
| mysql_group_replication_hostgroups |
| mysql_query_rules |
| mysql_query_rules_fast_routing |
| mysql_replication_hostgroups |
| mysql_servers |
| mysql_users |
| proxysql_servers |
| runtime_checksums_values |
| runtime_global_variables |
| runtime_mysql_group_replication_hostgroups |
| runtime_mysql_query_rules |
| runtime_mysql_query_rules_fast_routing |
| runtime_mysql_replication_hostgroups |
| runtime_mysql_servers |
| runtime_mysql_users |
| runtime_proxysql_servers |
| runtime_scheduler |
| scheduler |
+--------------------------------------------+
20 rows in set (0.00 sec)
等等,我有点晕,这然道真的不是登入到mysql数据库吗?
真的很像,这样上手这个软件就更加没有难度了。
5.小试牛刀,用proxysql登入数据库试一下
5.1在数据库端创建Proxysql登入的用户:
以下sql是目标数据库中执行的
mysql> CREATE USER 'proxysql'@'%' IDENTIFIED BY 'proxysql';
Query OK, 0 rows affected (0.41 sec)
mysql> grant usage on *.* to 'proxysql'@'%';
Query OK, 0 rows affected (0.03 sec)
mysql> create user 'sbuser'@'%' IDENTIFIED BY 'sbpass';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL ON * . * TO 'sbuser'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.07 sec)
5.2 在proxysql端进行配置,将目标数据库以及用户名密码告诉proxysql
mysql> INSERT INTO MySQL_servers(hostgroup_id, hostname, port) VALUES (0,'172.17.61.131',3306);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO MySQL_users(username,password,default_hostgroup) VALUES ('sbuser','sbpass',0);
Query OK, 1 row affected (0.00 sec)
mysql> UPDATE global_variables SET variable_value='proxysql' where variable_name='mysql-monitor_username';
Query OK, 1 row affected (0.00 sec)
mysql> UPDATE global_variables SET variable_value='proxysql' where variable_name='mysql-monitor_password';
Query OK, 1 row affected (0.00 sec)
5.3要配置生效,需要将这些信息传到runtime层和disk层。
mysql> LOAD MYSQL SERVERS TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)
mysql> LOAD MYSQL USERS TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)
mysql> SAVE MYSQL SERVERS TO DISK;
Query OK, 0 rows affected (0.03 sec)
mysql> SAVE MYSQL USERS TO DISK;
Query OK, 0 rows affected (0.01 sec)
目前了解proxysql有三层架构,runtime层(也是就运行层),memory层(update命令影响到的层),disk层(配置文件层)。三层的配置可以不同也可以相同,最终系统只识别runtime层的配置。所以要想配置生效,必须将memory层以及disk层的配置导到入runtime层。
5.4 通过端口6033可以登入到已配置好的数据库
[root@qht134 /]# mysql -usbuser -psbpass -h 127.0.0.1 -P 6033 -e "select @@hostname"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| qht131 |
+------------+
[root@qht134 /]# mysql -usbuser -psbpass -h 127.0.0.1 -P 6033
mysql: [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 10
Server version: 5.5.30 (ProxySQL)
Copyright (c) 2000, 2018, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| l5m |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.24 sec)
mysql> use l5m
Database changed
mysql> show tables;
+---------------+
| Tables_in_l5m |
+---------------+
| test_mgr |
+---------------+
1 row in set (0.00 sec)
mysql> select * from test_mgr;
+----+
| c1 |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+----+
8 rows in set (0.04 sec)
可以的,通过proxysql登入到mysql数据库了!
参考:http://www.fordba.com/mysql_proxysql.html