OpenResty
OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。
OpenResty® 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。
官网
http://openresty.org/cn/installation.html
http://openresty.org/cn/download.html
安装依赖:
yum -y install openssl-devel pcre-devel zlib-devel
缺少perl组件
错误:
Can't locate File/Temp.pm in @INC
安装perl组件
yum -y install perl-File-Temp
下载解压
基于版本 openresty 1.19.9.1
wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
编译安装Luajit
cd bundle/LuaJIT-2.1-20180420
make clean && make && make install
#最后 被安装到/usr/loca/bin下
==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local ====
#ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
下载ngx_cache_purge模块
该模块用于清理nginx缓存
cd bundle
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
#https://github.com/FRiCKLE/ngx_cache_purge/archive/refs/tags/2.3.tar.gz
tar -xvf 2.3.tar.gz
下载nginx_upstream_check_module模块
该模块用于ustream健康检查
cd bundle
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
#https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/tags/v0.3.0.tar.gz
tar -xvf v0.3.0.tar.gz
下载nginx-upstream-fair模块,未成功
链接:https://pan.baidu.com/s/1gcggcFoDmqoJefm72hro3A
提取码:x54f
解压,目录命名为 :nginx-upstream-fair
把nginx-upstream-fair 拷贝到openresty/bundle
安装OpenResty
#包含nginx-upstream-fair
./configure --prefix=/usr/local/openresty --with-stream --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/nginx-upstream-fair/ --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2
#不包含nginx-upstream-fair
./configure --prefix=/usr/local/openresty --with-stream --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2
gmake && gmake install
socket代理需要使用nginx的 ngx_stream_core_module 模块,且该模块在安装时并不是默认构建的。
因此在执行 ./configure 时需要加上参数 --with-stream
如何新增module
#如安装模块 ngx_slab_stat
#下载解压
wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
tar -xf tengine-2.3.2.tar.gz
#进入源码目录:
cd /home/openresty/openresty-1.19.9.1
./configure --add-module=../tengine-2.3.2/modules/ngx_slab_stat/
#执行编译
gmake #不要执行gmake install,重要的事情说三遍
#备份原sbin目录下的nginx执行文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old
#用编译后的nginx覆盖
cp /home/openresty/openresty-1.19.9.1/build/nginx-1.19.9/objs/nginx /usr/local/nginx/sbin/
OpenResty下nginx.conf配置
#user nobody;
worker_processes 4;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /var/run/nginx.pid;
events {
#worker_connections 1024;
worker_connections 10240;
accept_mutex on;
multi_accept on;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $request_time $upstream_response_time $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server_tokens off;
tcp_nodelay on;
#-------gzip----------------
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/json;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
#proxy_intercept_errors on;
fastcgi_intercept_errors on;
error_page 400 401 402 403 404 405 408 410 412 413 414 415 /404.html;
error_page 500 501 502 503 504 506 /500.html;
include /usr/local/nginx/conf/conf.d/*.conf;
}