admin 发表于 2023-3-17 15:42:26

openresty教程

<img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038931205.gif" style="width: 100%; margin-bottom: 20px;"><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038931967.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">SocketLinux Socket程式设计应用领域为了处置大批相连允诺情景,需要采用非堵塞I/O和F83E43Se,select、poll、epoll是Linux API提供的I/OF83E43Se形式,好景不长Linux2.6中加入了epoll之后,高效能服务项目器应用领域得到广泛的应用应用领域,Nignx是采用</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">epoll来实现I/OF83E43Se全力支持高mammalian对于“高效能”服务项目端而言,他们所关注的并不是词汇的操控性,而要缓存和词汇全力支持触发器非堵塞缓存针对缓存要明白通讯速度的回转次序缓存&gt;SSD&gt;机械硬盘本机&gt;网络传奇服务端化内 &gt; 传奇服务端化间。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">缓存控制系统的最终目标是期望在传奇服务端化内的胜率是最低的,那么此时缓存控制系统整体的工作效率也是最低的触发器非堵塞期望出访资料库、出访网络,出访一些很慢的IO设备时,不要在等待上花费大批时间而要采用设计模式的形式,当控制系统顺利完成某类任务后再来通知他们。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">这样就能将服务项目器CPU的空余资源,用来服务项目顾客端相连OpenRestyOpenResty是如前所述Ngnix和Lua的高效能web平台,外部软件系统上乘的LUa库、服务器端组件、倚赖项用于方便构筑能够处置高mammalian、可扩展性很高的静态web应用应用领域、web服务项目、静态网关。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">能采用Lua脚本初始化Ngnix全力支持的C和Lua组件,快速构筑10K~1000K单机mammalian相连的高效能web应用应用领域控制系统OpenResty的最终目标是让web服务项目直接运转在Nginx服务项目外部,利用Ngnix的非堵塞IO数学模型,对HTTP顾客端允诺和后端DB进行一致的高效能积极响应。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">OpenResty的出现能说是摒弃了高效能服务项目端的开发模式。OpenResty实际上是Nginx+LuaJIT的轻松女团。</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038932532.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">由于Nginx采用的是master-worker数学模型,也是两个master主传奇服务端化管理工作数个worker传奇服务端化,基本的阿提斯鲁夫尔谷都是放在worker中,master仅负责许多全片初始化,和对worker的管理工作。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">在OpenResty中,每一worker采用两个LuaVM,每一允诺被分配到worker时,将在那个LuaVM中建立两个coroutinePulseAudioPulseAudio之间数据隔绝,每一PulseAudio具有独立的函数初始化_GLua中的PulseAudio和多缓存下的缓存类似,都有自己的栈、局部变量、命令操作符…,但是和其他PulseAudio流程共享资源函数初始化等信息。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">缓存和PulseAudio主要不同在于:虚拟化的情况下,概念上来说多缓存是同时运转数个缓存,而PulseAudio是通过标识符来顺利完成PulseAudio的转换,时时刻刻多于两个PulseAudio流程在运转并且那个在运转的PulseAudio多于明确被要求挂起时才会被挂起根据实际试验,OpenResty操控性接近于Nginx 操控性之王c module,甚至超过。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">OpenResty 架构负载均衡LVS+HAProxy将流量转发给核心Nginx1和Nginx2,即实现了流量的负载均衡。</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038933050.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">单机闭环所有想要的数据都能从本服务项目器直接获取,大多数时候无需通过网络或去其他服务项目器获取。</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038933638.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">分布式闭环单机闭环会遇到2个主要问题数据不一致例如没有主从架构导致不同服务项目器数据不一致遇到存储瓶颈硬盘或缓存遇到天花板解决数据不一致比较好的办法是采用主从或分布式集中存储,而遇到存储瓶颈就需要进行按业务键进行分片,将数据分散到多台服务项目器。</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038934168.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">接入网关接入网关又叫接入层,即接收流量的入口,在入口处做如下事情:</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038934670.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">OpenResty环境构筑安装前准备,必须安装perl、libpcre、libssl库# 从控制系统路径中查看必备库是否已经安装$ sudo ldconfig -v# 安装必备库$ sudo apt install libpcre3-dev libssl-dev perl make build-essential curl libreadline-dev libncurses5-dev。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">下载并解压OpenResty后进入其目录$ wget https://openresty.org/download/ngx_openresty-1.13.6.1.tar.gz$ tar -zxvf ngx_openresty-1.13.6.1.tar.gz</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ mv openresty-1.13.6.1 openresty$ cd openresty$ ./configure默认会被安装到/usr/local/openresty目录下# 编译并安装$ sudo make &amp;&amp; make install</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ cd /usr/local/openresty启动Nginx$ sudo /usr/local/openresty/nginx/sbin/nginx$ ps -ef | grep nginx$ service nginx status</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">Nginx启动若出现nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)nginx: still could not bind()</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"> | grep 80。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ sudo killall -9 nginx重新编辑Nginx配置文件$ sudo vim /etc/nginx/conf/nginx.conflisten 80;listen [::]:80 ipv6only=on default_server;</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">采用curl工具或在浏览器出访默认80端口$ curl 127.0.0.1浏览器输入http://127.0.0.1/将Nginx工具配置到当前用户的控制系统环境变量中$ sudo vim ~/.bashrc</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">export PATH=$PATH:/usr/local/openresty/nginx/sbin$ source ~./bashrc$ cd ~$ nginx -s reloadnginx: kill(12267, 1) failed (1: Operation not permitted)</p>

    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ vim /usr/local/openresty/nginx/conf/nginx.conflocation /test { default_type text/html; content_by_lua ngx.say("hello openresty");</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">}# 重启Nginx$ /usr/local/openresty/nginx/sbin/nginx -s reload# 浏览器出访 127.0.0.1/testcontent_by_lua_file$ vim nginx.conf</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">location /test { content_by_lua_file html/test.lua;}$ vim ../html/test.luangx.say("hello lua")$ sudo /usr/local/nginx/sbin/nginx -s reload</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ curl 127.0.0.1/testhello lua为避免每次修改都需要重启Nginx,可在Nginx的server选项中配置lua_code_cache选项$ vim nginx.confserver{</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"> lua_code_cache off; location /test{ content_by_lua_file html/test.lua; }}$ sudo /usr/local/openresty/nginx/sbin/nginx -s reload</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">nginx: lua_code_cache is off; this will hurt performance in /usr/local/openresty/nginx/conf/nginx.conf:48</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">OpenResty入门建立工作目录OpenResty安装之后就有配置文件及相关目录,为了工作目录和安装目录互不干扰,另外建立OpenResty工作目录,并另写配置$ mkdir -p ~/openresty/test/logs ~/openresty/test/conf。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ vim ~/openresty/test/conf/nginx.conf# 设置Nginx worker工作传奇服务端化数量,即CPU核数worker_processes 1;# 设置错误日志文件路径error_log logs/error.log;。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"># 配置Nginx服务项目器与用户的网络相连events{ # 设置每一工作传奇服务端化的最大相连数 worker_connections 10224;}http{ # 虚拟机主机块定义 server{</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"> # 监听端口 listen 8001; # 配置允诺的路由 location /{ default_type text/html;</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"> content_by_lua_block{ ngx.say("hello world"); } } }}$ nginx -p ~/openresty/test</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ curl 127.0.0.1:8001hello world$ vim nginx.conflocation /test{ content_by_lua_file "lua/test.lua";}</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ cd .. &amp;&amp; mkdir lua &amp;&amp; cd lua$ vim test.lualocal args = ngx.req.get_uri_args()local salt = args.salt</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">if not salt then ngx.exit(ngx.HTTP_BAD_REQUEST)endlocal md5str = ngx.md5(ngx.time()..salt)ngx.say(md5str)</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">$ sudo /usr/local/openresty/nginx/sbin/nginx -s reload$ curl -i 127.0.0.1/test?salt=luaHTTP/1.1 200 OK</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">Server: openresty/1.13.6.2Date: Sun, 27 Jan 2019 10:07:17 GMTContent-Type: application/octet-streamTransfer-Encoding: chunked</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">Connection: keep-aliveb55b77f75e46b96b11778ca7edfe8d55若标识符中出现错误则需要直接查看Nginx的错误日志进行查看$ vim nginx/logs/error.log</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">2019/01/27 17:37:15 15764#0: *6 failed to load external Lua file "/usr/local/openresty/nginx/test.lua":</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">cannot open /usr/local/openresty/nginx/test.lua: No such file or...Windows控制系统下查看Nginx传奇服务端化λ tasklist /fi "imagename eq nginx.exe"</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">映像名称 PID 会话名 会话# 缓存采用========================= ======== ================ =========== ============</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">nginx.exe 9072 Console 1 7,840 Knginx.exe 7692 Console 1 12,304 K</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">nginx.exe 8120 Console 1 7,840 Knginx.exe 4552 Console 1 12,188 K</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">nginx.exe 9588 Console 1 7,828 Knginx.exe 6256 Console 1 12,216 K</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">nginx.exe 7308 Console 1 7,828 Knginx.exe 10192 Console 1 12,212 K</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">λ taskkill /im nginx.exe /f成功: 已终止传奇服务端化 "ng</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">GOPS 2020&nbsp;全球运维大会 ·&nbsp;深圳站正式起航!&nbsp;9月25-26日&nbsp;,敬请期待~精彩专场&nbsp;⬇️</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038935408.png" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">来一份闪亮亮的日程(持续更新)&nbsp;⬇️</p><img src="https://www.88m2.com/tu/uploads/2023-03-17/1679038936511.jpeg" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">扫描二维码报名立享九折!</p><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 100%; margin-bottom: 20px;">
    <img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 100%; margin-bottom: 20px;">
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">点个“在看”,一年不宕机</p>






页: [1]
查看完整版本: openresty教程