LoginSignup
3
1

More than 3 years have passed since last update.

【忘備録】AmazonLinux2にデスクトップ環境を作成し、GUIで操作する。

Last updated at Posted at 2020-08-22

概要

内容

  • AmazonLinux2インスタンスにリモートデスクトップでselenium環境を立てる方法

利点

  • EC2をGUIで操作したい時のseleniumの挙動をGUIで確認したい時に便利

環境

  • AWS:EC2
  • OS:Amazon Linux2

作業工程

EC2インスタンスを作成

  • セキュリティグループのインバウンドルールを下記ポートを開ける
    • ポート番号:5901
    • ソース:パブリックにならないように、良きに設定する。

MATE(デスクトップ環境)のインストール

  • Amazon Linux 2 の Extras Library で提供されているデスクトップ環境 MATE をインストール
$ sudo amazon-linux-extras install mate-desktop1.x

TigerVNCをインストール

  • VNCサーバには、yum でパッケージ提供されている TigerVNC を利用
$ sudo yum install tigervnc-server
  • TigerVNCのユニットファイルを配置し、ディスプレイ番号は「1」に配置
$ sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
  • VNC接続用のパスワードを設定
$ vncpasswd

Password: <パスワードを入力>
Verify: <パスワードを入力>
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
  • TigerVNCの起動ユーザ設定
    • 起動ユーザの設定を ec2-user を変更
変更前
 sudo vi /etc/systemd/system/vncserver@:1.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target
変更後
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l ec2-user -c "/usr/bin/vncserver %i -SecurityTypes=TLSVnc"
PIDFile=/home/ec2-user/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target
  • 起動時にVNCサーバが立ち上がるようにサービスを登録
$ sudo systemctl enable vncserver@:1.service
  • xstartupファイルを作成し MATE が起動するように設定
$ vi ~/.vnc/xstartup
xstartup
#! /bin/sh
exec mate-session &
  • 実行権限を追加
$ chmod +x ~/.vnc/xstartup
  • TigerVNCを起動
    • ステータスを確認し、問題なく立ち上がっていることを確認
$ sudo systemctl start vncserver@:1.service

$ sudo systemctl status vncserver@:1.service

TigerVNCで、デスクトップに接続

  • クライアント側で、TigerVNCのソフトウェアをインストール

  • VNCServerに下記を入力して接続

    • VNC Server:{IPv4 パブリック IP}:5901
    • パスワード:vncpasswdで設定したパスワード
  • デスクトップが立ち上がっている事を確認したら終了。
    スクリーンショット 2020-09-06 16.19.26.png

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1