Install VNC Server on CentOS 7

The operation process of this article is based on https://docs.oracle.com/cd/E52668_01/E54669/html/ol7-vnc-config.html

 

system version

 

$ uname -a

Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64

kernel

 

 

$ cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

The minimal installation mode was selected at the time of installation, so if you have already installed a system with a graphical interface, you can skip the X-Window installation below and install VNC Server directly

 

 

The following commands must be run with root privileges. To switch to root, or add the user who wants to execute the operation to sudo, prefix each command with sudo to indicate that the current user temporarily has the same execution authority as root.

# visudo

Find "root ALL=(ALL) ALL" and add a line below: XXX ALL=(ALL) ALL, where XXX is the username

Well, without further ado, let's start installing VNC Server

 

1 First you need to install X-Window

 

# yum check-update

# yum groupinstall "X Window System"

# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

Or directly the following command

# yum groupinstall -y "GNOME Desktop"

 

 

2 Install the VNC server (need to have a network, if there is no network, set the yum source as a CD installation disk)

 

# yun list|grep vnc #View related vnc package information under yum

# rpm -qa|grep vnc #Check if vnc is installed

# yum install tigervnc-server -y # Installation of the CentOS/RHEL 6 starting version

If it is CentOS/RHEL 5, execute the following command

# yum install vnc-server -y

 

 

3 Set the vncpasswd password

# vncpasswd

.... Enter the user's login password, if the command does not respond, it is recommended to reinstall vncserver

If you set the login password of a common user, please switch to the common user first, and then execute vncpasswd to set it.

 

Here to popularize the relevant knowledge points of vnc

# systemctl status vncserver@:.service

● vncserver@:.service - Remote desktop service (VNC)

   Loaded: loaded (/usr/lib/systemd/system/[email protected]; disabled; vendor preset: disabled)

   Active: inactive (dead)

# systemctl is-enabled [email protected]

disabled

Why is it unavailable? This is because each user is an independent instance under the VNC daemon service thread; on the other hand, VNC cannot only run a single thread to process each user request.

Every time a user connects to VNC, VNC starts a new daemon instance. CentOS 7 uses the systemd daemon to initialize other services. Each service installed through yum runs under systemd, and the respective service unit module files are stored in the /lib/systemd/system directory.

A link to related services is stored in the /etc/systemd/system/ directory. When boot starts, threads can be automatically started according to the link.

So in this case you can see the file with the following command

# ls -l /lib/systemd/system/vnc*

-rw-r--r--. 1 root root 1738 Apr  1  2016 /lib/systemd/system/[email protected]

# ls -l /etc/systemd/system/*.wants/vnc*

