Nginx+Lua+OpenResty安装
1,安装依赖
yum install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl
2,下载ngx_openresty-xxx.tar.gz并解压(ngx_openresty-xxx/bundle目录里存放着nginx核心和很多第三方模块,比如有我们需要的Lua和LuaJIT。)
wget https://openresty.org/download/ngx_openresty-1.9.7.2.tar.gz
tar xvf ngx_openresty-1.9.7.2.tar.gz
cd ngx_openresty-1.9.7.2
3,安装LuaJIT
cd bundle/LuaJIT-2.1-20151219/
make clean && make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
4,下载ngx_cache_purge模块,该模块用于清理nginx缓存
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar xvf 2.3.tar.gz
5,下载nginx_upstream_check_module模块,该模块用于upstream健康检查
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar xvf v0.3.0.tar.gz
6,安装ngx_openresty
cd ..
./configure --prefix=/data/webserver/openresty --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_gzip_static_module --with-http_ssl_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2
make && make install
参数说明:
--with*** 安装一些内置/集成的模块
--with-http_realip_module 取用户真实ip模块
-with-pcre Perl兼容的达式模块
--with-luajit 集成luajit模块
--add-module 添加自定义的第三方模块,如此次的ngx_che_purge
7,到/data/webserver/openresty目录下用ll命令查看,会发现多出来了如下目录,说明安装成功
[root@php_web openresty]# ll
total 16
drwxr-xr-x 2 root root 4096 Apr 28 09:07 bin
drwxr-xr-x 6 root root 4096 Apr 28 09:07 luajit
drwxr-xr-x 5 root root 4096 Apr 28 09:07 lualib
drwxr-xr-x 6 root root 4096 Apr 28 09:07 nginx
说明:
/data/webserver/openresty/luajit :luajit环境,luajit类似于java的jit,即即时编译,lua是一种解释语言,通过luajit可以即时编译lua代码到机器代码,得到很好的性能;
/data/webserver/openresty/lualib:要使用的lua库,里边提供了一些默认的lua库,如redis,json库等,也可以把一些自己开发的或第三方的放在这;
/data/webserver/openresty/nginx :安装的nginx,通过/data/webserver/openresty/nginx/sbin/nginx -V 查看nginx版本和安装的模块
[root@php_web openresty]# /data/webserver/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.9.7.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/data/webserver/nginxopen/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.58 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.29 --add-module=../form-input-nginx-module-0.11 --add-module=../encrypted-session-nginx-module-0.04 --add-module=../srcache-nginx-module-0.30 --add-module=../ngx_lua-0.9.20 --add-module=../ngx_lua_upstream-0.04 --add-module=../headers-more-nginx-module-0.29 --add-module=../array-var-nginx-module-0.04 --add-module=../memc-nginx-module-0.16 --add-module=../redis2-nginx-module-0.12 --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,/data/webserver/nginxopen/luajit/lib --user=www --group=www --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_gzip_static_module --with-http_ssl_module --with-pcre --add-module=/data/ngx_openresty-1.9.7.2/bundle/ngx_cache_purge-2.3 --add-module=/data/ngx_openresty-1.9.7.2/bundle/nginx_upstream_check_module-0.3.0
8,启动nginx
/data/webserver/openresty/nginx/sbin/nginx -s reload


编译安装luarocks-2.2.2
wget http://keplerproject.github.io/luarocks/releases/luarocks-2.2.2.tar.gz
tar zxvf luarocks-2.2.2.tar.gz
cd luarocks-2.2.2
./configure --prefix=/data/webserver/openresty/luajit --with-lua=/data/webserver/openresty/luajit/ --lua-suffix=jit-2.1.0-beta1 --with-lua-include=/data/webserver/openresty/luajit/include/luajit-2.1
make build
make install

安装murmurhash插件
/data/webserver/openresty/luajit/bin/luarocks install murmurhash3
ln -s  /data/webserver/openresty/luajit/lib/lua/5.1/murmurhash3.so   /usr/local/lib/lua/5.1/murmurhash3.so