在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

独立观察员 2023 年 4 月 15 日

概述

本文介绍了如何在树莓派系统中安装和使用远程桌面(VNC 协议)软件 TightVNC;前几小结顺序介绍了一开始走的弯路,不过过程中体现了一些 Linux 的操作知识(比如:在树莓派中安装 Yum 并配置源、安装 imake 等),所以保留;之后使用软件商店成功安装了 TightVNC 的服务端软件(tightvncserver),其实通过包管理器安装也可以(在 “开机自启” 一节中有体现);然后介绍了 tightvncserver 的一些使用方式,如 开机自启、公网访问、客户端使用 等;最后与 RealVNC 进行了对比。

 

下载

https://www.tightvnc.com/download-old.php 

旧版(1.3 版本)支持 Linux,不过只有源码:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

帮助文件:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

文件内容节选:

  TightVNC version 1.3.10
  Source distribution for Unix platforms

======================================================================

This distribution is based on the standard VNC source and includes new
TightVNC-specific features and fixes, such as additional low-bandwidth
optimizations, major GUI improvements, and more.

//略

There are five programs here:

    vncviewer - this is the VNC viewer, or client, program for X.

    vncserver - this is a wrapper script which makes starting an X VNC
            server (i.e. desktop) more convenient.  It is written in
            Perl, so to use the script you need that.

    vncpasswd - this program allows you to change the password used to
            access your X VNC desktops.  The vncserver script uses
            this program when you first start a VNC server.

    vncconnect - this program tells a running instance of Xvnc to connect
             to a listening VNC viewer (normally the connection is made
             the other way round i.e. the viewer connects to Xvnc).

    Xvnc - this is the X VNC server - it is both an X server and a VNC
           server.  You normally use the vncserver script to start Xvnc.


First you must have a reasonably recent version of X installed (this includes
/usr/openwin on Solaris machines).  Also, TightVNC requires JPEG and zlib
libraries installed in the system (e.g. under /usr/local).  To build
everything but Xvnc, do:

    % xmkmf
    % make World

This should build first the vncauth library which is used by each of the
programs, then vncviewer, vncpasswd and vncconnect.

Xvnc differs from the other programs in that it is built inside a cut-down
version of the X build tree.  This is based around the XFree86 3.3.2 "server
only" distribution, which in turn is based on the X11R6.3 distribution from
the X consortium.  To build Xvnc, do:

    % cd Xvnc
    % ./configure
    % make

If you have trouble building Xvnc, see the Xvnc/README file for more details.

If it all builds OK you should copy the programs to some directory which
is in your PATH environment variable, such as /usr/local/bin.  Also, it's
handy to install manual pages in a directory where the man utility can find
them.  You can use the vncinstall script to do this for you (man path is
optional):

    % cd ..
    % ./vncinstall /usr/local/bin /usr/local/man

