1.下载三个包,传到/root下面

centos7安装tigervnc-server服务并且黑屏的解决方法_dconf

2.依次安装

centos7安装tigervnc-server服务并且黑屏的解决方法_vnc_02

3.复制文件

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

4.因为我有两个两个用户,一个是root ,另外一个是普通用户,我决定让普通用户使用vnc,那么编辑

/etc/systemd/system/vncserver@:1.service这个文件,将其中的<user>改为普通用户名即可

vim /etc/systemd/system/vncserver@\:1.service

centos7安装tigervnc-server服务并且黑屏的解决方法_vnc_03

5.切换到普通用户,设置vncpasswd

centos7安装tigervnc-server服务并且黑屏的解决方法_dconf_04

6.切换到root,启动vnc服务

[root@ ~]# systemctl daemon-reload
[root@ ~]# systemctl start vncserver@\:1.service
[root@ ~]# systemctl enable vncserver@\:1.service
[root@ ~]# systemctl status vncserver@\:1.service
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-07-22 14:27:34 CST; 9min ago
Main PID: 380762 (vncserver_wrapp)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
├─ 22539 sleep 5
└─380762 /bin/sh /usr/bin/vncserver_wrapper cdssadmin :1

Jul 22 14:27:34 hm-db systemd[1]: Starting Remote desktop service (VNC)...
Jul 22 14:27:34 hm-db systemd[1]: Started Remote desktop service (VNC).
Jul 22 14:27:37 hm-db vncserver_wrapper[380762]: New 'hm-db:1 (cdssadmin)' desktop is hm-db:1
Jul 22 14:27:37 hm-db vncserver_wrapper[380762]: Starting applications specified in /home/cdssadmin/.vnc/xstartup
Jul 22 14:27:37 hm-db vncserver_wrapper[380762]: Log file is /home/cdssadmin/.vnc/hm-db:1.log
Jul 22 14:27:42 hm-db vncserver_wrapper[380762]: 'vncserver :1' has PID 380786, waiting until it exits ...
[root@ ~]# netstat -lnpt|grep Xvnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 380786/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 380786/Xvnc
tcp6 0 0 :::5901 :::* LISTEN 380786/Xvnc
tcp6 0 0 :::6001 :::* LISTEN 380786/Xvnc



7.问题,启动后,用vnc viewer能连接上,但是

黑屏,查看日志发现此处错误:

centos7安装tigervnc-server服务并且黑屏的解决方法_dconf_05

8.删掉/run/user/100[root@hm-db ~]# rm /run/user/1002/dconf/user

[root@ ~]# rm /run/user/1002/dconf/user
rm: remove regular file ‘/run/user/1002/dconf/user’? y


问题4.报这个错误

Xvnc TigerVNC 1.8.0 - built Oct 13 2020 16:13:03
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12004000, The X.Org Foundation


Thu Nov 3 10:35:12 2022
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5901
vncext: created VNC server for screen 0
mv: 无法将"/home/gkadmin/.cache/imsettings/log" 移动至"/home/gkadmin/.cache/imsettings/log.bak": 权限不够

(imsettings-check:18779): IMSettings-WARNING **: 10:35:15.680: 无法连接:拒绝连接

(imsettings-check:18779): GLib-GIO-CRITICAL **: 10:35:15.680: g_dbus_proxy_call_sync_internal: assertion 'G_IS_DBUS_PROXY (proxy)' failed

** (process:18719): WARNING **: 10:35:15.823: Could not make bus activated clients aware of XDG_CURRENT_DESKTOP=GNOME environment variable: Could not connect: Connection refused
/home/gkadmin/.vnc/xstartup: 行 5: 18719 已终止 /etc/X11/xinit/xinitrc
Killing Xvnc process ID 18700

经查看,发现系统装了python,  

(base) [root@gggg imsettings]# echo $PATH
/opt/anaconda3/bin:/opt/anaconda3/condabin:/gxaio/liquibase:/opt/anaconda3/bin:/usr/java/jdk1.8.0_321-amd64/bin:/usr/java/jdk1.8.0_321-amd64/jre/bin:/gxaio/liquibase:/opt/anaconda3/bin:/opt/anaconda3/condabin:/opt/anaconda3/bin:/usr/java/jdk1.8.0_321-amd64/bin:/usr/java/jdk1.8.0_321-amd64/jre/bin:/gxaio/liquibase:/opt/anaconda3/bin:/opt/anaconda3/condabin:/opt/anaconda3/bin:/usr/java/jdk1.8.0_321-amd64/bin:/usr/java/jdk1.8.0_321-amd64/jre/bin:/usr/java/jdk1.8.0_321-amd64/bin:/usr/java/jdk1.8.0_321-amd64/jre/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
(base) [root@gggg imsettings]#

修改该用户下的 ~/.bashrc 或者 ~/.bash_profile  让 /usr/bin 在Anconda 的环境变量之前就行

修改完:source 一下

再查看一下:echo $PATH 是否修改成功

9.接着就正常了。

centos7安装tigervnc-server服务并且黑屏的解决方法_tigervnc_06