測試環境為 CentOS 7 Minimal Install.測試環境建議可以先關閉 firewall 與 selinux http://benjr.tw/95368
先來討論一下 Minimal Install 可以使用 VNC 嗎?
我們得先了解 X-Window 的運作方式, X Server 負責顯示介面與繪圖,並將使用者的輸入行為告知 X Client,而 X client application 則是負責產生繪圖的數據並回傳給 X Server,通常我們的 dispaly server 和 client application 都是在同一台電腦上面.
所以第一步還是要先幫 CentOS 安裝 GNOME 桌面系統 (GNOME Desktop),不可能一個一個套件安裝,可以直接透過 group install 即可.關於 group install 可以參考 http://benjr.tw/96155
[root@localhost ~]# yum groups install "GNOME Desktop" Loaded plugins: fastestmirror There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: centos.cs.nctu.edu.tw * extras: centos.cs.nctu.edu.tw * updates: centos.cs.nctu.edu.tw Resolving Dependencies --> Running transaction check ---> Package ModemManager.x86_64 0:1.1.0-8.git20130913.el7 will be installed --> Processing Dependency: ModemManager-glib(x86-64) = 1.1.0-8.git20130913.el7 for package: ModemManager-1.1.0- .... [root@localhost ~]# reboot
再來安裝 CentOS 7 所使用的 TigerVNC.這跟之前使用的 VNC http://benjr.tw/715 不太一樣.
[root@localhost ~]# yum install tigervnc-server
接下來啟動 vncserver 即可.
[root@localhost ~]# vncserver You will require a password to access your desktops. Password: Verify: xauth: file /root/.Xauthority does not exist New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1 Creating default startup script /root/.vnc/xstartup Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/localhost.localdomain:1.log
localhost.localdomain:1 (root) 的意思是說,啟動一個 VNC 在 port 5900+1 即 5901 , vncviewer 可以透過這個埠連線,使用者為 root.
我們可以透過 netstat 來確認一下.
[root@localhost ~]# yum install net-tools [root@localhost ~]# netstat -tlnp |grep -i 59 tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 10136/Xvnc tcp6 0 0 :::5901 :::* LISTEN 10136/Xvnc
的確在 0.0.0.0:5901 已經開啟 VNC ,這時候就可以透過 vncviewer 去與遠端連線了.VNC 連線後等左上方的顯示訊息跑完就可以看到遠端桌面.
如果要讓 VNC 在開機的時候就啟動可以透過
- Copy this file to /etc/systemd/system/vncserver@.service
- Edit
and vncserver parameters appropriately (“runuser -l -c /usr/bin/vncserver %i -arg1 -arg2″) - Run `systemctl daemon-reload`
- Run `systemctl enable vncserver@:
.service`
如果只是想要單純把 Linux X-window 的程式執行畫面傳過來,其實透過 SSH + X11 forwarding – http://benjr.tw/3285 就可以了.