java openresty 调用_Openresrt最佳案例第3篇:Openresty的安装

本文记录了一台全新CentOS 7服务器上安装OpenResty的详细步骤,包括解决gcc未找到、安装依赖库(gcc, pcre-devel, zlib, OpenSSL)以及配置Lua项目的过程。最后成功启动Nginx并实现 Lua 'hello world' 示例。" 130434121,11379383,Quartz重复调度问题排查与解决,"['Java', 'JVM', '开发语言', '任务调度', 'Quartz框架']
摘要由CSDN通过智能技术生成

我的服务器为一台全新的centos 7的服务器,所以从头安装openresty,并记录了安装过程中出现的问题,以及解决办法。

1.首先安装openresty

安装过程中出现以下的错误:

gcc: Command not found

2.安装gcc

3.重新make

4.下载ngx_cache_purge模块,该模块用于清理nginx缓存

cd /usr/servers/ngx_openresty–1.11.2.4/bundle

wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz

tar -xvf 2.3.tar.gz

5.下载nginx_upstream_check_module模块,该模块用于ustream健康检查

cd /usr/servers/ngx_openresty-1.11.2.4/bundle

wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz

tar -xvf v0.3.0.tar.gz

6.重新安装opresty

提示错误,安装pcre库

<1> gcc 安装

安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

<2> PCRE pcre-devel 安装

PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

<3> zlib 安装

zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

<4> OpenSSL 安装

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。

nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

<5>.重新安装OpenResty

<6>.启动Nginx

浏览器访问http://116.196.177.123:

安装成功了。

6.配置nginx

错误提示没有安装vim

1、在http部分添加如下配置

lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找

lua_package_path "/usr/servers/lualib/?.lua;;"; #lua 模块

lua_package_cpath "/usr/servers/lualib/?.so;;"; #c模块

2、在nginx.conf中的http部分添加include lua.conf包含此文件片段

Java代码 收藏代码

include lua.conf;

在/usr/server/nginx/conf下

vim lua.conf

7.环境变量:

vim /etc/profile

source /etc/profile

测试:

nginx -t

nginx: the configuration file /usr/servers/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/servers/nginx/conf/nginx.conf test is successful

nginx -s reload

浏览器访问http://116.196.177.123/lua

,浏览器显示:

hello world

8.将Lua项目化:

mkdir /usr/example

cp -r /usr/servers/lualib/ /usr/example/

mkdir /usr/example/lua

cd /usr/example

vim example.conf

vim /usr/example/lua/test.lua

cd /usr/servers/nginx/conf/

vim nginx.conf

http模块:

nginx -t

nginx: lua_code_cache is off; this will hurt performance in /usr/example/example.conf:7

nginx: the configuration file /usr/servers/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/servers/nginx/conf/nginx.conf test is successful

nginx -s reload

浏览器访问http://116.196.177.123/lua ,

hello world

导出history的所有命令:

参考资料

http://www.linuxidc.com/Linux/2016-09/134907.htm

http://jinnianshilongnian.iteye.com/blog/2186270

https://openresty.org/en/

本文著作权归作者所有,如若转载,请注明出处

转载请注明:文章转载自「 Java极客技术学习」https://www.javajike.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值