OpenResty部署

产品介绍:是新一代的应用性能管理(APM)产品,为OpenResty和其他开源软件使用,100% 使用非侵入式的动态跟踪技术。 它可以自动监控、发现、排除故障,并为广泛的用户提供修复建议。 在您运行的OpenResty应用程序中出现各种性能和安全问题。 和其他类型的服务器应用,包括但不限于高CPU使用率。 堵塞和低吞吐量,内存占用率高,内存泄漏,延迟长。 进程崩溃和核心转储,以及更多请参考官网地址

基础环境

基础环境 基础信息 备注说明
操作系统版本 CentOS Linux release 7.9.2009 (Core)
硬盘 | 内存 100GB、8GB
防火墙 |时间 防火墙关闭、时间同步开启 # sed -i s+SELINUX=enforcing+SELINUX=disabled+ /etc/selinux/config && setenforce 0
OpenResty 版本号:1.21.4.1 版本【推荐[openresty-1.21.4.1.tar.gz] https://openresty.org/cn/download.html】
OpenResty_PATH /usr/local/openresty 服务安装路径

操作系统优化

[root@localhost ~]#  cat /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

安装相关依赖环境

[root@localhost ~]# yum install readline-devel pcre pcre-devel openssl openssl-devel gcc curl  GeoIP-devel perl

部署过程

编译时相关配置参数,可选择添加

参数配置 备注说明
--with-luajit 支持lua语法
--with-pcre 设置PCRE库
--with-http_gzip_static_module 静态文件压缩
--with-http_realip_module 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
--with-http_geoip_module 增加了根据ip获得城市信息,经纬度等模块
--with-http_ssl_module 使用HTTPS协议模块
--with-http_stub_status_module 监控nginx状态
--with-http_sub_module 支持请求响应过滤
--with-pcre-jit --with-ipv6 提供IPv6支持
--add-module=ngx_http_substitutions_filter_module http_sub_module 的加强版,它可以用正则替换,并可以多处替换
[root@localhost ~]# ./configure \
--with-luajit \
--with-pcre \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_geoip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-pcre-jit --with-ipv6 \
--add-module=/root/Packages/release/ngx_http_substitutions_filter_module-0.6.4
[root@localhost ~]# gmake && gmake install

优化nginx配置

[root@localhost ~]# cd /usr/local/openresty/nginx/conf
[root@localhost ~]# cp nginx.conf nginx.conf-bak
[root@localhost ~]# mkdir -p conf.d
[root@localhost ~]# mkdir -p /var/log/nginx/vhosts

nginx主配置文件

[root@localhost ~]# cat nginx.conf

user  nobody;
worker_processes  auto;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    client_max_body_size    20m;
    client_header_buffer_size       32k;
    large_client_header_buffers     4 32k;
    sendfile    on;
    tcp_nopush      on;
    tcp_nodelay             on;

    keepalive_timeout  65;
    client_header_timeout   10;
    client_body_timeout             10;
    send_timeout                    10;

    proxy_connect_timeout 300;
    proxy_read_timeout 300;
    proxy_send_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers   4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    gzip  on;
    gzip_min_length         1k;
    gzip_buffers            4       16k;
    gzip_http_version       1.1;
    gzip_comp_level         2;
    gzip_types      text/plain application/x-javascript text/css application/xml;
    gzip_vary                       on;

    include conf.d/*.conf;
}

nginx扩展配置文件

[root@localhost ~]# vim conf.d/production_8427_hp.conf
upstream hpapilist01 {
  # ip_hash;
    server 1xx.2xx.15x.230:8301;
  # server 1xx.2xx.15x.230:8301 weight=3 fail_timeout=10 max_fails=20;
}

server {
    listen       8427;
    server_name  api.hp.com;

    error_log /var/log/nginx/vhosts/pro_8427.error2.log error;
    location / {
        access_log      /var/log/nginx/vhosts/pro_8427.access.log    main;

        #  proxy_pass http://hpapilist01;
          proxy_pass http://1xx.2xx.15x.230:8301;
          proxy_cookie_domain 1xx.2xx.15x.230:8301 api.hp.com;
          proxy_buffering off;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header User-Agent $http_user_agent;
          proxy_set_header referer "http://1xx.2xx.15x.230:8301$request_uri";

    }
}

启动NGINX服务

# 检测服务配置是否正确
[root@localhost ~]# /usr/local/openresty/nginx/sbin/nginx -t 
# 启动服务
/usr/local/openresty/nginx/sbin/nginx