If you want to use the Java VNC viewer, you should copy the class files from
the classes directory to some suitable installation directory such as
/usr/local/vnc/classes:

    % mkdir -p /usr/local/vnc/classes
    % cp classes/* /usr/local/vnc/classes

We recommend that you use the vncserver script to run Xvnc for you.  You can
edit the script as appropriate for your site.  Things you may need to change
include:

 * The location of Perl - if Perl is not installed in /usr/bin you'll need
   to edit the "#!/usr/bin/perl" first line of vncserver.

 * $vncClasses - this specifies the location of the Java classes for
   the VNC viewer applet.  The default is /usr/local/vnc/classes.

 * Xvnc's font path and color database.  If you have an installation of
   X which is not in the standard place you may need to add arguments to the
   Xvnc command line to set these.  These should be appended to the $cmd
   variable at the comment "# Add font path and color database...".

 

安装 xmkmf

软件库中没有:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

参考:《linux – 我在哪里可以获得 RedHat Linux 的 xmkmf?

它是 imake 包的一部分,您可以通过 yum install imake 使用 yum 安装它,或者直接下载,例如来自 http://rpmfind.net/linux/rpm2html/search.php?query=imake .

 

安装 yum:

在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

安了 yum,还没配置源,所以源中没有 imake 包:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

先来试试直接安装 rpm 包吧,下载 rpm 包(armv7hl 架构):

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

直接安装 rpm 包,失败了,因为缺少很多依赖(所以一般不推荐直接安装 rpm 包):

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

在树莓派系统中配置 Yum 源(华为源)

163 的源用不了:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

参考:《Raspberry Pi 3 Model B 使用 CentOS 7 系统配置 Yum 源

 

使用华为源,并进行硬编码修改,最终 /etc/yum.repos.d/CentOS-arm.repo 内容如下:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-7 - Base - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-altarch/7/os/armhfp/
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos-altarch/7/os/armhfp/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-7 - Updates - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-altarch/7/updates/armhfp/
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos-altarch/7/os/armhfp/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-altarch/7/extras/armhfp/
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos-altarch/7/os/armhfp/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-altarch/7/centosplus/armhfp/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.huaweicloud.com/centos-altarch/7/os/armhfp/RPM-GPG-KEY-CentOS-7

#CentOS-armhfp-kernel.repo 
[centos-kernel]
name=CentOS Kernels for armhfp
baseurl=https://repo.huaweicloud.com/centos-altarch/7/kernel/armhfp/kernel-rpi2/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32

 

yum makecache 更新缓存:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

安装 imake

软件包中还是没有:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

直接安装 rpm 包也还是不行:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

在软件商店中搜索 imake,发现可以通过 xutils-dev 来间接安装:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

make World 1

xmkmf:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

make World:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

失败:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

先试试编译 Xvnc:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

make 编译,也是不成功:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

搜索某个组件在哪个包中

参考:《【解决】fatal error: X11/XXXX.h: No such file or directory

 

搜索方法

sudo apt-get install apt-file
sudo apt-file update
apt-file search XXXX.h

 

安装 apt-file:

在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

更新 apt-file:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

示例 1(原文示例)

# 安装库文件 libx11-dev
sudo apt-get install libx11-dev
sudo apt-get install libxt-dev  

 

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

示例 2(搜索后单个结果)

再次编译,提示缺少 X11/Xmu/StdSel.h :

在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

使用 apt-file search 命令进行搜索 StdSel.h,找到了是需要 libxmu-headers,直接安装:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

示例 3(搜索后多个结果)

再次 make World,并搜索缺少的文件 Viewport.h :

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

搜索出很多结果,不过通过对比错误信息,找到了是需要 libxaw7-dev:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

安装:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

make World 2

再次 make World,只有一些警告,没有错误了,但是还是失败了:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

运行 xmkmf 后再运行 make World,警告也没有了,但是还是失败:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

主要错误就是 undefined reference to symbol’socket@@GLIBC_2.4′

网上的问题:https://stackoverflow.com/questions/51076458/undefined-reference-to-symbol-socketglibc-2-4-while-linking 

 

问了 ChatGPT:

在树莓派系统中安装和使用远程桌面软件 TightVNC

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

系统里是安了 GLIBC 的:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

总之,最终是解决不了,通过源码编译也就以失败告终了。

 

最终使用软件商店安装 tightvncserver

直接搜索 tightVnc,看到有个 virtual network computing server software,查看描述,应该就是本尊,而且版本也正是 1.3:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

描述上说没有也不需要图形界面:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

输入 tightvncserver 命令,设置密码(8 位),输出连接信息(bpi-iot-ros-ai:1)等:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

使用 MobaXterm 连接:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

成功:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

和 RealVnc(左)合个影:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

两者的区别就是,这个版本的 RealVnc 是公网服务的(当然也可以自己安装局域网版本,不过记得也挺麻烦的),而今天的主角 TightVnc 是局域网的(后面有介绍公网访问)。

 

后记 1:发现导致 RealVNC 用不了了,还是还原吧。

后记 2:还原系统到一周前,RealVNC 恢复正常了,tightVnc 也还在,可能是还原的时候没有勾选清除新内容吧,这样挺好的。

 

开机自启(摘录)

这个 TightVnc(tightvncserver)没有开机自启,而且输入命令启动后却是在 root 用户下,而之前系统启动默认登陆的是 pi 用户,看看有没有方法解决。

使用 tightvncserver /? 显示帮助菜单:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

没有相关选项,继续百度,找到了文章《树莓派:VNC 远程登录 Raspbian 图形界面(tightvncserver)》,写得比我好,摘录部分内容如下:


 <<<↓↓↓摘录开始↓↓↓>>>

安装

命令行输入:

sudo apt-get install tightvncserver

 

安装好之后请一定先使用此命令设置一个 VNC 密码:

vncpasswd

 

先输入操作密码两次,然后会询问是否设置一个查看 (view-only) 密码,按自己喜欢,一般没必要。

 

[dlgcy] 应该使用 tightvncpasswd 命令:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

设置开机启动

设置开机启动,需要在 /etc/init.d/ 中创建一个文件。例如 tightvncserver:
(注:启动脚本的名称,有和程序名一致的习惯)

sudo vi /etc/init.d/tightvncserver
#[dlgcy]或者使用其它编辑器,如 LeafPad 图形化编辑器:
sudo leafpad /etc/init.d/tightvncserver

 

内容如下:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          tightvncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop tightvncserver
### END INIT INFO
 
# More details see:
# http://www.penguintutor.com/linux/tightvnc
 
### Customize this entry
# 设置在哪个用户下启动 tightvncserver
export USER='pi'
### End customization required

eval cd ~$USER
 
case "$1" in
  start)
    # 启动命令行。此处自定义分辨率、控制台号码或其它参数。
    su $USER -c '/usr/bin/tightvncserver -depth 16 -geometry 1920x1080 :1'
    echo "Starting TightVNC server for $USER "
    ;;
  stop)
    # 终止命令行。此处控制台号码与启动一致。
    su $USER -c '/usr/bin/tightvncserver -kill :1'
    echo "Tightvncserver stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/tightvncserver {start|stop}"
    exit 1
    ;;
esac
exit 0

 

(注:USER 变量的值为默认用户名,这里是 pi。)

 

[dlgcy] 图示(使用 leafpad 打开方便编辑):

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

然后给 tightvncserver 文件加执行权限:

sudo chmod 755 /etc/init.d/tightvncserver

 

并更新开机启动列表:

sudo update-rc.d tightvncserver defaults

 

重启树莓派:

sudo shutdown -r now
#[dlgcy]或者
reboot

 

[dlgcy] 整个过程:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

手动启动

当然也可以手动启动 VNC 服务器程序,使用以下命令:

tightvncserver -geometry 1920x1080 :1

 

如果首次启动,并且未曾使用 vncpasswd 命令设置密码,程序会要求设置密码。开机启动很方便,所以还是推荐开机启动。

 

命令参数说明

一、指定控制台的号码。

启动多个控制台,可以提供互不影响的多个桌面环境。如果不加此参数,tightvncserver 会自动寻找从 1 开始的下一个空闲控制台。加上此参数,会强制使用指定的控制台,如果此控制台已经启动则报错。加此参数可有效防止无意多次启动程序(会启动多个控制台)白白浪费系统资源。

特殊的 0 号控制台 ——0 号控制台就是连接真实显示器真正输出图像的那个桌面。对于 VNC 客户端,不输入端口号登录,默认就登录到 0 号控制台,方便。但是因为 0 号是真正的桌面,所以和开机启动桌面环境存在冲突。因此自动启动的配置教程中,使用 1 号控制台。

 

二、-geometry 800×600,分辨率。可以不加。

终止 VNC 控制台:

tightvncserver -kill :1​

 

<<<↑↑↑摘录结束↑↑↑>>>


 

分辨率改为 1920*1080,看着真不错:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

外网访问

这个需要内网穿透,比如使用 frp,配置一个端口(由于控制台号为 1,所以本地端口号为 5901,指定外网端口号为 9010):

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

MobaXterm 按如下设置:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

TightVNC Viewer 按如下设置:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

输入密码后即可连接:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

连接成功:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

使用 RealVNC 的 VNC Viewer 也可以:

在树莓派系统中安装和使用远程桌面软件 TightVNC

 

优缺点

与 RealVNC 对比,TightVNC 有以下优缺点:

优点:可设置大分辨率,RealVNC 好像不能设置(当然可能自己搭的版本可以设置)。

缺点:

1、有些操作执行有问题

比如在命令行中以管理员方式启动图形界面编辑器 LeafPad 在这里就不行了:

在树莓派系统中安装和使用远程桌面软件 TightVNC

当然,猜测可能是和控制台号不是 0 有关。

 

2、不能和本地计算机(Windows)的剪贴板打通

也就是两者之间不能复制粘贴,这个试了上节中提到的三个客户端(MobaXterm、TightVNC Viewer、RealVNC 的 VNC Viewer)都不行,而用 RealVNC 的 VNC Viewer 连接它的服务器端是可以的,而且 Windows 下 TightVNC 的服务端和客户端之间连接后也不支持复制粘贴,所以应该是 TightVNC 的问题,这个问题还挺大的。

 

好了,就说这么多吧,其它的大家可以自己探索。全文完,感谢阅读。

 

原创文章,转载请注明: 转载自 独立观察员(dlgcy.com)

本文链接地址: [在树莓派系统中安装和使用远程桌面软件 TightVNC](https://dlgcy.com/raspbian-tightvnc/)

关注微信公众号 独立观察员博客(DLGCY_BLOG) 第一时间获取最新文章

%title插图%num

发表评论