

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 重启 RHEL 源服务器 SELinux 后，无需禁用 AWS 复制代理即可自动重启 AWS 复制代理
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server"></a>

*Anil Kunapareddy、Venkatramana Chintha 和 Shanmugam Shanker，Amazon Web Services*

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

AWS Application Migration Service 可帮助简化、加快和自动将您的 Red Hat Enterprise Linux (RHEL) 工作负载迁移至 Amazon Web Services (AWS) Cloud。要将源服务器添加到 Application Migration Service，您可以在服务器上安装 AWS Replication Agent。

Application Migration Service 提供实时、异步、块级复制。这意味着您可以在整个复制过程中继续正常的 IT 操作。 这些 IT 操作可能需要您在迁移期间重新引导或重新启动 RHEL 源服务器。如果发生这种情况，AWS Replication Agent 将不会自动重启，您的数据复制也将停止。通常，您可以将安全增强型 Linux (SELinux) 设置为**禁用**或**允许**模式以自动重启 AWS Replication Agent。但是，贵组织的安全策略可能禁止禁用 SELinux，您可能还必须[重新标记文件](https://access.redhat.com/solutions/3176)。

此模式描述了如何在迁移期间 RHEL 源服务器重启或重新启动 SELinux 时自动重启 AWS Replication Agent 而无需关闭。 

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

**先决条件**
+ 一个有效的 Amazon Web Services account。
+ 您想要迁移到 Amazon Web Services Cloud 的本地 RHEL 工作负载。 
+ Application Migration Service 已从 Application Migration Service 控制台初始化。仅首次使用此服务时才需要初始化。有关说明，请参阅 [Application Migration Service 文档](https://docs.aws.amazon.com/mgn/latest/ug/mandatory-setup.html)。
+ 适用于 Application Migration Service 的现有 [AWS Identity and Access Management (IAM) policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)。有关更多信息，请参阅 [Application Migration Service 文档](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)。

**版本**
+ RHEL 版本 7 或更高版本

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

**AWS 服务**
+ [AWS 应用程序迁移服务](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)是一种高度自动化 lift-and-shift（重新托管）的解决方案，可简化、加快应用程序迁移到 AWS 并降低其成本。

**Linux 命令**

下表列出了您将在 RHEL 源服务器上运行的 Linux 命令。在此模式的操作说明和场景中也有描述。 


| 
| 
| 命令 | 说明 | 
| --- |--- |
| `#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 Replication Agent 并重启 RHEL 源服务器
<a name="install-the-aws-replication-agent-and-reboot-the-rhel-source-server"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建具有访问密钥与秘密访问密钥的 Application Service 用户。 | 要安装 AWS Replication Agent，您必须使用所需 AWS 凭证创建 Application Migration Service 用户。有关说明，请参阅 [Application Migration Service 文档](https://docs.aws.amazon.com/mgn/latest/ug/credentials.html)。 | 迁移工程师 | 
| 安装 AWS Replication Agent。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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 源服务器。 | 迁移工程师 | 
| 检查数据复制状态。 | 等待一小时，然后在迁移控制面板上再次检查**数据复制状态**。它应该处于**健康**状态。 | 迁移工程师 | 

### 检查 RHEL 源服务器上的 AWS Replication Agent 状态
<a name="check-aws-replication-agent-status-on-the-rhel-source-server"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 确定系统版本。 | 打开 RHEL 源服务器命令行界面，然后运行以下命令来识别系统版本：`#systemctl –version` | 迁移工程师 | 
| 列出所有活跃服务。 | 要列出 RHEL 服务器上可用的所有活动服务，请运行以下命令：`#systemctl list-units --type=service` | 迁移工程师 | 
| 列出所有正在运行的服务。 | 要列出 RHEL 服务器上当前运行的所有服务，请使用以下命令：`#systemctl list-units --type=service \| grep running` | 迁移工程师 | 
| 列出所有加载失败服务。 | 要列出 RHEL 服务器重新引导或重新启动后加载失败的所有服务，请运行以下命令：`#systemctl list-units --type=service \| grep failed` | 迁移工程师 | 

### 创建并运行 SELinux 模块
<a name="create-and-run-the-selinux-module"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 更改安全上下文。 | 在 RHEL 源服务器的命令行界面中，运行以下命令以将安全上下文更改为 AWS 复制服务：`restorecon -Rv /etc/rc.d/init.d/aws-replication-service` | 迁移工程师 | 
| 安装核心实用程序。 | 要安装 SELinux 系统及其策略运行所需的核心实用程序，请运行以下命令：`yum install policycoreutils*` | 迁移工程师 | 
| 搜索审核日志并创建策略模块。 | 运行命令：`ausearch -c "insmod" --raw \| audit2allow -M my-modprobe` | 迁移工程师 | 
| 显示 my-modprobe-te文件内容。 | 该 `my-modprobe.te` 文件由 **audit2allow** 命令生成。它包括 SELinux 域、策略源目录和子目录，并指定与这些域相关的访问向量规则和过渡。运行以下命令以显示文件的内容：`cat my modprobe.te` | 迁移工程师 | 
| 激活策略。 | 若要插入模块并激活策略包，请运行以下命令：`semodule -i my-modprobe.pp` | 迁移工程师 | 
| 检查模块是否已加载。 | 运行如下命令：`semodule -l \| grep my-modprobe`加载 SELinux 模块后，迁移期间无需再设置 SELinux 为**禁用**模式**或允许**模式。 | 迁移工程师 | 
| 重启 RHEL 源服务器并验证数据复制状态。 | 打开 AWS Migration Service 控制台，导航至**数据复制进度**，然后重启您的 RHEL 源服务器。现在，数据复制应在 RHEL 源服务器重新启动后自动恢复。 | 迁移工程师 | 

## 相关资源
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-resources"></a>
+ [Application Migration Service 文档](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)
+ [技术培训材料](https://docs.aws.amazon.com/mgn/latest/ug/mgn-training.html)
+ [对 AWS Replication Agent 问题进行故障排除](https://docs.aws.amazon.com/mgn/latest/ug/Troubleshooting-Agent-Issues.html)
+ [Application Migration Service 策略](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)