欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenResty服务部署

程序员文章站 2022-04-21 23:49:22
...

一、环境

cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)
nginx version:openresty/1.13.6.2

二、OpenResty安装

[aaa@qq.com ~]# yum install yum-fastestmirror     #更新源
[aaa@qq.com ~]# yum update
[aaa@qq.com ~]# 

三、OpenResty所需依赖的包安装

[aaa@qq.com ~]# yum install gcc gcc-c++ libreadline-dev libncurses5-dev libpcre3-dev libssl-dev pcre pcre-devel zlib zlib-devel openssl openssl-devel readline-devel  perl -y

下载nginx_upstream_check_module模块,该模块用于ustream健康检查

[aaa@qq.com ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
[aaa@qq.com ~]# tar -zxvf v0.3.0.tar.gz

下载ngx_cache_purge模块,该模块用于清理nginx缓存

[aaa@qq.com ~]#  wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
[aaa@qq.com ~]#  tar zxvf ngx_cache_purge-2.3.tar.gz

四、编译安装OpenResty

[aaa@qq.com tools]# wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
[aaa@qq.com tools]# tar -zxvf openresty-1.13.6.2.tar.gz
[aaa@qq.com tools]# cd openresty-1.13.6.2
[aaa@qq.com openresty-1.13.6.2]# groupadd www
[aaa@qq.com openresty-1.13.6.2]# useradd -M -g www -s /sbin/nologin www
[aaa@qq.com openresty-1.13.6.2]#  ./configure --prefix=/usr/local/OpenResty --user=www --group=www --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_realip_module --with-pcre --with-luajit --add-module=/home/tools/ngx_cache_purge-2.3/ --add-module=/home/tools/nginx_upstream_check_module-0.3.0/ --with-http_stub_status_module --with-http_ssl_module -j2
[aaa@qq.com openresty-1.13.6.2]# gmake && gmake install
[aaa@qq.com openresty-1.13.6.2]# cd /app/OpenResty/nginx/sbin/
[aaa@qq.com sbin]# [aaa@qq.com sbin]# ./nginx -V
nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/OpenResty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.13 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.5 --with-ld-opt=-Wl,-rpath,/usr/local/OpenResty/luajit/lib --user=www --group=www --with-http_realip_module --with-pcre --add-module=/home/tools/ngx_cache_purge-2.3 --add-module=/home/tools/nginx_upstream_check_module-0.3.0 --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module

五、将OpenResty配置成服务,设置开机启动

[aaa@qq.com nginx]# vim /lib/systemd/system/nginx.service
[Unit]                 #服务的说明
Description=nginx      #描述服务
After=network.target   #描述服务类别

[Service]              #服务运行参数的设置
Type=forking           #后台运行的形式,
ExecStart=/usr/local/OpenResty/nginx/sbin/nginx             #服务的具体运行命令
ExecReload=/usr/local/OpenResty/nginx/sbin/nginx reload     #重启命令
ExecStop=/usr/local/OpenResty/nginx//sbin/nginx quit        #停止命令
PrivateTmp=true        #给服务分配独立的临时空间

[Install]
WantedBy=multi-user.target
[aaa@qq.com nginx]# systemctl enable nginx
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx on
[aaa@qq.com nginx]#

六、OpenResty配置文件

[aaa@qq.com tools]# cd /usr/local/OpenResty/nginx/conf
[aaa@qq.com conf]# cp nginx.conf{,.bak}
[aaa@qq.com conf]# vim nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

七、测试是否搭建成功
OpenResty服务部署
浏览器出现以上信息说明成功!

相关标签: 部署