#!/bin/bash
#1.显示系统版本
check_system_version() {
awk '{print $(NF-1)}' /etc/redhat-release
}
#2.更新yum源
check_yum() {
tt=$(awk '{print $(NF-1)}' /etc/redhat-release)
if [ ${tt%%.*} -eq "6" ];then
mkdir -p /etc/yum.repos.d/backup
\mv /etc/yum.repos.d/.*repo /etc/yum.repos.d/backup/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
elif [ ${tt%%.*} -eq "7" ];then
mkdir -p /etc/yum.repos.d/backup
\mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
fi
yum clean all && yum makecache
}
#3.安装基础软件包
package_install() {
yum install -y net-tools vim tree htop iftop \
iotop lrzsz wget unzip telnet nmap nc ntpdate \
bash-completion bash-completion-extra sysstat rsync nfs-utils -y
}
#4.关闭selinux
disable_selinux() {
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforc 0 &> /dev/null
}
#5.关闭firewalld
disable_firewalld() {
systemctl stop firewalld.service
systemctl disable firewalld.service
}
#6.配置sshd服务
ssh_config() {
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
}
#7.加大文件描述符
limit_conf() {
echo '* - nofile 65535 ' >>/etc/security/limits.conf
}
#8.时间同步
date_time() {
echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null' >/var/spool/cron/root
}
menu() {
cat <<EOF
##########################################
## 1、操作系统发行版本 ##
## 2、部署yum源 ##
## 3、安装系统软件包 ##
## 4、关闭Selinux ##
## 5、关闭Firewalld ##
## 6、配置SSHD服务 ##
## 7、加大文件描述符 ##
## 8、同步系统时间 ##
## 9、打印菜单 ##
## q、退出程序 ##
##########################################
EOF
}
#打印菜单
menu
while true
do
read -p "您想干什么?就请输入上面对应的字符:" n
case $n in
1)
check_system_version
;;
2)
check_yum &>/dev/null
echo $? &>/dev/null && echo "yum源更新完成" || echo "yum源更新失败"
;;
3)
echo "安装软件包需要一部分时间,请耐心等待,正在安装中......."
package_install &>/dev/null
echo $? &>/dev/null && echo "基础软件包安装完成" || echo "基础软件包安装报错"
;;
4)
disable_selinux &>/dev/null
echo $? &>/dev/null && echo "Selinux 关闭成功" || echo "Selinux 关闭失败"
;;
5)
disable_firewalld &>/dev/null
echo $? &>/dev/null && echo "Firewalld 关闭成功" || echo "Firewalld 关闭失败"
;;
6)
ssh_config &>/dev/null
echo $? &>/dev/null && echo "sshd服务配置完成" || echo "sshd服务配置报错"
;;
7)
limit_conf &>/dev/null
echo $? &>/dev/null && echo "文件描述符数量修改成功" || echo "文件描述符数量修改失败"
;;
8)
date_time &>/dev/null
echo $? &>/dev/null && echo "定时任务添加成功" || echo "定时任务添加失败"
;;
9)
clear
menu
;;
q)
echo "您即将退出程序!"
exit 1
esac
done
标签:脚本,初始化,系统,dev,echo,repo,etc,yum,null
From: https://www.cnblogs.com/xiutai/p/17817003.html