如何配置RHEL或CentOS 9的VNC?

RHEL-Like

1 前言

VNC在RHEL或CentOS的每个大版本的配置细节都有差异,笔者记录如下,给有需要的人参考。

2 实践部分

2.1 基础配置

2.1.1 安装基础包

dnf groupinstall -y "Server with GUI"
dnf install -y tigervnc-server

2.1.2 禁用SELinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

2.2 配置VNC

2.2.1 创建vnc密码

vncpasswd

向导如下,

Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used

2.2.2 配置启动服务

cp /usr/lib/systemd/user/vncserver@.service /etc/systemd/system/vncserver\@:1.service
vim /etc/systemd/system/vncserver\@:1.service

修改如下配置:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
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

如果无法启动可使用如下命令检查日志,

cat ~/.vnc/*.log

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.4.4 配置防火墙

firewall-cmd --permanent --add-port 5900/tcp
firewall-cmd  --reload
firewall-cmd --list-all

2.5 其他服务管理命令

vncserver -list
vncserver -kill :1

2.6 错误处理

Oct 16 16:40:16 389ds gnome-session[2504]: gnome-session-binary[2504]: WARNING: Could not retrieve current screensaver active state: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Shell.ScreenShield was not provided by any .service files
Oct 16 16:40:16 389ds gnome-session-binary[2504]: WARNING: Could not retrieve current screensaver active state: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Shell.ScreenShield was not provided by any .service files
Oct 16 16:40:16 389ds libcanberra-login-sound.desktop[2867]: Failed to play sound: Not available
Oct 16 16:40:16 389ds journal[2718]: Failed to grab accelerator for keybinding settings:rotate-video-lock
Oct 16 16:40:16 389ds journal[2718]: Failed to grab accelerator for keybinding settings:hibernate
Oct 16 16:40:16 389ds journal[2718]: Failed to grab accelerator for keybinding settings:playback-repeat
Oct 16 16:40:16 389ds journal[2718]: Failed to grab accelerator for keybinding settings:playback-random

如果遇到以上错误,通过如下命令确定总线启动程序的位置,

whereis dbus-launch

可见如下显示,

dbus-launch: /usr/bin/dbus-launch /usr/anaconda3/bin/dbus-launch /usr/share/man/man1/dbus-launch.1.gz

从上面可知,默认启动总线程序有两个,系统默认的应为“/usr/bin/dbus-launch”,可使用如下命令解决,

vim /etc/X11/xinit/xinitrc.d/00-start-message-bus.sh

修总线程序的执行文件为绝对路径,配置修改如下,

#!/bin/sh
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
        eval `/usr/bin/dbus-launch --sh-syntax --exit-with-session`
fi

注:将启动总线程序改为绝对路径的“/usr/bin/dbus-launch”防止去启动错误的总线启动程序“/usr/anaconda3/bin/dbus-launch”即可修复此问题。

参阅文档
=================
RHEL或CentOS 7的VNC的配置
———————-
https://www.cmdschool.org/archives/1884

TigerVNC的配置
——————-
https://wiki.archlinux.org/index.php/TigerVNC

没有评论

发表回复

RHEL-Like
如何配置rsyncd服务?

1 前言 一个问题,一篇文章,一出故事。 由于笔者想实现文件通过rsync自动传输,但是又不想使用o …

RHEL-Like
如何用pam_google_authenticator认证模块实现SSH 2FA?

1 前言 一个问题,一篇文章,一出故事。 笔者想开启2FA以便增强SSH服务的安全性,于是便整理此文 …

RHEL-Like
如何升级RHEL clamav杀毒?

1 前言 一个问题,一篇文章,一出故事。 笔者需要卸载旧的病毒软件,然后更新rpm包的病毒软件,于是 …