CentOS 7.1にVNC Serverをインストールする
Oracleの環境を構築するために、RHEL7.1にGUIをインストールすることになったが、対象がリモートの環境になるのでVNCを使用する。
以下はRHELで構築することを考慮して、ひとまずCentOSを対象に調査したときのまとめ。
環境
自作したvagrant boxのCentOS 7.1。boxは最小構成でインストールしたもの。
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[vagrant@localhost ~]$ uname -ar
Linux localhost.localdomain 3.10.0-229.4.2.el7.x86_64 #1 SMP Wed May 13 10:06:09 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
手順
GUI環境の構築
GUIの環境として、GNOMEをインストールする。
[vagrant@localhost ~]$ LANG=C sudo yum groupinstall "GNOME Desktop"
VNC Serverのインストール
TigerVNCをインストールする。
[vagrant@localhost ~]$ sudo yum install tigervnc-server
VNCのパスワードを設定
接続時にvagrantユーザでログインするために、vncpasswd
コマンドでパスワード設定する。
[vagrant@localhost ~]$ vncpasswd
serviceの設定
VNC Serverのservice unitファイルをコピーし、編集する。
[vagrant@localhost ~]$ sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
[vagrant@localhost ~]$ sudoedit /etc/systemd/system/vncserver@.service
編集したものがこちら。
[vagrant@localhost ~]$ diff -u /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
--- /usr/lib/systemd/system/vncserver@.service 2014-06-10 15:15:02.000000000 +0900
+++ /etc/systemd/system/vncserver@.service 2015-05-21 23:43:46.153717683 +0900
@@ -37,8 +37,8 @@
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=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
-PIDFile=/home/<USER>/.vnc/%H%i.pid
+ExecStart=/sbin/runuser -l vagrant -c "/usr/bin/vncserver %i"
+PIDFile=/home/vagrant/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
<USER>
をvagrant
に変更した。
serviceの起動
systemctl
コマンドでVNC Serverを起動する。自動起動の設定はしない。
[vagrant@localhost ~]$ sudo systemctl start vncserver@:1.service
起動後の確認。
[vagrant@localhost ~]$ sudo systemctl status vncserver@:1.service
vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@.service; disabled)
Active: active (running) since 木 2015-05-21 23:44:28 JST; 6s ago
Process: 1605 ExecStart=/sbin/runuser -l vagrant -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
Process: 1602 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 1630 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
‣ 1630 /usr/bin/Xvnc :1 -desktop localhost.localdomain:1 (vagrant) -auth /home/vagrant/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /home/vagrant/.vnc/passwd -rfbport 5901 -fp ...
5月 21 23:44:25 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...
5月 21 23:44:28 localhost.localdomain systemd[1]: Started Remote desktop service (VNC).
firewallの設定
VNC Serverへの接続を許可する。永続的な設定はしない。
[vagrant@localhost ~]$ sudo firewall-cmd --add-service=vnc-server --zone=public
success
設定後の確認。
[vagrant@localhost ~]$ sudo firewall-cmd --list-service
dhcpv6-client ssh vnc-server
ちなみに、add-service
オプションで指定した値と同名のファイルが/usr/lib/firewalld/services
ディレクトリにある。
[vagrant@localhost ~]$ sudo ls /usr/lib/firewalld/services
RH-Satellite-6.xml dhcpv6-client.xml http.xml ipsec.xml libvirt-tls.xml mysql.xml pmproxy.xml proxy-dhcp.xml smtp.xml transmission-client.xml
amanda-client.xml dhcpv6.xml https.xml kerberos.xml libvirt.xml nfs.xml pmwebapi.xml radius.xml ssh.xml vnc-server.xml
bacula-client.xml dns.xml imaps.xml kpasswd.xml mdns.xml ntp.xml pmwebapis.xml rpc-bind.xml telnet.xml wbem-https.xml
bacula.xml ftp.xml ipp-client.xml ldap.xml mountd.xml openvpn.xml pop3s.xml samba-client.xml tftp-client.xml
dhcp.xml high-availability.xml ipp.xml ldaps.xml ms-wbt.xml pmcd.xml postgresql.xml samba.xml tftp.xml
このファイルの内容が、VNC Serverに関するfirewallの設定になる。
[vagrant@localhost ~]$ sudo cat /usr/lib/firewalld/services/vnc-server.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>Virtual Network Computing Server (VNC)</short>
<description>A VNC server provides an external accessible X session. Enable this option if you plan to provide a VNC server with direct access. The access will be possible for displays :0 to :3. If you plan to provide access with SSH, do not open this option and use the via option of the VNC viewer.</description>
<port protocol="tcp" port="5900-5903"/>
</service>
VNC Clientからの接続
VNC Clientを起動して接続できることを確認する。