Centos8.0+VNC Server
图形化界面安装
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端口状态
firewall-cmd --query-port=5901/tcp
设置5901端口开放后,要进行reload
firewall-cmd --reload
随后复制配置文件
cp /lib/systemd/system/[email protected] /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的过程
最后附连接成功图