centos7常用脚本
时间: 2023-07-07 21:07:29 浏览: 112
以下是 CentOS 7 上常用的一些脚本:
1. 安装常用软件
```
yum install -y vim wget curl net-tools lsof tcpdump
```
2. 配置防火墙
```
# 允许 SSH 服务
firewall-cmd --add-service=ssh --permanent
# 允许 HTTP 和 HTTPS 服务
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
# 重启防火墙
firewall-cmd --reload
```
3. 配置 SELinux
```
# 查看 SELinux 状态
sestatus
# 如果状态为 enforcing,则修改为 permissive 或 disabled
setenforce 0
# 修改配置文件 /etc/selinux/config 中的 SELINUX=permissive 或 SELINUX=disabled
```
4. 配置时区
```
# 查看当前时区
timedatectl
# 设置时区
timedatectl set-timezone Asia/Shanghai
```
5. 配置 NTP 服务
```
# 安装 NTP 服务
yum install -y ntp
# 启动 NTP 服务
systemctl start ntpd
# 设置 NTP 服务开机自启动
systemctl enable ntpd
```
6. 配置 Yum 源
```
# 备份原有 Yum 源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载阿里云 Yum 源并配置
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 清除 Yum 缓存并重建
yum clean all
yum makecache
```
7. 配置 Swap 分区
```
# 创建一个 2 GB 的 Swap 文件
dd if=/dev/zero of=/swapfile bs=1M count=2048
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# 修改 /etc/fstab 文件,使 Swap 文件在开机时自动挂载
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
```
以上是一些常用的 CentOS 7 脚本,可根据实际需求进行修改。
阅读全文
相关推荐

















