//by yan 20220705
docker 安装mysql
[vagrant@localhost vagrant]$ docker pull mysql:latest
docker 创建启动 mysql
[vagrant@localhost vagrant]$ docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest
docker 进入 mysql容器
[vagrant@localhost vagrant]$ docker exec -it 7ae50b3885da bash
root@7ae50b3885da:/# mysql --user=root --password
Enter password:
mysql> show databases;
mysql> show grants for root;
mysql> grant all privileges on . to ‘root’@‘%’;
docker 停止 mysql容器
[vagrant@localhost vagrant]$ docker stop 7ae50b3885da
docker 启动 mysql容器
[vagrant@localhost vagrant]$ docker start 7ae50b3885da
docker 删除 mysql容器
[vagrant@localhost vagrant]$ docker rm mysql-server
问题:
Navicat连接mysql报错 1251错误
解决:
[vagrant@localhost vagrant]$ docker exec -it 7ae50b3885da bash
root@7ae50b3885da:/# mysql --user=root --password
mysql> ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user from user;
ERROR 1046 (3D000): No database selected
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
±----------±-----------------+
| host | user |
±----------±-----------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
±----------±-----------------+
5 rows in set (0.00 sec)
mysql> flush privileges
Navicat连接docker mysql 成功。
mysql> exit
Bye
root@87ff40d8bdc8:/# exit
exit
[vagrant@localhost vagrant]$
==============================================
//by yan 20220706
在docker 上部署xxl-job-admin容器实例
centos 安装 jdk
//查看云端目前支持安装的jdk版本,两种查询方式
[vagrant@localhost vagrant]$ yum search java|grep jdk
[vagrant@localhost vagrant]$ yum -y list java*
选一个版本安装
[vagrant@localhost vagrant]$ yum install java-1.8.0-openjdk.x86_64
启动微服务应用
[vagrant@localhost applogs]$ sudo -s
[root@localhost vagrant]# java -jar xxl-job-admin-2.3.1-SNAPSHOT.jar &
微服务jar启动时,控制台日志监控方法。(tomcat可以监控catalina.out,微服务jar应用最好自己指定,默认可能是按操作系统的默认日志路径里去了。)
nohup java -jar xxx.jar > consoleMsg.log 2>&1 &
[root@localhost vagrant]# java -jar xxl-job-admin-2.3.1-SNAPSHOT.jar >> console-xxljob.log 2>&1 &
上面的2 和 1 的意思如下:
0 标准输入(一般是键盘)
1 标准输出(一般是显示屏,是用户终端控制台)
2 标准错误(错误信息输出)
docker 安装xxl-job-admin容器
[root@localhost vagrant]# docker pull xuxueli/xxl-job-admin:2.3.1
2.3.1: Pulling from xuxueli/xxl-job-admin
214ca5fb9032: Downloading [=> ] 649.6kB/31.38MB
ebf31789c5c1: Downloading [=============================> ] 944.5kB/1.582MB
ab322dde1f12: Download complete
bff82a7b3b2f: Downloading [=> ] 848.8kB/41.7MB
ea84816897f1: Waiting
[root@localhost vagrant]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 0ef9083d9892 8 days ago 524MB
xuxueli/xxl-job-admin 2.3.1 252b168021da 6 weeks ago 237MB
docker 创建启动 xxl-job-admin
[root@localhost vagrant]# docker run -p 8081:8080 -v /tmp:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:2.3.1
问题:数据库连接失败。
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
docker 不能删除运行中的容器
[root@localhost vagrant]# docker rm xxl-job-admin
Error response from daemon: You cannot remove a running container c0e361d6fb89ee260b2cd079196ea0f4ba265525e24806a01150a7f1a15e8ac8. Stop the container before attempting removal or force remo
[root@localhost vagrant]# docker stop xxl-job-admin
xxl-job-admin
[root@localhost vagrant]# docker rm xxl-job-admin
xxl-job-admin
[root@localhost vagrant]# docker run -e PARAMS=“–spring.datasource.url=jdbc:mysql://192.168.33.10:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai” -p 8081:8080 -v /tmp:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:2.3.1
775693380cf6a5001d1b1e4565e3823dd50cb9bf923aef5194e180d67babf4f0
问题:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
Caused by: com.mysql.cj.exceptions.CJException: Access denied for user ‘root’@‘172.17.0.3’ (using password: YES)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
解决:
root 的用户名/密码不对,弄半天不是配置问题也不是网络问题。因为容器里的实例是从docker云端拉下来的。
[vagrant@localhost ~]$ docker run -e PARAMS=“–spring.datasource.url=jdbc:mysql://192.168.33.10:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=123456” -p 8081:8080 -v /tmp:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:2.3.1
4093265312a1ba31f2741a1232ec7b17a37d2d13a0eee0a30605f57d0c071a45
启动成功,数据库连接成功,日志不报错。
//查看mysql-server容器的ip等配置信息
[root@localhost vagrant]# docker inspect mysql-server
//容器里安装ping
root@743879d6c5e9:/# ping
bash: ping: command not found
root@743879d6c5e9:/# apt-get update
root@743879d6c5e9:/# apt install iputils-ping
//从配置信息里可以找到,配置信息的存储路径,然后可以修复
[vagrant@localhost ~]$ cd /var/lib/docker/containers/743879d6c5e946d9faf3a3455867d3e5d7798cf85564031648a7db23ab514de4
[root@localhost 743879d6c5e946d9faf3a3455867d3e5d7798cf85564031648a7db23ab514de4]# vi config.v2.json
访问http://192.168.33.10:8080/xxl-job-admin/joblog,成功。