使用vnc远程操控Centos7.6

安装vncserver

[root@elegant-snap-3 ~]# yum install tigervnc-server -y
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.fileplanet.com
 * elrepo-kernel: repos.lax-noc.com
 * extras: mirror.hostduplex.com
 * updates: mirror.hostduplex.com

(many more lines supressed)

Installed:
  tigervnc-server.x86_64 0:1.8.0-13.el7                                                                                                                                                                                 

Dependency Installed:
  libICE.x86_64 0:1.0.9-9.el7          libSM.x86_64 0:1.2.2-2.el7                 libX11.x86_64 0:1.6.5-2.el7                    libX11-common.noarch 0:1.6.5-2.el7       libXau.x86_64 0:1.0.8-2.1.el7                
  libXcursor.x86_64 0:1.1.15-1.el7     libXdamage.x86_64 0:1.1.4-4.1.el7          libXdmcp.x86_64 0:1.1.2-6.el7                  libXext.x86_64 0:1.3.3-3.el7             libXfixes.x86_64 0:5.0.3-1.el7               
  libXfont2.x86_64 0:2.0.3-1.el7       libXi.x86_64 0:1.7.9-1.el7                 libXinerama.x86_64 0:1.1.3-2.1.el7             libXmu.x86_64 0:1.1.2-2.el7              libXrandr.x86_64 0:1.5.1-2.el7               
  libXrender.x86_64 0:0.9.10-1.el7     libXt.x86_64 0:1.1.5-3.el7                 libXtst.x86_64 0:1.2.3-1.el7                   libXxf86misc.x86_64 0:1.0.3-7.1.el7      libXxf86vm.x86_64 0:1.1.4-1.el7              
  libfontenc.x86_64 0:1.1.3-3.el7      libglvnd.x86_64 1:1.0.1-0.8.git5baa1e5.el7 libglvnd-glx.x86_64 1:1.0.1-0.8.git5baa1e5.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7      libxcb.x86_64 0:1.13-1.el7                   
  libxkbfile.x86_64 0:1.0.9-3.el7      libxshmfence.x86_64 0:1.2-1.el7            llvm-private.x86_64 0:6.0.1-2.el7              mesa-dri-drivers.x86_64 0:18.0.5-4.el7_6 mesa-filesystem.x86_64 0:18.0.5-4.el7_6      
  mesa-libGL.x86_64 0:18.0.5-4.el7_6   mesa-libglapi.x86_64 0:18.0.5-4.el7_6      pixman.x86_64 0:0.34.0-1.el7                   tigervnc-license.noarch 0:1.8.0-13.el7   tigervnc-server-minimal.x86_64 0:1.8.0-13.el7
  xkeyboard-config.noarch 0:2.24-1.el7 xorg-x11-server-utils.x86_64 0:7.7-20.el7  xorg-x11-xauth.x86_64 1:1.0.9-1.el7            xorg-x11-xinit.x86_64 0:1.3.4-2.el7      xorg-x11-xkb-utils.x86_64 0:7.7-14.el7       

Complete!
[root@elegant-snap-3 ~]# 

yum groupinstall "GNOME Desktop"来安装xwindow,然后复制配置文件并修改为你的用户名,生效配置,配置白名单,切换到目标用户vncpasswd设置密码

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

                                                                                                                                    
[root@23 ~]# cat /etc/systemd/system/vncserver@:1.service|grep -v ^#|grep -v ^$
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l king -c "/usr/bin/vncserver %i"
PIDFile=/home/king/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
[root@23 ~]# systemctl daemon-reload
[root@23 ~]# systemctl start vncserver@:1
Failed to execute operation: File exists
[root@23 ~]# systemctl status vncserver@:1
● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-08-27 14:55:18 CST; 1h 55min ago
 Main PID: 1557 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
           ‣ 1557 /usr/bin/Xvnc :1 -auth /home/king/.Xauthority -desktop localhost.localdomain:1 (king) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /home/king/.vnc/passwd -rfbport 5901 -rfbwa...

