覚え書きなページ

VNCサーバを探す

まずはapt-getで簡単お手軽インストールできるVNCサーバを探してみる。aptでインストール出来るパッケージを探すのにはapt-cacheを使う。探すだけだから管理者権限は要らない。
pi@birth ~ $ apt-cache search vnc server
autocutsel - Keep the X clipboard and the cutbuffer in sync
avahi-ui-utils - Avahi GTK+ utilities
conspy - Remote control of Linux virtual consoles
directvnc - VNC client using the framebuffer as display
guacd - Guacamole proxy daemon
krdc - Remote Desktop Connection client
libvncserver-config - API to write one's own vnc server - library utility
libvncserver-dev - API to write one's own vnc server - development files
libvncserver0 - API to write one's own vnc server
libvncserver0-dbg - debugging symbols for libvncserver
linuxvnc - VNC server to allow remote access to a tty
ssvnc - Enhanced TightVNC viewer with SSL/SSH tunnel helper
tightvncserver - virtual network computing server software
vinagre - remote desktop client for the GNOME Desktop
vino - VNC server for GNOME
vncsnapshot - A utility that takes JPEG snapshots from VNC servers
x11vnc - VNC server to allow remote access to an existing X session
x2vnc - Link a VNC and an X display together, simulating a multiheaded display
xrdp - Remote Desktop Protocol (RDP) server
xtightvncviewer - virtual network computing client software for X
pi@birth ~ $ 
なにやらいっぱい出てきた。rdpなんかもvncで探すと出てくるんだ。'xrdp'もインストール可能らしい、これは次に試してみよう。ざっと見ると'tightvncserver'か'x11vnc'あたりは使ったことがある。'TightVNC'をSSL/SSH拡張するssvncなんてあるのも初めて知った。とりあえず、つなげればいいのでTightVNCを入れよう。

TightVNCインストールと設定

インストール

pi@birth ~ $ sudo apt-get install tightvncserver 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の特別パッケージがインストールされます:
  x11-xserver-utils xfonts-base
提案パッケージ:
  tightvnc-java nickle cairo-5c xorg-docs-core
以下のパッケージが新たにインストールされます:
  tightvncserver x11-xserver-utils xfonts-base
アップグレード: 0 個、新規インストール: 3 個、削除: 0 個、保留: 0 個。
7,148 kB のアーカイブを取得する必要があります。
この操作後に追加で 10.4 MB のディスク容量が消費されます。
続行しますか [Y/n]? 
取得:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main tightvncserver armhf 1.3.9-6.4 [786 kB]
取得:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main x11-xserver-utils armhf 7.7~3 [181 kB]
取得:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main xfonts-base all 1:1.0.3 [6,181 kB]
7,148 kB を 4秒 で取得しました (1,506 kB/s)
以前に未選択のパッケージ tightvncserver を選択しています。
(データベースを読み込んでいます ... 現在 69854 個のファイルとディレクトリがインストールされています。)
(.../tightvncserver_1.3.9-6.4_armhf.deb から) tightvncserver を展開しています...
以前に未選択のパッケージ x11-xserver-utils を選択しています。
(.../x11-xserver-utils_7.7~3_armhf.deb から) x11-xserver-utils を展開しています...
以前に未選択のパッケージ xfonts-base を選択しています。
(.../xfonts-base_1%3a1.0.3_all.deb から) xfonts-base を展開しています...
man-db のトリガを処理しています ...
menu のトリガを処理しています ...
fontconfig のトリガを処理しています ...
tightvncserver (1.3.9-6.4) を設定しています ...
update-alternatives: /usr/bin/vncserver (vncserver) を提供するために 自動モード で /usr/bin/tightvncserver を使います
update-alternatives: /usr/bin/Xvnc (Xvnc) を提供するために 自動モード で /usr/bin/Xtightvnc を使います
update-alternatives: /usr/bin/vncpasswd (vncpasswd) を提供するために 自動モード で /usr/bin/tightvncpasswd を使います
x11-xserver-utils (7.7~3) を設定しています ...
xfonts-base (1:1.0.3) を設定しています ...
menu のトリガを処理しています ...
pi@birth ~ $ 

