银河麒麟v10服务器系统配置vnc及一些坑
关闭selinux
setenforce 0
#修改/etc/selinux/config文件,因为文件好几个SELINUX=disabled给注释了暂时手动修改/etc/selinux/config文件
vim /etc/selinux/config
#SELINUX=disabled
# setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
安装依赖
安装vnc安装包: yum install tigervnc-server tigervnc-server-module
复制 vnc 启动脚本
复制 vnc 启动脚本并更改名称。如vncserver@:1.service
中的 :1 表示“桌面号” 对应启动的网络端口号就是 5900+桌面号 ,即 5901 。
如果再有一个就是 2 ,端口号就是 5902 ,以此类推:
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
以 root 用户访问 VNC 为例,编辑/etc/systemd/system/vncserver@:1.service
文件:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
#WorkingDirectory=/home/<USER>
#User=<USER>
#Group=<USER>
PIDFile=/root/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver :1"
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
Restart=on-success
RestartSec=15
[Install]
WantedBy=multi-user.target
设置 VNC 密码
执行vncpasswd
vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
重新加载系统配置文件
重新加载系统配置文件(系统新增或配置文件发生变化时,都需要执行 daemon-reload 子命令)
systemctl daemon-reload
设置开机启动并启动服务
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
# 关闭:vncserver -kill :1
防火墙配置相应规则
如关闭防火墙可忽略
firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload
解决麒麟系统VNC黑屏
查看日志
[root@k8s-188 .vnc]# more k8s-188:1.log
Xvnc TigerVNC 1.10.0 - built Aug 25 2022 14:20:49
Copyright (C) 1999-2019 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12008000, The X.Org Foundation
Tue Dec 19 17:48:55 2023
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5902
vncext: created VNC server for screen 0
The XKEYBOARD keymap compiler (xkbcomp) reports:
> Internal error: Could not resolve keysym XF86FullScreen
Errors from xkbcomp are not fatal to the X server
/root/.vnc/xstartup:行8: /usr/bin/mate-session: 没有那个文件或目录
Tue Dec 19 17:52:13 2023
ComparingUpdateTracker: 0 pixels in / 0 pixels out
ComparingUpdateTracker: (1:-nan ratio)
重点错误:
/root/.vnc/xstartup:行8: /usr/bin/mate-session: 没有那个文件或目录
处理问题
安装缺失的组件
yum install mate-session-manager mate-desktop
重启服务
systemctl restart vncserver@\:1.service
vnc界面乱码问题
安装缺失的组件
yum install cjkuni-ukai-fonts
yum install *google-noto-fonts*
#yum install google-noto-sans
最终效果
验证后最终效果
另设置普通账号vnc
切换账号设置vnc密码
su - glj
[glj@k8s-188 ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
[glj@k8s-188 ~]$ exit
注销
[root@k8s-188 yum.repos.d]#
创建普通账号 vnc配置文件
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
修改信息
/etc/systemd/system/vncserver@:2.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/home/glj
User=glj
Group=glj
PIDFile=/home/glj/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
#ExecStart=/usr/bin/vncserver -autokill %i
ExecStart=/usr/bin/vncserver %i -geometry 1920x1080
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-success
RestartSec=15
[Install]
WantedBy=multi-user.target
刷新systemctl信息并启动
systemctl daemon-reload
systemctl start vncserver@:2.service
查看启动状态是否正常,或者错误信息
systemctl status vncserver@:2.service