Without going into too much introduction, the following will directly record the operation record of installing and configuring vncserver under the centos7 system
1 ) Turn off the firewall
The centos firewall is firewalld, the command to turn off the firewall
[ root@localhost ~]# systemctl stop firewalld.service #stop firewall
[ root@localhost ~]# systemctl disable firewalld.service #Prohibit firewall from booting up
[ root@localhost ~]# setenforce 0
[ root@localhost ~]# getenforce
[ root@localhost ~]# cat /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted
2 )install software:
[ root@localhost ~]# yum update
[ root@localhost ~]# yum groupinstall "GNOME Desktop" "X Window System" "Desktop"
[ root@localhost ~]# yum install tigervnc-server tigervnc vnc vnc-server
3 ) Configure vnc connection
[ root@localhost ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
Modify /etc/systemd/system/vncserver@:1.service
Find this line
ExecStart=/sbin/runuser -l
PIDFile=/home/
Here I log in directly with the root user, so I replaced it with
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
If it is another user, for example, replace john as follows
ExecStart=/sbin/runuser -l john -c "/usr/bin/vncserver %i"
PIDFile=/home/john/.vnc/%H%i.pid
As the root user logs in directly, the configuration is as follows:
[ root@localhost ~]# cat /etc/systemd/system/vncserver@:1.service
.........
[ Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[ Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[ Install]
WantedBy=multi-user.target
Set a password for VNC
[ root@localhost ~]# vncpasswd
123456
[ root@localhost ~]# vim /etc/libvirt/qemu.conf
vnc_password = "123456"
vnc_listen = "0.0.0.0"
Reload systemd
[ root@localhost ~]# systemctl daemon-reload
Start vnc
[ root@localhost ~]# systemctl enable vncserver@:1.service
[ root@localhost ~]# systemctl start vncserver@:1.service
Note that the firewall is turned off here
If the firewall is enabled, you need to enable the following rules:
[ root@localhost ~]# firewall-cmd --permanent --add-service vnc-server
[ root@localhost ~]# systemctl restart firewalld.service
If it is iptable, you need to add in /etc/sysconfig/iptables:
Close vnc connection
[ root@localhost ~]# /usr/bin/vncserver -kill :1
Test vnc connection:
[ root@localhost ~]# novnc_server --vnc 192.168.1.8:5901 --listen 6081
Warning: could not find self.pem
Starting webserver and WebSockets proxy on port 6081
WebSocket server settings:
Navigate to this URL:
http://kvm-server:6081/vnc.html?host=kvm-server&port=6081 #http access method
Press Ctrl-C to exit
Since the host name of kvm-server is 112.112.113.56 for ip, input in the browser:
http://112.112.113.56:6081/vnc.html?host=112.112.113.56&port=6081
Recommended Posts