温馨提示×

centos minimal如何设置

小樊
41
2026-08-03 05:44:27
栏目: 智能运维

下面以 CentOS 7 / 8 / Stream(Minimal 安装) 为例,给你一套从安装后到可用的最小配置清单,适合服务器/虚拟机环境。


一、安装后第一件事(必做)

1️⃣ 配置网络(重点)

Minimal 安装 默认网络通常是关闭的

查看网卡名

ip addr

一般是:ens33 / eth0

方法一:DHCP 自动获取 IP(推荐)

vi /etc/sysconfig/network-scripts/ifcfg-ens33

修改或确认:

BOOTPROTO=dhcp
ONBOOT=yes

重启网络:

systemctl restart network

方法二:设置静态 IP(服务器常用)

BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=114.114.114.114

重启网络:

systemctl restart network

验证:

ip addr
ping -c 3 www.baidu.com

二、更新系统(强烈建议)

yum update -y

或(CentOS 8 / Stream):

dnf update -y

三、安装常用基础工具(Minimal 很“裸”)

yum install -y \
vim \
wget \
curl \
net-tools \
bash-completion \
lrzsz \
tree

常用说明:

  • net-tools:ifconfig、netstat
  • bash-completion:命令自动补全
  • lrzsz:rz / sz 上传下载

四、配置主机名(推荐)

hostnamectl set-hostname server01

查看:

hostname

五、配置 SSH(安全 & 方便)

1️⃣ 允许 root 远程登录(可选)

vim /etc/ssh/sshd_config

确认或修改为:

PermitRootLogin yes

重启 SSH:

systemctl restart sshd

2️⃣ 禁用 SSH DNS 反向解析(加速登录)

UseDNS no

六、关闭 SELinux(服务器常用)

vim /etc/selinux/config

修改为:

SELINUX=disabled

重启生效:

reboot

临时关闭(不重启):

setenforce 0

七、防火墙(firewalld)基础设置

查看状态

systemctl status firewalld

开放常用端口(如 SSH)

firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload

关闭防火墙(测试环境)

systemctl stop firewalld
systemctl disable firewalld

八、配置时钟 & 时区(重要)

timedatectl set-timezone Asia/Shanghai

确认:

timedatectl

九、添加普通用户(推荐)

useradd admin
passwd admin

赋予 sudo 权限:

echo "admin ALL=(ALL) ALL" >> /etc/sudoers

十、系统优化(常用)

1️⃣ 文件描述符

vim /etc/security/limits.conf

添加:

* soft nofile 65535
* hard nofile 65535

2️⃣ 禁用不必要的服务

systemctl disable postfix

十一、CentOS 8 / Stream 特别说明

CentOS 8 官方源已停止维护,需换源:

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

✅ 最小可用总结(必做)

项目 是否必做
网络配置
更新系统
安装基础工具
SSH 设置
SELinux
时区

如果你告诉我:

  • 虚拟机 / 物理机 / 云服务器
  • CentOS 7 还是 8 / Stream
  • 用来做 Web / 数据库 / K8s / 桌面

我可以给你一套更精确、更精简的配置方案

0