喵星之旅-狂奔的兔子-centos7安装vnc服务端(tigervnc)

服务器系统为含桌面的centos7,直接切换root用户安装。

 

1、安装服务端

yum install tigervnc-server -y

通过rpm -qa|grep tigervnc-server验证结果为两条记录

 

2、创建配置文件

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

 

3、编辑配置文件

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

结果如下:

 

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Replace <USER> with the actual user name and edit vncserver
#    parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# 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

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
#ExecStart=/usr/bin/vncserver_wrapper bunny %i
ExecStart=/usr/sbin/runuser -l bunny -c "/usr/bin/vncserver %i"
PIDFile=/home/bunny/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

 

 

 

其中bunny为正常使用的用户名

 

4、设置密码

vncpasswd

两套密码,一套可以控制(必须配置),一套只读(可选,需要讯问时选择y)


 

5刷新systemctl

systemctl daemon-reload


6、开放防火墙的59005901端口

firewall-cmd --zone=public --add-port=5900/tcp --permanent

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


7、(慎用、如果用的话千万别错)如果已经可以使用就不需要这步,关闭SELinux,编辑/etc/selinux/config 文件:

vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

 

8、启动服务(正常使用用户操作即可)

(1)启动、关闭(虚拟会话桌面,第一次连接需要可操作用户配置一下,不同于本机操作页面,是新建的会话):

systemctl start vncserver@:1.service #启动
systemctl stop vncserver@:1.service #关闭
systemctl restart vncserver@:1.service #重启

(2)分享当前 X11 桌面会话 (使用客户端连接,地址为ip地址,连接的桌面就是使用者当前桌面)

x0vncserver PasswordFile=/home/bunny/.vnc/passwd display=':0.0'

 

posted @ 2020-08-28 15:28  喵星兔  阅读(571)  评论(0编辑  收藏  举报