Detailed explanation of VNC Server remote desktop configuration under CentOS7

VNC: VNC (Virtual Network Computing), is a screen sharing and remote operation software using RFB protocol. This software can send keyboard and mouse actions and real-time screen images through the network. VNC has nothing to do with the operating system, so it can be used across platforms, for example, you can use Windows to connect to a Linux computer, and vice versa. Even on a computer without a client program installed, as long as there is a browser that supports JAVA, it can be used. VNC includes two operating software, client and server.
VNC Server: The VNC server receives the connection request of VNC Viewer and transfers the screen to the client. In this example, you need to install VNC Server
VNC Viewer on CentOS7 : VNC client to forward the keyboard and mouse actions to the server. In this example, you need to install Viewer on windows to connect to a remote Linux server

1. If the current system does not have a desktop environment, you need to install the desktop environment first.
1. Update the system
---------------------------------------------- -----------------------------------------------
[root @ CentOS7 ~] # yum update ## To avoid some unexpected errors in the system, it is best to update yum to the latest, there is business running in the production environment, it is not recommended to update
------------------ -------------------------------------------------- -------------------------

2. Install the GNOME Desktop graphical desktop service
------------------------------------------ -------------------------------------------------- -
[root @ CentOS7 ~] # yum groupinstall "GNOME Desktop"
------------------------------------ -------------------------------------------------- -------

3. Check the system operation mode
-------------------------------------------- -------------------------------------------------
[ root @ CentOS7 ~] # systemctl get-default
---------------------------------------- -------------------------------------------------- ---

4. Switch to desktop operating mode
------------------------------------- --------------------------------------------------
[root @ CentOS7 ~] # systemctl set-default graphical.target
------------------------------------ -------------------------------------------------- -------

5. Start the desktop mode
--------------------------------------------- ------------------------------------------------
[root @ CentOS7 ~] # init 5
------------------------------------------- --------------------------------------------------


2. VNC configuration

1. Install vnc, CentOS7 uses tigervnc software by default to provide vnc service
------------------------------------- -------------------------------------------------- ------
[root @ CentOS7 ~] # yum install tigervnc-server
-------------------------------- -------------------------------------------------- -----------

2. Start the VNC service
Use the vncserver command to start the VNC service, the command format is "vncserver: desktop number", where "desktop number" is represented by "number", each user connection needs to occupy 1 desktop
startup number 1 desktop Examples are as follows
------------------------------------------------ ---------------------------------------------
[laopi @ ​​CentOS7 ~ ] $ vncserver: 1

You will require a password to access your desktops.

Password: ## Login to the vnc password, you can use the vncpasswd command to change the password in the future
Verify: ## Re-enter the vnc password
Would you like to enter a view-only password (y / n)? N ## Do you want to view only the user Password, here is not set
A view-only password is not used

New 'CentOS77:1 (laopi)' desktop is CentOS7:1

Creating default startup script /home/laopi/.vnc/xstartup
Creating default config /home/laopi/.vnc/config
Starting applications specified in /home/laopi/.vnc/xstartup
Log file is /home/laopi/.vnc/CentOS7 : 1.log
---------------------------------------------- -----------------------------------------------
Command execution It is executed under the laopi user who needs to log in remotely, and it is also the first time. The .vnc subdirectory and corresponding configuration file will be generated in the user's home directory (/ home / laopi /), and a password is required ( vncviewer end uses this user's access password), the password is encrypted and stored in the user's home directory in the .vnc subdirectory (/home/laopi/.vnc/passwd); at the same time in the user's home directory. The xstartup configuration file (/home/laopi/.vnc/xstartup) is automatically created for users, and the configuration information in this file is read each time the VNC service is started. The above is to add the access rights of ordinary users through VNC. If you want to add the access rights of other users, you need to perform the above operations at the corresponding user command prompt (such as test users also need to execute [test @ localhost ~] $ vncserver: 1 in Generate the corresponding .vnc subdirectory under the corresponding main directory). Access password changes for different users also need to be operated at the corresponding command prompt.
There is also a "CentOS7: 1.pid" file in the /home/laopi/.vnc/ directory. This file records the process number of the corresponding operating system after starting VNC. It is used to accurately locate the process number when stopping the VNC service.

