以root用戶運行如下命令來安裝vncserver;spa
yum install tigervnc-server unix
一樣運行如下命令來安裝vncviewer;code
yum install vncserver
中止並禁用防火牆;ip
systemctl stop firewalld.serviceci
systemctl disable firewalld.serviceget
vncviewer基本上不用配置;it
vncserver的配置,建立一個新的配置文件,以開啓1號窗口爲例(也能夠同時開啓多個窗口,修改數字便可),方法以下:
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
或者再增長一個窗口:
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service
編輯/lib/systemd/system/vncserver@:1.service,設置用戶root相關參數,最終內容以下:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=
/bin/sh
-c
'/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=
/sbin/runuser
-l root -c
"/usr/bin/vncserver %i"
PIDFile=
/root/
.vnc/%H%i.pid
ExecStop=
/bin/sh
-c
'/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
|
上述內容中最好設置爲root用戶,不然可能會看到如下報錯:
vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (
/usr/lib/systemd/system/vncserver
@:1.service; enabled)
Active: failed (Result:
exit
-code) since Tue 2015-04-14 10:09:24 CST; 1min 36s ago
Process: 3258 ExecStart=
/sbin/runuser
-l sysadmin -c
/usr/bin/vncserver
%i (code=exited, status=1
/FAILURE
)
Process: 3254 ExecStartPre=
/bin/sh
-c
/usr/bin/vncserver
-
kill
%i >
/dev/null
2>&1 || : (code=exited, status=0
/SUCCESS
)
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Starting Remote desktop service (VNC)...
Apr 14 10:09:24 F1A-VMHOST-SWPE runuser[3258]: Password:
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: vncserver@:1.service: control process exited, code=exited status=1
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Failed to start Remote desktop service (VNC).
Apr 14 10:09:24 F1A-VMHOST-SWPE systemd[1]: Unit vncserver@:1.service entered failed state.
Warning: Unit
file
changed on disk,
'systemctl daemon-reload'
recommended.
|
更新systemctl以使其生效;
systemctl daemon-reload
設置vncserver的密碼;
vncpasswd root
按提示輸入密碼以及確認密碼
啓動該服務用來啓用vnc的1號窗口;
systemctl start vncserver@:1.service 或者 vncserver :1
關閉1號窗口:
systemctl stop vncserver@:1.service 或者 vncserver -kill :1
設置爲開機自動啓動;
systemctl enable vncserver@:1.service
End.