1
2
3
4
| [root@localhost ~]# yum -y install tigervnc-server tigervnc
[root@localhost ~]# ll /lib/systemd/system/vncserver@.service
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
[root@localhost ~]# vim /lib/systemd/system/vncserver@\:1.service
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking //forking to simple
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' //%i to :1
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" //<USER> to root
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' //%i to :1
[Install]
WantedBy=multi-user.target
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [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 :1 > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver :1"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
|
1
2
3
4
5
6
7
8
9
10
11
| [root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable vncserver@:1.service
[root@localhost ~]# vncpasswd //需要到对应的用户下面运行这个命令
[root@localhost ~]# systemctl start vncserver@:1.service
[root@localhost ~]# chmod 777 /root/.vnc/xstartup
[root@localhost ~]# systemctl status vncserver@:1.service
[root@localhost ~]# netstat -lnt | grep 590*
[root@localhost ~]# grep vnc /var/log/messages
[root@localhost ~]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
[root@localhost ~]# service iptables restart
|