欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

使用vnc远程操控Centos7.6

程序员文章站 2022-10-25 23:46:22
安装vncserver[root@elegant-snap-3 ~]# yum install tigervnc-server -yLoaded plugins: fastestmirrorDetermining fastest mirrors * base: mirror.fileplanet.c... ......

安装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 ~]$ 

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

使用vnc远程操控Centos7.6使用vnc远程操控Centos7.6

好了,实际生产中,也是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 ~]#