Instructions for VNC Installation and Configuration under CentOS7
table of Contents
- Vnc overview 2
- Vnc installation and deployment 2
2.1 Environment check 2
2.2 Graphical desktop installation 3
2.3 Vnc software installation 4 - Vnc Configuration 5
3.1 Key Documents Need to Know 5
3.2 Vnc Configuration File Configuration 5
3.3 Establishing VNC User 7 - Vncserver service running 7
4.1 vncserver startup 7
4.2 vncserver self-start 9
4.3 Vncserver shutdown 9 - Firewall configuration 9
- Vnc client installation steps 10
6.1 Software installation 10
6.2 Environment settings 14 - Vnc connection black screen solution 15
7.1 Modify xstartup file 15
7.2 Set xstartup file permissions 16
7.3 Configure vncservers file 16
7.4 Restart host 16
1. Vnc overview
VNC: virtual network console virtual network console. It is a commonly used remote control tool software.
VNC includes the following four commands: vncserver, vncviewer, vncpassword and vncconnect.
VNCclient connects to the vnc server remotely through the VNC protocol for desktop sharing and interaction;
commonly used VNC software mainly includes: RealVNC, TightVNC, TigerVNC, UltraVNC.
RealVNC: developed by some members of the VNC team, divided into full-featured commercial version and free version;
TightVNC: streamlined, less bandwidth;
TigerVNC: is a high-speed version of VNC based on RealVNC 4 and X.org code base;
UltraVNC: can be combined Active Directory and NTLM account and password authentication, but only the Windows version.
VNC uses TCP port 5900 by default.
The port number used by the VNC service is related to the desktop number. The port starts from 5900. The corresponding relationship is as follows:
desktop number is "1" ---- port number is 5901
desktop number is "2" ---- port number is 5902
desktop number Is "3" ---- port number is 5903
…… The
TCP port of the Java-based VNC client program web service starts from 5800, and the corresponding relationship is as follows:
desktop number is "1" ---- port number is 5801
desktop number is " 2" ---- The port number is 5802 The
desktop number is "3" ---- The port number is 5803
2.Vnc 安装部署
2.1 Environment check
Before installation, you need to check the system version and whether the vnc software has been installed.
Moreover, because the client connects to the desktop of the server through vnc, Linux needs to install the graphical desktop before installing and deploying the VNC server.
[root@localhost ~]# cat /etc/redhat-release #Check the system version
[root@localhost ~]# rpm -qa | grep vnc #Check if vnc is installed
[root@localhost ~]# systemctl get-default #Check the current run level
[root@localhost ~]# yum grouplist #Check the installable group
Available Environment Groups:
GNOME Desktop
Available Groups:
Graphical Administration Tools
Check to see that the GNOME desktop and corresponding graphical management tools are supported.
2.2 Graphical desktop installation
Use the yum command to start installing GNOME packages and graphical management tools.
[root@localhost ~]# yum groupinstall "GNOME Desktop"
[root@localhost ~]# yum groupinstall "Graphical Administration Tools"
After installation, check again, the following results indicate that the graphical desktop has been installed OK:
[root@localhost ~]# yum grouplist
Installed Environment Groups:
GNOME Desktop
Installed Groups:
Graphical Administration Tools
2.3 Vnc software installation After the
graphical desktop is installed, install the tightVNC software package through yum:
[root@localhost ~]# yum isntall nvc-server
After installation, check the vnc installation package again
[root@localhost ~]# rpm -qa |grep vnc
3.
After the Vnc configuration is installed, don't rush to start it, first understand several basic configuration files of vnc.
3.1 Key documents to know
/lib/systemd/system/[email protected] #vnc configuration file
/usr/lib/systemd/system/[email protected] #vnc configuration file
/etc/systemd/system/vncserver@:N. service #vnc configuration file, N stands for number
/etc/sysconfig/vncservers #vnc user configuration file
/usr/bin/vncconfig
/usr/bin/vncpasswd #vnc user password change process
/usr/bin/vncserver #vnc service process
3.2 Vnc configuration file configuration
Open the /lib/systemd/system/[email protected] file and configure according to the prompts:
Follow the above prompt:
Step 1: Copy the /lib/systemd/system/[email protected] file to the /etc/systemd/system/ directory and name it vncserver@:1.service
#cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
第二步:配置 /etc/systemd/system/vncserver@:1.service文件
[root@localhost system]# vim /etc/systemd/system/vncserver@:1.service
[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
Step 3: Reload the systemd service . After the [email protected] file is configured, you need to reload the systemd service.
[root@localhost system]# systemctl daemon-reload
Step 4: Start the vncserver service.
[root@localhost system]# systemctl start vncserver@:1.service
Note: If multiple users need to connect to the vnc server through VNC, repeat the above steps to create multiple vncserver@:N.service files and run them.
3.3 Create a VNC user
Add a new user and set a password:
[root@localhost system]# useradd user
[root@localhost system]# passwd user
Log in as the user just created:
[root@localhost system]# su-user
[user@localhost ~]$ vncpasswd
As shown in the figure above, you can set two passwords for the vnc account. The vncpasswd password has normal user permissions;
use the view-only password to connect to vnc, and only have desktop browsing permissions.
After setting the vncpasswd password, a .vnc file will be automatically created in the account's home directory:
4. Vncserver service running
4.1 vncserver startup
can enable the corresponding vncserver service for different vnc users.
[root@localhost ~]# systemctl start vncserver@:1.service
[root@localhost ~]# systemctl status vncserver@:1.service
After enabling the service, check the service status again. As can be seen from the above figure, vncserver@:1.service has loaded the /etc/systemd/system/vncserver@:1.service file.
Check the listening port:
[root@localhost ~]# netstat -nutpl |grep vnc
[root@localhost ~]# ps -ef |grep vnc
View log information:
A corresponding log file will be generated under each vnc user directory
[root@localhost ~]# tail -f /home/user/.vnc/localhost.localdomain\:1.log
4.2vncserver self-startup
[root@localhost ~]# systemctl enable vncserver@:1.service
will establish a corresponding ln connection under /etc/systemd/system/multi-user.target.wants/ after the systemctl enable vncserver@:1.service command is executed. The vncserver@:1.service process will be automatically loaded.
4.3 Vncserver shutdown br/>Use the following command to shut down the vncserver@:1.service process, only shut down the vnc service of this user, and will not affect the vnc connection of other users.
[root@localhost ~]# systemctl stop vncserver@:1.service
5. After the firewall configuration is
all configured, the service is started, and the firewall needs to be opened for the service.
It can be released for the port or for the service.
The default port of the firewall is TCP 5900-590N, the first vnc user uses TCP 5901, the second vnc user uses TCP 5902, and so on.
[root@localhost~]# firewall-cmd --zone=public --add-port=5901/tcp --permanent
If you are worried about port changes, you can also let the service open:
[root@localhost ~]# firewall-cmd --add-service vnc-server --permanent
After the service is released, you need to reload the firewall to make the changes take effect:
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# firewall-cmd --list-services
6. Vnc client installation steps
6.1 Software installation
You can download the corresponding software from the official website according to your hobbies. I use realvnc viewer here.
First enter the official website: https://www.realvnc.com/en/connect/download/viewer/
After downloading, double-click VNC-Viewer-6.19.715-Windows.exe to start installation:
select voice:
Click Next:
Accept the license agreement:
Select installation components:
Click to install:
After installation, enter the installation directory C:\Program Files\RealVNC\VNC Viewer to open the vncviewer program:
Enter the connected vncserver IP address and port:
The vncviewer will automatically retain the connection just established:
Double-click to open, enter the user's vnc connection password:
6.2 Environment settings
If you log in for the first time, you also need to configure the basic desktop environment and
language settings:
Location service settings:
Online account, you can skip it directly, you can set it if necessary in the future:
After configuration, click to start application:
At this point, VNC has been basically configured and can be used officially.
7. Vnc connection black screen solution
After connecting through vncviewer, a black screen appears, the main solution:
7.1 Modify the xstartup file and
enter the xsartup file in the vnc user home directory
[root@localhost ~]# vim /home/user/.vnc/xstartup
# !/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
#/etc/X11/xinit/xinitrc
#vncserver -kill $DISPLAY
exec /etc/X11/xinit/xinitrc
[-x /etc/vnc/xstartup] && exec /etc/vnc/ xstartup
[-r $HOME/ .Xresources ] && xrdb $HOME/ .Xresources
xsetroot -solid grey
vncconfig
-iconic & #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
gnome-session &
7.2 Set xstartup file permissions
Xstartup permissions default to
You can set the permissions to 777
[root@localhost ~]# chmod 777 /home/user/.vnc/xstartup
7.3配置vncservers文件
[root@localhost ~]# vim /etc/sysconfig/vncservers
#THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
VNCSERVERS=”1:root”
VNCSERVERARGS[1]="-geometry 800×600"
7.4 Restart the host
After the configuration is complete, restart the service. If it still fails, restart the host.
Zabbix5.0 enterprise-level distributed monitoring system: Intensive talk and enterprise applications:
Zabbix5.0 enterprise-level distributed monitoring system