3, port number and number of the desktop using VNC service relationship
VNC port number and the number of services used in relation to the desktop, VNC uses TCP port from the beginning of 5900, following correspondence between
the desktop number "1" ---- port number is 5901
Desktop The number is "2" ---- The port number is 5902 The
desktop number is "3" ---- The port number is 5903
.......
Based on the above introduction, if the firewall function is enabled in Linux, you need to manually open it The corresponding port.

4. Firewall settings, here I will rudely turn off the firewall

-------------------------------------------------- -------------------------------------------
[laopi @ ​​CentOS7 ~] # systemctl stop firewalld.service ## Stop firewall
[laopi @ ​​CentOS7 ~] # systemctl disable firewalld.service ## Forbid firewall to start

---------------------------------------------------------------------------------------------

5. Test VNC service, through RealVNC Viewer client software

Set login information

Log in

 

After successful login, enter the user name and password of the system to log in

 

Three, configure multiple desktops
can use the following method to start multiple desktops VNC
vncserver: 1
vncserver: 2
vncserver: 3
......
But this manual start method will be invalid after the server is restarted, therefore, the following describes how to make the system Automatically manage the VNC of multiple desktops by creating a Systemd Unit file.
The format of the file is: vncserver @: desktop number.service, the Unit file is convenient for quick start, stop, restart service

1. Create Systemd Unit files for laopi users. (The first user vncserver @: 1.service, the second user vncserver @: 2.service, and so on), can be created by copying the template file
-------------- -------------------------------------------------- -----------------------------
[root @ CentOS7 ~] # cp /lib/systemd/system/[email protected] / etc /systemd/system/vncserver@:1.service ## Requires root user operation
--------------------------------- -------------------------------------------------- ----------

3. Modify the /etc/systemd/system/vncserver@:1.service file. The copied file is a template file. Replace the <user> in the file to the user who needs to log in. The type is changed from the default forking to simple, here If you don't change the later startup, you will get an error
------------------------------------------ -------------------------------------------------- -
[user1 @ localhost ~] $ vim /etc/systemd/system/vncserver\@\:1.service
[Unit]
Description = Remote desktop service (VNC)
After = syslog.target network.target
[Service]
Type = simple #
#Here the forking is changed to simple ExecStartPre = / bin / sh -c '/ usr / bin / vncserver -kill% i> / dev / null 2> & 1 ||:'
ExecStart = / usr / sbin / runuser -l laopi- c "/ usr / bin / vncserver% i" ## Here <user> is changed to the user who needs to log in laopi
PIDFile = / home / laopi / .vnc /% H% i.pid ## here will be <user>Change to the user who needs to log in laopi
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
---------------------------------------------------------------------------------------------

3、刷新systemctl
---------------------------------------------------------------------------------------------
[root@CentOS7 ~]# systemctl daemon-reload
---------------------------------------------------------------------------------------------

4. Start the service
---------------------------------------------- -----------------------------------------------
[root @ CentOS7 ~] # systemctl start vncserver @: 1.service #Start
------------------------------------ -------------------------------------------------- -------
If the server fails to start as follows:
[root @ CentOS7 ~] # 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.
-------------------------------- -------------------------------------------------- ----------- The
above error is most likely that the Type has not been changed from the default forking to simple, restart the service after the change, and restart it a few times once it is not easy to use, because of this I wasted a lot For half a day, many articles do not need to change this, but I only changed this option under CentOS 7.7 to use it. I do n’t know why.
This method is solved: delete the /tmp/.X11-unix/ directory and enable it again. This is just a record without verification.

5. Set the service to start
-------------------------------------------- -------------------------------------------------
[ root @ CentOS7 ~] # systemctl enable vncserver @: 1.service
------------------------------------ -------------------------------------------------- -------

6. Common options
---------------------------------------------- -----------------------------------------------
systemctl stop vncserver @: 1.service #Close
systemctl restart vncserver @: 1.service #Restart
--------------------------------- -------------------------------------------------- ----------

7. View the status of the server

 

The above status is normal, if not, please check

 

Note: After the above configuration is completed, restart the system. When I often look at the service of vncserver @: 1.service, the status is abnormal, but the connection is still available. After restarting the service, the status is normal. I do n’t know what the reason is. Font error

 

 

 reference:

http://blog.itpub.net/31559985/viewspace-2674525/

https://blog.51cto.com/shaonian/2090283

 

Guess you like

Origin www.cnblogs.com/pipci/p/12731317.html
Recommended