CentOS 7.5 安裝配置tigervnc-server


系統版本:

[root@s10 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

1.安裝 Gnome 包

[root@s10 ~]# yum groupinstall "GNOME Desktop" "Graphical Administration Tools" -y

2.更新系統的運行級別 (此步驟不是必須)
自動進入圖形界面,那么我們需要更改系統的運行級別,輸入下面的命令來啟用圖形界面。

[root@s10 ~]# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

3.安裝vnc軟件包

[root@s10 ~]# yum -y install tigervnc-server 
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.cn99.com
http://mirrors.163.com/centos/7.5.1804/virt/x86_64/libvirt-latest/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
正在嘗試其它鏡像。
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

正在解決依賴關系
--> 正在檢查事務
---> 軟件包 tigervnc-server.x86_64.0.1.8.0-13.el7 將被 安裝
--> 解決依賴關系完成

依賴關系解決

=============================================================================================================================================================================================
 Package                                            架構                                      版本                                             源                                       大小
=============================================================================================================================================================================================
正在安裝:
 tigervnc-server                                    x86_64                                    1.8.0-13.el7                                     base                                    215 k

事務概要
=============================================================================================================================================================================================
安裝  1 軟件包

總下載量:215 k
安裝大小:509 k
Downloading packages:
tigervnc-server-1.8.0-13.el7.x FAILED                                          
http://mirrors.cqu.edu.cn/CentOS/7.6.1810/os/x86_64/Packages/tigervnc-server-1.8.0-13.el7.x86_64.rpm: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"/s |    0 B  --:--:-- ETA 
正在嘗試其它鏡像。
tigervnc-server-1.8.0-13.el7.x86_64.rpm                                                                                                                               | 215 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : tigervnc-server-1.8.0-13.el7.x86_64                                                                                                                                      1/1 
  驗證中      : tigervnc-server-1.8.0-13.el7.x86_64                                                                                                                                      1/1 

已安裝:
  tigervnc-server.x86_64 0:1.8.0-13.el7                                                                                                                                                      

完畢!

4.關閉防火牆

[root@s10 ~]# systemctl stop firewalld
[root@s10 ~]# systemctl disable firewalld

5.復制配置文件

[root@s10 ~]# cp /lib/systemd/system/vncserver@.service  /etc/systemd/system/vncserver@:1.service

6.修改配置文件

[root@s10 ~]# vim /etc/systemd/system/vncserver@\:1.service 

  1 # The vncserver service unit file
  2 #
  3 # Quick HowTo:
  4 # 1. Copy this file to /etc/systemd/system/vncserver@.service
  5 # 2. Replace <USER> with the actual user name and edit vncserver
  6 #    parameters appropriately
  7 #    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
  1 # The vncserver service unit file
  2 #
  3 # Quick HowTo:
  4 # 1. Copy this file to /etc/systemd/system/vncserver@.service
  5 # 2. Replace <USER> with the actual user name and edit vncserver
  6 #    parameters appropriately
  7 #    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
  1 # The vncserver service unit file
  2 #
  3 # Quick HowTo:
  4 # 1. Copy this file to /etc/systemd/system/vncserver@.service
  5 # 2. Replace <USER> with the actual user name and edit vncserver
  6 #    parameters appropriately
  7 #    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
  8 #     PIDFile=/home/<USER>/.vnc/%H%i.pid)
  9 # 3. Run `systemctl daemon-reload`
 10 # 4. Run `systemctl enable vncserver@:<display>.service`
 11 #
 12 # DO NOT RUN THIS SERVICE if your local area network is
 13 # untrusted!  For a secure way of using VNC, you should
 14 # limit connections to the local host and then tunnel from
 15 # the machine you want to view VNC on (host A) to the machine
 16 # whose VNC output you want to view (host B)
 17 #
 18 # [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
 19 #
 20 # this will open a connection on port 590N of your hostA to hostB's port 590M
 21 # (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
 22 # See the ssh man page for details on port forwarding)
 23 #
 24 # You can then point a VNC client on hostA at vncdisplay N of localhost and with
 25 # the help of ssh, you end up seeing what hostB makes available on port 590M
 26 #
 27 # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
 28 #
 29 # Use "-localhost" to prevent remote VNC clients connecting except when
 30 # doing so through a secure tunnel.  See the "-via" option in the
 31 # `man vncviewer' manual page.
 32 
 33 
 34 [Unit]
 35 Description=Remote desktop service (VNC)
 36 After=syslog.target network.target
 37 
 38 [Service]
 39 Type=forking
 40 
 41 # Clean any existing files in /tmp/.X11-unix environment
 42 ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
 43 ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
 44 PIDFile=/home/<USER>/.vnc/%H%i.pid
 45 ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
 46 
 47 [Install]
 48 WantedBy=multi-user.target

將第43、44行中的<USER>修改為root或者你想通過vnc登錄的賬號,如tom 或jerry 如下所示:

43 ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
44 PIDFile=/root/.vnc/%H%i.pid

7.重新加載systemd服務

[root@s10 ~]# systemctl daemon-reload

8.設置VNC密碼

[root@s10 ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:

9.啟動VNC服務

[root@s10 ~]# systemctl start  vncserver@:1.service
[root@s10 ~]# systemctl enable  vncserver@:1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.
[root@s10 ~]# systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2019-04-02 15:02:08 CST; 7s ago
  Process: 29678 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
  Process: 29675 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
 Main PID: 29705 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
           ‣ 29705 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop s10.sangame.com:1 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /root/.vnc/passwd -rfbport...

4月 02 15:02:04 s10.sangame.com systemd[1]: Starting Remote desktop service (VNC)...
4月 02 15:02:08 s10.sangame.com systemd[1]: Started Remote desktop service (VNC).

查看VNC服務端口啟動狀態:

[root@s10 ~]# netstat  -tunpl |grep  :590
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      4334/qemu-kvm       
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      29705/Xvnc          
tcp        0      0 0.0.0.0:5903            0.0.0.0:*               LISTEN      5876/qemu-kvm       
tcp        0      0 0.0.0.0:5904            0.0.0.0:*               LISTEN      5644/qemu-kvm       
tcp        0      0 0.0.0.0:5905            0.0.0.0:*               LISTEN      5710/qemu-kvm       
tcp6       0      0 :::5901                 :::*                    LISTEN      29705/Xvnc          

10.測試連接

  

點擊連接並輸入密碼:

  

如下所示:

  

一切看上去都沒有問題。接下來可以體驗一下VNC服務。  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM