1.ProxySQL 介绍和安装
ProxySQL 是一种高性能、高可用的开源中间件,适用于mysql和相关的数据库,如MariaDB
官网:安装
发行版本下载链接:
Ubuntu / Debian:
添加源
apt-get install -y lsb-releasewget -O - 'http://repo.proxysql.com/ProxySQL/repo_pub_key' | apt-key add -echo deb http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/$(lsb_release -sc)/ ./ \| tee /etc/apt/sources.list.d/proxysql.list
安装:
apt-get updateapt-get install proxysql OR apt-get install proxysql=version
Red Hat / CentOS:
添加源
cat <
安装
yum install proxysql OR yum install proxysql-version
proxysql开启/关闭/重启
开启service proxysql start关闭service proxysql stop重启service proxysql restart
管理员交互界面开启和关闭
进入管理界面# mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '开启Admin> proxysql start;Query OK, 0 rows affected (0.00 sec)关闭Admin> proxysql stop;ERROR 2013 (HY000): Lost connection to MySQL server during query重启Admin> proxysql restart;ERROR 2013 (HY000): Lost connection to MySQL server during query
Proxysql 架构以及在线修改配置
Proxysql有三层架构,最底层是disk和config file,第二层是memory,最顶层是runtime
当第一次启动时,proxysql会抓取本地配置文件proxy.cnf并且加载至内存z中,并且最终加载到runtime生效,后续如果在线修改了配置后,需要load至runtime层使其生效,如果需要持久化保存,则需要save至磁盘即可
搭建一个最简单的Proxysql
预先安装好proxysql和mysql
proxysql按照上文安装方法就好
mysql安装:()
进入proxysql管理界面
# mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '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 1Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.Admin>
添加服务器的信息
Admin> INSERT INTO mysql_servers(hostgroup_id,hostname,port) VALUES (1,'127.0.0.1',3306);Query OK, 1 row affected (0.00 sec)
将数据推到runtime和保存至本地磁盘
Admin> LOAD MYSQL SERVERS TO RUNTIME;Query OK, 0 rows affected (0.00 sec)Admin> SAVE MYSQL SERVERS TO DISK;Query OK, 0 rows affected (0.04 sec)
添加用户信息
Admin> INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('root','root',1);Query OK, 1 row affected (0.00 sec)
将数据推到runtime和保存至本地磁盘
Admin> LOAD MYSQL USERS TO RUNTIME;Query OK, 0 rows affected (0.00 sec)Admin> save mysql users to disk;Query OK, 0 rows affected (0.01 sec)
测试proxysql
# mysql -uroot -proot -h 127.0.0.1 -P6033 -e "SELECT @@port"mysql: [Warning] Using a password on the command line interface can be insecure.+--------+| @@port |+--------+| 3306 |+--------+[root@MiWiFi-R3P-srv proxysql]#