由于全段时间在Cubieboard 群里有人问到如何安装VNC,于是写一篇博客。其实我是不常用VNC远程控制Linux 的,因为作为Linux 服务器 基本不会用到图形界面。可能部分使用者不是使用Cubieboard Linux 作为服务器,而是作为图形桌面在使用。一般控制Linux 服务器都是使用Putty等工具通过命令行方式来控制。

本文主要针对Cubieboard Linux 操作系统搭建 VNC 服务远程访问Linux主机,它适用 Debian 所有版本。当然也适用于Cubieboard Linux 服务器版本。

当然你可以对Cubieboard Linux 服务器做更多的学习与研究:

如果你只是针对Debian Linux操作系统搭建VNC感兴趣,可以直接开始阅读下面的文章。

什么是VNC?

VNC(Virtual Network Computing),是一种使用RFB协定的屏幕画面分享及远程操作软件。此软件借由网络,可传送键盘与鼠标的动作及实时的屏幕画面。

VNC与操作系统无关,因此可跨平台使用,例如可用Windows连接到某Linux的电脑,反之亦同。甚至在没有安装客户端程序的电脑中,只要有支持JAVA的浏览器,也可使用。

VNC由Olivetti & Oracle研究室所开发,此研究室在1999年并入美国电话电报公司(AT&T)。AT&T于2002年中止了此研究室的运作,并把VNC以GPL发布。

因为它是免费的, 以及可用于数量庞大的不同操作系统, 它的简单、可靠、和向后兼容性, 使之进化成为最为广泛使用的远程控制软件,多平台的支持对网络管理员是十分重要的,他使网络管理员可以使用一种工具管理几乎所有系统。像RealVNC, VNC tight 和UltraVNC, 他们具有全面的向后兼容。至少对于基本的远程控制功能而言。 Real VNC 是当前最活跃和强大的主流应用。

VNC对于简单的远程控制几乎完美,但是缺少对于大机构的桌面帮助功能, 主要是日志记录和安全功能没有足以达到此目的。 VNC为远程工作人员或瘦客户机也没有做好准备, 因为目前还没有支持远程应用程序的本地打印。

因为VNC 本来是开发用在局域网的环境, 因此用在互联网上存在安全问题, 当您计划在远程位置访问远程PC,你应该考虑一个专用的调制解调器或ISDN的拨号连接,×××隧道,所有使用SSL或包裹VNC通信。

VNC 工作流程:

1、在服务器端启动 VNC Server。

2、VNC客户端通过浏览器或 VNC Viewer 连接至VNC Server。

3、VNC Server传送一对话窗口至客户端,要求输入连接密码, 以及存取的VNC Server显示装置。

4、在客户端输入联机密码后,VNC Server验证客户端是否具有存取权限。

5、若是客户端通过 VNC Server 的验证,客户端即要求VNC Server显示桌面环境。

6、VNC Server通过X Protocol 要求X Server将画面显示控制权交由VNC Server负责。

7、VNC Server将来由 X Server 的桌面环境利用VNC通信协议送至客户端, 并且允许客户端控制VNC Server的桌面环境及输入装置。

Cubieboard Linux VNC 安装与配置

第一步,安装VNC Server。

root@cubieboard:~# apt-get install tightvncserver

执行以上命令,没有安装VNC server,则会自动安装,如果安装过的了,不会重复安装,会自动跳过。

可以检查一下是否安装,通过以下命令:

root@cubieboard:~# dpkg -l | grep tightvncserver
ii  tightvncserver                        1.3.9-6.4                               armhf        virtual network computing server software

如果提示没有找到 tightvncserver 软件包(Unable to locate package),可以安装 vncserver 或者 vnc4server。可以使用命令:apt-get install vncserver 或者 apt-get install vnc4server,最后都可以 VNC 服务。

第二步,初始化启动VNC Server 并设置密码。

# vncserver
You will require a password to access your desktops.
Password:
Verify:
Password too long – only the first 8 characters will be used
xauth: creating new authority file /root/.Xauthority
New ‘xxx:1 (root)’ desktop is xxx:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/xxx:1.log
Would you like to enter a view-only password (y/n)? n

先输入操作密码两次,然后会询问是否设置一个查看(view-only)密码,一般不需要设置,输入n就可以了。这里两次输入的密码,在后面VNC验证时输入。如下图:

VNC-Password-Authentication VNC 这里两次输入的密码,在后面VNC验证时输入。

图1 VNC登录验证密码。

设置VNC 输入两次的密码,会在当前用户主目录下 生成 .vnc 目录和配置文件。当前我是在root用户下启动的。

root@cubieboard:~# cd /root/.vnc/
root@cubieboard:~/.vnc# ll
total 60
drwx——  2 root root 4096 Jul  5 13:23 ./
drwx—— 19 root root 4096 Jul  5 13:23 ../
-rw-r–r–  1 root root 4705 Jul  5 13:21 cubieboard:1.log
-rw-r–r–  1 root root    6 Jul  5 12:04 cubieboard:1.pid
-rw——-  1 root root    8 Jul  5 13:19 passwd
-rwxr-xr-x  1 root root  242 Jul  5 12:03 xstartup*

