OpenResty允许开发人员使用lua编程语言构建现有的Nginx的C模块,支持高流量的应用程序。 OpenResty官网:https://openresty.org/cn/download.html
安装依赖
# yum install -y readline-devel pcre-devel openssl-devel perl gcc gcc-c++ libreadline-dev libncurses5-dev libpcre3-dev libssl-dev
编译安装OpenResty
[root@localhost src]# tar zxvf openresty-1.11.2.5.tar.gz
[root@localhost src]# cd openresty-1.11.2.5
[root@localhost openresty-1.11.2.5]# groupadd www
[root@localhost openresty-1.11.2.5]# useradd -s /sbin/nologin -M -g www www
[root@localhost openresty-1.11.2.5]# ./configure --prefix=/app/OpenResty \
>--user=www \
>--group=www \
>--with-luajit \
>--without-http_redis2_module \
>--with-http_iconv_module \
>--with-http_realip_module \ #获取用户真实ip模块
>--with-pcre \ #Perl兼容的达式模块
>--with-luajit \ #集成luajit模块
>--add-module=./bundle/ngx_cache_purge-2.3/ \ #添加自定义的模块
>--add-module=./bundle/nginx_upstream_check_module-0.3.0/ \
>-j2 #支持多核 make 工作的特性,
[root@localhost openresty-1.11.2.5]# gmake && gmake install
[root@localhost openresty-1.11.2.5]# cd /app/OpenResty/nginx/sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# ./nginx -V
nginx version: openresty/1.11.2.5
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/app/OpenResty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.10 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/app/OpenResty/luajit/lib --user=www --group=www --with-http_realip_module --with-http_ssl_module
[root@localhost sbin]# ./nginx -v
nginx version: openresty/1.11.2.5
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /app/OpenResty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /app/OpenResty/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ./nginx -t -c /app/OpenResty/nginx/conf/nginx.conf
nginx: the configuration file /app/OpenResty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /app/OpenResty/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps -ef|grep -i nginx
root 18014 1 0 10:57 ? 00:00:00 nginx: master process ./nginx
www 18015 18014 0 10:57 ? 00:00:00 nginx: worker process
root 18017 2603 0 10:57 pts/0 00:00:00 grep -i nginx
[root@localhost sbin]#
配置服务
[root@localhost nginx]# cat /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /app/nginx/conf/nginx.conf
# pidfile: /app/nginx/logs/nginx.pid
# 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_PATH="/app/OpenResty/nginx"
nginx="$NGINX_PATH/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="$NGINX_PATH/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
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
[root@localhost nginx]# chkconfig --add nginx
[root@localhost nginx]# chkconfig nginx on
[root@localhost nginx]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@localhost nginx]#
nginx升级
#查看原来的参数
[root@localhost sbin]# pwd
/app/OpenResty2/nginx/sbin
[root@localhost sbin]# ./nginx -V
nginx version: web/999.999.9.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/app/OpenResty2/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.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.07 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.11 --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.18 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.08 --add-module=../ngx_stream_lua-0.0.3 --with-ld-opt=-Wl,-rpath,/app/OpenResty2/luajit/lib --user=www --group=www --with-http_realip_module --with-pcre --add-module=/app/soft/naxsi-master/naxsi_src --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module
[root@localhost sbin]#
查看当前的版本号
[root@Super sbin]# ./nginx -V
nginx version: openresty/1.11.2.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/openresty//nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.10 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/opt/openresty/luajit/lib --add-module=/opt/soft/naxsi-master/naxsi_src --with-http_ssl_module --with-http_stub_status_module
[root@Super sbin]#
下载要升级的版本、重新编译
[root@Super soft]# wget
[root@Super soft]# tar -zxvf openresty-1.13.6.2.tar.gz
[root@Super soft]# cd openresty-1.13.6.2
[root@Super openresty-1.13.6.2]# ./configure --prefix=/opt/openresty/ --add-module=/opt/soft/naxsi-master/naxsi_src --with-http_ssl_module --with-http_stub_status_module --with-luajit
[root@Super openresty-1.13.6.2]# gmake
此步切记不要make install
备份老的nginx文件、覆盖最新的文件
[root@Super openresty-1.13.6.2]# mv /opt/openresty/nginx/sbin/nginx{,.20180907bak}
[root@Super openresty-1.13.6.2]# cp build/nginx-1.13.6/objs/nginx /opt/openresty/nginx/sbin/
[root@Super openresty-1.13.6.2]# /opt/openresty/nginx/sbin/nginx -t -c /opt/openresty/nginx/conf/nginx.conf
nginx: the configuration file /opt/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/openresty/nginx/conf/nginx.conf test is successful
[root@Super openresty-1.13.6.2]#
使用make upgrade替换老的nginx进程
[root@Super openresty-1.13.6.2]# make upgrade
此步在要升级的新版本中执行
[root@Super openresty-1.13.6.2]# /opt/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/openresty//nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --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=../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.5 --with-ld-opt=-Wl,-rpath,/opt/openresty/luajit/lib --add-module=/opt/soft/naxsi-master/naxsi_src --with-http_ssl_module --with-http_stub_status_module --with-stream