OpenResty 介绍
OpenResty是一个魔改版NGINX,相比原NGINX,有更多的功能,并且极为适合开发人员利用lua语言快速开发。
OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。
OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。
360,UPYUN,阿里云,新浪,腾讯网,去哪儿网,酷狗音乐等都是 OpenResty 的深度用户。
OpenResty是一个魔改版NGINX,相比原NGINX,有更多的功能,并且极为适合开发人员利用lua语言快速开发。
OpenResty的下载十分方便,下载地址为:OpenResty® - 中文官方站 ,选择一个适合的版本下载即可。我这里下载的openresty-1.19.3.1.tar.gz
编译安装命令为:
编译环境安装
yum install pcre pcre-devle openssl openssl-devle zlib zlib-devel autoconf gcc gcc-c++ -y
正式编译:
解压上述文件openresty-1.19.3.1.tar.gz,cd到解压目录,执行安装命令:
./configure --prefix=/usr/local/openresty
gmake
gmake install
编译完成后,openresty将会安装在/usr/local/openresty 目录下,但此时,没有启动脚本,如果需要进行调试将会比较麻烦,因此,编写启动脚本:
#!/bin/sh
#
# openresty - this script starts and stops the openresty daemin
#
# chkconfig: - 85 15
# description: OpenResty is a full-fledged web platform that integrates \
# the standard Nginx core, LuaJIT, many carefully written Lua libraries, \
# lots of high quality 3rd-party Nginx modules, and most of their external dependencies.
# processname: openresty
# config: /usr/local/openresty/nginx/conf/nginx.conf
# pidfile: /usr/local/openresty/nginx/logs/nginx.pid
# Last Updated 2018.07.15
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/openresty/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/openresty/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/openresty/nginx/logs/nginx.pid"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
#service php-fpm start
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
$nginx -s stop
echo_success
retval=$?
echo
#service php-fpm stop
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
$nginx -s reload
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
启动脚本管理命令为:
systemctl status/start/restart/ openresty
例如:查看OpenResty的状态:
[root@centos1 init.d]# systemctl status openresty
● openresty.service - SYSV: OpenResty is a full-fledged web platform that integrates the standard Nginx core, LuaJIT, many carefully written Lua libraries, lots of high quality 3rd-party Nginx modules, and most of their external dependencies.
Loaded: loaded (/etc/rc.d/init.d/openresty; bad; vendor preset: disabled)
Active: active (running) since Sat 2022-06-04 16:31:50 CST; 7min ago
Docs: man:systemd-sysv-generator(8)
Process: 1014 ExecStart=/etc/rc.d/init.d/openresty start (code=exited, status=0/SUCCESS)
Main PID: 1028 (nginx)
CGroup: /system.slice/openresty.service
├─1028 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
└─1029 nginx: worker process
Jun 04 16:31:50 centos1 systemd[1]: Starting SYSV: OpenResty is a full-fledged web platform that integrates the standard Nginx core, LuaJI...ncies....
Jun 04 16:31:50 centos1 openresty[1014]: Starting nginx: [ OK ]
Jun 04 16:31:50 centos1 systemd[1]: Started SYSV: OpenResty is a full-fledged web platform that integrates the standard Nginx core, LuaJIT...dencies..
Hint: Some lines were ellipsized, use -l to show in full.
就这样简单的安装完OpenResty了,顺带看看OpenResty编译了哪些模块吧,可以看到自带redis模块了:
[root@centos1 sockproc-master]# /usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.19.3.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (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.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --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.32 --add-module=../ngx_lua-0.10.19 --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=../redis2-nginx-module-0.15 --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.9 --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