Blogger Information
Blog 291
fans 0
comment 0
visits 353016
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
在 Ubuntu 上使用源码安装 OpenResty
Original
832 people have browsed it

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

本文将介绍如何在 Ubuntu 上使用源码安装 OpenResty。

目标

  • Ubuntu 18.04
  • OpenResty 1.19.3.2

安装依赖

zlib1g-dev: the HTTP gzip module requires the zlib library.

  1. apt-get update -y
  2. apt-get install -y libpcre3-dev \
  3. libssl-dev \
  4. perl \
  5. make \
  6. build-essential \
  7. curl \
  8. zlib1g-dev</pre>

下载 OpenResty

  1. cd /opt
  2. curl -LO https://openresty.org/download/openresty-1.19.3.2.tar.gz
  3. tar zxf openresty-1.19.3.2.tar.gz</pre>

安装 OpenResty

  1. .configure \
  2. --with-http_gzip_static_module \
  3. --with-http_v2_module \
  4. --with-http_stub_status_module
  5. make
  6. make install</pre>

使用 systemd 管理 OpenResty 服务

编写 Service 文件

/usr/lib/systemd/system 目录下创建一个 openresty.service 文件,文件内容如下:

  1. # Stop dance for OpenResty
  2. # =========================
  3. #
  4. # ExecStop sends SIGSTOP (graceful stop) to OpenResty's nginx process.
  5. # If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
  6. # and sends SIGTERM (fast shutdown) to the main process.
  7. # After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
  8. # SIGKILL to all the remaining processes in the process group (KillMode=mixed).
  9. #
  10. # nginx signals reference doc:
  11. # http://nginx.org/en/docs/control.html
  12. #
  13. [Unit]
  14. Description=The OpenResty Application Platform
  15. After=syslog.target network-online.target remote-fs.target nss-lookup.target
  16. Wants=network-online.target
  17. [Service]
  18. Type=forking
  19. PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
  20. ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
  21. ExecStart=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;'
  22. ExecReload=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
  23. ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/openresty/nginx/logs/nginx.pid
  24. TimeoutStopSec=5
  25. KillMode=mixed
  26. [Install]
  27. WantedBy=multi-user.target</pre>

启动 OpenResty

  1. # 设置自启动
  2. systemctl enable openresty
  3. # 启动 OpenResty
  4. systemctl start openresty
  5. # 查看 OpenResty 服务状态
  6. systemctl status openresty
  7. openresty.service - The OpenResty Application Platform
  8. Loaded: loaded (/usr/lib/systemd/system/openresty.service; enabled; vendor preset: enabled)
  9. Active: active (running) since Sat 2021-07-10 11:36:07 CST; 26min ago
  10. Process: 12735 ExecStart=/usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  11. Process: 12734 ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  12. Main PID: 12736 (nginx)
  13. Tasks: 2 (limit: 1126)
  14. CGroup: /system.slice/openresty.service
  15. ├─12736 nginx: master process /usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on;
  16. └─12737 nginx: worker process
  17. Jul 10 11:36:07 iZj6c0qglm7rjjctj7zxnfZ systemd[1]: Starting The OpenResty Application Platform...
  18. Jul 10 11:36:07 iZj6c0qglm7rjjctj7zxnfZ systemd[1]: openresty.service: Failed to parse PID from file /usr/local/openresty/nginx/logs/nginx.pid:
  19. Jul 10 11:36:07 iZj6c0qglm7rjjctj7zxnfZ systemd[1]: Started The OpenResty Application Platform.</pre>

一键安装脚本

GitHub Gist

本文转自:https://segmentfault.com/a/1190000040325948

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post