tnginx调用lua模块编译安装

nginx 牛B之处 略

lua    牛B之处 略


1.软件下载(目前最稳定版本):


tnginx最新动态

[2014-01-08] Tengine-2.0.0 开发版正式发布(变更列表)

[2013-11-22] Tengine-1.5.2 稳定版正式发布(变更列表)


最新版特性:

继承Nginx-1.4.4的所有特性,100%兼容Nginx的配置;

动态模块加载(DSO)支持。加入一个模块不再需要重新编译整个Tengine;

支持SPDY v3协议,自动检测同一端口的SPDY请求和HTTP请求;

流式上传到HTTP后端服务器或FastCGI服务器,大量减少机器的I/O压力;

更加强大的负载均衡能力,包括一致性hash模块、会话保持模块,还可以对后端的服务器进行主动健康检查,根据服务器状态自动上线下线;

输入过滤器机制支持。通过使用这种机制Web应用防火墙的编写更为方便;

支持设置proxy、memcached、fastcgi、scgi、uwsgi在后端失败时的重试次数

动态脚本语言Lua支持。扩展功能非常高效简单;

支持管道(pipe)和syslog(本地和远端)形式的日志以及日志抽样;

组合多个CSS、JavaScript文件的访问请求变成一个请求;

自动去除空白字符和注释从而减小页面的体积

自动根据CPU数目设置进程个数和绑定CPU亲缘性;

监控系统的负载和资源占用从而对系统进行保护;

显示对运维人员更友好的出错信息,便于定位出错机器;

更强大的防攻击(访问速度限制)模块;

更方便的命令行参数,如列出编译的模块列表、支持的指令等;

可以根据访问文件类型设置过期时间;

...



开发板

wget http://tengine.taobao.org/download/tengine-2.0.0.tar.gz

稳定版

wget http://tengine.taobao.org/download/tengine-1.5.2.tar.gz


LuaJIT-2.0.2.tar.gz

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz


ngx_devel_kit-0.2.19.tar.gz

https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19


lua-nginx-module-0.9.4.tar.gz

https://github.com/chaoslawful/lua-nginx-module/releases/tag/v0.9.4


参考站点

https://github.com/chaoslawful/lua-nginx-module#installation


2.建立nginx运行用户和程序目录:


groupadd www

useradd -s /sbin/nologin -g www www

mkdir -p /usr/local/nginx

mkdir -p /usr/local/pcre


3.安装pcre

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.zip

3.1:安装pcre-8.32

unzip pcre-8.32.zip

cd pcre-8.32

./configure --prefix=/usr/local/pcre --enable-utf8 --enable-pcregrep-libbz2 --enable-pcregrep-libz

make && make install


4. 安装LuaJIT-2.0.2.tar.gz


mkdir -p /usr/local/luajit

tar -xvf LuaJIT-2.0.2.tar.gz

cd LuaJIT-2.0.2

make

make install PREFIX=/usr/local/luajit


4.1 LIB库位置

[root@tzhadoop08 LuaJIT-2.0.2]# ll /usr/local/luajit/lib/

total 1212

-rw-r--r--. 1 root root 775134 Jan 25 22:31 libluajit-5.1.a

lrwxrwxrwx. 1 root root     22 Jan 25 22:31 libluajit-5.1.so -> libluajit-5.1.so.2.0.2

lrwxrwxrwx. 1 root root     22 Jan 25 22:31 libluajit-5.1.so.2 -> libluajit-5.1.so.2.0.2

-rwxr-xr-x. 1 root root 451984 Jan 25 22:31 libluajit-5.1.so.2.0.2

drwxr-xr-x. 3 root root   4096 Jan 25 22:31 lua

drwxr-xr-x. 2 root root   4096 Jan 25 22:31 pkgconfig


4.2INC路径


[root@tzhadoop08 LuaJIT-2.0.2]# ll /usr/local/luajit/include/luajit-2.0/

total 40

-rw-r--r--. 1 root root  6006 Jan 25 22:31 lauxlib.h

-rw-r--r--. 1 root root  4339 Jan 25 22:31 luaconf.h

-rw-r--r--. 1 root root 11964 Jan 25 22:31 lua.h

-rw-r--r--. 1 root root   135 Jan 25 22:31 lua.hpp

-rw-r--r--. 1 root root  2573 Jan 25 22:31 luajit.h

-rw-r--r--. 1 root root  1113 Jan 25 22:31 lualib.h


4.3

配置一下 luajit 或 lua 的环境变量(Nginx编译时需要):


我的测试环境里,配置如下:

