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

本文将介绍如何在 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

更多相关文章

  1. 运行Android(安卓)Studio时,APP安装失败--Installation failed wi
  2. Android(安卓)启动线程OOM
  3. android apk安装结束的系统广播的监听
  4. Android(安卓)代码安装APK文件
  5. Android应用程序启动画面
  6. android 学习知识点累计
  7. android + eclipse + 后台静默安装(一看就会)
  8. Android(安卓)启动activity并且获取他的返回值
  9. centos7.2下安装mysql5.7数据库的命令详解

随机推荐

  1. 扑克牌魔术里面的算法
  2. 使用pm2后台运行nodejs程序
  3. Android性能优化案例研究(上)
  4. 一个正确的编程学习方法
  5. 速成编程、副业挣钱有无可能?
  6. 我总是半途而废
  7. B 站,牛逼!
  8. 排序算法 #1 选择排序(文字版)
  9. 一道 LeetCode 周赛的题目,让我自信满满!
  10. 每日前端夜话(0x03):2018年JavaScript状态