前提
VirtualBox-7.2.2已安装
CentOS-Stream-8 最小化安装:https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8-stream/isos/x86_64/CentOS-Stream-8-20240603.0-x86_64-boot.iso
注:CentOS-Stream-8选择最小的boot镜像就可以了,安装过程中选择最小化安装,过程中可能会出现“设置基础软件仓库出错”,可以参考Centos8安装源出错 设置基础软件仓库出错(已解决-秒解)
需要配置的地址可以换成下面的(需要手打)
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8-stream/BaseOS/x86_64/os/
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/8-stream/AppStream/x86_64/os/
VirtualBox设置网络模式为桥接模式
基础系统配置
关闭防火墙
# 关闭防火墙,注意本地实验环境可以这么做,生成环境不要这么做
systemctl stop firewalld
systemctl disable firewalld
# 查看IP
ip addr
后面就可以使用远程连接22端口进行远程登录操作了,centos-stream默认是运行root远程登录的
YUM 源替换成阿里云源
cd /etc/yum.repos.d && mkdir -p backup && mv *.repo backup/
cat << EOF > Aliyun-Centos-Stream-8.repo
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/8-stream/BaseOS/x86_64/os/
enabled=1
gpgcheck=0
[Appstream]
name=Appstream
baseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/x86_64/os/
enabled=1
gpgcheck=0
[Extras]
name=Extras
baseurl=https://mirrors.aliyun.com/centos/8-stream/extras/x86_64/os/
enabled=1
gpgcheck=0
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/centos/8-stream/PowerTools/x86_64/os/
enabled=1
gpgcheck=0
EOF
dnf clean all
dnf makecache
更新系统
dnf update -y
dnf install epel-release -y
dnf update -y
安装常用软件
# 安装常用工具
dnf install -y wget curl vim net-tools unzip bash-completion git
# 安装常用开发工具(如需要编译 C/C++)
dnf groupinstall "Development Tools" -y
时区设置
# 设置时区为中国
timedatectl set-timezone Asia/Shanghai
# 开启时间同步
timedatectl set-ntp true
新增非root用户
# 创建用户
useradd demo
passwd demo
# 添加到 wheel 组获取 sudo 权限
usermod -aG wheel demo
总结
最小化安装结合基础系统配置,就可以得到一个很小的比较纯净测试环境了。
tips:配置完基础系统之后,记得使用VirtualBox生成一个系统快照,这样以后就想要恢复就很方便了。