0、环境:
debian10的操作系统,
arm-v8,64位开发板子
vnc介绍:
1、更新源:
#deb [ trusted=yes arch=arm64 ] http://uos-packages.deepin.com/uos eagle main contrib non-free
#deb [ trusted=yes arch=arm64 ] http://uos-packages.deepin.com/printer eagle non-free
#deb [ trusted=yes arch=arm64 ] http://mirrors.aliyun.com/uos eagle main contrib non-free
#deb [ trusted=yes arch=arm64 ] http://mirrors.aliyun.com/printer eagle non-free
deb [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster main non-free contrib
deb [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
deb-src [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster main non-free contrib
deb-src [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb-src [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb-src [ trusted=yes arch=arm64 ] http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
之后再:
sudo apt update
sudo apt upgrade
因为之前有安装gmetad的东西,所以先把这玩意给拆卸了,从开机启动的服务中给删除:
sudo rm -rf /etc/init.d/gmetad
sudo rm -rf /lib/systemd/system/gmetad.service
2、安装vnc
2.1、 安装Xfce桌面环境
sudo apt install xfce4 xfce4-goodies
2.2、安装TightVNC服务器
sudo apt install tightvncserver
要在安装后完成VNC服务器的初始配置,请使用vncserver命令设置安全密码并创建初始配置文件:
vncserver // 完成初始化,会有一些密码的输入:因为有6-8位的限制所以设置为raspberr
稍等半分钟等待初始化完成
ps -ef | grep vnc // 查看,可以看到已经启动了vncserver,端口5901已经在监听了
2.3、配置VNC服务器
在上一步中已经创建了vnc的启动脚本:在~/.vnc/下的xstartup配置文件中,我们想自己设置启动程序:
首先停止在端口5901上运行的VNC服务器实例
vncserver -kill :1
备份
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak 备份
编写自己的启动文件:
vim ~/.vnc/xstartup
#!/bin/bash // 配置文件内容
xrdb $HOME/.Xresources
startxfce4 &
增加执行权限,并重启
chmod +x xstartup # 如果不给执行权限,客户端显示出来的没影雪花
启动vncserver
vncserver 重启
看到
New 'X' desktop is pi0048:1
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/pi0048:1.log
就算成功了
2.4、使用客户端连接
1、使用本机命令测试:
ssh -L 5901:127.0.0.1:5901 -C -N -l pi 192.168.43.196
会显示:
$ ssh -L 5901:127.0.0.1:5901 -C -N -l pi 192.168.43.196
# bind [127.0.0.1]:5901: Address already in use
2、使用客服端尝试连接:
通过ip和端口进行连接:
我使用的客服端是VNC Viewer
如果服务器使用vncserver命令开启vnc服务时候显示信息如下:则客户端连接的端口是:5903 (:1也即是5901被占用,:2也即是5902被占用)
pi@pi0046:~/.vnc$ vncserver
Warning: pi0046:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server pi0046:1
Warning: pi0046:2 is taken because of /tmp/.X2-lock
Remove this file if there is no X server pi0046:2
New 'X' desktop is pi0046:3
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/pi0046:3.log
如果正常就:
然后显示如下就是成功了、
3、将VNC作为系统服务运行
编写成为系统服务的脚本:
sudo vim /etc/systemd/system/vncserver@.service
#内容:
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=sammy
Group=sammy
WorkingDirectory=/home/sammy
PIDFile=/home/sammy/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
重新加载系统服务
sudo systemctl daemon-reload
启用单位文件。
sudo systemctl enable vncserver@1.service
使用系统命令开启服务,不过失败了,以后再搞吧
sudo systemctl start vncserver@1
失败了:
$ systemctl status vncserver@1.service
● vncserver@1.service - Start TightVNC server at startup
Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-06-18 15:56:26 CST; 2min 25s ago
Process: 10083 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=216/GROUP)
Process: 10084 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=216/GROUP)
Jun 18 15:56:26 pi0048 systemd[1]: Starting Start TightVNC server at startup...
Jun 18 15:56:26 pi0048 systemd[10083]: vncserver@1.service: Failed to determine group credentials: No such process
Jun 18 15:56:26 pi0048 systemd[10083]: vncserver@1.service: Failed at step GROUP spawning /usr/bin/vncserver: No such process
Jun 18 15:56:26 pi0048 systemd[10084]: vncserver@1.service: Failed to determine group credentials: No such process
Jun 18 15:56:26 pi0048 systemd[10084]: vncserver@1.service: Failed at step GROUP spawning /usr/bin/vncserver: No such process
Jun 18 15:56:26 pi0048 systemd[1]: vncserver@1.service: Control process exited, code=exited, status=216/GROUP
Jun 18 15:56:26 pi0048 systemd[1]: vncserver@1.service: Failed with result 'exit-code'.
Jun 18 15:56:26 pi0048 systemd[1]: Failed to start Start TightVNC server at startup.