openresty nginx 安装过程记录

转载请注明原始地址 http://www.cnblogs.com/dongxiao-yang/p/4877799.html 

一 :系统版本

1 cat /etc/issue:

CentOS release 6.2 (Final)

Kernel \r on an \m

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 一样弱 :) 绝对不要在生产环境使用它! 



> 看了下这里依赖于 socket.core 模块,貌似luajit下没有这个模块,但是lua 5.1 是有的. 现在在openresty 下跑不起来. 


标准 Lua 5.1 解释器的官方源码发布包中绝对不会有 socket.core 这种东西 :) 


> 我想问的是   luasocket 模块有什么替代么,我看 lua-resty-http 里面用了 local sock = tcp() 这个tcp 
> 的socket 这个可以替代么? 


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/路径下,可以各种配置了。

 

三 nginx error_log 和  ngx.log api

nginx配置会有一个error_log属性,比如下面

error_log  /opt/logs/nginx/error/ng_err.log;

这个日志是nginx本身产生的日志,设置成info级别后在nginx启动时可以看到更多的信息

2015/10/15 16:22:40 [notice] 10439#0: using the "epoll" event method

2015/10/15 16:22:40 [notice] 10439#0: openresty/1.9.3.1

2015/10/15 16:22:40 [notice] 10439#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 

2015/10/15 16:22:40 [notice] 10439#0: OS: Linux 2.6.32-220.el6.x86_64

2015/10/15 16:22:40 [notice] 10439#0: getrlimit(RLIMIT_NOFILE): 65536:65536

2015/10/15 16:22:40 [notice] 10440#0: start worker processes

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10441

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10442

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10444

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10445

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10446

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10447

2015/10/15 16:22:40 [notice] 10440#0: start worker process 10448

...........................

另外还有一种log是在nginx lua模块调用ngx.log(log_level, ...) api接口时产生的err.log,这个日志位于nginx 目录logs文件夹下,调用ngx.log() api

输出的日志都在这个文件里 

 

 

 

 

 



 

 

 

 

 

posted @ 2015-10-14 19:18  sanmutongzi  阅读(1296)  评论(0编辑  收藏  举报