ProxySQL - 图1
镜像拉取

  1. ## 官方的镜像(里面不带MySQL Client)
  2. docker pull proxysql/proxysql:2.0.8
  3. # severalnines的镜像(里面带了MySQL Client)
  4. docker pull severalnines/proxysql:2.0.8

创建配置文件 proxysql.cnf

  1. datadir="/var/lib/proxysql"
  2. admin_variables=
  3. {
  4. admin_credentials="admin:admin;radmin:radmin"
  5. mysql_ifaces="0.0.0.0:6032"
  6. refresh_interval=2000
  7. web_enabled=true
  8. web_port=6080
  9. stats_credentials="stats:admin"
  10. }
  11. mysql_variables=
  12. {
  13. threads=4
  14. max_connections=2048
  15. default_query_delay=0
  16. default_query_timeout=36000000
  17. have_compress=true
  18. poll_timeout=2000
  19. interfaces="0.0.0.0:6033"
  20. default_schema="information_schema"
  21. stacksize=1048576
  22. server_version="5.5.30"
  23. connect_timeout_server=3000
  24. monitor_username="monitor"
  25. monitor_password="monitor"
  26. monitor_history=600000
  27. monitor_connect_interval=60000
  28. monitor_ping_interval=10000
  29. monitor_read_only_interval=1500
  30. monitor_read_only_timeout=500
  31. ping_interval_server_msec=120000
  32. ping_timeout_server=500
  33. commands_stats=true
  34. sessions_sort=true
  35. connect_retries_on_failure=10
  36. }
  37. mysql_replication_hostgroups =
  38. (
  39. { writer_hostgroup=0 , reader_hostgroup=1 , comment="host groups" }
  40. )
  41. mysql_servers =
  42. (
  43. {
  44. address="mysql"
  45. port=3306
  46. hostgroup=0
  47. max_connections=2048
  48. },
  49. {
  50. address="mysql1"
  51. port=3306
  52. hostgroup=1
  53. max_connections=2048
  54. },
  55. {
  56. address="mysql2"
  57. port=3306
  58. hostgroup=1
  59. max_connections=2048
  60. }
  61. )
  62. mysql_query_rules =
  63. (
  64. {
  65. rule_id=100
  66. active=1
  67. match_pattern="^SELECT .* FOR UPDATE"
  68. destination_hostgroup=0
  69. apply=1
  70. },
  71. {
  72. rule_id=200
  73. active=1
  74. match_pattern="^SELECT .*"
  75. destination_hostgroup=1
  76. apply=1
  77. },
  78. {
  79. rule_id=300
  80. active=1
  81. match_pattern=".*"
  82. destination_hostgroup=0
  83. apply=1
  84. }
  85. )
  86. mysql_users:
  87. (
  88. {
  89. username = "proxysql"
  90. password = "proxysql"
  91. default_hostgroup = 0
  92. max_connections=1000
  93. default_schema="information_schema"
  94. active = 1
  95. }
  96. )

端口号说明:

  • 6032 :服务端的端口
  • 6033 :MySQL连接的端口
  • 6080 :前台UI的端口


    容器创建

    1. docker run -d \
    2. -p 16032:6032 \
    3. -p 16033:6033 \
    4. -p 16034:6080 \
    5. -v proxysql.cnf:/etc/proxysql.cnf \
    6. -name proxysql
    7. severalnines/proxysql:2.0.8
  1. mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '

参考

MGR单主模式和ProxySQL