Centos7、Redhat7
#安装tigervnc-server软件包
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt
[root@localhost mnt]# cd Packages/
[root@localhost Packages]# rpm -ivh tigervnc-server-1.3.1-9.el7.x86_64.rpm
[root@localhost Packages]# cd /lib/systemd/system
[root@localhost system]# cp vncserver@.service vncserver@:2.service
[root@localhost system]# vim vncserver@:2.service
将文件中的<User>用你当前的用户替换,将%i替换为:1
[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 :1 > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver :1"
PIDFile=/root/.vnc/%H%1.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl start vncserver@:2.service
[root@localhost system]# systemctl enable vncserver@:2.service
使用vncview 输入192.168.52.79:2即可打开。
注意:非正常关机启动后,会报
PID 4286 read from file /root/.vnc/localhost.localdomain:1.pid does not exist or is a zombie
或者 PID file /root/.vnc/localhost.localdomain:2.pid not readable (yet?) after start.
解决方法:cd /tmp/.X11-unix
Rm -rf *
Centos6,Redhat6
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt
[root@localhost mnt]# cd Packages/
[root@localhost Packages]# rpm -ivh tigervnc-server-1.1.0-5.el6_4.1.x86_64.rpm
[root@localhost ~]# vncserver
You will require a password to access your desktops.
Password:overseas
Verify:overseas
xauth: creating new authority file /root/.Xauthority
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
[root@localhost ~]# cd /root/.vnc/
[root@localhost .vnc]# vim xstartup
注释:#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
添加:gnome-session &
[root@localhost .vnc]# vim /etc/sysconfig/vncservers
添加:
VNCSERVERS="2:root"
VNCSERVERARGS[2]= "-geometry 1024x768"
[root@localhost .vnc]# chmod 777 /root/.vnc/xstartup
[root@localhost .vnc]# service iptables stop 或者将5901,5902端口放行,以此类推
[root@localhost .vnc]# chkconfig vncserver on
[root@localhost .vnc]# /etc/init.d/vncserver start