過去ページ vnc20241229

VNC(Virtual Network Computing)

RFB Protocol(remote framebuffer)を使ってリモート操作を可能にします.
vncサーバを立てて、vncクラアントで接続して画面を操作する形です.

運用方法はいろいろあるかと思いますが、systemdで管理せず、各自ユーザ側で管理する形を提示します

vncサーバは大抵 port番号 5900 を使い、複数vncサーバを立てると連続して 5901, 5902 とport番号を消費します。

管理運用を楽にしたいので、ユーザ毎に使っていいport番号を割り振って運用してみる.
port番号が分かれば画面にアクセスできることになるが、当然個別にvncサーバにアクセスする際にパスワードを設ける.

vncサーバをインストールします

ディストリビューションが提供するvncサーバの他に、turbovncとかもあります. こちらturbovncはVirtualGLで使ってます.
ここでは ディストリビューションが提供するvncサーバで構築します

[root@rockylinux8 ~]# dnf install tigervnc-server
 
(ポートを開けます)
[root@rockylinux8 ~]# firewall-cmd --add-service=vnc-server --zone=public --permanent
[root@rockylinux8 ~]# firewall-cmd --reload

firewall-cmdで読み込ませている「vnc-server」サービスの中身は「/usr/lib/firewalld/services/vnc-server.xml」でしが
こちらは 5900 から 5903 までの4つしか許可されてないです。もし増やすなら「--add-port=5904-5909/tcp」とかで増やします.

ユーザ権限で vncサーバを立ち上げる

まずはパスワードを定義します. 計算機にログインするためのパスワードではなくリモートから vncサーバ にアクセスする時に問われるパスワードです

[saber@rockylinux8 ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n     <-- 見るだけのパスワードは設けてないです
A view-only password is not used
[saber@rockylinux8 ~]$

次に vncサーバ を自分のアカウントで起動させます

[saber@rockylinux8 ~]$ vncserver :0
 
WARNING: vncserver has been replaced by a systemd unit and is now considered deprecated and removed in upstream.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.
 
Warning: rockylinux8:0 is taken because of /tmp/.X11-unix/X0
Remove this file if there is no X server rockylinux8:0
A VNC server is already running as :0
[saber@rockylinux8 ~]$

っとどうやら :0 つまりは 5900 はコンソールのXで使われているみたい. なので次の番号で

[saber@rockylinux8 ~]$ vncserver :1
 
WARNING: vncserver has been replaced by a systemd unit and is now considered deprecated and removed in upstream.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.
xauth:  file /home/saber/.Xauthority does not exist
 
New 'rockylinux8:1 (saber)' desktop is rockylinux8:1
 
Creating default startup script /home/saber/.vnc/xstartup
Creating default config /home/saber/.vnc/config
Starting applications specified in /home/saber/.vnc/xstartup
Log file is /home/saber/.vnc/rockylinux8:1.log
 
[saber@rockylinux8 ~]$

っと立ち上がったみたい.  このプロセスはずっとバックグラントで実行したままです。この後にログアウトしてもこのプロセスは残ります。

確認は「vncserver -list」か「lsof -i」で

[saber@rockylinux8 ~]$ vncserver -list
 
WARNING: vncserver has been replaced by a systemd unit and is now considered deprecated and removed in upstream.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.
 
TigerVNC server sessions:
 
X DISPLAY #     PROCESS ID
:1              1928
 
[saber@rockylinux8 ~]$ lsof -i
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
Xvnc      1928 saber    6u  IPv4  36762      0t0  TCP *:5901 (LISTEN)
Xvnc      1928 saber    7u  IPv6  36763      0t0  TCP *:5901 (LISTEN)
 :
[saber@rockylinux8 ~]$

WARNING: vncserver has been replaced by a systemd unit and is now considered deprecated and removed in upstream. Please read /usr/share/doc/tigervnc/HOWTO.md for more information.」と言われるが、
これは今後「vncserver :1」と使わずに systemd 経由で立ち上げてねというもの.

リモートのvncクライアントから起動したvncサーバにアクセスする

windows/macOSにnvcクライアントをインストールする.
TurboVNC (https://www.turbovnc.org/)、RealVNC (https://www.realvnc.com/en/connect/download/viewer/)、UltraVNC (https://github.com/ultravnc/UltraVNC) とかから選ぶ.
windowsならmobaXterm (https://mobaxterm.mobatek.net/ )でいいかも.

ここでは mobaXterm で接続してみます.
mobaXtermを起動させ、Sessionボタンを押下します。
Remote hostname or IP addressには対象のマシン名を入れて、portは「vncserver -list」「lsof -i」で調べた自分のport番号を入れます.
2024y12m29d_194204303.png

すると先ほどvncpasswdで設定したパスワードが求められ、ここにその値を入れてokボタンを押下します
2024y12m29d_194416989.png

パスワードが符合すれば画面が開きます
2024y12m29d_195015679.png

ここでこの画面の状態でmobaXtermを閉じて、その後再びmobaXtermで同じように vnc セッションを開くと先ほどの閉じる直前の画面から再スタートできます.

っで、ここで画面右上でログアウトを選択すると、「vncserver :1」として実行したプロセスも終了します。
ssh接続で「vncserver -list」としてもプロセスがないので何も表示されないです。

画面について、、GNOMEで使いずらい...GNOME Classicに変更したい.
環境変数で定義します
「$HOME/.bashrc」に「export GNOME_SHELL_SESSION_MODE=classic」を入れて、一旦ログアウト。そして再度ログインして「vncserver :1」を実行します
これでgnome-classicのディスクトップ環境になります
2024y12m29d_210011189.png

中座して入り直す

作業の途中で中座したい場合、mobaXterm自体を停止しても大丈夫です。
そして、再びアクセスすれば、作業中断前の画面に戻ります。

vncを停止するまで画面環境は継続されます。

停止

画面でログアウトすれば、「vncserver :1」のプロセスが停止して終了となります。「vncserver -list」にも残りません。

画面ではなくSSH接続画面で「vncserver :1」のプロセスを停止するには「vncserver -kill :1」とします

[saber@rockylinux8 ~]$ vncserver -kill :1
 
WARNING: vncserver has been replaced by a systemd unit and is now considered deprecated and removed in upstream.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.
Killing Xvnc process ID 4408
[saber@rockylinux8 ~]$

gdm/GNOMEを使わずに lightdm/Xfce でvncを使う

lightdm/Xfce の方が動作が軽い?数値結果は持ってないけど、一応取り換えてみる

[root@rockylinux8 ~]# systemctl disable gdm.service
[root@rockylinux8 ~]# dnf install epel-release -y
[root@rockylinux8 ~]# dnf --enablerepo=epel install lightdm -y
[root@rockylinux8 ~]# dnf groupinstall Xfce -y
[root@rockylinux8 ~]# reboot

っで

[saber@rockylinux8 ~]$ vi .vnc/config
geometry=1600x1200
 
[saber@rockylinux8 ~]$ cp .vnc/xstartup .vnc/xstartup.orig
[saber@rockylinux8 ~]$ vi .vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4
if [ -e /usr/bin/xfce4-session ]; then
    vncserver -kill $DISPLAY
fi
 
[saber@rockylinux8 ~]$

と設定を施して、vncserverを起動します

[saber@rockylinux8 ~]$ vncserver :1

これで vncクライアントで接続すると lightdm/xfce の画面が表示されます

2024y12m30d_005956696.png

vncserver を使わず systemd で行うには

前段は各ユーザ側で vncserver を使って画面番号と接続用portを作っていました。

こんどは systemd を使って強制的に ユーザA は 5901 、ユーザB は 5902 と決め打ちで使いたい場合のお話.

ディスプレイ番号ポート番号ユーザ備考
:05900 + 0 = 5900コンソールの画面に割り当てられるみたい
:15900 + 1 = 5901saber
:25900 + 2 = 5902illya

こんな感じで.

[root@rockylinux8 ~]# dnf install tigervnc-server
[root@rockylinux8 ~]# firewall-cmd --add-service=vnc-server --zone=public --permanent
[root@rockylinux8 ~]# firewall-cmd --reload
 
[root@rockylinux8 ~]# vi /etc/tigervnc/vncserver-config-defaults
session=gnome-classic      <-- ディスクトップ環境を「gnome-classic」にしてます
alwaysshared
securitytypes=vncauth,tlsvnc
desktop=sandbox
geometry=2000x1200
 
[root@rockylinux8 ~]# vi /etc/tigervnc/vncserver.users
:1=saber
:2=illya
 
[root@rockylinux8 ~]#

そしてvncserverのデーモンをディスプレイ番号毎に(:1, :2 とか)で起動するようにします.

[root@rockylinux8 ~]# systemctl enable vncserver@:1   <-- 再起動しても :1 はユーザsaberのものです
[root@rockylinux8 ~]# systemctl enable vncserver@:2   <-- 再起動しても :2 はユーザillyaのものです  

っで実際の起動ですが、各ユーザの $HOME/.vnc がないと起動しないようです.
なのでまずは各ユーザにvncpasswdでvncにアクセスする際のパスワードを定義頂くのが先. ログインパスワードではないです.

[saber@rockylinux8 ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
[saber@rockylinux8 ~]$

こうして

[root@rockylinux8 ~]# systemctl start vncserver@:1
[root@rockylinux8 ~]# systemctl start vncserver@:2

とします.
あとは、5901(saber向け)とか 5902(illya向け) にvncクライアントでアクセスします。

nvidiaカードで運用しているなら「/etc/gdm/custom.conf」の「daemon」欄で「WaylandEnable=false」を有効にします

[root@rockylinux8 ~]# vi /etc/gdm/custom.conf
[daemon]
WaylandEnable=false
[security]
[xdmcp]
[chooser]
[debug]
 
[root@rockylinux8 ~]#

ここで注意. vncクライアントの中でログアウトすると、vncserver@:x も停止します. なので再開には再度「systemctl start vncserver@:x」が必要となります.

vncserver を使わず systemd で行うには(lightdm/Xfceで使いたい)

[root@rockylinux8 ~]# systemctl disable gdm.service
[root@rockylinux8 ~]# dnf --enablerepo=epel install lightdm -y
[root@rockylinux8 ~]# dnf groupinstall Xfce -y
 
[root@rockylinux8 ~]# dnf install tigervnc-server -y
[root@rockylinux8 ~]# firewall-cmd --add-service=vnc-server --zone=public --permanent
[root@rockylinux8 ~]# firewall-cmd --reload
 
[root@rockylinux8 ~]# vi /etc/tigervnc/vncserver-config-defaults
session=xfce
alwaysshared
securitytypes=vncauth,tlsvnc
desktop=sandbox
geometry=2000x1200
 
[root@rockylinux8 ~]# vi /etc/tigervnc/vncserver.users
:1=saber
:2=illya
 
[root@rockylinux8 ~]# systemctl enable  vncserver@:1  vncserver@:2
[saber@rockylinux8 ~]$ vncpasswd
[root@rockylinux8 ~]# reboot
最新の60件
2025-03-23 2025-03-22 2025-03-20 2025-03-17 2025-03-16 2025-03-15 2025-03-10 2025-03-08 2025-03-06 2025-03-03 2025-03-02 2025-03-01 2025-02-23 2025-02-18 2025-02-17 2025-02-14 2025-02-12 2025-02-03 2025-02-02 2025-01-27 2025-01-26 2025-01-25 2025-01-24 2025-01-23 2025-01-20 2025-01-13 2025-01-12 2025-01-08 2024-12-30
  • vnc
2024-12-29 2024-12-22 2024-12-20 2024-12-17 2024-12-15 2024-12-14 2024-12-12 2024-12-11 2024-12-10 2024-12-09 2024-11-28 2024-11-22 2024-11-15 2024-11-14 2024-11-12 2024-11-06 2024-11-05

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-12-30 (月) 19:59:18