因为版本问题 yum下载会报错 Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare
1.进入yum.repos.d目录
[root@localhost ~]# cd /etc/yum.repos.d/
2.输入以下指令更新仓库
sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
2或者输入这个指令更新
sudo sed -i -e
"s|mirrorlist=|#mirrorlist=|g"
/etc/yum.repos.d/CentOS-*
sudo sed -i -e
"s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g"
/etc/yum.repos.d/CentOS
3.清楚缓存
yum makecache
4.更新
yum update -y
5.dnf方式下载
dnf install yum-utils -y
6.安装管理工具 yum-utils 用yum和dnf都可以
dnf install yum-utils -y
#配置nginx官方yum源
cat>/etc/yum.repos.d/nginx.repo<<EOF
[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
EOF
cat /etc/yum.repos.d/nginx.repo
7.安装yum配置管理
dnf install yum-utils -y
#列出nginx模块相关的版本
dnf module list nginx
8.#安装nginx,这样会连官网稳定版本1.18和模块一起安装
dnf module install:1.16 -y
9.查看版本,应该是目前最新稳定版本1.18.0
nginx -v
#检查语法
nginx -t
10.#启动nginx
systemctl start nginx
这一步检查的时候可能会遇到 测试通过了 但是 启动失败的问题
ERROR:Job for nginx.service failed because the control process exited with error code.
通过systemctl status nginx.service查看状态
这就是80端口被占用了 使用 fuser -k 80/tcp 命令杀死占用80的进程
11.#再次启动nginx
#查看是否开机启动
systemctl list-unit-files|grep enable|grep nginx
systemctl enable nginx