现在已经启动了 VNC Server,默认端口为5901,可以通过客户端VNC Viewer连接。

VNC Viewer 下载地址:http://www.realvnc.com/download/viewer/

VNC-Viewer-login 客户端VNC Viewer 连接VNC Server

图2 客户端VNC Viewer 连接VNC Server

Server为:IP@端口,上图中我的Cubieboard Server IP地址为192.168.1.59,端口默认为5901,即为:192.168.1.59:5901,点击OK。出现图1 进行VNC登录验证密码。

如果没有安装桌面系统 Gnome、X-Window 或者 xfce4,将会出现如下提示:

Xsession: unable to start X session — no "/root/.xsession" file, no
"/root/.Xsession" file, no session managers, no window managers, and no
terminal emulators found; aborting.

第三步,配置桌面系统Session。

选择一:如果你想使用强大的Gnome 桌面,可以通过如下命令安装:

root@cubieboard:~# apt-get install gnome-desktop-environment

安装Gnome桌面系统大概要 1210 MB 空间。修改 xstartup 文件 把 gnome-session & 启用。

文件位置:vi /root/.vnc/xstartup

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
#xfce4-session &
gnome-session &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession

注意:由于Gnome太大,我没有安装,你可以自行安装。所以没有截图了。

选择二:使用 X-Window 桌面,可以通过如下命令安装:

root@cubieboard:~# apt-get install x-window-system-core
Reading package lists… Done
Building dependency tree
Reading state information… Done
Note, selecting ‘xorg’ instead of ‘x-window-system-core’

它会提示使用xorg 替换 x-window-system-core,Xorg是X11的一个实现。

root@cubieboard:~# apt-get install xorg

然后修改 xstartup 文件把 x-window-manager & 启用。

文件位置:vi /root/.vnc/xstartup

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
#xfce4-session &
# Fix to make GNOME work
#export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession

安装后,启动X-Window系统看到的就是只有一个窗口,其他空白一片,如下图:

VNC-X-Window-Desktop VNC 启动X-Window系统

图3 VNC Server 使用X Window 桌面。

选择三:使用 xfce4 桌面,Xfce是一个轻量级的Linux或类Unix的桌面系统。可以通过如下命令安装:

root@cubieboard:~# apt-get install xfce4

安装Xfce 4 桌面系统大概要120多MB 。修改 xstartup 文件 把 xfce4-session & 启用。

文件位置:vi /root/.vnc/xstartup

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
xfce4-session &
# Fix to make GNOME work
#export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession

安装后,启动Xfce 系统看到的如下图:

VNC-Xfce-Inital VNC Viewer 客户端初始化使用 Xfce 桌面系统。

图4 VNC Viewer 客户端初始化使用 Xfce 桌面系统。

点击“Use Default config”按钮,即使用默认的配置。

然后就获得了这样的界面:

VNC-Xfce-Desktop VNC Viewer 客户端开始使用 Xfce 桌面系统

图5 VNC Viewer 客户端开始使用 Xfce 桌面系统。

最后,请根据你自己的实际情况选择VNC所支持的桌面系统。

第四步,可以添加一下中文字体来好好体验Linux系统的桌面功能。

apt-get install xfonts-intl-chinese xfonts-wqy ttf-wqy-zenhei ttf-wqy-microhei

比如浏览器中缺少中文字体会很难看。


第五步,设置VNC Server为开机启动项。

root@cubieboard:~# update-rc.d vncserver defaults

不需要开启启动的,手动启动也很方便,看下面的常用命令。

VNC 常用命令

启动VNC 服务:

下面的三条命令中任何一条都可以。

root@cubieboard:~# vncserver
root@cubieboard:~# vncserver :1
root@cubieboard:~# tightvncserver :1

启动VNC Server时调整分辨率:


root@cubieboard:~# tightvncserver -geometry 1024×768 :1

终止VNC 服务:

下面的两条命令中任何一条都可以。

root@cubieboard:~# vncserver -kill :1
root@cubieboard:~# tightvncserver -kill :1

查看运行中的VNC进程:

root@cubieboard:~# ps -axjf | grep vnc

显示5901 端口的进程是否是VNC Server:

root@cubieboard:~# lsof -i | grep 5901
Xtightvnc 20316     root    3u  IPv4 160992      0t0  TCP *:5901 (LISTEN)

总结一下。Cubieboard Linux 服务器教程六主要讲解Cubieboard Linux 操作系统搭建 VNC 服务远程访问Linux主机,它适用 Debian 所有版本。当然也适用于Cubieboard Linux 服务器版本。

感谢你继续对LixiPHP Cubieboard Linux服务器系列文章的关注。

欢迎收藏本文,并继续关注本系列文章。

如果你对本文有什么疑问,请在留言中评论,必定回复!