背景
WAF进行证书替换时,发现部分过滤节点 nginx重启遇到上述异常。
故障定位
1.使用“nginx -V” 查看waf nginx安装时添加的编译参数及配置信息。确认http-client-body-temp-path在编译过程当中配置存储路径,确认是否为安装问题。
http-client-body-temp-path配置说明
对生节点执行“nginx -V”;结果如下:
nginx version: styx2.5.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/waf/nginx_lua.conf --error-log-path=/usr/local/nginx/logs/waf.error.log --http-log-path=/usr/local/nginx/logs/waf.access.log --pid-path=/usr/local/nginx/logs/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_sub_module --with-http_gzip_static_module --without-http_upstream_hash_module --with-http_realip_module --with-file-aio --with-ipv6 --with-openssl=/usr/local/soft/waf_package/CNN55XX-SDK/apps/Turbo_SSL/openssl-1.1.1 --with-zlib=../zlib-1.2.8 --with-pcre=../pcre-8.38 --add-module=../ngx_devel_kit-master --add-module=../lua-nginx-module-0.10.12 --add-module=../nginx_upstream_hash-master --add-module=../nginx_upstream_check_module-master --add-module=../ngx_http_dyups_module-master --http-client-body-temp-path=/usr/local/soee/nginx/client_body_temp --http-proxy-temp-path=/usr/local/soee/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/soee/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/soee/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/soee/nginx/scgi_temp --with-cc-opt=' -DCAVIUM_SSL -DCAVIUM_ASYNC_SUPPORT -I /usr/local/soft/waf_package/CNN55XX-SDK/include -I/usr/local/soft/waf_package/CNN55XX-SDK/apps/Turbo_SSL/openssl-1.1.1 -I/usr/local/soft/waf_package/CNN55XX-SDK/apps/Turbo_SSL/openssl-1.1.1/ssl' --with-ld-opt='-Wl,-rpath=/usr/local/ssl/lib -L/usr/local/ssl/lib'
通过运维平台确认生产环境部分编辑路径与运维的安装脚本不一致;
运维安装手册对应的“http-client-body-temp-path”配置信息如下,确认生产环境存在该配置存储目录有多个:
--add-module=../ngx_devel_kit-master \
--add-module=../lua-nginx-module-0.10.7 \
--add-module=../nginx_upstream_hash-master \
--add-module=../nginx_upstream_check_module-master \
--add-module=../ngx_http_dyups_module-master \
--http-client-body-temp-path=/usr/local/nginx/client_body_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
通过对故障节点目录权限的检查,包括编译参数的检查,除发现节点上“http-client-body-temp-path”配置存储路径与运维安装脚本不一致,并未发现异常;
检查运维当晚重启报错故障节点编译配置等
[root@host10108929 ~]# nginx -V
nginx version: styx2.5.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
built with OpenSSL 1.0.2j 26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/waf/nginx_lua.conf --error-log-path=/usr/local/nginx/logs/waf.error.log --http-log-path=/usr/local/nginx/logs/waf.access.log --pid-path=/usr/local/nginx/logs/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_sub_module --with-http_gzip_static_module --without-http_upstream_hash_module --with-http_realip_module --with-file-aio --with-ipv6 --with-zlib=../zlib-1.2.8 --with-pcre=../pcre-8.38 --add-module=../ngx_devel_kit-master --add-module=../lua-nginx-module-0.10.7 --add-module=../nginx_upstream_hash-master --add-module=../nginx_upstream_check_module-master --add-module=../ngx_http_dyups_module-master --http-client-body-temp-path=/var/tmp/nginx/client_body --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-cc-opt='-I/usr/local/ssl/include -Wno-error=deprecated-declarations' --with-ld-opt='-Wl,-rpath=/usr/local/ssl/lib -L/usr/local/ssl/lib'
发现其对应的目录与其他节点目录不一样、其他节点多为/usr/local……,进一步调研分析发现“/var/tmp”因为操作系统内部存在定时任务,其任务当中有脚本会定期清理/var/tmp目录内容,从而导致nginx再一次重启的时候因为该目录下内容被系统清理,从而发生nginx在重启过程当中出现该错误“[emerg] mkdir() "/var/tmp/nginx/client_body" failed (13: Permission denied)”
下面该代码段为cron脚本,默认情况30天清理未使用的文件及目录;
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
解决方案:
1.重启的过程当中如果发现类似错误,可以通过重新创建"/var/tmp/nginx/client_body"目录,nginx可以正常运行。但后续该节点可能出现用户上传过大文件丢失等问题。
2.重新安装,通过在编译参数当中自定义指定非/var/tmp目录,避免再被系统清理。如下所示
--add-module=../ngx_devel_kit-master \
--add-module=../lua-nginx-module-0.10.7 \
--add-module=../nginx_upstream_hash-master \
--add-module=../nginx_upstream_check_module-master \
--add-module=../ngx_http_dyups_module-master \
--http-client-body-temp-path=/usr/local/nginx/client_body_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
3.通过调整nginx.conf配置文件,重新指定“http-client-body-temp-path”配置存储位置,重启nginx后即可,具体配置如下:
http {
default_type application/octet-stream;
server_tokens off;
sendfile on;
client_max_body_size 200m;
client_body_buffer_size 4096k;
client_body_temp_path /usr/local/nginx/client_body_temp;
client_header_buffer_size 256k;
large_client_header_buffers 8 256k;
附录
《关于Linux系统中/tmp目录的清除问题》关于Linux系统中/tmp目录的清除问题-CSDN博客
《Linux临时目录/tmp与/var/tmp》https://www.cnblogs.com/fuqian/p/17143415.html
《Module ngx_http_core_module》Module ngx_http_core_module