#!/bin/bash
#判断用户执行
if [ $UID != "0" ];then
echo "请使用root用户运行"
exit 1
fi
# 关闭selinux
setenforce 0
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
# 关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
# 添加常用命令别名和变量
cat>>/root/.bashrc<<EOF
alias rnet='systemctl restart network'
alias res='systemctl restart'
alias start='systemctl start'
alias status='systemctl status'
NET='/etc/sysconfig/network-scripts'
EOF
source /root/.bashrc
# 修改主机名
hostnamectl set-hostname zero # 你的主机名
# ssh优化配置
sed -i "s|^#UseDNS yes|UseDNS no|g" /etc/ssh/sshd_config
sed -i "s|GSSAPIAuthentication yes|GSSAPIAuthentication no|g" /etc/ssh/sshd_config
# 配置清华大学yum源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
yum clean all && yum makecache fast
# 安装常用工具
yum install -y net-tools vim wget
centos7 系统初始化脚本
最新推荐文章于 2023-02-22 11:45:21 发布