export LUAJIT_LIB=/usr/local/luajit/lib

export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0


4.4

验证

[root@tzhadoop08 LuaJIT-2.0.2]# echo $LUAJIT_LIB

/usr/local/luajit/lib

[root@tzhadoop08 LuaJIT-2.0.2]# echo $LUAJIT_INC

/usr/local/luajit/include/luajit-2.0


5,解压需要编译的文件(ngx_devel_kit,lua-nginx-module,echo-nginx-module)到/usr/local/

[root@tzhadoop08 tnginx]# ll

total 5616

drwxr-xr-x. 6 health public    4096 Jan 10 18:51 echo-nginx-module-master

-rw-r--r--. 1 health public   87994 Jan 25 22:05 echo-nginx-module-master.zip

-rw-r--r--. 1 health public  470131 Jan 24 06:42 lua-nginx-module-0.9.4.tar.gz

-rw-r--r--. 1 health public   65029 Jan 24 06:41 ngx_devel_kit-0.2.19.tar.gz

drwxr-xr-x. 9 root   root     12288 Jan 25 22:14 pcre-8.32

-rw-r--r--. 1 health public 1434777 Jan 15 00:52 tengine-1.5.0.tar.gz



tar -xvf ngx_devel_kit-0.2.19.tar.gz -C /usr/local/


tar -xvf lua-nginx-module-0.9.4.tar.gz -C /usr/local/


unzip  echo-nginx-module-master.zip

mv echo-nginx-module-master /usr/local/


6,编译tnginx,需要注意编译顺序


tar -xvf tengine-1.5.2.tar.gz

cd tengine-1.5.2


./configure --user=www --group=www \

--prefix=/usr/local/nginx \

--with-pcre \

--with-pcre=/workspace/pcre-8.32 \

--with-http_ssl_module \

--with-http_gzip_static_module \

--with-http_stub_status_module  \

--with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" \

--add-module=/usr/local/ngx_devel_kit-0.2.19 \

--add-module=/usr/local/echo-nginx-module-master \

--add-module=/usr/local/lua-nginx-module-0.9.4


make

make install


上传启动文件:(见附件)

/etc/init.d/nginx start


如果升级现有Tnginx,参考如下:

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

cp -rp objs/nginx /usr/local/nginx/sbin/

/usr/local/nginx/sbin/nginx -t

/etc/init.d/nginx reload


7.tnginx调用LUA测试配置文件:


[root@computer ~]# more /usr/local/nginx/conf/nginx.conf

worker_processes  auto;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type  application/octet-stream;

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                     '$status $body_bytes_sent "$http_referer" '

                     '"$http_user_agent" "$http_x_forwarded_for"';

   #access_log  logs/access.log  main;

   sendfile        on;

   #tcp_nopush     on;

   #keepalive_timeout  0;

   keepalive_timeout  65;

   #gzip  on;




   server {

       listen       80;

       server_name  localhost;


       access_log  /data/logs/access_kjh.log  main;

location /echo {

default_type 'text/plain';

echo 'hello echo';

                               }


location /lua {

default_type 'text/plain';

   content_by_lua 'ngx.say("hello, lua")';

                               }


                               }  


    }


7.1测试访问:

[root@computer ~]# curl http://127.1/lua

hello, lua

[root@computer ~]# curl http://127.1/echo

hello echo


8.付tnginx启动文件;

#! /bin/sh

# chkconfig: 2345 55 25


### BEGIN INIT INFO

# Provides:          nginx

# Required-Start:    $all

# Required-Stop:     $all

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: starts the nginx web server

# Description:       starts nginx using start-stop-daemon

### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="nginx daemon"

NAME=nginx

DAEMON=/usr/local/nginx/sbin/$NAME

CONFIGFILE=/usr/local/nginx/conf/$NAME.conf

PIDFILE=/usr/local/nginx/logs/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME


set -e

[ -x "$DAEMON" ] || exit 0


do_start() {

$DAEMON -c $CONFIGFILE || echo -n "nginx already running"

}


do_stop() {

kill -INT `cat $PIDFILE` || echo -n "nginx not running"

}


do_reload() {

kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"

}


case "$1" in

start)

echo -n "Starting $DESC: $NAME"

do_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

do_stop

echo "."

;;

reload|graceful)

echo -n "Reloading $DESC configuration..."

do_reload

echo "."

;;

restart)

echo -n "Restarting $DESC: $NAME"

do_stop

do_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2

exit 3

;;

esac


exit 0


你可能感兴趣的:(lua,编译安装,tnginx)