Linux ❀ 配置使用VNC Viewer访问Linux系统的图形化界面

Posted 国家级干饭型选手°

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux ❀ 配置使用VNC Viewer访问Linux系统的图形化界面相关的知识,希望对你有一定的参考价值。

1、安装RPM包


需要实现准备好一台Linux系统,并安装图形化界面;

#先备份掉centos自带的yum源配置文件
[root@localhost ~]# mkdir /etc/yum.repos.d/back/
[root@localhost ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
#配置本地yum源文件
[root@localhost ~]# cat /etc/yum.repos.d/base.repo
[base]
name=base
baseurl=file:///mnt
gpgcheck=0
enable=1
#挂载对应的镜像或光盘
[root@localhost ~]# mount /dev/sr0 /mnt
#清理并本地缓存yum源
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
#安装VMC RPM服务包
[root@localhost ~]# yum -y install tigervnc tigervnc-server

2、创建VNC连接密码


[root@localhost yum.repos.d]# vncserver

You will require a password to access your desktops.

Password:[此处配置登录密码]
Verify:[此处确认配置的密码]

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

3、修改配置文件


[root@localhost ~]# cat /root/.vnc/xstartup
#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop"&
gnome-session &
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; then
    vncserver -kill $DISPLAY
fi

4、开启VNC服务


[root@localhost ~]# vncserver :1
A VNC server is already running as :1
#查看对应的服务端口
[root@localhost ~]# netstat -tulp | grep 590*
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      5440/Xvnc
tcp6       0      0 [::]:5901               [::]:*                  LISTEN      5440/Xvnc

5、防火墙配置


[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

#firewalld放通策略
[root@localhost ~]# firewall-cmd --permanent --add-port=5901/tcp
success
[root@localhost ~]# firewall-cmd --reload
success

#iptables防火墙放通策略
[root@localhost ~]# iptables -A INPUT -p tcp --dport 5900 -j ACCEPT

6、VNC连接图形化界面


登录密码为第二节设置的密码,无用户名,直接可以登录即可完成操作。
VNC Viewer下载地址:https://www.realvnc.com/en/connect/download/viewer/

7、查看VNC登录日志


[root@localhost ~]# cat ./.vnc/localhost.localdomain\\:1.log

Xvnc TigerVNC 1.3.1 - built Nov 16 2016 13:38:44
Copyright (C) 1999-2011 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 11702000, The X.Org Foundation


Mon Sep 27 20:46:37 2021
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5901
 vncext:      created VNC server for screen 0
gnome-session-is-accelerated: llvmpipe detected.

Mon Sep 27 20:53:28 2021
 Connections: accepted: 192.168.11.1::62957
 SConnection: Client needs protocol version 3.8
 SConnection: Client requests security type VncAuth(2)

Mon Sep 27 20:53:32 2021
 VNCSConnST:  Server default pixel format depth 24 (32bpp) little-endian rgb888
 VNCSConnST:  Client pixel format depth 6 (8bpp) rgb222

Mon Sep 27 20:53:33 2021
 VNCSConnST:  Client pixel format depth 24 (32bpp) little-endian rgb888

Mon Sep 27 20:57:20 2021
 Connections: closed: 192.168.11.1::62957 (Clean disconnection)
 SMsgWriter:  framebuffer updates 60
 SMsgWriter:    raw rects 1, bytes 16396
 SMsgWriter:    hextile rects 41, bytes 2211277
 SMsgWriter:    ZRLE rects 6, bytes 247006
 SMsgWriter:    raw bytes equivalent 14901944, compression ratio 6.021768

Mon Sep 27 21:07:31 2021
 Connections: accepted: 192.168.11.1::63841
 SConnection: Client needs protocol version 3.8
 SConnection: Client requests security type VncAuth(2)

Mon Sep 27 21:07:52 2021
 VNCSConnST:  Server default pixel format depth 24 (32bpp) little-endian rgb888

Mon Sep 27 21:07:53 2021
 VNCSConnST:  Client pixel format depth 6 (8bpp) rgb222
 VNCSConnST:  Client pixel format depth 24 (32bpp) little-endian rgb888

Mon Sep 27 21:07:57 2021
 Connections: closed: 192.168.11.1::63841 (Clean disconnection)
 SMsgWriter:  framebuffer updates 5
 SMsgWriter:    raw rects 1, bytes 16396
 SMsgWriter:    ZRLE rects 5, bytes 21316
 SMsgWriter:    raw bytes equivalent 7094560, compression ratio 188.124735

以上是关于Linux ❀ 配置使用VNC Viewer访问Linux系统的图形化界面的主要内容,如果未能解决你的问题,请参考以下文章

VNC Viewer

Vnc viewer Linux远程连接

Linux Mint:VNC Server配置

Linux centos 安装VNC 服务过程

vnc viewer使用方法,8步详解vnc viewer使用方法

vnc viewer 远程桌面,11步实现vnc viewer 远程桌面连接Linux