高性能Web平台-OpenResty安装部署

avatar 2023年8月12日18:41:58 评论 1,097 次浏览

在如今的一些项目架构中,访问接入层,一把都会使用web服务器。

这里一般的web服务器,可以选择的有apache,nginx,可能很少人会用到OpenResty。

那我们今天就来谈一下,高性能Web平台-OpenResty。主要从以下这些方面进行描述:

  • OpenResty安装部署

  • OpenResty压力测试

  • OpenResty调优

  • lua脚本安装,语法

我们都知道,入门的第一步是比较重要的,那我们今天就主要的分享一下OpenResty安装部署的教程。

OpenResty

OpenResty是一个基于 Nginx 与 Lua 的 高性能 Web 平台 ,其内部集成了大量精良的 Lua 库、第三方模 块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务 和动态网关。

OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言 调动 Nginx 支持的各种 C 以及 Lua 模块, 快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高 性能 Web 应用系统。

什么是OpenResty

OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不 仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都 进行一致的高性能响应。

Nginx:路由

  • 静态资源服务器

  • 反向代理服务器

  • 负载均衡服务器

  • 支持动态资源:API

什么是Nginx?

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现 较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

OpenResty安装部署

下载地址:https://openresty.org/en/download.html

 [root@www.wulaoer.org ~]# wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
 [root@www.wulaoer.org ~]# tar xf openresty-1.19.9.1.tar.gz
 [root@www.wulaoer.org ~]# cd openresty-1.19.9.1
 [root@www.wulaoer.org openresty-1.19.9.1]#./configure --prefix=/usr/local/openresty-1.19.9.1 --with-http_iconv_module --with-file-aio --with-poll_module --with-threads  --with-http_ssl_module  --with-http_v2_module  --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --with-http_perl_module --with-stream_geoip_module --with-stream_realip_module --with-pcre --with-pcre-jit
 [root@app-01 openresty-1.19.9.1]# make -j 4 && make install

查看安装的可执行文件

 [root@www.wulaoer.org ~]# ls -l /usr/local/openresty/bin/
 total 164
 -rwxr-xr-x 1 root root 19185 Nov  1 13:45 md2pod.pl
 -rwxr-xr-x 1 root root 15994 Nov  1 13:45 nginx-xml2pod
 lrwxrwxrwx 1 root root    37 Nov  1 13:45 openresty -> /usr/local/openresty/nginx/sbin/nginx
 -rwxr-xr-x 1 root root 63510 Nov  1 13:45 opm
 -rwxr-xr-x 1 root root 36623 Nov  1 13:45 resty
 -rwxr-xr-x 1 root root 14957 Nov  1 13:45 restydoc
 -rwxr-xr-x 1 root root  8873 Nov  1 13:45 restydoc-index

修改nginx的配置文件

 [root@www.wulaoer.org ~]# vim /usr/local/openresty/nginx/conf/nginx.conf
 server {
         listen       8081;
         server_name  localhost;
 }

配置环境变量

 [root@www.wulaoer.org ~]# ln -sv /usr/local/openresty-1.19.9.1/ /usr/local/openresty
 ‘/usr/local/openresty’ -> ‘/usr/local/openresty-1.19.9.1/’
 [root@www.wulaoer.org ~]# echo "export PATH=$PATH:/usr/local/openresty/bin" >> /etc/profile.d/openresty.sh
 [root@www.wulaoer.org ~]# . /etc/profild
 [root@www.wulaoer.org ~]# openresty -v
 
 nginx version: openresty/1.19.9.1

添加openresty.service

 [root@www.wulaoer.org ~]# cat /lib/systemd/system/openresty.service
 [Unit]
 Description=openresty
 After=network.target
 
 
 [Service]
 
 Type=forking
 
 ExecStart=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf
 
 ExecReload=/usr/local/openresty/bin/openresty -s reload
 
 ExecStop=/usr/local/openresty/bin/openresty -s quit
 
 PrivateTmp=true
 
 
 [Install]
 
 WantedBy=multi-user.target

设置开机启动

 [root@www.wulaoer.org ~]# systemctl enable openresty
 Created symlink from /etc/systemd/system/multi-user.target.wants/openresty.service to /usr/lib/systemd/system/openresty.service.
 [root@www.wulaoer.org ~]# systemctl start openresty
 [root@www.wulaoer.org ~]# systemctl status openresty
 ● openresty.service - openresty
    Loaded: loaded (/usr/lib/systemd/system/openresty.service; enabled; vendor preset: disabled)
    Active: active (running) since Mon 2021-11-01 14:09:39 CST; 3s ago
   Process: 37679 ExecStart=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
  Main PID: 37680 (openresty)
    CGroup: /system.slice/openresty.service
            ├─37680 nginx: master process /usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf
            └─37681 nginx: worker process
 Nov 01 14:09:39 www.wulaoer.org systemd[1]: Starting openresty...
 
 Nov 01 14:09:39www.wulaoer.org systemd[1]: Started openresty.

端口验证

 [root@www.wulaoer.org ~]# netstat -tnlp 
 Active Internet connections (only servers)
 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
 tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      42195/zabbix_agentd 
 tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      922/php-fpm: master 
 tcp        0      0 127.0.0.1:9200          0.0.0.0:*               LISTEN      15102/php-fpm: pool 
 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      846/nginx: master p 
 tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      37680/nginx: master 
 tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      786/sshd            
 tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      846/nginx: master p 
 tcp6       0      0 :::10050                :::*                    LISTEN      42195/zabbix_agentd 
 tcp6       0      0 :::22                   :::*                    LISTEN      786/sshd     
 
avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: