LoginSignup
16
13

More than 5 years have passed since last update.

RaspberryPiにx11vncを導入する手順

Last updated at Posted at 2017-09-18

目的

これまではTightVNC(tightvncserver)を使用していた。

しかし、opencv-pythonを使用して、
リアルタイムにカメラのプレビューを表示しようとしたら、
下記のエラーが発生してしまった。

GdkGLExt-WARNING **: Window system doesn't support OpenGL.

「TightVNCは起動中のデスクトップとは別のデスクトップを作成して接続するもの」という記述を見かけたので、そうではないx11vncをインストールしてみる。

インストール

$ sudo apt-get install x11vnc

接続した際に~/nohup.outの権限が無いとPermission Deniedエラーが発生する。
よって、権限を与えておく。

$ sudo chmod 666 ~/nohup.out

実行

まずは接続する際のパスワードを設定する。

$ x11vnc -storepasswd

大体の記事で起動時に-createオプションを付けずに実行していたが、
私の環境ではなぜか以下のエラーが出た。

$ x11vnc -usepw -forever
 .
 .
 .
18/09/2017 00:21:56 *** XOpenDisplay failed (:0)

*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.
*** There may be "Xlib:" error messages above with details about the failure.

Some tips and guidelines:

** An X server (the one you wish to view) must be running before x11vnc is
   started: x11vnc does not start the X server.  (however, see the -create
   option if that is what you really want).

** You must use -display <disp>, -OR- set and export your $DISPLAY
   environment variable to refer to the display of the desired X server.
 - Usually the display is simply ":0" (in fact x11vnc uses this if you forget
   to specify it), but in some multi-user situations it could be ":1", ":2",
   or even ":137".  Ask your administrator or a guru if you are having
   difficulty determining what your X DISPLAY is.

** Next, you need to have sufficient permissions (Xauthority) 
   to connect to the X DISPLAY.   Here are some Tips:

 - Often, you just need to run x11vnc as the user logged into the X session.
   So make sure to be that user when you type x11vnc.
 - Being root is usually not enough because the incorrect MIT-MAGIC-COOKIE
   file may be accessed.  The cookie file contains the secret key that
   allows x11vnc to connect to the desired X DISPLAY.
 - You can explicitly indicate which MIT-MAGIC-COOKIE file should be used
   by the -auth option, e.g.:
       x11vnc -auth /home/someuser/.Xauthority -display :0
       x11vnc -auth /tmp/.gdmzndVlR -display :0
   you must have read permission for the auth file.
   See also '-auth guess' and '-findauth' discussed below.

** If NO ONE is logged into an X session yet, but there is a greeter login
   program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
   to find and use the raw display manager MIT-MAGIC-COOKIE file.
   Some examples for various display managers:

-createオプションを付けることで治った。

x11vnc -usepw -forever -create
18/09/2017 10:07:21 -usepw: found /home/pi/.vnc/passwd
18/09/2017 10:07:21 x11vnc version: 0.9.13 lastmod: 2011-08-10  pid: 9992
18/09/2017 10:07:21 
18/09/2017 10:07:21 wait_for_client: WAIT:cmd=FINDCREATEDISPLAY-Xvfb
18/09/2017 10:07:21 
18/09/2017 10:07:21 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/2560
18/09/2017 10:07:21 
18/09/2017 10:07:21 Autoprobing TCP port 
18/09/2017 10:07:21 Autoprobing selected TCP port 5900
18/09/2017 10:07:21 Autoprobing TCP6 port 
18/09/2017 10:07:21 Autoprobing selected TCP6 port 5900
18/09/2017 10:07:21 listen6: bind: Address already in use
18/09/2017 10:07:21 Not listening on IPv6 interface.
18/09/2017 10:07:21 

The VNC desktop is:      raspberrypi:0
PORT=5900

ちなみに、

  • -usepwはパスワードを使用して接続するオプション
  • -foreverは最初に接続したユーザーが切断しても、x11vncが終了しないようにするオプション

自動起動設定

Raspberry Piを立ち上げるたびにx11vncを起動するのは面倒なので、
自動起動設定もしておく。

TightVNCの自動起動設定していたので削除。

$ rm ~/.config/autostart/tightvnc.desktop

x11vncの自動起動設定を追加。

$ sudo vi ~/.config/autostart/x11vnc.desktop
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=X11VNC
Comment=X11VNC
Exec=x11vnc -usepw -forever -create
StartupNortify=false
Terminal=false
Hidden=false

再起動する。

$ sudo reboot

接続確認

Raspberry Piを再起動してから起動完了するまでちょっとだけ時間を置いてから、
手元のMacで、Finder => 移動 => サーバへ接続と進み、

vnc://(Raspberry PiのIPアドレス):5900

と入力して接続ボタンを押す。

cli.png

む。。。なんか黒い。
あ、Raspberry Piの起動設定をCLIにしてたんだった。

$ sudo raspi-config

Boot Options => Desktop / CLI => Desktop Autologinを選択。
再起動を促してくるので、再起動する。

時間を置いてMacで接続し直すと・・・

desktop

この環境ではWindow system doesn't support OpenGL.も出なくなった。

preview

まとめ

  • 基本的にTightVNCよりもx11vncを使用した方が制約が少ない。
  • x11vncの起動時に-createオプションを付与しないとエラーが起こった。
  • Raspberry PiをDesktopモードで起動しないと、表示が崩れる。
16
13
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
16
13