Direkt zum Inhalt

Install GUI (graphical desktop) on Amazon EC2 instances running RHEL/Rocky Linux

Lesedauer: 8 Minute
Inhaltsebene: Fortgeschrittene Anfänger
2

Steps to install desktop environment, desktop manager and Amazon DCV high performance remote display protocol server on RHEL (Red Hat Enterprise Linux) and Rocky Linux versions 8, 9 and 10

Overview

This article suggests how you can install GUI (Graphical User Interface) on Amazon EC2 instances running RHEL/Rocky Linux 8/9/10, and access it using Amazon DCV remote display protocol.

This article applies to RHEL/Rocky Linux on AWS only. Similar articles are available for AL2, AL2023, Ubuntu Linux and SLES 15

GPU instance

If you are using NVIDIA GPU instances, you may want to install graphics drivers. Refer to Install NVIDIA GPU driver, CUDA Toolkit, NVIDIA Container Toolkit on Amazon EC2 instances running RHEL/Rocky Linux and NVIDIA drivers for your Amazon EC2 instance for guidance.

Notice

Your use of DCV is subject to DCV end user license agreement

Requirements

Supported OS versions

The following versions are supported by Amazon DCV server

While the steps may work on other RHEL compatible Linux OSs such as AlmaLinux, it is not supported.

EC2 instance prerequisites

  • EC2 instance with 2 GiB or more memory
  • Attached security group allows inbound TCP and UDP port 8443 from your IP
  • More than 3 GB free disk space to install graphical desktop components and DCV server
  • Attached EC2 IAM role with the below policy for license validation. Replace REGION with your instance AWS Region code. Alternatively, attach AmazonS3ReadOnlyAccess managed policy.
{
    "Version": "2012-10-17",
    "Statement": [
       {
           "Effect": "Allow",
           "Action": "s3:GetObject",
           "Resource": "arn:aws:s3:::dcv-license.REGION/*"
       }
    ]
}

Installing DCV

Optional: Install SSM agent

Install SSM agent (if not installed) to enable Session Manager access. This requires EC2 instance to have attached IAM role with the AmazonSSMManagedInstanceCore policy

if (! systemctl list-units | grep -q amazon-ssm-agent); then
  if (arch | grep -q x86); then
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
  else
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
  fi
fi

Optional: Install EC2 Instance Connect

Install EC2 Instance Connect to allow secure SSH access

cd /tmp

if (arch | grep -q x86); then
  ARCH=amd64
else
  ARCH=arm64
fi
OS_VERSION=$(. /etc/os-release;echo $VERSION_ID | sed -e 's/\..*//g')
EIC_VERSION="2.0.0-6"
curl -L -O https://amazon-ec2-instance-connect-us-west-2.s3.us-west-2.amazonaws.com/latest/linux_$ARCH/ec2-instance-connect-$EIC_VERSION.rhel$OS_VERSION.$(arch).rpm
curl -L -O https://amazon-ec2-instance-connect-us-west-2.s3.us-west-2.amazonaws.com/latest/linux_$ARCH/ec2-instance-connect-selinux-$EIC_VERSION.noarch.rpm
sudo dnf install -y ./ec2-instance-connect-$EIC_VERSION.rhel$OS_VERSION.$(arch).rpm ./ec2-instance-connect-selinux-$EIC_VERSION.noarch.rpm

Install desktop environment and desktop manager

Install GNOME desktop

sudo dnf update -y
sudo dnf groupinstall -y 'Server with GUI'
sudo dnf groupinstall -y GNOME
if [ -f /etc/gdm/custom.conf ]; then
  sudo sed -i '/^\[daemon\]/a WaylandEnable=false' /etc/gdm/custom.conf
fi
sudo systemctl set-default graphical.target

Install DCV server

Install NICE DCV server components, and enable server daemon

cd /tmp
sudo rpm --import https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY
OS_VERSION=$(. /etc/os-release;echo $VERSION_ID | sed -e 's/\..*//g')
curl -L -O https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-el$OS_VERSION-$(arch).tgz
tar -xvzf nice-dcv-el$OS_VERSION-$(arch).tgz && cd nice-dcv-*-el$OS_VERSION-$(arch)
sudo dnf install -y ./nice-dcv-server-*.rpm
sudo dnf install -y ./nice-dcv-web-viewer-*.rpm
if [ -f ./nice-xdcv* ]; then
  sudo dnf install -q -y ./nice-xdcv*.rpm
fi
sudo systemctl enable dcvserver

RHEL/Rocky 8/9: Use Xdcv with console session

For non-GPU instance, configure console session to be served by Xdcv instead of Xorg for dynamic resizing and multi-monitor support

