概要
本記事は、AlmaLinuxを新規インストールした直後に行うべき、最小限かつ実用的な初期セットアップ手順を解説します。サーバー用途を前提とした内容です。
なぜ必要か
AlmaLinuxはインストール直後、セキュリティや管理性、ネットワーク接続の観点から追加設定が必要です。ここで紹介する手順により、アプリケーション導入前の安定した基盤を整えます。
手順
Step 1: ホスト名の変更
hostnamectl set-hostname your-hostname
echo "127.0.0.1 localhost your-hostname" >> /etc/hosts
Step 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"
Step 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
Step 4: SELinuxを無効化
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
Step 5: システムの更新
dnf update -y
dnf upgrade -y
Step 6: ファイアウォールの設定
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
Step 7: タイムゾーンとNTPの設定
timedatectl set-timezone Asia/Tokyo
systemctl enable --now chronyd
Step 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
Step 9: SELinux無効化反映のため再起動
reboot
結論
この初期セットアップ手順により、AlmaLinuxをセキュアかつ安定したサーバーとして利用するための基盤を構築できます。ホスト名・ネットワーク・プロキシ・ファイアウォール・時刻設定・SELinuxなどの基本的構成が含まれます。