在CentOS 7上通过SCL安装Nginx 1.16

首先

使用软件集合(SCL)在CentOS 7中安装Nginx 1.16
原文:Nginx的各种安装方法和EOL综述
参考:快速入门-软件集合

支持

如果使用这种方法进行引入,根据Red Hat软件集产品生命周期 – Red Hat客户门户网站,2021年12月被认为是终止支持日期。之后可能不会进行对报告的漏洞和问题的解决。

登录

仓库注册

# yum install -y centos-release-scl

安装

由于CentOS7.7启动失败,我使用了7.6版本。
Systemd错误:“拒绝接受通过不安全的符号链接链获得的服务控制组之外的进程ID” – 可能受到Red Hat客户门户的影响,但尚未调查。

# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

# yum install -y rh-nginx116 which
# scl enable rh-nginx116 bash
... 略

启动/停止nginx

# systemctl start rh-nginx116-nginx
# systemctl status -l rh-nginx116-nginx
● rh-nginx116-nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/rh-nginx116-nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-01-30 03:30:15 UTC; 5s ago
  Process: 1431 ExecStart=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1425 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1418 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /usr/bin/scl_enabled rh-nginx116 (code=exited, status=0/SUCCESS)
  Process: 1417 ExecStartPre=/usr/bin/rm -f /var/opt/rh/rh-nginx116/run/nginx/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1437 (nginx)
   CGroup: /docker/285f4a924c86a08e019904bd193ea56b61ec9cf87e8fa795e3855778d20f6f4d/system.slice/rh-nginx116-nginx.service
           tq1437 nginx: master process /opt/rh/rh-nginx116/root/usr/sbin/nginx
           mq1438 nginx: worker process
           ? 1437 nginx: master process /opt/rh/rh-nginx116/root/usr/sbin/nginx

Jan 30 03:30:15 285f4a924c86 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 30 03:30:15 285f4a924c86 nginx-scl-helper[1425]: nginx: the configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf syntax is ok
Jan 30 03:30:15 285f4a924c86 nginx-scl-helper[1425]: nginx: configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf test is successful
Jan 30 03:30:15 285f4a924c86 systemd[1]: Failed to read PID from file /var/opt/rh/rh-nginx116/run/nginx/nginx.pid: Invalid argument
Jan 30 03:30:15 285f4a924c86 systemd[1]: Started The nginx HTTP and reverse proxy server.
# systemctl stop rh-nginx116-nginx
# systemctl status -l rh-nginx116-nginx
● rh-nginx116-nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/rh-nginx116-nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Jan 30 03:30:15 285f4a924c86 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 30 03:30:15 285f4a924c86 nginx-scl-helper[1425]: nginx: the configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf syntax is ok
Jan 30 03:30:15 285f4a924c86 nginx-scl-helper[1425]: nginx: configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf test is successful
Jan 30 03:30:15 285f4a924c86 systemd[1]: Failed to read PID from file /var/opt/rh/rh-nginx116/run/nginx/nginx.pid: Invalid argument
Jan 30 03:30:15 285f4a924c86 systemd[1]: Started The nginx HTTP and reverse proxy server.
Jan 30 03:30:46 285f4a924c86 systemd[1]: Stopping The nginx HTTP and reverse proxy server...
Jan 30 03:30:46 285f4a924c86 systemd[1]: Stopped The nginx HTTP and reverse proxy server.

在CentOS7.7发生了一个错误。

# systemctl start rh-nginx116-nginx
Job for rh-nginx116-nginx.service failed because a timeout was exceeded. See "systemctl status rh-nginx116-nginx.service" and "journalctl -xe" for details.
# systemctl status -l rh-nginx116-nginx.service
● rh-nginx116-nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/rh-nginx116-nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: timeout) since Thu 2020-01-30 03:37:24 UTC; 31s ago
  Process: 1744 ExecStart=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1738 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /opt/rh/rh-nginx116/root/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1731 ExecStartPre=/opt/rh/rh-nginx116/root/usr/libexec/nginx-scl-helper enable $RH_NGINX116_SCLS_ENABLED -- /usr/bin/scl_enabled rh-nginx116 (code=exited, status=0/SUCCESS)
  Process: 1730 ExecStartPre=/usr/bin/rm -f /var/opt/rh/rh-nginx116/run/nginx/nginx.pid (code=exited, status=0/SUCCESS)
   CGroup: /docker/285f4a924c86a08e019904bd193ea56b61ec9cf87e8fa795e3855778d20f6f4d/docker/285f4a924c86a08e019904bd193ea56b61ec9cf87e8fa795e3855778d20f6f4d/system.slice/rh-nginx116-nginx.service
           tq1750 nginx: master process /opt/rh/rh-nginx116/root/usr/sbin/nginx
           mq1751 nginx: worker process

Jan 30 03:35:54 285f4a924c86 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 30 03:35:54 285f4a924c86 nginx-scl-helper[1738]: nginx: the configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf syntax is ok
Jan 30 03:35:54 285f4a924c86 nginx-scl-helper[1738]: nginx: configuration file /etc/opt/rh/rh-nginx116/nginx/nginx.conf test is successful
Jan 30 03:35:54 285f4a924c86 systemd[1]: Failed to parse PID from file /var/opt/rh/rh-nginx116/run/nginx/nginx.pid: Invalid argument
Jan 30 03:35:54 285f4a924c86 systemd[1]: Refusing to accept PID outside of service control group, acquired through unsafe symlink chain: /var/opt/rh/rh-nginx116/run/nginx/nginx.pid
Jan 30 03:37:24 285f4a924c86 systemd[1]: rh-nginx116-nginx.service start operation timed out. Terminating.
Jan 30 03:37:24 285f4a924c86 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jan 30 03:37:24 285f4a924c86 systemd[1]: Unit rh-nginx116-nginx.service entered failed state.
Jan 30 03:37:24 285f4a924c86 systemd[1]: rh-nginx116-nginx.service failed.

自动启动/取消Nginx配置。

# systemctl enable rh-nginx116-nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-nginx116-nginx.service to /usr/lib/systemd/system/rh-nginx116-nginx.service.

# systemctl list-unit-files --type=service |grep nginx
rh-nginx116-nginx.service              enabled
# systemctl disable rh-nginx116-nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/rh-nginx116-nginx.service.

# systemctl list-unit-files --type=service |grep nginx
rh-nginx116-nginx.service              disabled

确认的各种方式

# which nginx
/opt/rh/rh-nginx116/root/usr/sbin/nginx

# nginx -v
nginx version: nginx/1.16.1

# yum info rh-nginx116
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * centos-sclo-rh: ftp.riken.jp
 * centos-sclo-sclo: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Installed Packages
Name        : rh-nginx116
Arch        : x86_64
Version     : 1.16
Release     : 1.el7
Size        : 0.0
Repo        : installed
From repo   : centos-sclo-rh
Summary     : Package that installs rh-nginx116
License     : GPLv2+
Description : This is the main package for rh-nginx116 Software Collection.