OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
OpenResty官方提供了大多数Linux发行版的预编译的包,所以安装非常简单,可以直接参考http://openresty.org/cn/installation.html 进行安装。但是官方的二进制包只支持X86_64 和AMD64 的CPU,如果需要在ARM CPU上安装openresty就需要从源码开始安装了。
这里介绍在Nvidia的Jetson Xavier 套件上安装openrety的方法, 使用的操作系统为ubuntu18.04。
1安装依赖
sudo apt-get install libpcre3-dev libssl-dev perl make build-essential curl
2下载源码
download source from http://openresty.org/cn/download.html
3 编译安装
- tar -xzvf openresty-VERSION.tar.gz
- cd openresty-VERSION/
- ./configure
- Make
- sudo make install
安装完成后,位于目录/usr/local/openresty/
4 添加到systemd自动启动
1)在/lib/systemd/system目录创建文件openresty.service
> cd /lib/systemd/system
> sudo touch openresty.service
2)在openresty.service中添加下面的内容:
[Unit]
Description=full-fledged web platform
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/openresty/nginx/logs/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
3)enable openresty
> sudo systemctl enable openresty
输出如下:
robin@ubuntu:/lib/systemd/system$ sudo systemctl enable openresty
Created symlink /etc/systemd/system/multi-user.target.wants/openresty.service → /lib/systemd/system/openresty.service.
4) 启动openresty
> sudo systemctl start openresty
> sudo systemctl status openresty
robin@ubuntu:/lib/systemd/system$ sudo systemctl start openresty
robin@ubuntu:/lib/systemd/system$ sudo systemctl status openresty
● openresty.service - full-fledged web platform
Loaded: loaded (/lib/systemd/system/openresty.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-06-22 11:00:03 CST; 1s ago
Process: 32078 ExecStart=/usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 32061 ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 32086 (nginx)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/openresty.service
├─32086 nginx: master process /usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on;
└─32088 nginx: worker process
6月 22 11:00:03 ubuntu systemd[1]: Starting full-fledged web platform...
6月 22 11:00:03 ubuntu systemd[1]: Started full-fledged web platform.