

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用獨立執行個體做為 AWS PCS 登入節點
<a name="working-with_login-nodes_standalone"></a>

您可以設定獨立的 EC2 執行個體來與 AWS PCS 叢集的 Slurm 排程器互動。這對於建立使用 AWS PCS 叢集但在 PCS 管理之外操作的登入節點、工作站或專用工作流程 AWS 管理主機非常有用。若要這樣做，每個獨立執行個體都必須：

1. 安裝相容的 Slurm 軟體版本。

1. 能夠連線至 AWS PCS 叢集的 Slurmctld 端點。

1. 使用 AWS PCS 叢集的端點和秘密正確設定 Slurm Auth 和 Cred Kiosk Daemon (`sackd`)。如需詳細資訊，請參閱 Slurm 文件中的 [sackd](https://slurm.schedmd.com/sackd.html)。

 本教學課程可協助您設定連接至 AWS PCS 叢集的獨立執行個體。

**Contents**
+ [步驟 1 – 擷取目標 AWS PCS 叢集的地址和秘密](working-with_login-nodes_standalone_get-addr.md)
+ [步驟 2 – 啟動 EC2 執行個體](working-with_login-nodes_standalone_launch.md)
+ [步驟 3 – 在執行個體上安裝 Slurm](working-with_login-nodes_standalone_install-slurm.md)
+ [步驟 4 – 擷取和存放叢集秘密](working-with_login-nodes_standalone_get-secret.md)
+ [步驟 5 – 設定 AWS PCS 叢集的連線](working-with_login-nodes_standalone_configure-connection.md)
+ [步驟 6 – （選用） 測試連線](working-with_login-nodes_standalone_test.md)

# 步驟 1 – 擷取目標 AWS PCS 叢集的地址和秘密
<a name="working-with_login-nodes_standalone_get-addr"></a>

使用 AWS CLI 搭配接下來的 命令，擷取目標 AWS PCS 叢集的詳細資訊。執行命令之前，請執行下列替換：
+ 將 *region-code* 取代為目標叢集執行 AWS 區域 所在的 。
+ 將 *cluster-ident* 取代為目標叢集的名稱或識別符

```
aws pcs get-cluster --region region-code --cluster-identifier cluster-ident
```

命令會傳回類似此範例的輸出。

```
{
    "cluster": {
        "name": "get-started",
        "id": "pcs_123456abcd",
        "arn": "arn:aws:pcs:us-east-1:111122223333:cluster/pcs_123456abcd",
        "status": "ACTIVE",
        "createdAt": "2024-12-17T21:03:52+00:00",
        "modifiedAt": "2024-12-17T21:03:52+00:00",
        "scheduler": {
            "type": "SLURM",
            "version": "25.05"
        },
        "size": "SMALL",
        "slurmConfiguration": {
            "authKey": {
                "secretArn": "arn:aws:secretsmanager:us-east-1:111122223333:secret:pcs!slurm-secret-pcs_123456abcd-a12ABC",
                "secretVersion": "ef232370-d3e7-434c-9a87-ec35c1987f75"
            }
        },
        "networking": {
            "subnetIds": [
                "subnet-0123456789abcdef0"
            ],
            "securityGroupIds": [
                "sg-0123456789abcdef0"
            ]
        },
        "endpoints": [
            {
                "type": "SLURMCTLD",
                "privateIpAddress": "10.3.149.220",
                "port": "6817"
            }
        ]
    }
}
```

在此範例中，叢集 Slurm 控制器端點的 IP 地址為 ，`10.3.149.220`且正在連接埠 上執行`6817`。`secretArn` 將在後續步驟中使用 來擷取叢集秘密。稍後的步驟將使用 IP 地址和連接埠來設定`sackd`服務。

# 步驟 2 – 啟動 EC2 執行個體
<a name="working-with_login-nodes_standalone_launch"></a>

**啟動 EC2 執行個體**

1. 開啟 [Amazon EC2 主控台](https://console.aws.amazon.com/ec2)。

1. 在導覽窗格中，選擇 **Instances** (執行個體)，接著選擇 **Launch Instances** (啟動執行個體) 來開啟新的啟動執行個體精靈。

1. （選用） 在**名稱和標籤**區段中，提供執行個體的名稱，例如 `PCS-LoginNode`。該名稱將指派作為執行個體的資源標籤 (`Name=PCS-LoginNode`)。

1. 在**應用程式和作業系統映像**區段中，為 AWS PCS 支援的其中一個作業系統選取 AMI。如需詳細資訊，請參閱[支援的作業系統](working-with_ami_installers.md#working-with_ami_installers_os)。

1. 在**執行個體類型**區段中，選取支援的執行個體類型。如需詳細資訊，請參閱[支援的執行個體類型](working-with_ami_installers.md#working-wth_ami_installers_instance-types)。

1. 在**金鑰對**區段中，選取要用於執行個體的 SSH 金鑰對。

1. 在**網路設定**區段中：

   1. 選擇**編輯**。

     1. 選取 AWS PCS 叢集的 VPC。

     1. 針對**防火牆 (安全群組)**，選擇**選取現有的安全群組**。

        1. 選取允許執行個體與目標 AWS PCS 叢集 Slurm 控制器之間流量的安全群組。如需詳細資訊，請參閱[安全群組需求和考量事項](working-with_networking_sg.md#working-with_networking_sg-requirements)。

        1. （選用） 選取允許傳入 SSH 存取執行個體的安全群組。

1. 在**儲存**區段中，視需要設定儲存磁碟區。請務必設定足夠的空間來安裝應用程式和程式庫，以啟用您的使用案例。

1.  在**進階**下，選擇允許存取叢集秘密的 IAM 角色。如需詳細資訊，請參閱[取得 Slurm 叢集秘密](working-with_clusters_secrets_get.md)。

1.  在**摘要**窗格中，選擇**啟動執行個體**。

# 步驟 3 – 在執行個體上安裝 Slurm
<a name="working-with_login-nodes_standalone_install-slurm"></a>

當執行個體啟動並變成作用中時，請使用您偏好的機制連線到執行個體。使用 提供的 Slurm 安裝程式 AWS ，在執行個體上安裝 Slurm。如需詳細資訊，請參閱[Slurm 安裝程式](working-with_ami_installers.md#working-with_ami_installers_slurm)。

下載 Slurm 安裝程式，解壓縮，然後使用`installer.sh`指令碼安裝 Slurm。如需詳細資訊，請參閱[步驟 3 – 安裝 Slurm](working-with_ami_custom_install-slurm.md)。

# 步驟 4 – 擷取和存放叢集秘密
<a name="working-with_login-nodes_standalone_get-secret"></a>

這些指示需要 AWS CLI。如需詳細資訊，請參閱《 [第 2 版使用者指南》中的安裝或更新至最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) *AWS Command Line Interface *。

使用下列命令存放叢集秘密。
+ 建立 Slurm 的組態目錄。

  ```
  sudo mkdir -p /etc/slurm
  ```
+ 擷取、解碼和存放叢集秘密。執行此命令之前，請將 *region-code* 取代為目標叢集正在執行的區域，並將 *secret-arn* 取代為[步驟 1 ](working-with_login-nodes_standalone_get-addr.md)中`secretArn`擷取的 值。

  ```
  aws secretsmanager get-secret-value \
   --region region-code \
   --secret-id 'secret-arn' \
   --version-stage AWSCURRENT \
   --query 'SecretString' \
   --output text | base64 -d | sudo tee /etc/slurm/slurm.key
  ```
**警告**  
在多使用者環境中，任何可存取執行個體的使用者，如果可以存取執行個體中繼資料服務 (IMDS)，就可能可以擷取叢集秘密。這反過來可以讓他們模擬其他使用者。考慮將 IMDS 的存取權限制為僅限根使用者或管理使用者。或者，請考慮使用不依賴執行個體描述檔的不同機制來擷取和設定秘密。
+ 設定 Slurm 金鑰檔案的擁有權和許可。

  ```
  sudo chmod 0600 /etc/slurm/slurm.key
  sudo chown slurm:slurm /etc/slurm/slurm.key
  ```
**注意**  
Slurm 金鑰必須由執行`sackd`服務的使用者和群組所擁有。

# 步驟 5 – 設定 AWS PCS 叢集的連線
<a name="working-with_login-nodes_standalone_configure-connection"></a>

若要建立與 AWS PCS 叢集的連線，請依照下列步驟啟動 `sackd` 做為系統服務。

**注意**  
 如果您使用 Slurm 25.05 或更新版本，您可以使用指令碼來設定登入節點，以改為連線至多個叢集。如需詳細資訊，請參閱[將獨立登入節點連接到 AWS PCS 中的多個叢集](multi-cluster-login-script.md)。

1. 使用下列命令設定 `sackd`服務的環境檔案。執行命令之前，請將 *ip-address* 和 *port* 取代為[步驟 1](working-with_login-nodes_standalone_get-addr.md) 中從端點擷取的值。

   ```
   sudo echo "SACKD_OPTIONS='--conf-server=ip-address:port'" > /etc/sysconfig/sackd
   ```

1. 建立用於管理`sackd`程序`systemd`的服務檔案。

   ```
   sudo cat << EOF > /etc/systemd/system/sackd.service
   [Unit]
   Description=Slurm auth and cred kiosk daemon
   After=network-online.target remote-fs.target
   Wants=network-online.target
   ConditionPathExists=/etc/sysconfig/sackd
   
   [Service]
   Type=notify
   EnvironmentFile=/etc/sysconfig/sackd
   User=slurm
   Group=slurm
   RuntimeDirectory=slurm
   RuntimeDirectoryMode=0755
   ExecStart=/opt/aws/pcs/scheduler/slurm-25.05/sbin/sackd --systemd \$SACKD_OPTIONS
   ExecReload=/bin/kill -HUP \$MAINPID
   KillMode=process
   LimitNOFILE=131072
   LimitMEMLOCK=infinity
   LimitSTACK=infinity
   
   [Install]
   WantedBy=multi-user.target
   EOF
   ```

1. 設定`sackd`服務檔案的擁有權。

   ```
   sudo chown root:root /etc/systemd/system/sackd.service && \
       sudo chmod 0644 /etc/systemd/system/sackd.service
   ```

1. 啟用 `sackd`服務。

   ```
   sudo systemctl daemon-reload && sudo systemctl enable sackd
   ```

1. 啟動 `sackd` 服務。

   ```
   sudo systemctl start sackd
   ```

# 步驟 6 – （選用） 測試連線
<a name="working-with_login-nodes_standalone_test"></a>

確認`sackd`服務正在執行。範例輸出如下。如果有錯誤，通常會顯示在這裡。

```
[root@ip-10-3-27-112 ~]# systemctl status sackd
[x] sackd.service - Slurm auth and cred kiosk daemon
   Loaded: loaded (/etc/systemd/system/sackd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2024-12-17 16:34:55 UTC; 8s ago
 Main PID: 9985 (sackd)
   CGroup: /system.slice/sackd.service
           └─9985 /opt/aws/pcs/scheduler/slurm-25.05/sbin/sackd --systemd --conf-server=10.3.149.220:6817

Dec 17 16:34:55 ip-10-3-27-112.ec2.internal systemd[1]: Starting Slurm auth and cred kiosk daemon...
Dec 17 16:34:55 ip-10-3-27-112.ec2.internal systemd[1]: Started Slurm auth and cred kiosk daemon.
Dec 17 16:34:55 ip-10-3-27-112.ec2.internal sackd[9985]: sackd: running
```

確認與叢集的連線正在使用 Slurm 用戶端命令，例如 `sinfo`和 `squeue`。以下是來自 的範例輸出`sinfo`。

```
[root@ip-10-3-27-112 ~]# /opt/aws/pcs/scheduler/slurm-25.05/bin/sinfo
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST
all up infinite 4 idle~ compute-[1-4]
```

您也應該能夠提交任務。例如，類似此範例的命令會在叢集中的 1 個節點上啟動互動式任務。

```
/opt/aws/pcs/scheduler/slurm-25.05/bin/srun --nodes=1 -p all --pty bash -i
```