Skip to content

vnc

参考

安装vnc-server

安装桌面

bash
yum groupinstall "Server with GUI"

安装vnc-server

bash
yum install tigervnc-server

创建新用户

bash
# 新建账号1
useradd -m -s /bin/bash u01
su - u01
vncpasswd

# 新建账号2
useradd -m -s /bin/bash u02
su - u02
vncpasswd

配置vnc-server

bash
# 复制配置文件
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

# 修改配置
vim /etc/systemd/system/vncserver@:1.service

# 启动服务
systemctl start vncserver@:1.service

显示分辨率配置

bash
# 配置显示分辨率等
/etc/tigervnc/vncserver-config-defaults

[root@VM-16-13-tencentos noVNC]# cat /etc/tigervnc/vncserver-config-defaults
## Default settings for VNC servers started by the vncserver service
#
# Any settings given here will override the builtin defaults, but can
# also be overriden by ~/.vnc/config and vncserver-config-mandatory.
#
# See HOWTO.md and the following manpages for more details:
#     vncsession(8) Xvnc(1)
#
# Several common settings are shown below. Uncomment and modify to your
# liking.

# session=gnome
# securitytypes=vncauth,tlsvnc
geometry=2000x1200
# localhost
# alwaysshared

# Default to GNOME session
# Note: change this only when you know what are you doing
session=gnome
[root@VM-16-13-tencentos noVNC]#

配置用户

bash
[root@VM-16-13-tencentos noVNC]# cat /etc/tigervnc/vncserver.users 
# TigerVNC User assignment
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=u01
:2=u02

[root@VM-16-13-tencentos noVNC]#

强制设置(不知道干嘛的)

bash
[root@VM-16-13-tencentos noVNC]# cat /etc/tigervnc/vncserver-config-mandatory 
## Mandatory settings for VNC servers started by the vncserver service
#
# Any settings given here will override the builtin defaults and
# settings specified in ~/.vnc/config or vnc-config-defaults.
#
# See HOWTO.md and the following manpages for more details:
#     vncsession(8) Xvnc(1)
#
# Several common settings are shown below. Uncomment and modify to your
# liking.

# session=gnome
# securitytypes=vncauth,tlsvnc
# geometry=2000x1200
# localhost
# alwaysshared
[root@VM-16-13-tencentos noVNC]#

安装noVNC

bash
./utils/novnc_proxy --vnc localhost:5901 --listen localhost:6081

./utils/novnc_proxy --vnc 172.16.16.13:5901 --listen 172.16.16.13:6081

./utils/novnc_proxy --vnc 172.16.16.13:5902 --listen 172.16.16.13:6082

访问测试

bash
# 默认
http://111.230.99.159:6081/vnc.html?host=111.230.99.159&port=6081&password=123456

# 轻量级、自动进入
http://111.230.99.159:6081/vnc_lite.html?host=111.230.99.159&port=6081&password=123456

# 连接第二个账号
http://111.230.99.159:6082/vnc.html?host=111.230.99.159&port=6082&password=123456

本地页面嵌套

html
<!DOCTYPE html>
<html style="margin: 0; padding: 0;">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body style="margin: 0; padding: 0;">
    <iframe  style="width: 100vw; height: 100vh; margin: 0; padding: 0; border: 0;" 
    src="http://111.230.99.159:6081/vnc_lite.html?host=111.230.99.159&port=6081&password=123456" ></iframe>
</body>
</html>

关闭锁屏

bash
关闭息屏,最后0是代表关闭锁屏,将0替换为60代表60s后自动息屏,以此类推。
gsettings set org.gnome.desktop.session idle-delay 0
 
 
关闭锁屏
gsettings set org.gnome.desktop.screensaver lock-enabled false

人生感悟