1 前言
本章针对Ubuntu的系统环境配置VNC,如有需要请参阅下文。
2 实践部分
2.1 基础配置
2.1.1 禁用默认的源
cp /etc/apt/sources.list /etc/apt/sources.list.default vim /etc/apt/sources.list
注:由于国外的源比较慢,所以我们使用编辑器注解以上源
2.1.2 配置国内的源
vim /etc/apt/sources.list.d/aliyun.list
加入如下内容,
deb http://mirrors.aliyun.com/ubuntu/ xenial main deb-src http://mirrors.aliyun.com/ubuntu/ xenial main deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
请根据系统的版本选择合适的源,其他版本的系统请参阅如下链接,
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11zCrwEM
配置完成后,你需要运行一下命令更新源,
apt update
2.1.3 安装基础包
apt install -y xfce4 xfce4-goodies apt install -y tightvncserver
2.2 配置VNC
2.2.1 创建vnc密码
vncpasswd
向导如下,
Using password file /root/.vnc/passwd VNC directory /root/.vnc does not exist, creating. Password:********* Warning: password truncated to the length of 8. Verify:********* Would you like to enter a view-only password (y/n)? n
2.2.2 手动测试服务运行
vncserver
可使用如下命令检查服务,
netstat -antp | grep vnc
可见如下显示,
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 17616/Xtightvnc tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 17616/Xtightvnc
另外,可使用如下命令手动关闭服务,
vncserver -kill :1
2.2.3 配置自动启动桌面环境
vim ~/.vnc/xstartup
配置修改如下,
#!/bin/sh xrdb $HOME/.Xresources startxfce4& #xsetroot -solid grey #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager & # Fix to make GNOME work #export XKL_XMODMAP_DISABLE=1 #/etc/X11/Xsession
2.2.4 配置启动服务
vim /etc/systemd/system/vncserver\@:1.service
修改如下配置:
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking User=root PIDFile=/root/.vnc/%H%i.pid # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/bin/sh -c "/usr/bin/vncserver %i" ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' Restart=on-success RestartSec=15 [Install] WantedBy=default.target
2.3 启动服务
systemctl daemon-reload systemctl start vncserver@:1.service systemctl enable vncserver@:1.service
2.4 优化VNC
2.4.1 修改VNC的起始端口
cp /usr/bin/vncserver /usr/bin/vncserver.default vim /usr/bin/vncserver
修改如下变量的赋值:
$vncPort = 5899 + $displayNumber;
2.4.2 重启服务使配置生效
systemctl restart vncserver@:1.service
2.4.3 确认端口修改成功
netstat -tunlp | grep -i vnc
2.5 其他服务管理命令
vncserver -kill :1
参阅文档
=================
RHEL或CentOS 7的VNC的配置
———————-
https://www.cmdschool.org/archives/1884
TigerVNC的配置
——————-
https://vitux.com/ubuntu-vnc-server/
https://wiki.archlinux.org/index.php/TigerVNC
阿里云源
————
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11zCrwEM
https://developer.aliyun.com/mirror/
没有评论