ls: cannot access /etc/systemd/system/*.wants/vnc.*: No such file ore direcotry

So you can directly copy the [email protected] file as the configuration file of the respective instance

Referenced from https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-remote-access-for-the-gnome-desktop-on-centos-7

 

4 Create a VNC configuration file

After the vncserver is installed normally, the file /lib/systemd/system/[email protected] has content. If the content of the file is empty, it is recommended to reinstall vncserver to reduce unnecessary trouble.

Here vncserver@:1.service is the login configuration file of the root user, and vncserver@:2.service is the configuration file of the ordinary user

 

# cp /lib/systemd/system/[email protected] \

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

# cp /lib/systemd/system/[email protected] \

/etc/systemd/system/vncserver@:2.service

 

# vi /etc/systemd/vncserver@:1.service

# The vncserver service unit file

#

# Quick HowTo:

# 1. Copy this file to /etc/systemd/system/[email protected]

# 2. Edit <USER> and vncserver parameters appropriately

#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")

# 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/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"

PIDFile=/home/<USER>/.vnc/%H%i.pid

ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

 

[Install]

WantedBy=multi-user.target

Modify the red font above to the user name and home directory, then save it, and execute the following command to make it take effect

# systemctl daemon-reload

 

5 Start the VNCServer service

# systemctl start vncserver@\:1.service

Job for vncserver@:1.service failed because the control process exited with error code. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.

An error occurs, follow the error prompt and execute the following command

# systemctl status vncserver@\:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)

   Active: failed (Result: exit-code) since Mon 2016-11-21 20:34:40 CST; 1min 32s ago

  Process: 11295 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=1/FAILURE)

  Process: 11292 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

 

Nov 21 20:34:39 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

Nov 21 20:34:40 localhost.localdomain runuser[11295]: Password:

Nov 21 20:34:40 localhost.localdomain systemd[1]: vncserver@:1.service: control process exited, code=exited status=1

Nov 21 20:34:40 localhost.localdomain systemd[1]: Failed to start Remote desktop service (VNC).

Nov 21 20:34:40 localhost.localdomain systemd[1]: Unit vncserver@:1.service entered failed state.

Nov 21 20:34:40 localhost.localdomain systemd[1]: vncserver@:1.service failed.

Seeing the above error message, I noticed that the vncpasswd password of the root user has not been set yet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# vncspasswd #Set the root vncpasswd password

# su XXX

$ vncpasswd #Set     XXX's vncpasswd password

# systemctl start vncserver@\:1.service #Start vnc service

# systemctl stop vncserver@\:1.service #Close the vnc service

# systemctl status vncserver@\:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)

   Active: active (running) since Mon 2016-11-21 20:38:42 CST; 1min 55s ago

  Process: 11346 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)

  Process: 11343 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

 Main PID: 11367 (Xvnc)

   CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service

           ‣ 11367 /usr/bin/Xvnc :1 -desktop localhost.localdomain:1 (root) -auth /root/.Xauthority -geometry 1024x7...

 

Nov 21 20:38:39 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

Nov 21 20:38:42 localhost.localdomain systemd[1]: Started Remote desktop service (VNC).

Seeing this prompt and displaying active (running) indicates that the vncserver has been successfully started.

# systemctl enable vncserver@:1.service #Set self-start at boot

Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.

# systemctl disable vncserver@:1.service #Cancel self-start at boot

Removed symlink /etc/systemd/system/multi-user.target.wants/vncserver@:1.service.

Note: If you modify the configuration file, you must reload the configuration and restart the service

# systemctl daemon-reload

# systemctl restart vncserver@:1.service

 

6 Configure the firewall

Centos has used firewalld by default since 7. This is based on iptables. Although it has the core of iptables, the service of iptables is not installed.

# firewall-cmd --state #View the startup status of the firewall

running

# systemctl start firewalld #If the firewall is not started, start it, for network security

# firewall-cmd --zone=public --add-service=vnc-server --permanent #Permanently add the vnc-server service to the firewall

# firewall-cmd --zone=public --list-services

# firewall-cmd --zone=public --add-port=5901-5902/tcp --permanent #Permanently add the port to the firewall

success

# firewall-cmd --zone=public --list-ports #View which ports are open

# firewall-cmd --reload #Restart the firewall to make the previous settings take effect

7 Configure the VNC desktop (what GUI to launch according to your preferences) [optional]

# vi ~ / .vnc / xstartup

add at the end

startkde &

Start kde when set to link

# systemctl restart vncserver@\:1.service

 

8 Under Windows, install VNC Viewer, enter the correct IP address, window number and password, and you can remotely

Or a client program that uses an SSH channel, such as: PuTTY

Referenced from https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-remote-access-for-the-gnome-desktop-on-centos-7

 

In the process of using, the VNC interface sometimes does not respond, what should I do at this time?

Log in to the system through SSH, and then restart your VNC Server through the command

$ ls ~/.vnc/ #Check what your port number is

$ vncserver -kill :2 #End VNC service and remote desktop

$ vncserver :2 -geometry 1280x760

At this point, log in through VNC Viewer and try it, it should be OK

Note: vncserver can only be closed by the user who started it, even root cannot close vncserver opened by other users, unless the process is killed with the kill command

 

During the installation process, when installing with yum at the beginning, complete is displayed, but when configuring, it is found that the configuration file is empty. When setting up according to various tutorials mentioned on the Internet, various other problems also occur. At this time, it is necessary to consider Did you uninstall it and then reinstall it? The errors encountered during this process are:

# /bin/systemctl start vncserver.service#Start vncserver service 

appear:

Failed to start vncserver.service: Unit vncserver.service failed to load: No such file or directory.

# systemctl enable vncserver.service

appear:

Failed to execute operation: Access denied

# service vncserver status

Redirecting to /bin/systemctl status  vncserver.service

● vncserver.service

   Loaded: not-found (Reason: No such file or directory)

   Active: inactive (dead)

# systemctl status vncserver@:.service

● vncserver@:.service

   Loaded: masked (/usr/lib/systemd/system/[email protected]; masked; vendor preset: disabled)

   Active: inactive (dead)

# systemctl is-enabled [email protected]

masked

# systemctl enable vncserver@:1.service

The unit files have no [Install] section. They are not meant to be enabled

using systemctl.

Possible reasons for having this kind of units are:

1) A unit may be statically enabled by being symlinked from another unit's

   .wants/ or .requires/ directory.

2) A unit's purpose may be to act as a helper for some other unit which has

   a requirement dependency on it.

3) A unit may be started when needed via activation (socket, path, timer,

   D-Bus, udev, scripted systemctl call, ...).

http://lists.opensuse.org/opensuse-bugs/2013-11/msg04269.html

Mailinglist Archive: opensuse-bugs (5295 mails)

# systemctl start vncserver@:1.service

Job for vncserver@:1.service failed because a configured resource limit was exceeded. 

See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.

# systemctl -l status vncserver@:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; static; vendor preset: disabled)

   Active: failed (Result: resources) since Mon 2016-11-21 18:49:42 CST; 12min ago

  Process: 9809 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i -geometry 1280x760 (code=exited, status=0/SUCCESS)

  Process: 9804 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

 

Nov 21 18:49:42 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

Nov 21 18:49:42 localhost.localdomain systemd[1]: PID file /root/.vnc/localhost.localdomain:1,pid not readable (yet?) after start.

Nov 21 18:49:42 localhost.localdomain systemd[1]: Failed to start Remote desktop service (VNC).

Nov 21 18:49:42 localhost.localdomain systemd[1]: Unit vncserver@:1.service entered failed state.

Nov 21 18:49:42 localhost.localdomain systemd[1]: vncserver@:1.service failed.

# systemctl -l status vncserver@:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)

   Active: failed (Result: resources) since Mon 2016-11-21 18:49:42 CST; 40min ago

 

Nov 21 18:49:42 localhost.localdomain systemd[1]: vncserver@:1.service failed.

Nov 21 19:15:55 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:11] Unknown lvalue 'ExectStop' in section 'Service'

Nov 21 19:15:55 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:13] Unknown section 'install'. Ignoring.

Nov 21 19:20:35 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:11] Unknown lvalue 'ExectStop' in section 'Service'

Nov 21 19:20:35 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:13] Unknown section 'install'. Ignoring.

Nov 21 19:20:45 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:11] Unknown lvalue 'ExectStop' in section 'Service'

Nov 21 19:20:45 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:13] Unknown section 'install'. Ignoring.

Nov 21 19:21:10 localhost.localdomain systemd[1]: Stopped Remote desktop service (VNC).

Nov 21 19:21:22 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:11] Unknown lvalue 'ExectStop' in section 'Service'

Nov 21 19:21:22 localhost.localdomain systemd[1]: [/etc/systemd/system/vncserver@:1.service:13] Unknown section 'install'. Ignoring.

Warning: vncserver@:1.service changed on disk. Run 'systemctl daemon-reload' to reload units.

# journalctl -xe | grep vncserver

...

-- Subject: Unit vncserver@:1.service has begun start-up

-- Unit vncserver@:1.service has begun starting up.

-- Subject: Unit vncserver@:1.service has failed

-- Unit vncserver@:1.service has failed.

Nov 21 19:32:48 localhost.localdomain systemd[1]: Unit vncserver@:1.service entered failed state.

Nov 21 19:32:48 localhost.localdomain systemd[1]: vncserver@:1.service failed.

# systemctl -l status vncserver@:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)

   Active: failed (Result: resources) since Mon 2016-11-21 19:32:48 CST; 10min ago

 

Nov 21 19:32:47 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

Nov 21 19:32:48 localhost.localdomain systemd[1]: PID file /root/.vnc/localhost.localdomain:1,pid not readable (yet?) after start.

Nov 21 19:32:48 localhost.localdomain systemd[1]: Failed to start Remote desktop service (VNC).

Nov 21 19:32:48 localhost.localdomain systemd[1]: Unit vncserver@:1.service entered failed state.

Nov 21 19:32:48 localhost.localdomain systemd[1]: vncserver@:1.service failed.

# systemctl -l status vncserver@:1.service

● vncserver@:1.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)

   Active: failed (Result: resources) since Mon 2016-11-21 20:12:15 CST; 57s ago

  Process: 10931 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)

  Process: 10926 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

 

Nov 21 20:12:15 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

Nov 21 20:12:15 localhost.localdomain systemd[1]: PID file /root/.vnc/localhost.localdomain:1.pid not readable (yet?) after start.

Nov 21 20:12:15 localhost.localdomain systemd[1]: Failed to start Remote desktop service (VNC).

Nov 21 20:12:15 localhost.localdomain systemd[1]: Unit vncserver@:1.service entered failed state.

Nov 21 20:12:15 localhost.localdomain systemd[1]: vncserver@:1.service failed.

 

 

# journalctl -xn|grep vncserver #This can view the specific error message

# netstat -tulnp #View vncserver startup status

 

In the process of setting, you should read more error messages, so that you can better prescribe the right medicine and solve the problem faster.

 

uninstall vncserver

# yum erase tigervnc*

# rpm -qa|grep vnc #Check whether to uninstall

 

The above are the various errors that I encountered when installing VNC Server, but in the end I solved it by my own efforts. I am really happy from the bottom of my heart~~~~, the above opinions are purely personal opinions, if there are any shortcomings , hope to correct, thank you :-)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395625&siteId=291194637