20200404为知笔记Docker无法访问

   

前因后果

这件事要从4月3日说起,经过简单的测试,就将为知笔记Docker版部署在了主服务器上,部署完毕后简单检查,发现没有什么问题就将笔记数据传上去了,结果今天起床发现无法访问了,映射出的端口访问就是Internal Server Error:scream:,着实令人沮丧,不过咱也是经理过大风大浪的,排查问题、发现问题、解决问题,记录如下:

查看日志

首先要先去看看docker容器里发生了什么:

[root@iz2ze2dqiy353ziqd8308kz ~]# docker ps -a
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                   NAMES
5ca5a428b1bc        wiznote/wizserver:latest   "bash /wiz/app/entry…"   26 hours ago        Up 15 minutes       0.0.0.0:12311->80/tcp   infallible_shamir
[root@iz2ze2dqiy353ziqd8308kz ~]# docker restart 5ca5a428b1bc
5ca5a428b1bc
[root@iz2ze2dqiy353ziqd8308kz ~]# docker logs -f --tail=200 5ca5a428b1bc
...
wait-for-it.sh: 127.0.0.1:3306 is available after 2 seconds
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) while connecting to the MySQL server
...
2020-04-04T12:31:52.828473Z 0 [ERROR] Another process with pid 82 is using unix socket file.
2020-04-04T12:31:52.828483Z 0 [ERROR] Unable to setup unix socket lock file.
2020-04-04T12:31:52.828487Z 0 [ERROR] Aborting
...

重启容器后,日志显示这个报错很明显是mysql报出来的,关于lock文件的,估计是意外停止留下的。

解决问题

说实话,这是一个常见的mysql无法启动问题,百度上有的是mysql无法启动案例,原因是是不能设置socket lock文件导致终止,应该是因为存在了sock的锁文件,导致启动的时候不能创建该文件导致的失败。

[root@iz2ze2dqiy353ziqd8308kz ~]# docker exec -it 5ca5a428b1bc  /bin/bash
[root@5ca5a428b1bc /]# find / -name mysql.sock.lock
/var/lib/mysql/mysql.sock.lock
[root@5ca5a428b1bc /]# mv /var/lib/mysql/mysql.sock.lock /var/lib/mysql/mysql.sock.lock.bak
[root@5ca5a428b1bc /]# exit
exit
[root@iz2ze2dqiy353ziqd8308kz ~]# docker restart 5ca5a428b1bc
5ca5a428b1bc
[root@iz2ze2dqiy353ziqd8308kz ~]# docker ps -a 
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                   NAMES
5ca5a428b1bc        wiznote/wizserver:latest   "bash /wiz/app/entry…"   26 hours ago        Up 15 minutes       0.0.0.0:12311->80/tcp   infallible_shamir

移动此文件后,重启容器,系统工作正常。

发表评论