研发周记,记录一周研发中遇到的疑难杂症,本周的研发中主要遇到两个问题,一个是 nginx 启动失败 另一个是 mysql数据插入失败,下面我们进入主题吧。
nginx 启动失败
突然发现,沙沙野 的用户登录系统不工作了,立马登录服务器查看,发现nginx没有运行,于是乎,systemctl start nginx
问题解决,结果第二天同样的问题再次诞生,而在此之前nginx 开机是能自启的,唯一的不同是修改了nginx配置文件。
于是第二天没有立马 start 而是查看log systemctl status nginx -l
发现输出如下:
● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 五 2018-07-20 16:27:53 CST; 17s ago 7月 20 16:27:53 izbp17twuiujek64ahvc5tz systemd[1]: Starting The nginx HTTP and reverse proxy server... 7月 20 16:27:53 izbp17twuiujek64ahvc5tz nginx[968]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 7月 20 16:27:53 izbp17twuiujek64ahvc5tz nginx[968]: nginx: [emerg] no "events" section in configuration 7月 20 16:27:53 izbp17twuiujek64ahvc5tz nginx[968]: nginx: configuration file /etc/nginx/nginx.conf test failed 7月 20 16:27:53 izbp17twuiujek64ahvc5tz systemd[1]: nginx.service: control process exited, code=exited status=1 7月 20 16:27:53 izbp17twuiujek64ahvc5tz systemd[1]: Failed to start The nginx HTTP and reverse proxy server. 7月 20 16:27:53 izbp17twuiujek64ahvc5tz systemd[1]: Unit nginx.service entered failed state. 7月 20 16:27:53 izbp17twuiujek64ahvc5tz systemd[1]: nginx.service failed.
而如果 执行 systemctl start nginx
后再次查看log,则输出如下:
● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since 五 2018-07-20 16:28:26 CST; 37s ago Process: 1616 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 1614 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 1612 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 1619 (nginx) CGroup: /system.slice/nginx.service ├─1619 nginx: master process /usr/sbin/ngin ├─1620 nginx: worker proces ├─1621 nginx: cache manager proces └─1622 nginx: cache loader proces 7月 20 16:28:25 izbp17twuiujek64ahvc5tz systemd[1]: Starting The nginx HTTP and reverse proxy server... 7月 20 16:28:26 izbp17twuiujek64ahvc5tz nginx[1614]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 7月 20 16:28:26 izbp17twuiujek64ahvc5tz nginx[1614]: nginx: configuration file /etc/nginx/nginx.conf test is successful 7月 20 16:28:26 izbp17twuiujek64ahvc5tz systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument 7月 20 16:28:26 izbp17twuiujek64ahvc5tz systemd[1]: Started The nginx HTTP and reverse proxy server.
通过分析出错时的log,可以确定问题是 nginx.conf 有问题,而我由于有特殊需求,每次开机部署项目,会将 nginx.conf 覆盖,那么应该是覆盖和 nginx 启动几乎同时发生了,导致nginx启动的时候读取不了nginx.conf而稍等一会文件覆盖一旦完成则可以启动了,为了验证是否如此,我关闭了开机部署项目时覆盖nginx.conf的选项。然后再重启,一切正常,问题至此结束。
Invalid utf8mb4 character string: '1\xEF'
在保存数据的时候,mysql突然报这样的一个错误,这让我莫名其妙,最终发现是英文逗号和中文逗号的问题,特此记录。