

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

# Linux Amazon DCV 服务器的先决条件
<a name="setting-up-installing-linux-prereq"></a>

Amazon DCV 允许客户端访问 Linux 服务器上的远程图形 X 会话。这会提供对相应 Linux 桌面的访问。Amazon DCV 支持两种类型的 Linux 桌面流：控制台会话和虚拟会话。有关控制台会话和虚拟会话的更多信息，请参阅[管理 Amazon DCV 会话](managing-sessions.md)。

本主题介绍了如何安装在 Linux 服务器上使用 Amazon DCV 所需的必备组件。

**Topics**
+ [安装桌面环境和桌面管理器](#linux-prereq-gui)
+ [禁用 Wayland 协议（GDM3 仅限）](#linux-prereq-wayland)
+ [配置 X 服务器](#linux-prereq-xserver)
+ [安装 glxinfo 实用程序](#linux-prereq-tools)
+ [验证 OpenGL 软件渲染](#linux-prereq-opengl)
+ [为图形实例安装GPU驱动程序](#linux-prereq-gpu)
+ [为非 GPU 实例安装 XDummy 驱动程序](#linux-prereq-nongpu)

## 安装桌面环境和桌面管理器
<a name="linux-prereq-gui"></a>

安装桌面环境和桌面管理器以改善您在 Linux 服务器上使用 Amazon DCV 的体验。

桌面环境是一个图形用户界面 (GUI)，有助于您与 Linux 操作系统交互。具有多种桌面环境，Amazon DCV 可以与其中的很多环境一起使用。桌面管理器是管理用户登录屏幕、启动和停止桌面环境会话和 X 服务器的项目。

以下选项卡式内容显示了在支持的操作系统上安装默认桌面环境和桌面管理器的步骤，还说明了如何在支持的操作系统上配置和启动 X 服务器。

------
#### [ RHEL, CentOS, and Rocky Linux ]

RHEL、CentOS 和 Rocky Linux 的默认桌面环境是 Gnome3，默认桌面管理器是 GDM。

**在 RHEL、CentOS 和 Rocky Linux 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包
   + RHEL 和 Rocky Linux

     ```
     $ sudo yum groupinstall 'Server with GUI'
     ```
   + CentOS

     ```
     $ sudo yum groupinstall "GNOME Desktop"
     ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo yum upgrade
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

------
#### [ Amazon Linux 2 ]

Amazon Linux 2 的默认桌面环境是 Gnome3，默认桌面管理器是 GDM。

**在 Amazon Linux 2 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包

   ```
   $ sudo yum install gdm gnome-session gnome-classic-session gnome-session-xsession
   ```

   ```
   $ sudo yum install xorg-x11-server-Xorg xorg-x11-fonts-Type1 xorg-x11-drivers 
   ```

   ```
   $ sudo yum install gnome-terminal gnu-free-fonts-common gnu-free-mono-fonts gnu-free-sans-fonts gnu-free-serif-fonts
   ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo yum upgrade
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

------
#### [ Amazon Linux 2023 ]

亚马逊 Linux 2023 的默认桌面环境是 Gnome3，默认桌面管理器是 GDM。

**在亚马逊 Linux 2023 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包

   ```
   $ sudo dnf groupinstall 'Desktop'
   ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo dnf upgrade
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

------
#### [ Ubuntu 20.x, 22.x, and 24.x ]

对于 Ubuntu 20.x/22.x/24.x，默认桌面环境为 Gnome3，默认桌面管理器为。 GDM3从 Ubuntu 20.x 开始，Amazon DCV 中不再支持 LightDM。

**在 Ubuntu 20.x/22.x/24.x 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包

   ```
   $ sudo apt update
   ```

   ```
   $ sudo apt install ubuntu-desktop
   ```

   安装 GDM3

   ```
   $ sudo apt install gdm3
   ```

1. 确认已将其设置 GDM3 为默认桌面管理器。

   ```
   $ cat /etc/X11/default-display-manager
   ```

   输出如下所示。

   ```
   /usr/sbin/gdm3
   ```

   如果 GDM3 未设置为默认桌面管理器，请使用以下命令将其设置为默认桌面管理器。

   ```
   $ sudo dpkg-reconfigure gdm3
   ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo apt upgrade
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

**注意**  
在**虚拟会话**中使用早于 2022.2 的 Amazon DCV 版本时，您可能会遇到[一个已知的 GDM 问题](https://gitlab.gnome.org/GNOME/gdm/-/issues/650)。要使虚拟会话正常工作，您可以采用以下解决方案之一：  
**在没有 GPU 的服务器上**，您可以禁用桌面管理器，因为不需要使用桌面管理器即可运行虚拟会话。在创建虚拟会话之前运行以下命令，以将系统配置为在多用户模式下运行：  

  ```
  $  sudo systemctl isolate multi-user.target
  ```
**在具有 GPU 的服务器上**，除了禁用桌面管理器以外，您还需要在创建虚拟会话之前在系统上启动 X 服务器。为此，请运行以下命令：  

  ```
  $  sudo systemctl isolate multi-user.target
  ```

  ```
  $  sudo dcvstartx &
  ```
Amazon DCV 2022.2 和更高版本不受该问题影响。

------
#### [ SUSE Linux Enterprise 12.x ]

SUSE Linux Enterprise 12.x 的默认桌面环境是 SLE Classic，默认桌面管理器是 GDM。

**在 SUSE Linux Enterprise 12.x 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包

   ```
   $ sudo zypper install -t pattern gnome-basic
   ```

1. 验证 GDM 是否设置为默认桌面管理器。

   ```
   $ sudo update-alternatives --set default-displaymanager /usr/lib/X11/displaymanagers/gdm
   ```

   ```
   $ sudo sed -i "s/DEFAULT_WM=\"\"/DEFAULT_WM=\"gnome\"/" /etc/sysconfig/windowmanager
   ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo zypper update
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

------
#### [ SUSE Linux Enterprise 15.x ]

SUSE Linux Enterprise 15.x 的默认桌面环境是 SLE Classic，默认桌面管理器是。 GDM3

**在 SUSE Linux Enterprise 15.x 上安装和配置桌面环境和桌面管理器**

1. 安装桌面环境和桌面管理器程序包

   ```
   $ sudo zypper install -t pattern gnome_basic
   ```

1. 验证 GDM 是否设置为默认桌面管理器。

   ```
   $ sudo update-alternatives --set default-displaymanager /usr/lib/X11/displaymanagers/gdm
   ```

   ```
   $ sudo sed -i "s/DEFAULT_WM=\"\"/DEFAULT_WM=\"gnome\"/" /etc/sysconfig/windowmanager
   ```

1. 更新软件包来确保 Linux 服务器是最新的。

   ```
   $ sudo zypper update
   ```

1. 重新启动 Linux 服务器。

   ```
   $ sudo reboot
   ```

**注意**  
在**虚拟会话**中使用早于 2022.2 的 Amazon DCV 版本时，您可能会遇到[一个已知的 GDM 问题](https://gitlab.gnome.org/GNOME/gdm/-/issues/650)。要使虚拟会话正常工作，您可以采用以下解决方案之一：  
**在没有 GPU 的服务器上**，您可以禁用桌面管理器，因为不需要使用桌面管理器即可运行虚拟会话。在创建虚拟会话之前运行以下命令，以将系统配置为在多用户模式下运行：  

  ```
  $  sudo systemctl isolate multi-user.target
  ```
**在具有 GPU 的服务器上**，除了禁用桌面管理器以外，您还需要在创建虚拟会话之前在系统上启动 X 服务器。为此，请运行以下命令：  

  ```
  $  sudo systemctl isolate multi-user.target
  ```

  ```
  $  sudo dcvstartx &
  ```
Amazon DCV 2022.2 和更高版本不受该问题影响。

------

## 禁用 Wayland 协议（GDM3 仅限）
<a name="linux-prereq-wayland"></a>

Amazon DCV 不支持 Wayland 协议。如果您使用的是 GDM3 桌面管理器，则必须禁用 Wayland 协议。如果您未使用 GDM3，请跳过此步骤。

**禁用 Wayland 协议**

1. 使用常用的文本编辑器打开以下文件。
   + RHEL、CentOS、SUSE Linux Enterprise 15.x 和 Amazon Linux 2023

     ```
     /etc/gdm/custom.conf
     ```
   + Ubuntu

     ```
     /etc/gdm3/custom.conf
     ```

1. 在 `[daemon]` 部分中，将 `WaylandEnable` 设置为 `false`。

   ```
   [daemon]
   WaylandEnable=false
   ```

1. 重新启动 GDM 服务。
   + RHEL、CentOS 和 Amazon Linux 2023

     ```
     $ sudo systemctl restart gdm
     ```
   + Ubuntu

     ```
     $ sudo systemctl restart gdm3
     ```
   + SUSE Linux Enterprise 15.x

     ```
     $ sudo systemctl restart xdm
     ```

## 配置 X 服务器
<a name="linux-prereq-xserver"></a>

如果要使用控制台会话或 GPU 共享，则必须确保 Linux 服务器具有一个配置正确且正在运行的 X 服务器。

**注意**  
如果您打算使用虚拟会话而不共享 GPU，则不需要使用 X 服务器。

X 服务器程序包通常作为桌面环境和桌面管理器的依赖项安装。我们建议您将 X 服务器配置为当 Linux 服务器启动时自动启动。

**在 Linux 上配置和启动 X 服务器：**

1. 将 X 服务器配置为当 Linux 服务器启动时自动启动。

   ```
   $ sudo systemctl get-default
   ```

   如果命令返回 `graphical.target`，则表明 X 服务器已配置为自动启动。继续下一步。

   如果该命令返回 `multi-user.target`，则 X 服务器未配置为自动启动。执行下面的 命令：

   ```
   $ sudo systemctl set-default graphical.target
   ```

1. 启动 X 服务器。

   ```
   $ sudo systemctl isolate graphical.target
   ```

1. 验证 X 服务器是否正在运行。

   ```
   $ ps aux | grep X | grep -v grep
   ```

   下面显示 X 服务器在运行时的示例输出。

   `root 1891 0.0 0.7 277528 30448 tty7 Ssl+ 10:59 0:00 /usr/bin/Xorg :0 -background none -verbose -auth /run/gdm/auth-for-gdm-wltseN/database -seat seat0 vt7 `

## 安装 glxinfo 实用程序
<a name="linux-prereq-tools"></a>

glxinfo 实用程序提供关于您的 Linux 服务器的 OpenGL 配置的信息。该实用程序可用于确定您的 Linux 服务器是否配置为支持 OpenGL 硬件或软件渲染。它提供有关驱动程序和支持的扩展的信息。

glxinfo 实用程序作为 DCV GL 的程序包依赖项安装。因此，如果您安装了 DCV GL，则 glxinfo 实用程序已随之安装在您的 Linux 服务器上。

------
#### [ RHEL, CentOS, Rocky Linux, Amazon Linux 2, and Amazon Linux 2023 ]

**安装 glxinfo 实用程序**  
运行如下命令：

```
$ sudo yum install glx-utils
```

------
#### [ Ubuntu ]

**安装 glxinfo 实用程序**  
运行如下命令：

```
$ sudo apt install mesa-utils
```

------
#### [ SUSE Linux Enterprise ]

**安装 glxinfo 实用程序**  
运行如下命令：

```
$ sudo zypper in Mesa-demo-x
```

------

## 验证 OpenGL 软件渲染
<a name="linux-prereq-opengl"></a>

在非 GPU 的 Linux 服务器上，仅在软件渲染模式下使用 Mesa 驱动程序支持 OpenGL。如果您使用非 GPU Linux 服务器并打算使用 OpenGL，请确保在 Linux 服务器上安装并正确配置 Mesa 驱动程序。

**注意**  
这仅适用于非 GPU 的 Linux 服务器。

**验证 OpenGL 软件渲染是否可用**  
确保 X 服务器正在运行，并使用以下命令。

```
$ sudo DISPLAY=:0 XAUTHORITY=$(ps aux | grep "X.*\-auth" | grep -v Xdcv | grep -v grep | sed -n 's/.*-auth \([^ ]\+\).*/\1/p') glxinfo | grep -i "opengl.*version"
```

下面显示了 OpenGL 软件渲染可用时的示例输出：

```
OpenGL core profile version string: 3.3 (Core Profile) Mesa 17.0.5
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 17.0.5
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.0.5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
```

## 为图形实例安装GPU驱动程序
<a name="linux-prereq-gpu"></a>

**Topics**
+ [安装和配置 NVIDIA 驱动程序](#gpu-nvidia)
+ [安装和配置 AMD 驱动程序](#gpu-amd)

### 安装和配置 NVIDIA 驱动程序
<a name="gpu-nvidia"></a>

对于具有专用 NVIDIA GPU 的 Linux 服务器，请确保安装并正确配置相应的 NVIDIA 驱动程序。有关如何在 Amazon EC2 Linux 实例上安装 NVIDIA 驱动程序的说明，请参阅《Amazon EC2 用户指南》中的[在 Linux 服务器上安装 NVIDIA 驱动程序](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-nvidia-driver.html)。**

**注意**  
这仅适用于搭载 NVIDIA GPUs 的 Linux 服务器。
对于每个安装的 GPU，GRID 驱动程序支持最多 4 个 4K 显示器。对于每个安装的 GPU，游戏驱动程序仅支持一个 4K 显示器。

在 Linux 服务器上安装 NVIDIA 驱动程序后，更新 `xorg.conf`。

**生成更新的 xorg.conf**

1. 运行如下命令。

   ```
   $  sudo nvidia-xconfig --preserve-busid --enable-all-gpus
   ```

   如果您使用 G3、G4 或 G5 Amazon EC2 实例，并希望使用多显示器控制台会话，请包含 `--connected-monitor=DFP-0,DFP-1,DFP-2,DFP-3` 参数。该参数如下所示。

   ```
   $  sudo nvidia-xconfig --preserve-busid --enable-all-gpus --connected-monitor=DFP-0,DFP-1,DFP-2,DFP-3
   ```
**注意**  
确保您的服务器没有旧 `/etc/X11/XF86Config` 文件。如果服务器具有该文件，则 `nvidia-xconfig` 将更新该配置文件，而不是生成所需的 `/etc/X11/xorg.conf` 文件。运行以下命令可删除旧 `XF86Config` 文件：  

   ```
   sudo rm -rf /etc/X11/XF86Config*
   ```

1. 重新启动 X 服务器以使更改生效。
   + 

     ```
     $ sudo systemctl isolate multi-user.target
     ```

     ```
     $ sudo systemctl isolate graphical.target
     ```

**验证您的 NVIDIA GPU 是否支持基于硬件的视频编码**  
确保它支持 NVENC 编码，并且其计算容量大于或等于 3.0；对于 Ubuntu 20，确保其计算容量大于或等于 3.5。

要验证 NVENC 支持，请参阅 [NVIDIA Video Encode and Decode GPU Support Matrix](https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new#Encoder)。要检查计算容量，请参阅 [NVIDIA Compute Capacility tables](https://developer.nvidia.com/cuda-gpus)。

如果您的 NVIDIA GPU 不支持 NVENC 编码或没有所需的计算容量，则会使用基于软件的视频编码。

**验证 OpenGL 硬件渲染是否可用**  
使用以下命令可确保 X 服务器正在运行。

```
$ sudo DISPLAY=:0 XAUTHORITY=$(ps aux | grep "X.*\-auth" | grep -v Xdcv | grep -v grep | sed -n 's/.*-auth \([^ ]\+\).*/\1/p') glxinfo | grep -i "opengl.*version"
```

下面显示了 OpenGL 硬件渲染可用时的示例输出。

```
OpenGL core profile version string: 4.4.0 NVIDIA 390.75
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL version string: 4.6.0 NVIDIA 390.75
OpenGL shading language version string: 4.60 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 390.75
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
```

### 安装和配置 AMD 驱动程序
<a name="gpu-amd"></a>

已挂载 AMD GPU 的实例（如 G4ad 实例）必须安装相应的 AMD 驱动程序。有关如何在兼容的 Amazon EC2 实例上安装 AMD GPU 驱动程序的说明，请参阅[在 Linux 实例上安装 AMD 驱动程序](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-amd-driver.html)。

有关 Amazon EC2 G4ad 实例的更多信息，请参阅 [Deep dive on the new Amazon EC2 G4ad instances](https://aws.amazon.com/blogs/compute/deep-dive-on-the-new-amazon-ec2-g4ad-instances/) 博客文章。

## 为非 GPU 实例安装 XDummy 驱动程序
<a name="linux-prereq-nongpu"></a>

**Topics**
+ [安装和配置 XDummy 驱动程序](#gpu-xdummy)

### 安装和配置 XDummy 驱动程序
<a name="gpu-xdummy"></a>

要在没有专用 GPU 的 Linux 服务器上使用控制台会话，请确保安装并正确配置了 Xdummy 驱动程序。当没有真正的 GPU 时，该 XDummy 驱动程序允许 X 服务器使用虚拟帧缓冲区运行。

**注意**  
如果您打算使用虚拟会话，则不需要这样做。
该 XDummy 驱动程序只能支持其配置中定义的分辨率。

------
#### [ RHEL, CentOS, Rocky Linux, Amazon Linux 2, and Amazon Linux 2023 ]

**安装 XDummy 驱动程序**  
运行如下命令：

```
$ sudo yum install xorg-x11-drv-dummy
```

------
#### [ Ubuntu ]

**安装 XDummy 驱动程序**  
运行如下命令：

```
$ sudo apt install xserver-xorg-video-dummy
```

------
#### [ SUSE Linux Enterprise ]

**安装 XDummy 驱动程序**  
运行如下命令：

```
$ sudo zypper in xf86-video-dummy
```

------

在 Linux 服务器上安装 XDummy 驱动程序后，请更新`xorg.conf`。

**要在 xorg.c XDummy onf 中进行配置**

1. 使用常用的文本编辑器打开 `/etc/X11/xorg.conf` 文件。

1. 将以下部分添加到配置中。

   ```
   Section "Device"
       Identifier "DummyDevice"
       Driver "dummy"
       Option "UseEDID" "false"
       VideoRam 512000
   EndSection
   
   Section "Monitor"
       Identifier "DummyMonitor"
       HorizSync   5.0 - 1000.0
       VertRefresh 5.0 - 200.0
       Option "ReducedBlanking"
   EndSection
   
   Section "Screen"
       Identifier "DummyScreen"
       Device "DummyDevice"
       Monitor "DummyMonitor"
       DefaultDepth 24
       SubSection "Display"
           Viewport 0 0
           Depth 24
           Virtual 4096 2160
       EndSubSection
   EndSection
   ```
**注意**  
提供的配置是一个示例。您可以添加更多模式并设置不同的 `virtual` 分辨率。您还可以配置多个虚拟显示器。

1. 重新启动 X 服务器以使更改生效。

   ```
   $ sudo systemctl isolate multi-user.target
   ```

   ```
   $ sudo systemctl isolate graphical.target
   ```