官方YUM源安装nginx的shell脚本

#!/usr/bin/bash
//关闭防火墙和selinux
systemctl stop firewalld && setenforce 0 && echo "防火墙已关闭" || echo "请手动检查"
systemctl disable firewalld &> /dev/null
//安装常用工具,lrzsz真机与虚拟机上传下载文件的命令包,elinks访问网页包,wget下载包,bash-completion自动补齐包
read -p "是否安装常用工具:" num
case $num in
y)
	yum install -y lrzsz  sysstat  elinks wget net-tools bash-completion &> /dev/null
	echo "安装完成"
;;
n)
	break
;;
*)
	echo "请输入正确选项"
	exit
;;
esac
//设置yum存储库
nginxflie="/etc/yum.repos.d/nginx.repo"
if [ ! -f $nginxfile ];then
	touch /etc/yum.repos.d/nginx.repo
else
	echo "文件已存在"
fi
	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
	EOF
//刷新yum库
yum makecache fast &> /dev/null 
if [ $? -eq 0 ];then
	echo "刷新成功"
fi
//安装nginx并启动
rpm -qa | grep nginx &> /dev/null
if [ $? -ne 0 ];then
	yum -y install nginx
	systemctl start nginx
	systemctl enable nginx
fi
systemctl status nginx
if [ $? -ne 0 ];then
	systemctl start nginx
	systemctl enable nginx &> /dev/null
	echo "启动成功"
fi

以上是官方yum源安装nginx。
还有一种方法是利用epel源安装nginx
方法:yum -y install epel-release;yum -y install nginx

原创文章 17 获赞 5 访问量 1264

猜你喜欢

转载自blog.csdn.net/Charon9688/article/details/105396685
今日推荐