AlmaLinux 初始操作系统设置指南

内容说明

本文提供了一份 AlmaLinux 在全新安装后的最小化初始配置指南,适用于服务器环境。

为什么要这样做

AlmaLinux 安装完成后需要进行基础配置,以确保系统安全、易于管理并具备网络连接能力。这些步骤有助于为后续的服务部署打下良好基础。

操作步骤

步骤 1:修改主机名

hostnamectl set-hostname your-hostname
echo "127.0.0.1   localhost your-hostname" >> /etc/hosts

步骤 2:配置网络(示例:静态 IP)

nmcli con mod "eth0" ipv4.addresses 192.168.1.100/24
nmcli con mod "eth0" ipv4.gateway 192.168.1.1
nmcli con mod "eth0" ipv4.dns 8.8.8.8
nmcli con mod "eth0" ipv4.method manual
nmcli con up "eth0"

步骤 3:设置代理(如有必要)

cat <<EOF > /etc/profile.d/proxy.sh
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1"
EOF
chmod +x /etc/profile.d/proxy.sh
source /etc/profile.d/proxy.sh
echo 'proxy=http://proxy.example.com:8080' >> /etc/dnf/dnf.conf

步骤 4:禁用 SELinux

sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0

步骤 5:更新系统

dnf update -y
dnf upgrade -y

步骤 6:配置防火墙

systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload

步骤 7:设置时区与启用 NTP

timedatectl set-timezone Asia/Tokyo
systemctl enable --now chronyd

步骤 8:创建管理员用户并设置 SSH 密钥

useradd adminuser
passwd adminuser
usermod -aG wheel adminuser
mkdir -p /home/adminuser/.ssh
chmod 700 /home/adminuser/.ssh
vi /home/adminuser/.ssh/authorized_keys  # 粘贴公钥
chmod 600 /home/adminuser/.ssh/authorized_keys
chown -R adminuser:adminuser /home/adminuser/.ssh

步骤 9:重启系统以应用 SELinux 设置

reboot

总结

此最小化设置流程可使 AlmaLinux 系统具备安全、稳定的服务器运行基础,包括主机名、网络与代理设置、系统更新、工具配置、SELinux 管理、防火墙与时间配置。

标题和URL已复制