Aug 27 14:55:15 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...
Aug 27 14:55:18 23.106.151.61.16clouds.com systemd[1]: Started Remote desktop service (VNC).
[root@23 ~]# netstat -antpul
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2103/mysqld         
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      1557/Xvnc           
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1436/nginx: master  
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      1557/Xvnc           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2153/dnsmasq        
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1322/pure-ftpd (SER 
tcp        0      0 0.0.0.0:29045           0.0.0.0:*               LISTEN      1260/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1243/cupsd          
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      1368/python         
tcp        0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      1436/nginx: master  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1963/master         
tcp        0      0 23.106.151.61:5901      61.133.171.204:17218    ESTABLISHED 1557/Xvnc           
tcp        0    336 23.106.151.61:29045     61.133.171.204:17013    ESTABLISHED 4790/sshd: root@pts 
tcp        0      0 23.106.151.61:29045     61.133.171.204:17123    ESTABLISHED 3140/sshd: root@pts 
tcp6       0      0 :::5901                 :::*                    LISTEN      1557/Xvnc           
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::6001                 :::*                    LISTEN      1557/Xvnc           
tcp6       0      0 :::21                   :::*                    LISTEN      1322/pure-ftpd (SER 
tcp6       0      0 :::29045                :::*                    LISTEN      1260/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1243/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1963/master         
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           701/avahi-daemon: r 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           746/chronyd         
udp        0      0 0.0.0.0:52705           0.0.0.0:*                           701/avahi-daemon: r 
udp        0      0 0.0.0.0:875             0.0.0.0:*                           703/rpcbind         
udp        0      0 192.168.122.1:53        0.0.0.0:*                           2153/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           2153/dnsmasq        
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1017/dhclient       
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd           
udp6       0      0 ::1:323                 :::*                                746/chronyd         
udp6       0      0 :::875                  :::*                                703/rpcbind         
udp6       0      0 :::111                  :::*                                1/systemd           
[root@23 ~]# firewall-cmd --add-port=5901/tcp --permanent 
success
[root@23 ~]# firewall-cmd --reload
success
[root@23 ~]# su - king
Last login: Tue Aug 27 11:38:03 CST 2019 on pts/0
[king@23 ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
[king@23 ~]$ 

可以在本机上安装客户端连接了

imageimage

好了,实际生产中,也是vnc使用较多



如何卸载,直接yum remove然后删除相关配置文件和目录即可

[root@23 ~]# yum -y remove tigervnc-server
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package tigervnc-server.x86_64 0:1.8.0-13.el7 will be erased
--> Finished Dependency Resolution
base/7/x86_64                                                                                                                                                                                    | 3.6 kB  00:00:00     
elrepo-kernel                                                                                                                                                                                    | 2.9 kB  00:00:00     
extras/7/x86_64                                                                                                                                                                                  | 3.4 kB  00:00:00     
updates/7/x86_64                                                                                                                                                                                 | 3.4 kB  00:00:00     

Dependencies Resolved

========================================================================================================================================================================================================================
 Package                                                  Arch                                            Version                                                  Repository                                      Size
========================================================================================================================================================================================================================
Removing:
 tigervnc-server                                          x86_64                                          1.8.0-13.el7                                             @base                                          509 k

Transaction Summary
========================================================================================================================================================================================================================
Remove  1 Package

Installed size: 509 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : tigervnc-server-1.8.0-13.el7.x86_64                                                                                                                                                                  1/1 
  Verifying  : tigervnc-server-1.8.0-13.el7.x86_64                                                                                                                                                                  1/1 

Removed:
  tigervnc-server.x86_64 0:1.8.0-13.el7                                                                                                                                                                                 

Complete!
[root@23 ~]# rm /etc/systemd/system/vncserver@:1.service
rm: remove regular file ‘/etc/systemd/system/vncserver@:1.service’? y
[root@23 ~]# rm -rf /home/king/.vnc
[root@23 ~]# 
posted @ 2019-08-27 16:58  九命猫幺  阅读(544)  评论(0编辑  收藏  举报