Linux系统初始化

#!/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 "系统初始化完成"
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值