CentOS安装最新VNC与开启过程

本人看了无数的答案一个也没有匹配的,根本就打不开,配置文件一点点也不一样。
首先第一步都一样

#yum install tigervnc-server -y

第二步关闭防火墙

[root@localhost zhuofai]# systemctl stop firewalld.service #关闭防火墙

第三步复制配置文件

[root@localhost zhuofai]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service#复制配置文件

如果你的vncserver@:1.service文件配置形式是这样的那就大可不必与我的步骤保持一致了

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

[Service]
Type=forking
User=root

Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

或者这样的
带有《USER》的
最新版的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默认配置文件一个字都不需要修改

我们看一下最新VNC软件的指导文件怎么说的

Add a user mapping

With this you can map a user to a particular port. The mapping should be done in
/etc/tigervnc/vncserver.users configuration file. It should be pretty
straightforward once you open the file as there are some examples, but basically
the mapping is in form

:x=user

For example you can have

:1=test
:2=vncuser

Configure Xvnc options

To configure Xvnc parameters, you need to go to the same directory where you did
the user mapping and open vncserver-config-defaults configuration file. This
file is for the default Xvnc configuration and will be applied to every user
unless any of the following applies:

  • The user has its own configuration in $HOME/.vnc/config
  • The same option with different value is configured in
    vncserver-config-mandatory configuration file, which replaces the default
    configuration and has even a higher priority than the per-user configuration.
    This option is for system administrators when they want to force particular
    Xvnc options.

Format of the configuration file is also quite simple as the configuration is
in form of

option=value
option

for example

session=gnome
securitytypes=vncauth,tlsvnc
desktop=sandbox
geometry=2000x1200
localhost
alwaysshared

上面这一段意思是说我们要在文件/etc/tigervnc/vncserver.users建立一个mapping即键值对,jason数据形式,那么我们来配置一下看看

# TigerVNC User assignment
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=root
:2=zhuofai#我自己天上的后两行即当我直接运行

Start the Tigervnc server

Finally you can start the server using systemd service. To do so just run

$ systemctl start vncserver@:x

as root or

$ sudo systemctl start vncserver@:x

as a regular user in case it has permissions to run sudo. Don’t forget to
replace the :x by the actual number you configured in the user mapping file.
Following our example by running

$ systemctl start vncserver@:1

上面这几句话的意思是我们如何启动VNCserver服务

但是我尝试了一下不行
[root@localhost etc]# systemctl status vncserver@:2
● vncserver@:2.service - Remote desktop service (VNC)
   Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; disabled; vendor>
   Active: inactive (dead)#状态直接是失败

Jan 24 19:03:29 localhost.localdomain systemd[1]: Starting Remote desktop servi>
Jan 24 19:03:29 localhost.localdomain systemd[1]: Started Remote desktop servic>
Jan 24 19:03:31 localhost.localdomain systemd[1]: vncserver@:2.service: Succeed>

所以我们还是将文件复制到

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service#复制配置文件

先将配置文件复制到etc下面
这样我们再来启动该服务试试该服务启动直接成功,虽然我也不知道是为啥,唉,弄两天才会一点点

在这里插入图片描述
这样我们的服务算是就启动了
下面我们来尝试启动端口服务吧

[root@localhost etc]# vncserver :1#尝试启动

WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.
A VNC server is already running as :1
[root@localhost etc]# vncserver -list#查看列表发现根本就没有

WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.

TigerVNC server sessions:

X DISPLAY #	PROCESS ID
[root@localhost etc]# vncserver -kill :1#尝试杀死该进程,但是怎么也杀不掉,在网上也搜素了很多的教程,但是不管用

WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.

Can't find file /root/.vnc/localhost.localdomain:1.pid
You'll have to kill the Xvnc process manually

然后我突发奇想不如直接来运行这样的代码吧

[root@localhost etc]# vncserver :2#这时候我聪明的直接选择了运行2号端口

WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.

New 'localhost.localdomain:2 (zhuofai)' desktop is localhost.localdomain:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log

[root@localhost etc]# vncserver -list

WARNING: vncserver has been replaced by a systemd unit and is about to be removed in future releases.
Please read /usr/share/doc/tigervnc/HOWTO.md for more information.

TigerVNC server sessions:

X DISPLAY #	PROCESS ID
:2		7996#可以发现该端口启动成功了

然后查看自己的ip地址

[root@localhost etc]# ifconfig

在windows电脑上面打开输入
ip地址:2就可以链接了在这里插入图片描述

ok我们来看一下效果
在这里插入图片描述

这样就配置成功了
其实默认的呢VNC主要的两个配置文件一个就是vncservice@.service配置文件用来启动vnc服务的
第二个配置文件就是在/home/user目录下自动创建的.vnc文件夹下面的xstartup文件用来控制视图端的界面配置文件如下所示,都是默认配置文件,不用修改,知道就行了

#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
if [ -e /usr/bin/gnome-session ]; then
    vncserver -kill $DISPLAY
fi
~   

如果有人知道如何杀死我的vncservice@:1进程的,请私信告诉我,万分感谢,CSDN上面的答案杀死进程我已经尝试了不太行。

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值