Container deployment and operation of ProxySQL based on Docker Hub image

ProxySQL container deployment and operation based on Docker Hub image:

1 pull image

The method to pull the ProxySQL database middleware image from Docker Hub is as follows.

# Pull the latest image
[root]# docker pull proxysql/proxysql
# Pull the image of the specified version
[root]# docker pull proxysql/proxysql:2.0.7

Pull the latest or specified version of ProxySQL image on demand

2 create an external volume

For example, create a volume named proxysql207 ﹣ 1 to hold persistent configuration data. The command is similar to the following.

Although ProxySQL configuration can be written as a. cnf file, it is mainly saved in the form of SQLite3 library. In order to avoid configuration data loss after container exception, an external volume is created to persist the configuration.

[root]# docker volume create --name proxysql207_1

3 edit initial profile

In order to enable ProxySQL to start normally and be configured remotely, edit the following configuration file (proxysql.cnf).

datadir="/var/lib/proxysql"

admin_variables=
{
    admin_credentials="admin:admin;radmin:radmin"
    mysql_ifaces="0.0.0.0:6032"
}

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
}

4 starting container

4.1 starting the container without configuration data

For example, based on the proxysql 2.0.7 image, start the container named proxysql207_. The command is similar to the following.

[root]# docker run --name proxysql207_1 \
-p 60321:6032 -p 60331:6033 \
-v /home/sid/config/proxysql/proxysql.cnf:/etc/proxysql.cnf -v proxysql207_1:/var/lib/proxysql \
-d proxysql/proxysql:2.0.7

– Name: Specifies the container name;
-p: Specifies the port mapping relationship inside and outside the docker environment. In this example, the management port (6032) and SQL port (6033) of ProxySQL are mapped to ports 60321 and 60331 outside the docker environment respectively;
-v: Specifies the storage mapping relationship inside and outside the docker environment. In this example, the initial configuration file is mapped to / etc/proxysql.cnf as the configuration file for the initial startup of ProxySQL; meanwhile, the docker column named ProxySQL207_ismounted to the / var/lib/proxysql directory in the container to achieve configuration persistence.

Note: when ProxySQL is started, it is mainly to read configuration from DISK library and load it into MEMORY and finally load it into RUNTIME to take effect.
Note: the mount of proxysql.cnf configuration file should precede the mount of / var/lib/proxysql directory, because only when the configuration file is correct can the correct configuration database be generated.

-d: Run the container in the background.

4.2 start the container when the configuration data is available

Assuming that the configuration data of ProxySQL has been stored in the docker column named ProxySQL207 ﹣ 1, start the container named ProxySQL207 ﹣ 1 based on the ProxySQL 2.0.7 image. The command is similar to the following.

[root]# docker run --name proxysql207_1 \
-p 60321:6032 -p 60331:6033 \
-v proxysql207_1:/var/lib/proxysql \
-d proxysql/proxysql:2.0.7

– Name: Specifies the container name;
-p: Specifies the port mapping relationship inside and outside the docker environment. In this example, the management port (6032) and SQL port (6033) of ProxySQL are mapped to ports 60321 and 60331 outside the docker environment respectively;
-v: Specifies the storage mapping relationship inside and outside the docker environment. In this example, you don't need to specify the startup configuration file any more. You just need to mount the docker column named proxysql207 [1] to the / var / lib / proxysqldirectory in the container to reuse the configuration.

Note: when ProxySQL is started, it is mainly to read configuration from DISK library and load it into MEMORY and finally load it into RUNTIME to take effect.

-d: Run the container in the background.

5 modify configuration

After the container is started, you can log in to the ProxySQL management side with the following command, and configure as required.

[root]# mysql -h127.0.0.1 -P60321 -uradmin -pradmin --prompt "ProxySQL Admin>"

reference material:

  1. https://hub.docker.com/r/proxysql/proxysql
Published 2 original articles, praised 0 and visited 5
Private letter follow

Tags: Docker Database SQL MySQL

Posted on Sun, 15 Mar 2020 23:43:32 -0700 by Adeus