CentOS 7 更换国内YUM源及初始化配置

CentOS7-YUM-Initialization

一、备份原有YUM源

1
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

二、更换为国内YUM源

1. 阿里云源

1
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

2. 或者使用清华源

1
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/centos7.repo

三、清理并重建YUM缓存

1
2
sudo yum clean all
sudo yum makecache

四、更新系统软件包(可选但推荐)

1
sudo yum update -y

五、其他常用初始化操作

1. 安装常用工具集

1
sudo yum install -y wget vim net-tools tree

2. 安装EPEL源(额外软件包)

1
2
sudo yum install -y epel-release
sudo yum makecache

3. 设置时区(如设置为亚洲/上海)

1
sudo timedatectl set-timezone Asia/Shanghai

4. 关闭防火墙(仅用于测试环境)

1
2
sudo systemctl stop firewalld
sudo systemctl disable firewalld

5. 禁用SELinux(可选)

1
2
sudo setenforce 0
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config