解决的问题
解决部署在多机的散乱定时任务,通过平台集中管理定时任务。
常见场景:用于替代部署在ECS虚拟机上的,各种杂乱脚本。
MySQL
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker pull mysql
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3218b38490ce 5 months ago 516MB
docker run -itd --name mysql-3306 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=xxxx mysql
f923e328bbd4803368668336534473ae6ca05a1aacf129bbbacbce79848ab47c
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f923e328bbd4 mysql "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-3306
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f923e328bbd4 mysql "docker-entrypoint.s…" 9 seconds ago Up 9 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-3306
[root@iZj6cbaawmbzi712wvf7jrZ ~]# netstat -antp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2797/docker-proxy
tcp6 0 0 :::3306 :::* LISTEN 2804/docker-proxy
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker exec -it f923e328bbd4 /bin/bash
root@f923e328bbd4:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'%' identified with mysql_native_password by 'xxxx';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> create database gocron;
Query OK, 1 row affected (0.01 sec)
[root@iZj6cbaawmbzi712wvf7jrZ ~]# docker inspect f923e328bbd4
[root@iZj6cbaawmbzi712wvf7jrZ ~]# mysql -u root -h 172.17.0.2 -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| gocron |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> exit
Bye
[root@iZj6cbaawmbzi712wvf7jrZ ~]#
gocron
#docker run --name gocron --link mysql:db -p 5920:5920 -d ouqg/gocron
docker run --name gocron --link mysql-3306:db -p 5920:5920 -d ouqg/gocron
cc60b948d280fd88b926561de355d88d445952d3545f2fbda417379ab582fc09
gcron-node
[root@iZj6cbaawmbzi712wvf7jrZ tas]# pwd
/data/tas
wget https://raw.githubusercontent.com/ouqiang/gocron/master/k8s-deploy/Dockerfile-agent
[root@iZj6cbaawmbzi712wvf7jrZ tas]# mv Dockerfile-agent Dockerfile
[root@iZj6cbaawmbzi712wvf7jrZ tas]# docker build -t="gocron/gocron-node" .
Successfully built 4b503aadcb8f
Successfully tagged gocron/gocron-node:latest
[root@iZj6cbaawmbzi712wvf7jrZ tas]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gocron/gocron-node latest 4b503aadcb8f 53 seconds ago 20.1MB
mysql latest 3218b38490ce 5 months ago 516MB
ouqg/gocron latest 44549565573b 2 years ago 41.4MB
alpine 3.7 6d1ef012b567 3 years ago 4.21MB
docker run --name gocron-node -p 5921:5921 -d gocron/gocron-node
9838e97512cae5f6513e4be734a9b8967adf621c3e537d0c34cf01a33070bef5
[root@iZj6cbaawmbzi712wvf7jrZ tas]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9838e97512ca gocron/gocron-node "/app/gocron-node -a…" 4 seconds ago Up 3 seconds 0.0.0.0:5921->5921/tcp, :::5921->5921/tcp gocron-node
cc60b948d280 ouqg/gocron "/app/gocron web" 33 minutes ago Up 33 minutes 0.0.0.0:5920->5920/tcp, :::5920->5920/tcp gocron
f923e328bbd4 mysql "docker-entrypoint.s…" 42 minutes ago Up 22 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-3306
[root@iZj6cbaawmbzi712wvf7jrZ tas]# docker inspect 9838e97512ca
[root@iZj6cbaawmbzi712wvf7jrZ tas]# netstat -antp | grep 5921