当前位置: 首页 > 工具软件 > OpenResty > 使用案例 >

1.openresty简介

能钟展
2023-12-01
openresty四个核心组成部分
nginx
luajit	高效的lua语言解释器编译器
ngx_lua	处理http协议,让lua程序嵌入nginx运行
stream_lua	与ngx_lua类似,但处理的是tcp、udp

常用lua组件
lua_mysql 
lua_redis
lua_websocket
lua_upload

辅助工具
opm 类似rpm用来安装组件
resty-cli 命令行的形式直接运行openresty/lua程序
restydoc 类似man的参考手册

结构分层
toolchain (opm resty-cli)

lua-resty (lua)core lua_xxx)

luajit 
	ngx_lua(http_lua)	stream_lua
nginx   (ngx_echo ngx_xx)
linux/windows

版本说明  OpenResty 1.15.8.2  前三个是大版本,第四个数字是小版本表示该大版本发布的次数

安装依赖:gcc perl libpcre libssl

opm.openresty.org 管理官方组件
opm  get/search info list upgrade(更新指定) update(更新全部) remove
默认操作 openresty/site 可以使用--install_modules=path指定 或者-cwd安装在当前目录


resty可以解析lua脚本,用于测试
-c 最大并发连接数,默认64
-I指定库搜索路径
-l指定加载库

resty -e "print(123)"
执行文件
1.lua 
#!/usr/local/openresty/bin/resty 
print(123)

./1.lua



openresty的典型架构

openresty负载均衡 -》 n* openresty业务应用 -》redis缓存  kafka消息队列 mysql数据库

openresty可以充当apigateway 以restful接口为基础聚合整理各种后端服务。
并增加监控、缓存、权限控制等功能。

openresty核心:nginx+ngx_lua/stream_lua

nginx有两个模块 http和stream stream里面的serverlisten默认tcp,udp需要指定


反向代理
upstream backend {
	least_conn; #负载均衡策略
	server 127.0.0.1:80;
	server ...
	
	keepalive 32; #使用连接池,长链接复用
}

location /passto {
	proxy_set_header Host $host; #使用变量转发原始请求的host头
	proxy_pass http://backend;
}


日志默认在log/*,可以自定义修改
运行日志:
access_log记录访问http/tcp的请求
log_format name format_string  ;#自定义一个格式 然后在下面的access_log中format指定该名字
access_log path  format buffer=size flush=time


error_log记录服务器各种错误信息
error_log file level;  #debug info notice  warn error crit alert emerg 默认error




opm -h
Can't locate Digest/MD5.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/openresty/bin/opm line 16.
BEGIN failed--compilation aborted at /usr/local/openresty/bin/opm line 16.

yum -y install perl-Digest-MD5




 类似资料: