P-IT Blog

Rocky Linux 9 安裝與基礎配置指南

Rocky Linux 是 CentOS 的繼任者,提供企業級的穩定性。本文檔介紹 Rocky Linux 9 的鏡像下載及系統初始化配置,包含開啟 Root SSH 登錄、時區設置及基礎環境優化。


1. 系統鏡像下載

推薦使用最小化安裝包 (Minimal) 以獲得最純淨的服務器環境。


2. 開啟 Root SSH 遠程登錄

默認情況下,為了安全起見,可能無法直接使用 Root 賬戶進行 SSH 登錄。

步驟 1:編輯 SSH 配置文件

使用 vi 編輯器打開配置文件:

vi /etc/ssh/sshd_config

步驟 2:修改權限設置

在文件中找到 PermitRootLogin 相關行。 確保其設置如下(如果被註釋,請取消註釋):

PermitRootLogin yes

步驟 3:重啟 SSH 服務

使配置生效:

systemctl restart sshd

3. 系統時區設置

將系統時區設置為台北時間 (Asia/Taipei)。

# 設置時區
timedatectl set-timezone Asia/Taipei

# 驗證設置
timedatectl

預期輸出中應包含:Time zone: Asia/Taipei (CST, +0800)


4. 系統更新與基礎工具安裝

在部署服務前,建議更新系統並安裝常用工具。

更新系統

dnf update -y

安裝基礎工具

安裝 wgetvimtar 等常用命令:

dnf install wget vim tar -y

5. 防火牆管理 (Firewalld)

Rocky Linux 默認使用 firewalld 管理防火牆。

  • 查看狀態

    systemctl status firewalld
    
  • 停止並禁用防火牆 (僅限內網或測試環境,生產環境建議配置規則):

    systemctl stop firewalld
    systemctl disable firewalld
    
  • 配置規則示例 (如果保留防火牆):

    # 放行 SSH 端口
    firewall-cmd --permanent --add-service=ssh
    # 放行 HTTP/HTTPS
    firewall-cmd --permanent --add-service=http
    firewall-cmd --permanent --add-service=https
    # 重載配置
    firewall-cmd --reload