

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

# 在 RHEL AWS 重新啟動後自動重新啟動複寫代理程式，而不停用 SELinux
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server"></a>

*Anil Kunapareddy，Amazon Web Services*

## 摘要
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-summary"></a>

AWS Transform MGN 有助於簡化、加速和自動化 Red Hat Enterprise Linux (RHEL) 工作負載遷移至 Amazon Web Services (AWS) 雲端。若要將來源伺服器新增至 MGN，請在伺服器上安裝[AWS 複寫代理](https://docs.aws.amazon.com/mgn/latest/ug/agent-installation.html)程式。

MGN 提供即時、非同步的區塊層級複寫。這表示在整個複寫過程中，您可以繼續正常的 IT 操作。 這些 IT 操作可能需要您在遷移期間重新啟動或重新啟動 RHEL 來源伺服器。如果發生這種情況， AWS 複寫代理程式不會自動重新啟動，而且您的資料複寫將會停止。一般而言，您可以將 Security-Enhanced Linux (SELinux) 設定為**停用**或**寬鬆**模式，以自動重新啟動 AWS 複寫代理程式。不過，您組織的安全政策可能禁止停用 SELinux，而且您可能也必須[重新標記檔案](https://access.redhat.com/solutions/3176)。

此模式說明如何在 RHEL AWS 來源伺服器在遷移期間重新啟動或重新啟動時，在不關閉 SELinux 的情況下自動重新啟動複寫代理程式。 

## 先決條件和限制
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 您要遷移至 的內部部署 RHEL 工作負載 AWS 雲端。 
+ 從 MGN 主控台初始化 MGN。只有在您第一次使用此服務時，才需要初始化。如需說明，請參閱 [MGN 文件](https://docs.aws.amazon.com/mgn/latest/ug/mandatory-setup.html)。
+ MGN 的現有 [AWS Identity and Access Management (IAM) 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)。如需詳細資訊，請參閱 [MGN 文件](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)。

**版本**
+ RHEL 第 7 版或更新版本

## Architecture
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-architecture"></a>

下圖顯示此方法的架構。

![RHEL 重新啟動後自動重新啟動 AWS 複寫代理程式](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/3257dc61-bdc0-439e-b008-c0a62dd223ef/images/cf064194-1a34-4bb7-bd0b-b36db2c67b9d.png)


## 工具
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-tools"></a>

*AWS 服務*
+ [AWS Transform MGN](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 是一種高度自動化lift-and-shift（重新託管） 解決方案，可簡化、加速和降低將應用程式遷移至 的成本 AWS。

*Linux 命令*

下表提供您在 RHEL 來源伺服器上執行的 Linux 命令清單。這些也會在此模式的 epics 和故事中說明。 


| 
| 
| **命令** | **Description** | 
| --- |--- |
| `#systemctl –version` | 識別系統版本 | 
| `#systemctl list-units --type=service` | 列出 RHEL 伺服器上可用的所有作用中服務 | 
| `#systemctl list-units --type=service \| grep running` | 列出目前在 RHEL 伺服器上執行的所有服務 | 
| `#systemctl list-units --type=service \| grep failed` | 列出 RHEL 伺服器重新啟動或重新啟動後無法載入的所有服務 | 
| `#restorecon -Rv /etc/rc.d/init.d/aws-replication-service` | 將內容變更為 `aws-replication-service` | 
| `#yum install policycoreutils*` | 安裝 SELinux 系統操作所需的政策核心公用程式 | 
| `#ausearch -c "insmod" --raw \| audit2allow -M my-modprobe` | 搜尋稽核日誌並建立 政策的模組 | 
| `#semodule -i my-modprobe.pp` | 啟用政策 | 
| `#cat my-modprobe.te` | 顯示`my-modprobe.te`檔案的內容 | 
| `#semodule -l \| grep my-modprobe` | 檢查政策是否已載入 SELinux 模組 | 

## 史詩
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-epics"></a>

### 安裝 AWS 複寫代理程式並重新啟動 RHEL 來源伺服器
<a name="install-the-aws-replication-agent-and-reboot-the-rhel-source-server"></a>


| 任務 | 說明 | 所需的技能 | 
| --- | --- | --- | 
| 產生 AWS 暫時登入資料。 | MGN 提供的[臨時登入](https://docs.aws.amazon.com/mgn/latest/ug/credentials.html)資料使用類似於 使用的機制[AWS Identity and Access Management Roles Anywhere](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/introduction.html)。<br />若要建立臨時登入資料，您需要：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.html) | 遷移工程師 | 
| 安裝 AWS 複寫代理程式。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.html) | 遷移工程師 | 
| 檢查資料複寫狀態。 | 等待複寫完成，然後檢查遷移儀表板上的**資料複寫狀態**。它應該處於**運作**狀態。 | 遷移工程師 | 
| 重新啟動或重新啟動 RHEL 來源伺服器。 | 重新啟動或重新啟動 RHEL 來源伺服器。請注意，**資料複寫狀態**會在[遷移儀表板](https://docs.aws.amazon.com/mgn/latest/ug/migration-dashboard.html)上顯示為**停滯**。 | 遷移工程師 | 

### 檢查 RHEL AWS 來源伺服器上的複寫代理程式狀態
<a name="check-the-aws-replication-agent-status-on-the-rhel-source-server"></a>


| 任務 | 說明 | 所需的技能 | 
| --- | --- | --- | 
| 識別系統版本。 | 開啟 RHEL 來源伺服器的命令列界面，並執行下列命令來識別系統版本：<br />`#systemctl –version` | 遷移工程師 | 
| 列出所有作用中的服務。 | 若要列出 RHEL 伺服器上可用的所有作用中服務，請執行下列命令：<br />`#systemctl list-units --type=service` | 遷移工程師 | 
| 列出所有執行中的服務。 | 若要列出目前在 RHEL 伺服器上執行的所有服務，請使用下列命令：<br />`#systemctl list-units --type=service \| grep running` | 遷移工程師 | 
| 列出所有無法載入的服務。 | 若要列出 RHEL 伺服器重新啟動或重新啟動後無法載入的所有服務，請執行 命令：<br />`#systemctl list-units --type=service \| grep failed` | 遷移工程師 | 

### 建立並執行 SELinux 模組
<a name="create-and-run-the-selinux-module"></a>


| 任務 | 說明 | 所需的技能 | 
| --- | --- | --- | 
| 變更安全內容。 | 在 RHEL 來源伺服器的命令列界面中，執行下列命令，將安全內容變更為 AWS 複寫服務：<br />`#restorecon -Rv /etc/rc.d/init.d/aws-replication-service` | 遷移工程師 | 
| 安裝核心公用程式。 | 若要安裝 SELinux 系統操作所需的核心公用程式及其政策，請執行下列命令：<br />`#yum install policycoreutils*` | 遷移工程師 | 
| 搜尋稽核日誌並建立 政策的模組。 | 執行以下命令：<br />`#ausearch -c "insmod" --raw \| audit2allow -M my-modprobe` | 遷移工程師 | 
| 顯示 `my-modprobe-te` 檔案的內容。 | `my-modprobe.te` 檔案是由 **audit2allow **命令產生。它包含 SELinux 網域、政策來源目錄和子目錄，並指定與網域相關聯的存取向量規則和轉換。若要顯示檔案的內容，請執行下列命令：<br />`#cat my modprobe.te` | 遷移工程師 | 
| 啟用政策。 | 若要插入模組並將政策套件設為作用中，請執行下列命令：<br />`#semodule -i my-modprobe.pp` | 遷移工程師 | 
| 檢查是否已載入模組。 | 執行以下命令：<br />`#semodule -l \| grep my-modprobe`<br />載入 SELinux 模組後，您不再需要在遷移期間將 SELinux 設定為**已停用**或**寬鬆**模式。 | 遷移工程師 | 
| 重新啟動或重新啟動 RHEL 來源伺服器，並驗證資料複寫狀態。 | 開啟 AWS Transform MGN 主控台，導覽至**資料複寫進度**，然後重新啟動或重新啟動 RHEL 來源伺服器。資料複寫現在應在 RHEL 來源伺服器重新啟動後自動恢復。 | 遷移工程師 | 

## 相關資源
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-resources"></a>
+ [MGN 文件](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)
+ [MGN 政策](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)
+ [技術訓練資料](https://docs.aws.amazon.com/mgn/latest/ug/mgn-training.html)
+ [對 AWS 複寫代理程式問題進行故障診斷](https://docs.aws.amazon.com/mgn/latest/ug/Troubleshooting-Agent-Issues.html)