

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

# 自动重启 AWS 在不禁用 SELinux 的情况下重新启动 RHEL 后的复制代理
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server"></a>

*Anil Kunapareddy，Amazon Web Services*

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

AWS Transform MGN 帮助简化、加快和自动将红帽企业 Linux (RHEL) 工作负载迁移到亚马逊网络服务 (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 源服务器重新启动或重新启动时，如何在不关闭 SELinux 的情况下自动重启 AWS 复制代理。 

## 先决条件和限制
<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 或更高版本

## 架构
<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_cn/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)是一种高度自动化的移动（重新托管）解决方案，可简化、加快应用程序迁移并降低向其迁移的成本。 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 复制代理并重新启动 RHEL 源服务器
<a name="install-the-aws-replication-agent-and-reboot-the-rhel-source-server"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 生成 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 />要创建临时证书，您需要：1. 使用`AWSApplicationMigrationAgentInstallationPolicy`策略@@ [创建新的 IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create.html)。<br />2. 使用 [AssumeRole API](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) 通过 AWS Security Token Service (AWS STS) [请求临时安全证书](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)。<br />您可以使用 AWS Command Line Interface (AWS CLI) 生成临时证书。有关示例，请参阅[AWS CLI 命令参考](https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html#examples)。 | 迁移工程师 | 
| 安装 AWS 复制代理。 | 1. 登录 AWS 管理控制台 并打开[AWS Transform MGN 控制台](https://console.aws.amazon.com/mgn/home)。<br />2. 按照 [MGN 文档](https://docs.aws.amazon.com/mgn/latest/ug/template-vs-server.html)中的说明配置复制设置。<br />3. 按照 [MGN 文档](https://docs.aws.amazon.com/mgn/latest/ug/agent-installation-instructions.html)中的说明安装 AWS 复制代理。<br />4. 在**源服务器**页面，选择 RHEL 源服务器，然后选择**复制**以开始初始复制。有关更多信息，请参阅 [MGN 文档](https://docs.aws.amazon.com/mgn/latest/ug/interracting.html)。 | 迁移工程师 | 
| 检查数据复制状态。 | 等到复制完成，然后在迁移仪表板上检查**数据复制状态**。它应该处于**健康**状态。 | 迁移工程师 | 
| 重启 RHEL 源服务器。 | 重启 RHEL 源服务器。请注意，在[迁移控制面板](https://docs.aws.amazon.com/mgn/latest/ug/migration-dashboard.html)上，**数据复制状态**显示为 “**已停止**”。 | 迁移工程师 | 

### 查看 AWS RHEL 源服务器上的复制代理状态
<a name="check-the-aws-replication-agent-status-on-the-rhel-source-server"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 确定系统版本。 | 打开 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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 更改安全上下文。 | 在 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)