nginx-2:部署生产级openresty nginx部署项目步骤
suiw9 2024-11-14 19:09 20 浏览 0 评论
目录
(1).下载源码
(2).openrestry低版本编译命令
(3).openrestry高版本编译命令
1.编译命令
2.注意事项
3.编译错误与解决
(4).openrestry安装第三方库lua_resty_http
1.安装第三方库lua_resty_http
2.安装第三方库nginx-lua-prometheus
(5).使用lua所必须的模块(openresty自带)
(6).configure参数详解
(7).相关阅读
(8).相关阅读
(1).下载源码
https://openresty.org/cn/download.html
我下载的是最新版本:openresty-1.15.8.1.tar.gz
tar -xzvf openresty-VERSION.tar.gz
cd openresty-VERSION/
#需要安装各种组件以适用于生产环境
下载第三方插件:
git clone https://github.com/replay/ngx_http_consistent_hash.git
后边安装openresty时有参数指向上述工程的本地地址。
(2).openrestry低版本编译命令
低版本编译时需要手动指定很多组件(使用高版本不用指定下述这么多):
./configure --prefix=/app/3rd/nginx/openresty --with-cc-opt=-O2 --add-module=build/ngx_devel_kit-0.3.1rc1 --add-module=build/ngx_stream_lua-0.0.7 --add-module=build/iconv-nginx-module-0.14 --add-module=build/echo-nginx-module-0.61 --add-module=build/xss-nginx-module-0.06 --add-module=build/ngx_coolkit-0.2 --add-module=build/set-misc-nginx-module-0.32 --add-module=build/form-input-nginx-module-0.12 --add-module=build/encrypted-session-nginx-module-0.08 --add-module=build/srcache-nginx-module-0.31 --add-module=build/ngx_lua-0.10.15 --add-module=build/ngx_lua_upstream-0.07 --add-module=build/headers-more-nginx-module-0.33 --add-module=build/array-var-nginx-module-0.05 --add-module=build/memc-nginx-module-0.19 --add-module=build/redis-nginx-module-0.3.7 --add-module=build/rds-json-nginx-module-0.15 --add-module=build/rds-csv-nginx-module-0.09 --with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib --add-module=/app/3rd/src-install/ngx_http_consistent_hash --with-http_stub_status_module --with-pcre-jit --with-stream_ssl_preread_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-openssl=/opt/openresty/openssl-1.1.0i --with-dtrace-probes --with-stream --with-stream_ssl_module --with-pcre=/opt/openresty/pcre-8.40
(3).openrestry高版本编译命令
1.15.8.1+,很多module不需要手工指定,默认安装:
1.编译命令
./configure --prefix=/app/3rd/nginx/openresty --with-cc-opt=-O2 --add-module=build/iconv-nginx-module-0.14 --with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib --add-module=/app/3rd/src-install/ngx_http_consistent_hash --with-http_stub_status_module --with-pcre-jit --with-stream_ssl_preread_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-openssl=/opt/openresty/openssl-1.1.0i --with-dtrace-probes --with-stream --with-stream_ssl_module --with-pcre=/opt/openresty/pcre-8.40
gmake
gmake install
2.注意事项
--add-module=build/ngx_stream_lua-0.0.7不需要加,因为:
ngx_stream_lua_module is already enabled in OpenResty by default. Your linker errors clearly indicate that. You should remove the option --add-module=build/ngx_stream_lua-0.0.7.
官方git issue回复:
https://github.com/openresty/openresty/issues/507
multiple definition of `ngx_http_rds_csv_output_more_field_data':表示add-module中的已经自动包含,不需要add-module主动指定。
3.编译错误与解决
3.1.编译错误1
configure阶段报错:the HTTP rewrite module requires the PCRE library
./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel与openssl-devel解决问题
yum -y install pcre-devel openssl openssl-devel
3.2.编译错误2
gmake阶段报错:dtrace command not foud错误:
安装dtrace
git clone https://github.com/dtrace4linux/linux.git
有可能提示libgcc需要upgrade,执行yum upgrade libgcc即可。
centos执行:tools/get-deps-fedora.sh安装依赖。
make all
make install
make load
3.3.编译错误3
gmake阶段报错:/opt/openresty/openssl-1.1.0i: No such file or directory
https://github.com/openssl/openssl/releases?after=OpenSSL_1_1_1-pre9
下载:
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0i.tar.gz
正常安装openssl的步骤:
./config --prefix=/opt/openresty/openssl-1.1.0i
make
make install
但是openrestry依赖的openssl不能这样安装,需要把openssl的源码copy到目录:
/opt/openresty/openssl-1.1.0i
然后执行openrestry阶段时,会自动到上边目录部署openssl.
错误提示(gmake阶段):collect2: error: ld returned 1 exit status
网上相同问题的解决方式:
https://blog.csdn.net/iaiot/article/details/78273921
openrestry执行configure时指定pcre目录。也可以参考官方文档:https://openresty.org/en/installation.html
./configure --with-pcre=../pcre-8.40 -j4
pcre8.40下载地址:
https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
all version:
https://ftp.pcre.org/pub/pcre/
但是又遇到了另一个问题:
configure: error: You need a C++ compiler for C++ support.
解决方法:
yum install -y gcc gcc-c++
/opt/openresty/pcre-8.40/missing: line 81: automake-1.15: command not found:
wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
./bootstrap.sh
./configure
make
make install
(4).openrestry安装lua第三方库
1.安装第三方库lua_resty_http
参考:
https://git.102no.com/2018/12/21/lua-resty-http/
第一步
首先找到项目地址:https://github.com/pintsized/lua-resty-http
第二步
然后将 lua-resty-http/lib/resty/ 目录下的 http.lua 和 http_headers.lua 两个文件拷贝到openresty/lualib/resty 目录下即可,
OpenResty 安装目录为 openresty)。不需要重启。(少数需要清空 Openresty shared_dict 数据的情况需要重启 )。
2.安装第三方库nginx-lua-prometheus
openrestry添加prometheus监控的Lua扩展:
参考:
https://www.jianshu.com/p/3341db428978
git clone https://github.com/knyar/nginx-lua-prometheus
prometheus.lua拷贝到lualib下。
(5).使用lua所必须的模块(openresty自带)
lua-nginx-module:是 Lua 的最基本模块。
luajit:官网,luajit 是采用 C 语言编写的 Lua 语言解释器。当然如果你不想用 luajit 的话,也可以 yum 安装 lua 并提供给 Nginx,不推荐那样而已。
ngx_devel_kit:一般简称 NDK,是一个供其它模块使用的拓展 Nginx 核心功能的模块,第三方模块开发可以基于它快速实现。强烈建议编译 Lua 时把它也带上,虽然不是必须的,缺少该依赖项时例如 set_by_lua* 和 ndk.set_var.* API 都将被自动禁用。
(6).configure参数详解
./configure
#指定安装的位置
--prefix=/app/3rd/nginx/openresty/nginx
#设置C编译器参数:
# -O1 提供基础级别的优化
# -O2提供更加高级的代码优化,会占用更长的编译时间
# -O3提供最高级的代码优化
--with-cc-opt=-O2
#一般简称 NDK,是一个供其它模块使用的拓展 Nginx 核心功能的模块;
# 第三方模块开发可以基于它快速实现。
# 强烈建议编译 Lua 时把它也带上,虽然不是必须的,缺少该依赖项时例如 set_by_lua* 和 ndk.set_var.* API 都将被自动禁用
--add-module=build/ngx_devel_kit-0.3.1rc1
#编码转换模块
--add-module=build/iconv-nginx-module-0.14
#nginx echo模块是在nginx程序上扩展了echo输出字符的功能, 对于调试很方便。
--add-module=build/echo-nginx-module-0.61
#Nginx 中的原生跨站点脚本支持
--add-module=build/xss-nginx-module-0.06
#操作cookie的模块
--add-module=build/ngx_coolkit-0.2
#模块是标准的HttpRewriteModule指令的扩展,提供更多的功能,如URI转义与非转义、JSON引述、Hexadecimal/MD5/SHA1/Base32/Base64编码与解码、随机数等等。
--add-module=build/set-misc-nginx-module-0.32
#作用是解析post请求中的参数。
--add-module=build/form-input-nginx-module-0.12
#encrypt and decrypt nginx variable values。
--add-module=build/encrypted-session-nginx-module-0.08
#针对代理层缓存,我们可以将静态资源放入cdn或者本地页面缓存加快用户访问速度,缓解服务器压力。比如结合pika实现。
--add-module=build/srcache-nginx-module-0.31
#Lua 的最基本模块。
--add-module=build/ngx_lua-0.10.15
#Lua&upstream模块。
--add-module=build/ngx_lua_upstream-0.07
#Set and clear input and output headers...more than "add"!
#提供操作header的各种方法。
--add-module=build/headers-more-nginx-module-0.33
#Add support for array variables to NGINX config files
#增加数组变量的支持。
--add-module=build/array-var-nginx-module-0.05
#提供memcached的各种操作。
--add-module=build/memc-nginx-module-0.19
#提供redis的各种操作。
--add-module=build/redis-nginx-module-0.3.7
#提供db的操作支持,json格式。
--add-module=build/rds-json-nginx-module-0.15
#提供db的操作支持,csv格式。
--add-module=build/rds-csv-nginx-module-0.09
#lua相关模块。
--add-module=build/ngx_stream_lua-0.0.7
#设置将会在链接(linking)过程中使用的额外参数。
--with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib
#通过一致性哈希算法来选择合适的后端节点。
--add-module=/tmp/open_install/openresty-1.13.6.2/../ngx_http_consistent_hash-master
#模块主要用于查看Nginx的一些状态信息。
--with-http_stub_status_module
# 打开pcre JIT支持,比不使用快好几倍。
--with-pcre-jit
#手头没证书,给https做代理时要用到这个功能。
--with-stream_ssl_preread_module
#在启用Mail模块后,单独地禁用pop3模块
--without-mail_pop3_module
#在启用mail模块后,单独地禁用IMAP模块
--without-mail_imap_module
#在启用mail模块后,单独地禁用smtp模块
--without-mail_smtp_module
#让nginx支持http/2。
--with-http_v2_module
#让nginx支持https。
--with-http_ssl_module
#获取真实IP模块。
--with-http_realip_module
#在响应之前或者之后追加文本内容,比如想在站点底部追加一个js或者css,可以使用这个模块来实现,这个模块和淘宝开发的nginx footer模块有点类似,但是还是有不同. 这个模块需要依赖子请求,nginx footer依赖nginx写死的配置.
--with-http_addition_module
#ngx_http_auth_request_module 第三方认证
# 编译 Nginx 时需要添加该模块 --with-http_auth_request_module
# 该模块可以将客户端输入的用户名、密码 username:password 通过 Base64 编码后写入 Request Headers 中
# 例如:wang:wang -> Authorization:Basic d2FuZzp3YW5n=
# 然后通过第三方程序解码后跟数据库中用户名、密码进行比较,Nginx 服务器通过 header 的返回状态判断是否认证通过。
--with-http_auth_request_module
#安全连接,用于防盗链。
#https://juejin.im/post/5bce737551882576e3102733
--with-http_secure_link_module
#如果你想提供从一个目录中随机选择文件的索引文件,那么这个模块需要被激活
--with-http_random_index_module
#nginx默认安装ngx_http_gzip_module,采用的是chunked方式的动态压缩,静态压缩需要使用http_gzip_static_module这个模块,进行pre-compress。
#模块 ngx_http_gzip_static_module 允许发送以".gz"作为文件扩展名的预压缩文件,以替代发送普通文件。需要指定 --with-http_gzip_static_module编译选项:
--with-http_gzip_static_module
#该模块实现了替代过滤,在响应中用一个字符串替代另一个字符串
--with-http_sub_module
#启用这个模块将激活使用WebDAV的配置指令。注意:这个模块也只在有需要使用的基础上启用,如果配置不正确,它将带来安全问题。
--with-http_dav_module
#如果需要提供Flash流媒体视频文件,那么该模块将会提供伪流媒体
--with-http_flv_module
#这个模块支持H.264/AAC文件伪流媒体
--with-http_mp4_module
#在服务端发送数据之前进行压缩也很重要。GZip 压缩就是其中的一种压缩方式。
#Nginx 默认就能提供上述功能,提供两个 GZip 压缩的增强插件:http_gzip_static_module,http_gunzip_module
--with-http_gunzip_module
#使用aio threads,需要添加--with-threads配置
#nginx这样配置:
server {
location /one { aio threads=one; } location /two { aio threads=two; } }
--with-threads
#指定nginx ssl模块依赖的ssl库
--with-openssl=/opt/openresty/openssl-1.1.0i
#openresty使用火焰图排查性能问题时要用到dtrace。
#参考文章:https://juejin.im/post/59ce27fef265da065b66d54b
--with-dtrace-probes
#把内网ip端口映射到外网地址。比如如果你想把云数据库(mysql等)开放外网地址。需要增加编译参数:--with-stream 与 --with-stream_ssl_module。
--with-stream
--with-stream_ssl_module
(7).相关阅读
相关推荐
- 5款Syslog集中系统日志常用工具对比推荐
-
一、为何要集中管理Syslog?Syslog由Linux/Unix系统及其他网络设备生成,广泛分布于整个网络。因其包含关键信息,可用于识别网络中的恶意活动,所以必须对其进行持续监控。将Sys...
- 跨平台、多数据库支持的开源数据库管理工具——DBeaver
-
简介今天给大家推荐一个开源的数据库管理工具——DBeaver。它支持多种数据库系统,包括Mysql、Oracle、PostgreSQL、SLQLite、SQLServer等。DBeaver的界面友好...
- 强烈推荐!数据库管理工具:Navicat Premium 16.3.2 (64位)
-
NavicatPremium,一款集数据迁移、数据库管理、SQL/查询编辑、智能设计、高效协作于一体的全能数据库开发工具。无论你是MySQL、MariaDB、MongoDB、SQLServer、O...
- 3 年 Java 程序员还玩不转 MongoDB,网友:失望
-
一、什么场景使用MongoDB?...
- 拯救MongoDB管理员的GUI工具大赏:从菜鸟到极客的生存指南
-
作为一名在NoSQL丛林中披荆斩棘的数据猎人,没有比GUI工具更称手的瑞士军刀了。本文将带你围观五款主流MongoDB管理神器的特性与暗坑,附赠精准到扎心的吐槽指南一、MongoDBCompass:...
- mongodb/redis/neo4j 如何自己打造一个 web 数据库可视化客户端?
-
前言最近在做neo4j相关的同步处理,因为产线的可视化工具短暂不可用,发现写起来各种脚本非常麻烦。...
- solidworks使用心得,纯干货!建议大家收藏
-
SolidWorks常见问题...
- 统一规约-关乎数字化的真正实现(规范统一性)
-
尽管数字化转型的浪潮如此深入人心,但是,对于OPCUA和TSN的了解却又甚少,这难免让人质疑其可实现性,因为,如果缺乏统一的语义互操作规范,以及更为具有广泛适用的网络与通信,则数字化实际上几乎难以具...
- Elasticsearch节点角色配置详解(Node)
-
本篇文章将介绍如下内容:节点角色简介...
- 产前母婴用品分享 篇一:我的母婴购物清单及单品推荐
-
作者:DaisyH8746在张大妈上已经混迹很久了,有事没事看看“什么值得买”已渐渐成了一种生活习惯,然而却从来没有想过自己要写篇文章发布上来,直到由于我产前功课做得“太过认真”(认真到都有点过了,...
- 比任何人都光彩照人的假期!水润、紧致的肌肤护理程序
-
图片来源:谜尚愉快的假期临近了。身心振奋的休假季节。但是不能因为这种心情而失去珍贵的东西,那就是皮肤健康。炙热的阳光和强烈的紫外线是使我们皮肤老化的主犯。因此,如果怀着快乐的心情对皮肤置之不理,就会使...
- Arm发布Armv9边缘AI计算平台,支持运行超10亿参数端侧AI模型
-
中关村在线2月27日消息,Arm正式发布Armv9边缘人工智能(AI)计算平台。据悉,该平台以全新的ArmCortex-A320CPU和领先的边缘AI加速器ArmEthos-U85NPU为核心...
- 柔性——面向大规模定制生产的数字化实现的基本特征
-
大规模定制生产模式的核心是柔性,尤其是体现在其对定制的要求方面。既然是定制,并且是大规模的定制,对于制造系统的柔性以及借助于数字化手段实现的柔性,就提出了更高的要求。面向大规模定制生产的数字化业务管控...
- 创建PLC内部标准——企业前进的道路
-
作者:FrankBurger...
- 标准化编程之 ----------- 西门子LPMLV30测试总结
-
PackML乃是由OMAC开发且被ISA所采用的自动化标准TR88.00.02,能够更为便捷地传输与检索一致的机器数据。PackML的主要宗旨在于于整个工厂车间倡导通用的“外观和感觉”,...
你 发表评论:
欢迎- 一周热门
-
-
Linux:Ubuntu22.04上安装python3.11,简单易上手
-
宝马阿布达比分公司推出独特M4升级套件,整套升级约在20万
-
MATLAB中图片保存的五种方法(一)(matlab中保存图片命令)
-
别再傻傻搞不清楚Workstation Player和Workstation Pro的区别了
-
Linux上使用tinyproxy快速搭建HTTP/HTTPS代理器
-
如何提取、修改、强刷A卡bios a卡刷bios工具
-
Element Plus 的 Dialog 组件实现点击遮罩层不关闭对话框
-
日本组合“岚”将于2020年12月31日停止团体活动
-
SpringCloud OpenFeign 使用 okhttp 发送 HTTP 请求与 HTTP/2 探索
-
tinymce 号称富文本编辑器世界第一,大家同意么?
-
- 最近发表
-
- 5款Syslog集中系统日志常用工具对比推荐
- 跨平台、多数据库支持的开源数据库管理工具——DBeaver
- 强烈推荐!数据库管理工具:Navicat Premium 16.3.2 (64位)
- 3 年 Java 程序员还玩不转 MongoDB,网友:失望
- 拯救MongoDB管理员的GUI工具大赏:从菜鸟到极客的生存指南
- mongodb/redis/neo4j 如何自己打造一个 web 数据库可视化客户端?
- solidworks使用心得,纯干货!建议大家收藏
- 统一规约-关乎数字化的真正实现(规范统一性)
- Elasticsearch节点角色配置详解(Node)
- 产前母婴用品分享 篇一:我的母婴购物清单及单品推荐
- 标签列表
-
- dialog.js (57)
- importnew (44)
- windows93网页版 (44)
- yii2框架的优缺点 (45)
- tinyeditor (45)
- qt5.5 (60)
- windowsserver2016镜像下载 (52)
- okhttputils (51)
- android-gif-drawable (53)
- 时间轴插件 (56)
- docker systemd (65)
- slider.js (47)
- android webview缓存 (46)
- pagination.js (59)
- loadjs (62)
- openssl1.0.2 (48)
- velocity模板引擎 (48)
- pcre library (47)
- zabbix微信报警脚本 (63)
- jnetpcap (49)
- pdfrenderer (43)
- fastutil (48)
- uinavigationcontroller (53)
- bitbucket.org (44)
- python websocket-client (47)