OpenResty服务部署

一、环境

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

二、OpenResty安装

[root@localhost ~]# yum install yum-fastestmirror     #更新源
[root@localhost ~]# yum update
[root@localhost ~]# 

三、OpenResty所需依赖的包安装

[root@localhost ~]# 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健康检查

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

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

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

四、编译安装OpenResty

[root@localhost tools]# wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
[root@localhost tools]# tar -zxvf openresty-1.13.6.2.tar.gz
[root@localhost tools]# cd openresty-1.13.6.2
[root@localhost openresty-1.13.6.2]# groupadd www
[root@localhost openresty-1.13.6.2]# useradd -M -g www -s /sbin/nologin www
[root@localhost 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
[root@localhost openresty-1.13.6.2]# gmake && gmake install
[root@localhost openresty-1.13.6.2]# cd /app/OpenResty/nginx/sbin/
[root@localhost sbin]# [root@mysql 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配置成服务,设置开机启动

[root@localhost 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
[root@localhost nginx]# systemctl enable nginx
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx on
[root@localhost nginx]#

六、OpenResty配置文件

[root@localhost tools]# cd /usr/local/OpenResty/nginx/conf
[root@localhost conf]# cp nginx.conf{,.bak}
[root@localhost 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服务部署_第1张图片
浏览器出现以上信息说明成功!

你可能感兴趣的:(部署)