Centos8.0+VNC Server

本文详细介绍了如何在CentOS8上通过yum安装图形界面并配置VNCServer。步骤包括安装Server with GUI,然后安装并配置VNCServer,设置防火墙规则,启动服务,并解决VNC连接超时问题。在安全组中开启5901端口后,使用vncviewer成功建立连接。
摘要由CSDN通过智能技术生成

图形化界面安装

yum groupinstall -y “Server with GUI”

VNC Server安装及配置

安装

yum install tigervnc-server -y

配置

首先是对防火墙的设置,查看防火墙状态并将5901端口(默认5901)开放

sudo firewall-cmd --zone=public --add-port=5901/tcp --permanent

启动防火墙并查看防火墙状态开放5901端口
5901端口开放后可以查看5901端口状态

firewall-cmd --query-port=5901/tcp

5901端口已开放
设置5901端口开放后,要进行reload

firewall-cmd --reload

随后复制配置文件

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

网上很多文章提到还要修改@:1.service的配置文件,但如果像我一样,配置文件内容如下所示,则不需要修改,这是最新版的VNC配置文件

# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "nolisten=tcp" to prevent X connections to your VNC server via TCP.
#
# Use "localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


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

[Service]
Type=forking
ExecStart=/usr/libexec/vncsession-start %i
PIDFile=/run/vncsession-%i.pid
SELinuxContext=system_u:system_r:vnc_session_t:s0

[Install]
WantedBy=multi-user.target

根据VNC指导文件说明,还需要对/etc/tigervnc/vncserver.users文件添加一个键值对:1=root
在这里插入图片描述
随后启动vncserver

vncserver :1

查看vncserver list看看启动了没

vncserver -list

在这里插入图片描述
到这一步其实server端就已经ok了,但是vnc viewer一直time out,找了很多并没有找到有效的解答,突发奇想前面关于端口号的设置是不是要在ECS的安全组里设置一下?将入方向和出方向都设置一下5901号端口,再次用vnc viewer连接,果然成功了。

vnc viewer连接时,以下面这种形式连接
ip地址:1

另外一开始在配置过程中,用过这种方式启动

systemctl start vncserver@:1.service

systemctl status vncserver@:1.service
查看1.service的状态,显示已经启动

但是查看list找不到这个进程

ps -ef | grep -i vnc | grep -v grep
查看所有vnc进程,找到该进程
通过kill -9 端口号结束该进程

再次启动vncserver,失败,根据提示要remove.Xl-lock文件和Xl文件

rm -f /tmp/.X1-lock
rm -f /tmp/.X11-unix/X1

再次启动vncserver,成功
其实上面是出现无法kill时,手动kill的过程
最后附连接成功图
连接成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值