使用OpenResty实现苍穹补丁更新

1 背景说明
因客户的安全规范要求,服务器不提供ssh连接方式,这将导致苍穹默认的升级补丁方式无法正常使用(K8S无法ssh连接nginx服务器),无法自动更新应用仓库和静态资源,手动更新补丁需要一定的运维能力且失误率高。为解决这一难题,可以使用OpenRestry方案来实现苍穹补丁更新。
两种更新方式的流程对比:

流程图-SSH方式更新苍穹补丁

流程图-Openresty方式更新苍穹补丁
2 openresty部署配置
2.1安装openresty
下载地址:http://openresty.org/cn/download.html
编译安装:
# ./configure --prefix=/usr/local/openresty --with-luajit --with-cc-opt=-O2 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module --with-http_iconv_module
# make && make install
修改配置文件参考下文
启动服务: /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
停止服务: /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf -s stop
注册系统服务:
新增或修改系统服务配置文件
# vi /usr/lib/systemd/system/openresty.service [Unit] Description=The openresty nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking #指定用户和组运行 User=root Group=root ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start openresty
2.2 权限配置
openresty的运行用户要能对服务根目录/var/appstatic、应用仓库路径、补丁仓库路径、静态资源路径进行操作,且能访问其根目录 (建议都配置在服务根目录下)。

2.3 访问配置
openresty/nginx/conf/的nginx.conf配置参考如下:
# cat /usr/local/openresty/nginx/conf/nginx.conf
user root; #设置普通用户运行需要对安装目录、日志目录、应用仓库等目录授权
worker_processes 4;
events {
use epoll;
multi_accept on;
worker_connections 61024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log logs/access.log main;
client_max_body_size 2048m;
sendfile on;
#tcp_nopush on;
gzip on;
gzip_buffers 4 8k;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_types text/plain text/json text/css application/x-httpd-php application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript image/png image/jpg image/jpeg image/gif image/bmp;
keepalive_timeout 65;
include conf.d/*.conf;
server{
listen 8188 default_server; #服务监听端口,可自定义修改
listen [::]:8188 default_server; #服务监听端口,可自定义修改
server_name localhost;
root /var/appstatic/; # 应用仓库和静态资源根路径
autoindex on; # 显示目录结构
autoindex_exact_size on; # 显示文件大小
autoindex_localtime on;# 显示文件时间
client_max_body_size 2048m;
location /upload {
content_by_lua_file lua/upload.lua;
}
location /copy {
content_by_lua_file lua/cp.lua;
}
location /unzip {
content_by_lua_file lua/unzip.lua;
}
location /mkdir {
content_by_lua_file lua/mkdir.lua;
}
location /clear {
content_by_lua_file lua/rm.lua;
}
}
}说明:
(1)本文以监听8188端口为例,具体可自定义修改。
(2)设置nginx的运行用户为root,可自定义用户,但需要提前授权: user root;
(3)
使用OpenResty实现苍穹补丁更新
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



