
镜像拉取
## 官方的镜像(里面不带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=2000web_enabled=trueweb_port=6080stats_credentials="stats:admin"}mysql_variables={threads=4max_connections=2048default_query_delay=0default_query_timeout=36000000have_compress=truepoll_timeout=2000interfaces="0.0.0.0:6033"default_schema="information_schema"stacksize=1048576server_version="5.5.30"connect_timeout_server=3000monitor_username="monitor"monitor_password="monitor"monitor_history=600000monitor_connect_interval=60000monitor_ping_interval=10000monitor_read_only_interval=1500monitor_read_only_timeout=500ping_interval_server_msec=120000ping_timeout_server=500commands_stats=truesessions_sort=trueconnect_retries_on_failure=10}mysql_replication_hostgroups =({ writer_hostgroup=0 , reader_hostgroup=1 , comment="host groups" })mysql_servers =({address="mysql"port=3306hostgroup=0max_connections=2048},{address="mysql1"port=3306hostgroup=1max_connections=2048},{address="mysql2"port=3306hostgroup=1max_connections=2048})mysql_query_rules =({rule_id=100active=1match_pattern="^SELECT .* FOR UPDATE"destination_hostgroup=0apply=1},{rule_id=200active=1match_pattern="^SELECT .*"destination_hostgroup=1apply=1},{rule_id=300active=1match_pattern=".*"destination_hostgroup=0apply=1})mysql_users:({username = "proxysql"password = "proxysql"default_hostgroup = 0max_connections=1000default_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 proxysqlseveralnines/proxysql:2.0.8
mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
