#!/bin/bash
echo "
+-----------------------------+
| Tools |
+-----------------------------+
| 1.修改默认官方yum源 |
| 2.修改为aliyun_repo |
| 3.安装常用命令 |
| 4.安装epel源 |
| 5.安装nginx服务 |
| 6.永久关闭防火墙 |
| 7.永久关闭selinux |
+-----------------------------+
"
read -p "请输入你的选择:" choose
case $choose in
1)
echo "update yum source"
sed -i "s/mirrorlist=http:/\#mirrorlist=http:/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s/\#baseurl=http:/baseurl=http:/g" /etc/yum.repos.d/CentOS-Base.repo
yum makecache
echo "update yum source complete!!!"
;;
2) # 获得当前 CentOS 系统发行版本号
# 第一个 awk 后边必须换行, 目前未查到原因
releasetmp=`cat /etc/redhat-release | awk '{match($0,"release ")
print substr($0,RSTART+RLENGTH)}' | awk -F '.' '{print $1}'`
echo $releasetmp
sleep 5
yum install wget -y
# 备份原文件 应该添加检测是否原来有备份文件, 有的话应该备份为别名文件 此处省略
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-$releasetmp.repo
if [[ $? -eq 0 ]];then
echo -e "\033[32m# yum 源已成功更新为 aliyun_repo #\033[0m"
sleep 3
else
echo -e "\033[31m# yum 源未成功更新为 aliyun_repo #\n3s 后退出...\033[0m"
exit
fi
# 添加EPEL源
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-$releasetmp.repo
# 重建缓存
yum clean all
yum makecache
# 自动更新包列表,可选择注释该行
yum update -y
;;
3)
echo "安装常用命令"
yum -y install vim lrzsz lsof wget net-tools killall
echo "安装完成"
;;
4)
echo "安装epel源"
yum -y install epel-release
echo "完成安装epel源"
;;
5) echo "安装nginx服务 并设置开机自启"
cat <<-EOF > /etc/yum.repos.d/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
EOF
yum makecache fast
echo " 安装nginx服务."
if [ $? -eq 0 ];then
yum -y install nginx
else
exit 502
fi
echo "添加新的内容到网站的首页文件中."
if [ -d /usr/share/nginx/html ];then
echo "hello nginx" >/usr/share/nginx/html/index.html
else
echo "请确认已经安装了nginx服务"
fi
# 启动nginx服务.
systemctl start nginx
systemctl enable nginx
;;
6)
systemctl stop firewalld
systemctl disable firewalld
;;
7)
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
;;
*)
exit
esac