sudo systemctl enable --now xdcv-console-update.service
sudo systemctl enable xdcv-console.path

If you have NVIDIA drivers installed, you may want to configure GPU-accelerated Xorg console session instead

if [ -f /usr/bin/nvidia-xconfig ]; then
  sudo /usr/bin/nvidia-xconfig --preserve-busid --enable-all-gpus
fi

RHEL/Rocky 8/9: Configure automatic console session

Configure automatic console session, file transfer and printing support

if (cat /etc/os-release | grep -q Rocky); then
  DCVUSER="rocky"
else
  DCVUSER="ec2-user"
fi
sudo sed -i "/^\[session-management\/automatic-console-session/a owner=\"$DCVUSER\"\nstorage-root=\"%home%\"" /etc/dcv/dcv.conf
sudo sed -i "s/^#create-session/create-session/g" /etc/dcv/dcv.conf

RHEL/Rocky 10: Automatic start virtual session

On Linux with Wayland, Amazon DCV supports virtual sessions only. To automatically start virtual session whenever the host starts, create a systemd service that runs dcv create-session.

if (cat /etc/os-release | grep -q Rocky); then
  DCVUSER="rocky"
else
  DCVUSER="ec2-user"
fi
sudo tee /etc/systemd/system/dcv-automatic-virtual-session.service> /dev/null << EOF
[Unit]
Description=Create DCV virtual session
After=dcvserver.service graphical.target
Wants=graphical.target
Requires=dcvserver.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/dcv create-session "$DCVUSER" --owner "$DCVUSER" --storage-root %home% --type virtual 

[Install]
WantedBy=graphical.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable dcv-automatic-virtual-session.service

Configure printing

Configure printing support

sudo dnf install -y cups
sudo usermod -a -G sys dcv
sudo systemctl enable --now cups

Open firewall port

Open firewall ports if firewall daemon is installed

if (which firewall-offline-cmd); then
  sudo systemctl stop firewalld
  sudo firewall-offline-cmd --add-port 8443/tcp
  sudo firewall-offline-cmd --add-port 8443/udp
  sudo systemctl start firewalld
fi

Restart graphical session and DCV server

sudo systemctl isolate multi-user.target && sudo systemctl isolate graphical.target
sudo systemctl stop dcvserver && sudo systemctl start dcvserver
if [ -f /etc/systemd/system/dcv-automatic-virtual-session.service ]; then
  sudo systemctl restart dcv-automatic-virtual-session
fi

Set user password

Specify a strong password for login user

Rocky

sudo passwd rocky

RHEL

sudo passwd ec2-user

Verify installation

To verify

dcv list-sessions

Ensure that user session for rocky/ec2-user exists

Rocky 8/9

Session: 'console' (owner:rocky type:console)

Rocky 10

Session: 'rocky' (owner:rocky type:virtual)

Access graphical desktop environment

Clients

DCV offers Windows, Linux, macOS and web browser clients.

You can connect to DCV server using web browser client at https://<EC2-IP>:8443 (where <EC2-IP> is your EC2 instance IP address). Native clients provide better user experience and additional features, and can be downloaded from Amazon DCV site.

Login as ec2-user (RHEL) or rocky (Rocky Linux) with your configured password

Do ensure that EC2 instance security group allow inbound TCP and UDP 8443 from your IP

Web browser client

Enter image description here

EC2 Install Script

You can use the below as install script (or user data) on a new RHEL or Rocky Linux EC2 instance.

#!/bin/bash
if (! systemctl list-units | grep -q amazon-ssm-agent); then
  if (arch | grep -q x86); then
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
  else
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
  fi
fi

if (arch | grep -q x86); then
  ARCH=amd64
else
  ARCH=arm64
fi
OS_VERSION=$(. /etc/os-release;echo $VERSION_ID | sed -e 's/\..*//g')
EIC_VERSION="2.0.0-6"
curl -s -L -O https://amazon-ec2-instance-connect-us-west-2.s3.us-west-2.amazonaws.com/latest/linux_$ARCH/ec2-instance-connect-$EIC_VERSION.rhel$OS_VERSION.$(arch).rpm
curl -s -L -O https://amazon-ec2-instance-connect-us-west-2.s3.us-west-2.amazonaws.com/latest/linux_$ARCH/ec2-instance-connect-selinux-$EIC_VERSION.noarch.rpm
sudo dnf install -y ./ec2-instance-connect-$EIC_VERSION.rhel$OS_VERSION.$(arch).rpm ./ec2-instance-connect-selinux-$EIC_VERSION.noarch.rpm

