1. RHEL
7安装TigerVNC Server
本文介绍如何在RHEL
7上安装VNC Server,以便远程访问。
2.
安装TigerVNC Server
建议使用root用户安装,-y代表直接安装
#yum
install -y tigervnc-server
3. 配置VNC
Service
以下方法是新方法,以前是要配置/etc/sysconfig/vncservers,现在第一步是将默认提供的文件复制到/etc/systemd/system,命令如下
#cp
/lib/systemd/system/vncserver@.service
/etc/systemd/system/vncserver@:1.service
接下来修改该配置文件
#vim
/etc/systemd/system/vncserver@:1.service
将其中替换为你想要的用户名,我这里是root,更改Type类型为simple,所有内容如下:
# 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=simple
# Clean any
existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c
'/usr/bin/vncserver -kill %i > /dev/null 2>&1 ||
:'
ExecStart=/sbin/runuser -l
root -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh -c
'/usr/bin/vncserver -kill %i > /dev/null 2>&1 ||
:'
[Install]
WantedBy=multi-user.target
保存文件并退出vim,重新加载配置
#systemctl
daemon-reload
也可以设置成开机启动
#systemctl
enable vncserver@:1.service
4.
修改防火墙
首先判断firewalld是否启动,输入以下命令判断
#firewall-cmd
--state
如果启动应该输出
running
如果是not
running,执行下面命令
#systemctl
start firewalld
添加端口号5901-5905
#firewall-cmd --permanent
--zone=public --add-port=5901-5905/tcp
重新加载防火墙
#firewall-cmd
--reload
可以使用下面命令查看端口号是否被加入
#firewall-cmd
--list-all-zones
5.
设置VNC密码
用root用户名登录到服务器,执行下面命令
#vncserver
终端会提示你输入密码,如下
You will
require a password to access your desktops.
Password:
Verify:
New
'vms001.example.com:1 (root)' desktop is
vms001.example.com:1
Creating
default startup script /root/.vnc/xstartup
Starting
applications specified in /root/.vnc/xstartup
Log file is
/root/.vnc/vms001.example.com:1.log
如果想修改密码,可以使用vncpasswd。现在已经有一个vnc服务在运行了,但我们需要使用刚刚配置的服务来启动,所以我们需要先杀死刚刚的vnc服务,使用下面命令。
#vncserver
-kill :1
接下来,重启我们配置的服务
#systemctl
daemon-reload
#systemctl
restart vncserver@:1.service
使用下面命令查看该服务是否正确运行
#systemctl
status vncserver@:1.service -l
如果正确启动,输出应为
vncserver@:1.service -
Remote desktop service (VNC)
Loaded: loaded
(/etc/systemd/system/vncserver@:1.service; enabled)
Active: inactive (dead) since 四 2018-08-23
15:40:31 CST; 8s ago
Process:
13103 ExecStop=/bin/sh -c /usr/bin/vncserver -kill %i >
/dev/null 2>&1 || : (code=exited,
status=0/SUCCESS)
Process:
13019 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i
(code=exited, status=0/SUCCESS)
Process:
13016 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i >
/dev/null 2>&1 || : (code=exited,
status=0/SUCCESS)
Main PID:
13019 (code=exited, status=0/SUCCESS)
8月 23
15:40:27 vms001.example.com systemd[1]: Starting Remote desktop
service (VNC)...
8月 23
15:40:27 vms001.example.com systemd[1]: Started Remote desktop
service (VNC).
如果想配置多用户同时访问,需要将上面vncserver@:1.service,改为vncserver@:2.service,然后配置其中用户名、分辨率参数,再按我的步骤走一遍就可以了。
参考链接:https://blog.csdn.net/u010638969/article/details/51244933