VNC(虚拟网络计算)使我们能够通过安全网络访问远程系统的 GUI。
安装在本地系统上的 VNC 客户端捕获鼠标和键盘的输入事件并将它们传输到远程 VNC 服务器。
这些事件在远程系统上执行,并将输出发送回客户端。
VNC是一个桌面共享工具,一般用于访问桌面系统进行远程管理和技术支持。
要运行 VNC,我们需要两个组件:
- VNC 服务器
- VNC 查看器
安装所需的包
- 检查服务器是否连接到公共/私有 Yum Repo 以避免依赖问题。
# yum repolist
- 要使 VNC 有用,还需要安装 X Windows 系统和窗口管理器。
# yum install xorg-x11-apps
- 如果尚未安装图形桌面环境,请使用以下命令进行安装。
推荐:
# yum groupinstall Desktop "Desktop Platform" "X Window System" "Internet Browser" "Graphical Administration Tools" Fonts
最小安装包:
# yum groupinstall Desktop "X Window System" Fonts
- 安装 vnc 服务器 RPM:
# yum install vnc*
这将安装最新版本的 RPM:tigervnc-server-module、tigervnc 和tigervnc-server。
从 VNC 客户端连接 VNC 服务器
我们可以在客户端计算机上安装任何 VNC 查看器软件以访问 VNC 服务器。
我在我的 MAC 上使用 realVNC 软件来访问 VNC 服务器。
我们可以根据我们使用的操作系统使用以下任何 VNC 查看器软件。
- TigerVNC : http://tigervnc.org
- TightVNC : https://www.tightvnc.com/download.php
- RealVNC : https://www.realvnc.com/en/connect/download/viewer
要使用 root 用户连接 VNC 服务器,请使用显示 (:1)。
这与我们使用“vncserver”命令启动 VNC 服务器时为 root 用户获得的显示相同。
我们可能会收到如下所示的警告,它告诉我们我们与 VNC 服务器的连接不安全。
继续到下一个屏幕并输入我们使用“vncpasswd”命令为 root 用户设置的密码。
现在我们已连接到 VNC 服务器。
配置 VNC 服务器
- 编辑“/etc/sysconfig/vncservers”文件以配置所需的显示。
以下条目为显示编号“:2”和“:3”启用 VNC。
请注意,在一行中定义了多个“display:user”对,但每个显示的参数是单独定义的。
# vim /etc/sysconfig/vncservers VNCSERVERS="2:root 3:user" VNCSERVERARGS[2]="-geometry 1280x1024 -nolisten tcp -localhost" VNCSERVERARGS[3]="-geometry 1280x1024"
第一行定义了允许登录系统的用户。
第二行列出了服务启动时传递给 VNC 服务器的参数。
以下是 VNC 服务器中一些最常用的参数。
参数 | 描述 |
---|---|
-geometry | 定义clinet连接时查看器的大小 |
-nolisten tcp | 定义到 VNC 服务器的 TCP 连接 |
-nohttpd | 拒绝 Web VNC 客户端连接 |
-localhost | 强制使用安全网关(端口转发) |
- 为“/etc/sysconfig/vncservers”文件中定义的所有用户设置VNC 密码。
确保为配置文件 /etc/sysconfig/vncservers 中定义的所有用户设置密码。
# su - user ### it is important to switch the user for which password needs to be set $ vncpasswd Password: Verify:
# vncpasswd root Password: Verify:
- 启用自动启动的“vncserver”服务并启动该服务:
# chkconfig vncserver on
# service vncserver start Starting VNC server: 2:root New 'geek.mylabserver.com:2 (root)' desktop is geek.mylabserver.com:2 Creating default startup script /root/.vnc/xstartup Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/geek.mylabserver.com:2.log 3:user New 'geek.mylabserver.com:3 (user)' desktop is geek.mylabserver.com:3 Creating default startup script /home/user/.vnc/xstartup Starting applications specified in /home/user/.vnc/xstartup Log file is /home/user/.vnc/geek.mylabserver.com:3.log [ OK ]
- 运行“vncserver”命令启动或者停止vncserver。
默认情况下,触发“vncserver”命令的用户将启动该用户的会话。
# vncserver New 'geek.mylabserver.com:1 (root)' desktop is geek.mylabserver.com:1 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/geek.mylabserver.com:1.log
VNC 服务器配置故障排除
如果我们不切换到要为其设置 VNC 服务器密码的用户,则在启动 vncserver 服务时可能会出现如下所示的错误。
# service vncserver start .... 3:user You will require a password to access your desktops. getpassword error: Inappropriate ioctl for device
如何列出和终止 VNC 服务器会话
要列出所有当前运行的tigerVNC 服务器会话,请使用命令“vncserver list”。
例如 :
# vncserver -list TigerVNC server sessions: X DISPLAY # PROCESS ID :4 1864 :5 1895 :6 1923 :1 1949 :2 1767
要终止任何正在运行的 VNC 服务器会话,请使用如下所示的命令。
# vncserver -kill :4 Killing Xvnc process ID 1864
其中:
:4 是 X 显示会话编号。