一.两个依赖包 有yum的直接
yum yum –y install openssl openssl-devel prce prce-devel zlib zlib-devel
没有yum环境的,可以源码安装:
cd /usr/local
wget https://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz
tar zxf pcre-8.37.tar.gz
cd pcre-8.37 && ./configure &&make&&make install
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar zxf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c.tar.gz &&./config --prefix=/usr/local/openssl -fPIC no-gost no-shared no-zlib
make depend &&make install
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz
cd /usr/local/zlib-1.2.11 &&./configure
二.然后安装LuaJIT
mkdir /usr/local/modules ###存放所以的第三方模块目录
cd /usr/local/modules
1.wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar -zxvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5
make install PREFIX=/usr/local/LuaJIT
最后一行会输出一下提示:
==== Successfully installed LuaJIT 2.0.5 to /usr/local/LuaJIT ====
vi /etc/profile
文件末尾加入环境变量:
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0
source /etc/profile
ln -s /usr/local/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2 #不增加这行,nginx启动会报错
2.下载ngx_devel_kit(NDK)模块 :https://github.com/simpl/ngx_devel_kit/tags,不需要安装
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz
3.下载最新的lua-nginx-module 模块 :https://github.com/openresty/lua-nginx-module/tags,不需要安装
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzvf v0.10.8.tar.gz
三.sticky模块(cookie负载均衡,存在客户端的)
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
tar -zxf master.tar.gz
nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d.tar.gz(这个包是tengine sticky的扩展包)
mv nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d/ nginx-sticky
四.tengine安装(nginx也是一样)
tengine-2.1.1.tar.gz
tar zxf tengine-2.1.1.tar.gz
cd tengine-2.1.1
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.37 --with-pcre-jit --with-zlib=/usr/local/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.0.1c --with-http_sub_module --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_realip_module --with-http_spdy_module --with-http_gunzip_module --with-http_gzip_static_module --add-module=/usr/local/modules/ngx_devel_kit-0.3.0 --add-module=/usr/local/modules/lua-nginx-module-0.10.8 --add-module=/usr/local/modules/nginx-sticky/
make
make install
安装后:
/usr/local/nginx/sbin/nginx -t 查看状态
/usr/local/nginx/sbin/nginx 启动nginx
在/usr/local/nginx/conf/nginx.conf中加入如下代码:
location /hello_lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
重启nginx
访问10.211.55.3/hello_lua会出现”hello, lua”表示lua安装成功