
RHEL-Like
1 前言
VNC在RHEL或CentOS的每个大版本的配置细节都有差异,笔者记录如下,给有需要的人参考。
2 实践部分
2.1 基础配置
2.1.1 安装基础包
yum groupinstall -y "Server with GUI" yum install -y tigervnc-server
2.1.2 配置GDM-GNOME以传统X方式运行
vim /etc/gdm/custom.conf
去掉注解启用如下配置,
WaylandEnable=false
注:通过“false”变量声明系统下次启动时使用Xorg作为显示管理器而非Wayland
2.1.3 禁用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
如果启动遇到如下错误提示,
localhost.localdomain systemd[1]: PID file /root/.vnc/localhost.localdomain:1.pid not readable (yet?) after start.
请按如下方法处理,
pgrep -u root Xvnc | xargs kill 2 rm -rf /tmp/.X11-unix/ reboot
如果无法启动可使用如下命令检查日志,
cat ~/.vnc/*.log
如果发现如下错误,
Xvnc TigerVNC 1.9.0 - built Feb 9 2019 10:21:52 Copyright (C) 1999-2018 TigerVNC Team and many others (see README.rst) See http://www.tigervnc.org for information on TigerVNC. Underlying X server release 12003000, The X.Org Foundation Wed Oct 16 13:39:06 2019 vncext: VNC extension running! vncext: Listening for VNC connections on all interface(s), port 5901 vncext: created VNC server for screen 0 dbus-update-activation-environment: error: unable to connect to D-Bus: Failed to connect to socket /tmp/dbus-khJAYpEYIO: Connection refused GLib-GIO-Message: 13:39:10.060: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. ** (process:6458): WARNING **: 13:39:10.079: Could not make bus activated clients aware of XDG_CURRENT_DESKTOP=GNOME environment variable: Could not connect: Connection refused /root/.vnc/xstartup: line 6: 6458 Terminated /etc/X11/xinit/xinitrc Killing Xvnc process ID 6436 Wed Oct 16 13:39:10 2019 ComparingUpdateTracker: 0 pixels in / 0 pixels out ComparingUpdateTracker: (1:-nan ratio)
通过如下命令确定总线启动程序的位置,
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”即可修复此问题。
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
参阅文档
=================
RHEL或CentOS 7的VNC的配置
———————-
https://www.cmdschool.org/archives/1884
TigerVNC的配置
——————-
https://wiki.archlinux.org/index.php/TigerVNC
没有评论