Article directory
The minimal version installed by default (that is, without a graphical interface) is installed by default in the general server installation system, so it is generally ssh
operated in the form of commands after connecting directly through the remote. For the development environment, or those who need to look at graphics (for example, I do image processing, I need to view images frequently during the development process, and for example, if I want to use IDE development, which must also require a graphical interface), having a graphical interface can It is convenient for us to quickly develop and verify the results. It is not recommended to install a graphical interface in a formal environment . The more common method is to install a graphical interface on the server, and then use a VNC
remote connection (note that this is mainly for servers that require remote connection. If it is a physical machine that you use, you can directly install the full version with a graphical interface).
Install GUI
Environment configuration operations are all performed root
under the user:
- update system
yum upgrade -y
- Update the installation dependency environment, otherwise an error will be reported when installing the graphical interface later
check error: file /boot/efi/EFI/centos from install of fwupdate-efi-12-5.e17.centos.x86_64 conflicts with file from package grub2-common-1:2.02-0.64.el7.centos.noarch
yum update grub2-common
yum install fwupdate-efi
- Install GUI
yum -y groupinstall "GNOME Desktop" "Graphical Administration Tools"
- reboot
reboot
Install VNC
- Install
tigervnc-server
yum install -y tigervnc-server
The version number I installed is:tigervnc-server.x86_64 0:1.8.0-22.el7
Configure VNC for root user
The current user is the root
user
- Copy and rename the vnc startup file to
/etc/systemd/system/
[root@centos ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncsercer@:1.service
- Set
root
VNC login password
[root@centos ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
- Open the file you just copied
vi /etc/systemd/system/vncserver@:1.service
After opening, the content is as follows (unmodified):
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/[email protected]
# 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=simple
# 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 <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
According to the prompt , you Replace <USER> with the actual user name
only need to modify <USER>
it root
to:
ExecStart=/usr/bin/vncserver_wrapper root %i
- Then turn off the firewall
systemctl stop firewalld
systemctl disable firewalld
- Start the vnc service and check the status
systemctl daemon-reload
systemctl start vncserver@:1.service
systemctl status vncserver@:1.service
Open successfully:
[root@centos ~]# 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 2021-01-18 17:59:52 CST; 6s ago
Process: 4691 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 4696 (vncserver_wrapp)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
├─4696 /bin/sh /usr/bin/vncserver_wrapper root :1
└─4919 sleep 0.1
- Set up to start automatically
systemctl enable vncserver@:1.service
- If you need to change the resolution, edit the
config
file:
vi ~/.vnc/config
Set geometry
to the resolution you want to use:
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared
- Restart the vnc service:
systemctl restart vncserver@:1.service
Configure VNC for custom user
- Enter the custom user account (here takes the user
centos
as an example)
su centos
Note that it is now under a non-root user
- Set
centos
the user's VNC login password
[centos@centos ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
- Log
root
in to the account again, the following configuration requires permissions
su
- Copy and rename the vnc startup file to
/etc/systemd/system/
(noteroot
the one just used:1
here:2
)
[root@centos ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncsercer@:2.service
- Open the file you just copied
vi /etc/systemd/system/vncserver@:2.service
Also <USER>
change it to the current username centos
:
ExecStart=/usr/bin/vncserver_wrapper centos %i
- Start the vnc service and check the status
systemctl daemon-reload
systemctl start vncserver@:2.service
systemctl status vncserver@:2.service
Open successfully:
[root@centos ~]# systemctl status vncserver@:2.service
● vncserver@:2.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:2.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2021-01-19 09:34:52 CST; 6s ago
Process: 14877 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 14881 (vncserver_wrapp)
CGroup: /system.slice/system-vncserver.slice/vncserver@:2.service
├─14881 /bin/sh /usr/bin/vncserver_wrapper centos :2
└─15221 sleep 0.1
- Set up to start automatically
systemctl enable vncserver@:2.service
- If you need to modify the resolution, edit the
config
file (note that this is to modify the corresponding user directoryconfig
):
vi /home/centos/.vnc/config
Set geometry
to the resolution you want to use:
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared
- Restart the vnc service:
systemctl restart vncserver@:2.service
Remote connection VNC graphical interface
If you connect to VNC remotely, you can use the VNC Viewer
tool and download it directly from the official website. It basically supports all major operating systems. The following is an example of the Windows client. After the installation is complete, click File
-> New connection
Create a connection in the upper left corner. Enter the user ID VNC Server
that needs to be connected to the remote host ip
+ + in. :
For example , if root
the user's ID is just now 1
, enter it ip:1
, and if you want to connect a custom user centos
, enter it ip:2
. Clicking OK
it will prompt you to enter a password, which is the corresponding user password created above, and then you can connect and log in.
Show after login:
VNC fails to start after abnormal interruption
Today, the connection to VNC was suddenly interrupted abnormally, and restarting the service did not help (after restarting the service, it was systemctl status
found that it exited immediately after the successful startup through the command view). Then ps -ef | grep vnc
I found a bunch of zombie processes through the instructions, which were caused by abnormal interruption during guessing, and then all were killed, and then restarted the service to be able to use normally.