1. yum介绍
Yum(全称为 Yellow dogUpdater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。
2. 安装源
Nginx官方提供了Yum源,使用yum安装更加方便。
默认情况Centos7中无Nginx的源,因此可以如下执行命令添加源:
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
3. 使用yum安装nginx
# 查看是否已经添加源成功
yum search nginx
# 安装nginx(默认最新的Stable Version) -y表示安装过程提示选择全部为"yes"
yum install -y nginx
# 安装指定版本,如:1.12.2
yum install nginx-1.12.2
# 安装位置 默认是/usr/sbin/nginx
which nginx
4. 启动Nginx 设置开机自启
# 启动nginx
systemctl start nginx.service
# 设置开机自启
systemctl enable nginx.service
systemctl daemon-reload
5. 常见操作
# 服务状态
systemctl status nginx
# 服务启动
systemctl start nginx
# 服务停止
systemctl stop nginx
# 服务重启
systemctl restart nginx
# 也可以直接使用nginx命令
# 验证配置是否正确
nginx -t
# 查看Nginx的详细的版本号
nginx -V
# 查看Nginx的简洁版本号
nginx -v
# 快速停止或关闭Nginx
nginx -s stop
# 正常停止或关闭Nginx
nginx -s quit
# 配置文件修改重装载命令
nginx -s reload
# 查询nginx进程
ps -ef|grep nginx
# 两种命令还是不要混用了,容易发生意想不到的问题!
ps:以上操作均在centos 7.6.1810下进行,对Yum不了解的小伙伴可以在网上多了解下。