镜像拉取
## 官方的镜像(里面不带MySQL Client)
docker pull proxysql/proxysql:2.0.8
# severalnines的镜像(里面带了MySQL Client)
docker pull severalnines/proxysql:2.0.8
创建配置文件 proxysql.cnf
datadir="/var/lib/proxysql"
admin_variables=
{
admin_credentials="admin:admin;radmin:radmin"
mysql_ifaces="0.0.0.0:6032"
refresh_interval=2000
web_enabled=true
web_port=6080
stats_credentials="stats:admin"
}
mysql_variables=
{
threads=4
max_connections=2048
default_query_delay=0
default_query_timeout=36000000
have_compress=true
poll_timeout=2000
interfaces="0.0.0.0:6033"
default_schema="information_schema"
stacksize=1048576
server_version="5.5.30"
connect_timeout_server=3000
monitor_username="monitor"
monitor_password="monitor"
monitor_history=600000
monitor_connect_interval=60000
monitor_ping_interval=10000
monitor_read_only_interval=1500
monitor_read_only_timeout=500
ping_interval_server_msec=120000
ping_timeout_server=500
commands_stats=true
sessions_sort=true
connect_retries_on_failure=10
}
mysql_replication_hostgroups =
(
{ writer_hostgroup=0 , reader_hostgroup=1 , comment="host groups" }
)
mysql_servers =
(
{
address="mysql"
port=3306
hostgroup=0
max_connections=2048
},
{
address="mysql1"
port=3306
hostgroup=1
max_connections=2048
},
{
address="mysql2"
port=3306
hostgroup=1
max_connections=2048
}
)
mysql_query_rules =
(
{
rule_id=100
active=1
match_pattern="^SELECT .* FOR UPDATE"
destination_hostgroup=0
apply=1
},
{
rule_id=200
active=1
match_pattern="^SELECT .*"
destination_hostgroup=1
apply=1
},
{
rule_id=300
active=1
match_pattern=".*"
destination_hostgroup=0
apply=1
}
)
mysql_users:
(
{
username = "proxysql"
password = "proxysql"
default_hostgroup = 0
max_connections=1000
default_schema="information_schema"
active = 1
}
)
端口号说明:
- 6032 :服务端的端口
- 6033 :MySQL连接的端口
6080 :前台UI的端口
容器创建docker run -d \
-p 16032:6032 \
-p 16033:6033 \
-p 16034:6080 \
-v proxysql.cnf:/etc/proxysql.cnf \
-name proxysql
severalnines/proxysql:2.0.8
mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '