可以通过epel或者nginx官方的源,yum安装部署nginx
【使用nginx官方的源】
1、下载aliyun的epel的repo文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2024-10-22 22:43:16-- https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 36.131.174.222, 36.131.174.224, 36.131.174.228, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|36.131.174.222|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’
100%[=============================================================>] 664 --.-K/s in 0s
2024-10-22 22:43:16 (101 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]
2、安装epel-release
[root@localhost ~]# yum install epel-release
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,791
extras/7/x86_64 CentOS-7 - Extras 526
updates/7/x86_64 CentOS-7 - Updates 6,173
repolist: 30,562
3、查看确认epel源里面是nginx 1.20.1-10.el7版本
[root@localhost yum.repos.d]# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-10.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.20.1-10.el7 for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Running transaction check
---> Package centos-indexhtml.noarch 0:7-9.el7.centos will be installed
---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
---> Package nginx-filesystem.noarch 1:1.20.1-10.el7 will be installed
---> Package openssl11-libs.x86_64 1:1.1.1k-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
nginx x86_64 1:1.20.1-10.el7 epel 588 k
Installing for dependencies:
centos-indexhtml noarch 7-9.el7.centos base 92 k
gperftools-libs x86_64 2.6.1-1.el7 base 272 k
nginx-filesystem noarch 1:1.20.1-10.el7 epel 24 k
openssl11-libs x86_64 1:1.1.1k-7.el7 epel 1.5 M
Transaction Summary
=======================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 2.4 M
Installed size: 6.7 M
【使用nginx官方的源】
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,791
extras/7/x86_64 CentOS-7 - Extras 526
nginx-stable/7/x86_64 nginx stable repo 364
updates/7/x86_64 CentOS-7 - Updates 6,173
repolist: 30,926
[root@localhost yum.repos.d]#
使用官方源安装的nginx是1.26.1版本
[root@localhost yum.repos.d]# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.26.1-2.el7.ngx will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: 1:nginx-1.26.1-2.el7.ngx.x86_64
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
nginx x86_64 1:1.26.1-2.el7.ngx nginx-stable 807 k
Installing for dependencies:
pcre2 x86_64 10.23-2.el7 base 201 k
Transaction Summary
=======================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 1.0 M
Installed size: 3.4 M
如果需要安装Mainline version 主要开发版本需要
[root@localhost yum.repos.d]# yum install yum-utils
[root@localhost yum.repos.d]# yum-config-manager --enable nginx-mainline
此时通过官方的源,安装的是1.27.1版本的nginx
[root@localhost yum.repos.d]# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
nginx-mainline | 2.9 kB 00:00:00
nginx-stable | 2.9 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.27.0-2.el7.ngx will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: 1:nginx-1.27.0-2.el7.ngx.x86_64
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
nginx x86_64 1:1.27.0-2.el7.ngx nginx-mainline 807 k
Installing for dependencies:
pcre2 x86_64 10.23-2.el7 base 201 k
Transaction Summary
=======================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 1.0 M
Installed size: 3.4 M
禁用官方源的mainline仓库
[root@localhost yum.repos.d]# yum-config-manager --disable nginx-mainline
装好之后查看安装的版本,和编译启用的模块
[root@localhost yum.repos.d]# nginx -v
nginx version: nginx/1.26.2
[root@localhost yum.repos.d]# nginx -V
nginx version: nginx/1.26.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_modul
启动nginx服务,关闭防火墙
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2024-10-23 08:29:14 CST; 1s ago
Docs: http://nginx.org/en/docs/
Process: 1764 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 1765 (nginx)
CGroup: /system.slice/nginx.service
├─1765 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─1766 nginx: worker process
Oct 23 08:29:13 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Oct 23 08:29:14 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) a...ory
Oct 23 08:29:14 localhost.localdomain systemd[1]: Started nginx - high performance web server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl stop firewalld.service
测试访问正常
补充:查看配置的仓库中所有可用的版本,并安装指定老版本(默认装最新的)
[root@localhost ~]# yum list nginx --showduplicates
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
nginx.x86_64 1:1.26.1-2.el7.ngx @nginx-stable
Available Packages
nginx.x86_64 1:1.8.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.8.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.10.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.10.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.10.2-1.el7.ngx nginx-stable
nginx.x86_64 1:1.10.3-1.el7.ngx nginx-stable
nginx.x86_64 1:1.12.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.12.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.12.2-1.el7_4.ngx nginx-stable
nginx.x86_64 1:1.14.0-1.el7_4.ngx nginx-stable
nginx.x86_64 1:1.14.1-1.el7_4.ngx nginx-stable
nginx.x86_64 1:1.14.2-1.el7_4.ngx nginx-stable
nginx.x86_64 1:1.16.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.16.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.18.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.18.0-2.el7.ngx nginx-stable
nginx.x86_64 1:1.20.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.20.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.20.1-10.el7 epel
nginx.x86_64 1:1.20.2-1.el7.ngx nginx-stable
nginx.x86_64 1:1.22.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.22.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.24.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.26.0-1.el7.ngx nginx-stable
nginx.x86_64 1:1.26.1-1.el7.ngx nginx-stable
nginx.x86_64 1:1.26.1-2.el7.ngx nginx-stable
[root@localhost ~]#
[root@localhost ~]# yum install nginx-1.26.1-1.el7.ngx