2012年8月10日金曜日

CentOS 6.3 (x86_64) に TigerVNC Server をインストールする手順

CentOS 6.3 (x86_64) に TigerVNC Server をインストールしたときの手順を記録のためにここに記す。

参考: 2009年09月19日 vncサーバー構築(CentOS5)

  1. TigerVNCServer をインストール
    yum -y install vnc-server
  2. 「/etc/sysconfig/vncservers」(VNC 用設定ファイルのうちの一つ) をバックアップ
    cp /etc/sysconfig/vncservers /etc/sysconfig/vncservers.bak
  3. 「/etc/sysconfig/vncservers」を vi で編集する。
    # VNCSERVERS="2:myusername"
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"


    VNCSERVERS="3:hachitaro"
    VNCSERVERARGS[3]="-geometry 1024x768 -nolisten tcp"
  4. VNC Viewer で VNC 接続するユーザーのパスワードをセットする。

    su コマンドを実行して、hachitaro ユーザーに切り替える。

    [root@pc101 ~]# su - hachitaro
    [hachitaro@pc101 ~]$
  5. VNC Viewer で VNC 接続するユーザーのパスワードをセットする。

    su コマンドを実行して、hachitaro ユーザーに切り替える。

    [hachitaro@pc101 ~]$ vncpasswd
    Password:
    Verify:
    [hachitaro@pc101 ~]$

    exit コマンドを実行して、元のユーザーに戻る。

    [hachitaro@pc101 ~]$ exit
    logout
    [root@pc101 ~]#
  6. いったん、vncserver サービスを起動して、その後 stop する。

    vncserver サービスを起動する。

    [root@pc101 ~]# service vncserver start
    VNC サーバー を起動中: 3:hachitaro xauth: creating new authority file /home/hachitaro/.Xauthority
    xauth: (stdin):1: bad display name "pc101:3" in "add" command

    New 'pc101:3 (hachitaro)' desktop is pc101:3

    Creating default startup script /home/hachitaro/.vnc/xstartup
    Starting applications specified in /home/hachitaro/.vnc/xstartup
    Log file is /home/hachitaro/.vnc/pc101:3.log

    [ OK ]
    [root@pc101 ~]#

    vncserver サービスを stop する。

    [root@pc101 ~]# service vncserver stop
    VNC サーバー を停止中: 3:hachitaro [ OK ]
    [root@pc101 ~]#
  7. VNC利用ユーザーの、「xstartup」ファイルを編集する。
    vi /home/hachitaro/.vnc/xstartup

    「/home/hachitaro/.vnc/xstartup」のファイル内容 (変更前)

    #!/bin/sh

    [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
    export LANG
    export SYSFONT
    vncconfig -iconic &
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    OS=`uname -s`
    if [ $OS = 'Linux' ]; then
    case "$WINDOWMANAGER" in
    *gnome*)
    if [ -e /etc/SuSE-release ]; then
    PATH=$PATH:/opt/gnome/bin
    export PATH
    fi
    ;;
    esac
    fi
    if [ -x /etc/X11/xinit/xinitrc ]; then
    exec /etc/X11/xinit/xinitrc
    fi
    if [ -f /etc/X11/xinit/xinitrc ]; then
    exec sh /etc/X11/xinit/xinitrc
    fi
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    twm &

    「/home/hachitaro/.vnc/xstartup」のファイルの一番下の2行を変更して、ファイルを保存する。

    「/home/hachitaro/.vnc/xstartup」のファイル内容 (変更後)

    #!/bin/sh

    [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
    export LANG
    export SYSFONT
    vncconfig -iconic &
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    OS=`uname -s`
    if [ $OS = 'Linux' ]; then
    case "$WINDOWMANAGER" in
    *gnome*)
    if [ -e /etc/SuSE-release ]; then
    PATH=$PATH:/opt/gnome/bin
    export PATH
    fi
    ;;
    esac
    fi
    if [ -x /etc/X11/xinit/xinitrc ]; then
    exec /etc/X11/xinit/xinitrc
    fi
    if [ -f /etc/X11/xinit/xinitrc ]; then
    exec sh /etc/X11/xinit/xinitrc
    fi
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    # xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    gnome-session &
  8. vncserver サービスを起動する。

    vncserver サービスを起動する。

    [root@pc101 ~]# service vncserver start
    VNC サーバー を起動中: 3:hachitaro xauth: (stdin):1: bad display name "pc101:3" in "add" command

    New 'pc101:3 (hachitaro)' desktop is pc101:3

    Starting applications specified in /home/hachitaro/.vnc/xstartup
    Log file is /home/hachitaro/.vnc/pc101:3.log

    [ OK ]
    [root@pc101 ~]#
  9. iptables の設定を変更 (VNC Server の利用する 5900-5910 のポートを開ける)
    [root@pc101 ~]# vi /etc/sysconfig/iptables
  10. 「/etc/sysconfig/iptables」の、「COMMIT」よりも上の場所に、以下の内容を追加する。追加した後はファイルを保存する。
    -A INPUT -p tcp -m tcp --dport 5900:5910 -j ACCEPT

    (変更前の例)

    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT

    (変更後の例)

    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m tcp --dport 5900:5910 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
  11. 「/etc/sysconfig/iptables」に加えた変更を有効にするために、iptables サービスを再起動する。
    [root@pc101 ~]# service iptables restart
    iptables: ファイアウォールルールを消去中: [ OK ]
    iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
    iptables: モジュールを取り外し中: [ OK ]
    iptables: ファイアウォールルールを適用中: [ OK ]
    [root@pc101 ~]#
  12. VNC Viewer (RealVNC など) で、VNC Server へ接続する。
    設定項目名称設定値備考
    IPアドレスとポート番号192.168.1.101::5903VNC Viewer の種類によっては「IPアドレス::ポート番号」「IPアドレス:ポート番号」など記述の方法が異なる場合がある。つながらない場合は記述を変更して試してみる。
    ユーザー名hachitaroVNC Viewer の種類によっては指定が不要な場合がある
    パスワード(上の vncpasswd でセットしたパスワードを入力する)