Centos installation and configuration vnc

Purpose, windows host can remotely access centos host. Of course, as long as the vnc client is installed, it can be accessed.

  1. Check if vnc is installed on centos
[root@localhost ~]# rpm -qa  |grep vnc
tigervnc-icons-1.8.0-19.el7.noarch
tigervnc-server-minimal-1.8.0-13.el7.x86_64
gtk-vnc2-0.7.0-3.el7.x86_64
gvnc-0.7.0-3.el7.x86_64
tigervnc-1.8.0-19.el7.x86_64
tigervnc-license-1.8.0-13.el7.noarch
tigervnc-server-1.8.0-19.el7.x86_64
  1. If there is no vnc-server, the installation command is as follows
yum -y install tigervnc-server
  1. Configuration
    Open /lib/systemd/system/[email protected]
# 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`

Follow the above method to do
3.1 Copy configuration file, 1 this is the display number, 2 3 4 etc. are also OK, just the identification

cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:1.service

3.2 Replace username
If the user is root, replace it with root
vim /lib/systemd/system/vncserver@:1.service

[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 root %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

3.3 Set password, set automatic start service, run service

vncpasswd 
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
  1. Client connection xxxx:1, enter the connection password, and perform a connection test

  2. If you can't connect to vnc, it is probably blocked by the firewall, or shut down the firewall violently. Either configure the following, the operation is as follows, it is recommended.

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=vnc-server
success
[root@localhost ~]# firewall-cmd --reload

Guess you like

Origin blog.csdn.net/niu91/article/details/109528621