一 :系统版本
1 cat /etc/issue:
CentOS release 6.2 (Final)
Kernel \r on an \m
2 cat /proc/version :
Linux version 2.6.32-220.el6.x86_64 (mockbuild@c6b18n3.bsys.dev.centos.org) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Dec 6 19:48:22 GMT 2011
二:openresty 安装
官网地址 http://openresty.org/
下载版本 ngx_openresty-1.9.3.1.tar.gz
1 安装依赖包:
yum install readline-devel pcre-devel openssl-devel gcc
2 安装openresty
(1) tar -zxvf ngx_openresty-1.9.3.1.tar.gz
(2) cd ngx_openresty-1.9.3.1
(3) 安装命令参考 https://www.nginx.com/resources/wiki/modules/lua/#lua-installation 。官方推荐的一键安装命令为
./configure --with-luajit && make && make install
这个命令会把openresty安装到默认路径 /usr/local/openresty
安装到指定路径可以在
./configure --prefix=/opt/openresty 指定
./configure --help 可以查看更多安装选项。
本次采用
./configure --prefix=/opt/openresty --with-luajit && make && make install
(4)luasocket 安装
参考 http://www.cnblogs.com/dongxiao-yang/p/4878323.html
openresty作者章亦春本人是非常讨厌luascoket这个库的,在https://groups.google.com/forum/#!topic/openresty/PD6lTehlhJY
邮件里他的回复是:
这个 luasocket 必会阻塞 nginx worker 进程,让你的 nginx 服务器瞬间退化成和 Apache httpd 和
php-fpm 一样弱 :) 绝对不要在生产环境使用它!
标准 Lua 5.1 解释器的官方源码发布包中绝对不会有 socket.core 这种东西 :)
ngx_lua 提供的 cosocket API 是非阻塞的,而且这个 API 故意设计成和 LuaSocket 库基本兼容,所以你把
Lua 社区里那些基于 LuaSocket 的 Lua 库移植到 ngx_lua 环境中,也不会很费劲。
然而没有用,作者提供的cosocket在nginx的上下文使用是有限制的,所以对于需要在nginx初始化时候通过init_by_lua 部分 利用tcp获取一些启动数据的应用来说还是需要安装的,不过https://www.nginx.com/resources/wiki/modules/lua/里面 todo的列表里作者已经提出了 cosocket: add support in the context of init_by_lua. 这个目标,坐等实现。
参考 https://groups.google.com/forum/#!topic/openresty/GPgAH-75gX8
lua-resty-mysql 使用的是 ngx_lua 的 TCP cosocket API,而这个 API 在 init_by_lua 的上下文中是禁用的: http://wiki.nginx.org/HttpLuaModule#ngx.socket.tcp 注意 ngx.socket.tcp 这个接口支持的上下文(Context)列表中并没有 init_by_lua.
同时,lua-resty-mysql 库的文档中对此也有提及:https://github.com/agentzh/lua-resty-mysql#limitations
引用一下原文,“This library cannot be used in code contexts like set_by_lua*,
log_by_lua*, and header_filter_by_lua* where the ngx_lua cosocket API
is not available.”
安装完毕,nginx位于/opt/openresty/nginx/路径下,可以各种配置了。
原文:http://www.cnblogs.com/dongxiao-yang/p/4877799.html