設定

起動すると初回はパスワードの設定が必要。括弧内は勝手に翻訳。
pi@birth ~ $ tightvncserver 

You will require a password to access your desktops. (デスクトップにアクセスするのにパスワードが必要だよ!)

Password: 
Verify:   
Would you like to enter a view-only password (y/n)? n (見るだけのパスワードも設定するかい?)
xauth:  file /home/pi/.Xauthority does not exist (.Xauthorityファイルがないよ)

New 'X' desktop is birth:1 (birth:1が新しいデスクトップだよ)

Creating default startup script /home/pi/.vnc/xstartup 
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/birth:1.log

pi@birth ~ $ 
.Xauthorityは多分実際にX Window Systemを起動したことがあると生成されているのかなぁ。

起動確認

ちゃんと起動しているかを確認してみよう。
pi@birth ~ $ ps | grep vnc
 4835 pts/0    00:00:01 Xtightvnc
pi@birth ~ $ netstat -lnt
稼働中のインターネット接続 (サーバのみ)
Proto 受信-Q 送信-Q 内部アドレス            外部アドレス            状態       
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN     
pi@birth ~ $ 
うむ、psでXtightvncが起動しているのが確認できた。netstatの22はssh、5901がvnc、6001もvncが使用しているみたい。とにかく動き始めた。

VNCサーバの終了と再起動

終了は下記。'-kill'と':1'の間にはスペースが必要なので注意。
pi@birth ~ $ vncserver -kill :1
Killing Xtightvnc process ID 2583
再起動時はパスワードの設定は要らない。
pi@birth ~ $ tightvncserver 

New 'X' desktop is birth:1

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/birth:1.log

Macから接続

macからVNCサーバへは特にアプリを入れなくても簡単に接続が出来る。
Folderの「移動」▶︎「サーバへ接続...」を選択
「サーバアドレス:」に「接続先のアドレス:5901」を入力する。よく使うサーバに登録したい場合は右の[+]ボタンで登録出来る。接続ボタンを押すと接続される。
パスワードを入力して接続
接続完了

VNCサーバの自動起動

動作確認は終了したが、今はまだ手動でVNCサーバを起動する必要がある。つまり私の環境ではいちいちsshやシリアル通信でログインしてtightvncserverを起動しなくてはならない。しかもsshをログアウトするとそれも終了してしまう。それでは面倒臭い。そこでVNCサーバの起動スクリプトを用意する。
/etc/init.d/の下にvncbootというファイルを作り起動させたり終了させたりするスクリプトを書いておく。
pi@birth ~ $ sudo vi /etc/init.d/vncboot
vncbootの内容は下記の通り。
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
    start)
        echo "Starting VNC Server"
        #Insert your favoured settings for a VNC session
        su $USER -c '/usr/bin/vncserver :1 -geometry 1600x900 -depth 24'
        ;;

    stop)
        echo "Stopping VNC Server"
        su $USER -c '/usr/bin/vncserver -kill :1'
        ;;

    *)
        echo "Usage: /etc/init.d/vncboot {start|stop}"
        exit 1
        ;;
esac

exit 0
実行権限を付与して確認し、自動起動設定を更新する。括弧内は説明。
pi@birth ~ $ sudo chmod 755 /etc/init.d/vncboot (実行権限付与)
pi@birth ~ $ ls -l /etc/init.d/vncboot
-rwxr-xr-x 1 root root 761  4月 12 16:27 /etc/init.d/vncboot (確認)
pi@birth ~ $ sudo update-rc.d vncboot defaults (自動起動設定更新)
update-rc.d: using dependency based boot sequencing
pi@birth ~ $ 
再起動して自動起動を確認する。
pi@birth ~ $ ps -ef | grep tightvnc | grep -v grep
pi        2211     1  0 16:41 ?        00:00:01 Xtightvnc :1 -desktop X -auth /home/pi/.Xauthority -geometry 1600x900 -depth 24 -rfbwait 120000 -rfbauth /home/pi/.vnc/passwd -rfbport 5901 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
pi@birth ~ $ 

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

管理人/副管理人のみ編集できます