sudo dnf update -y
sudo dnf groupinstall -y 'Server with GUI'
sudo dnf groupinstall -y GNOME
if [ -f /etc/gdm/custom.conf ]; then
  sudo sed -i '/^\[daemon\]/a WaylandEnable=false' /etc/gdm/custom.conf
fi
sudo systemctl set-default graphical.target

cd /tmp
OS_VERSION=$(. /etc/os-release;echo $VERSION_ID | sed -e 's/\..*//g')

sudo rpm --import https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY
curl -L -O https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-el$OS_VERSION-$(arch).tgz
tar -xvzf nice-dcv-el$OS_VERSION-$(arch).tgz && cd nice-dcv-*-el$OS_VERSION-$(arch)
sudo dnf install -y ./nice-dcv-server-*.rpm
sudo dnf install -y ./nice-dcv-web-viewer-*.rpm
if [ -f ./nice-xdcv* ]; then
  sudo dnf install -q -y ./nice-xdcv*.rpm
fi
sudo systemctl enable dcvserver

sudo dnf install -y cups
sudo usermod -a -G sys dcv
sudo systemctl enable --now cups

if (cat /etc/os-release | grep -q Rocky); then
  DCVUSER="rocky"
else
  DCVUSER="ec2-user"
fi

if (! echo $OS_VERSION | grep -q "^1[0-9]" ); then
  sudo systemctl enable --now xdcv-console-update.service
  sudo systemctl enable xdcv-console.path

  sudo sed -i "/^\[session-management\/automatic-console-session/a owner=\"$DCVUSER\"\nstorage-root=\"%home%\"" /etc/dcv/dcv.conf
  sudo sed -i "s/^#create-session/create-session/g" /etc/dcv/dcv.conf
else
  sudo tee /etc/systemd/system/dcv-automatic-virtual-session.service> /dev/null << EOF
[Unit]
Description=Create DCV virtual session
After=dcvserver.service graphical.target
Wants=graphical.target
Requires=dcvserver.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/dcv create-session "$DCVUSER" --owner "$DCVUSER" --storage-root %home% --type virtual 

[Install]
WantedBy=graphical.target
EOF
  sudo systemctl daemon-reload
  sudo systemctl enable dcv-automatic-virtual-session.service
fi

if (which firewall-offline-cmd); then
  sudo systemctl stop firewalld
  sudo firewall-offline-cmd --add-port 8443/tcp
  sudo firewall-offline-cmd --add-port 8443/udp
  sudo systemctl start firewalld
fi

sudo systemctl isolate multi-user.target && sudo systemctl isolate graphical.target
sudo systemctl stop dcvserver && sudo systemctl start dcvserver
if [ -f /etc/systemd/system/dcv-automatic-virtual-session.service ]; then
  sudo systemctl restart dcv-automatic-virtual-session.service
fi

Restart your EC2 instance, and set ec2-user/rocky user password

Additional information

Refer to DCV Administrator Guide and User Guide for up-to-date guidance

For help navigating graphical desktop, refer to Learn GNOME

DCV sessions

Amazon DCV on Linux with X11 offers two types of sessions: console sessions and virtual sessions. This article use console session that is served by Xdcv. Virtual sessions support multiple concurrent sessions.

To switch to virtual session, connect to EC2 instance as ec2-user/rocky, disable console session, configure multi-user.target (optional) and reboot

sudo sed -i "s/^create-session/#create-session/g" /etc/dcv/dcv.conf
sudo systemctl restart dcvserver
sudo systemctl set-default multi-user.target
sudo systemctl isolate multi-user.target
sudo reboot

You will need to create a virtual session manually

if (cat /etc/os-release | grep -q Rocky); then
  DCVUSER="rocky"
else
  DCVUSER="ec2-user"
fi

sudo dcv create-session $DCVUSER --owner $DCVUSER --storage-root %home% --type virtual

To verify that virtual session has been created

sudo dcv list-sessions

Output should be similar to below

 Session: 'rocky' (owner:rocky type:virtual)

Refer to Using the command line on a Linux Amazon DCV Server for more information

Other options

Consider managed EUC (End User Computing) services such as Amazon WorkSpaces

To quickly get up and running with DCV for internal testing, you can use CloudFormation template at DCV CloudFormation page.

You can also explore amazon-ec2-nice-dcv-samples CloudFormation templates to provision your own EC2 instances with graphical desktop environment, DCV server and other features such as multiple virtual sessions support and GPU driver installation.

AMIs preconfigured with graphical desktop environment are available from AWS Marketplace.

AWS
EXPERTE

veröffentlicht vor 2 Jahren4605 Aufrufe