在CentOS 7.4下配置VNC Server服务

安装步骤

1. 查询系统是否安装vnc-server

[root@localhost ~]# rpm -qa | grep vnc
如果有返回值,类似于vnc-server-的值,说明已经安装了vnc-server

2. 配置epel的yum源,然后安装

yum -y install tigervnc tigervnc-server tigervnc-server-module
如果无法安装或者安装失败,可以到阿里开源镜像站将安装包下载下来el7版本,支持vnc-server关键字搜索功能
https://opsx.alibaba.com/mirror
或者,直接下载相关安装包,然后安装
tigervnc-server-1.8.0-21

3. 为root用户设置vnc

复制配置模板文件为vncserver@:1.service
(注意路径是不一样的,直接复制粘贴命令即可)
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
修改vncserver@:1.service配置文件
vi /etc/systemd/system/vncserver\@\:1.service
删除底部原有代码,粘贴下列代码

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
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 || :'
[Install]
WantedBy=multi-user.target

4. 输入命令vncserver,配置登录密码

[root@ln10test system]# vncserver

5. 重新载入配置文件

[root@localhost ~]# systemctl daemon-reload

6. root账户下启动vncserver@:1.service服务,并设置开机自启

[root@localhost ~]# systemctl start vncserver@:1.service
[root@localhost ~]# systemctl enable vncserver@:1.service

7. 防火墙中放行vnc

[root@localhost ~]# firewall-cmd --permanent --add-service="vnc-server" --zone="public"
[root@localhost ~]# firewall-cmd –reload

8. 使用vncviewer,连接至服务器

192.168.1.88:1

机器名:1

错误处理

  • 启动服务时报错
    [root@localhost ~]# systemctl start vncserver@:1.service
    Job for vncserver@:1.service failed because the control process exited with error code. See
    "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
    解决办法
    删除/tmp/.X11-unix/ 目录,再次启用服务
    [root@localhost ~]# rm -rf /tmp/.X11-unix/*

    将配置文件中Type=forking 改为 Type=simple
    然后再次启动服务

  • 服务可以启动,不再报错,但是使用vnc客户端连接时报错
    The connection was refused by the computer
    解决方法
    登录root用户,重新初始化一下vncserver
    [root@ln10test system]# vncserver
    另,可以分别尝试使用机器名:1或者IP:1

posted on 2022-06-17 17:01  越野兔  阅读(576)  评论(0编辑  收藏  举报

导航