#!/bin/bash
#判断是否为root用户
if [ `whoami` != "root" ];then
echo " only root can run it"
exit 1
fi
#执行前提示
echo -e "\033[31m 这是centos7系统初始化脚本,请慎重运行!\033[0m"
read -s -n1 -p "Press any key to continue or ctrl+C to cancel"
echo "Your inputs: $REPLY"
#1.定义关闭selinux的函数
close_selinux(){
setenforce 0
sed -i 's/enforcing/disabled/g' /etc/selinux/config
}
#2.关闭防火墙
close_firewalld(){
systemctl stop firewalld.service &> /dev/null
systemctl disable firewalld.service &> /dev/null
}
#3.切换yum,以及更新缓存
yum_config(){
yum install -y wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
mv /etc/yum.repos.d/CentOS7-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
}
#4.安装常用工具
#bash-completion为命令补齐
yum_tools(){
yum install -y vim wget curl curl-devel bash-completion lsof iotop iostat unzip bzip2 bzip2-devel
yum install -y gcc gcc-c++ make cmake autoconf openssl-devel openssl-perl net-tools
}
#5.时间同步
date_config(){
yum -y install ntp
ntpdate time1.aliyun.com
}
#执行脚本
main(){
close_selinux;
close_firewalld;
yum_config;
yum_tools;
date_config;
}
main
echo "系统初始化完成"
Linux系统初始化
最新推荐文章于 2023-06-21 15:57:13 发布