1.服务器安装VNC服务端
可以直接rpm安装vnc的服务端:
[root@ZDAPP ~]# cd /mnt/ios/Packages
[root@ZDAPP Packages]# rpm -ivh tigervnc-server-1.1.0-5.el6_4.1.x86_64.rpm
warning: tigervnc-server-1.1.0-5.el6_4.1.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:tigervnc-server ########################################### [100%]
如果rpm安装时发现有依赖,建议直接使用yum安装,轻松解决依赖问题:
[root@ZDAPP /]# yum install tigervnc-server
如果系统安装时并没有安装桌面选项,那么就还需要用yum安装一下桌面:
[root@ZDAPP /]# yum groupinstall "X Window System" "Desktop"
2.编辑vnc配置文件
[root@ZDAPP Packages]# vim /etc/sysconfig/vncservers
添加如下内容
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600 -alwaysshared -depth 24"
注:分辨率可以根据实际情况调整,分辨率不合适可能导致vnc连接显示黑屏的现象。
3.设定VNC的密码
[root@ZDAPP Packages]# vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
xauth: (stdin):1: bad display name "ZDAPP:1" in "add" command
New 'ZDAPP:1 (root)' desktop is ZDAPP:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ZDAPP:1.log
后期若想修改密码,可使用vncpasswd命令修改
[root@ZDAPP ~]# vncpasswd
Password:
Verify:
4.查看vnc的会话信息
重启vncserver服务:
[root@ZDAPP Packages]# /etc/init.d/vncserver restart
Shutting down VNC server: 1:root [ OK ]
Starting VNC server: 1:root xauth: (stdin):1: bad display name "ZDAPP:1" in "add" command
New 'ZDAPP:1 (root)' desktop is ZDAPP:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ZDAPP:1.log
[ OK ]
查看vnc的会话信息:
[root@ZDAPP Packages]# vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:1 17371
查看是否启动命令(5901-5903对应1-3端口)
[root@ZDAPP Packages]# netstat -anlpt | grep 5901
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 17371/Xvnc
启动VNC
[root@ZDAPP /]# vncserver :1
xauth: (stdin):1: bad display name "ZDAPP:1" in "add" command
New 'ZDAPP:1 (root)' desktop is ZDAPP:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ZDAPP:1.log
停止VNC
[root@ZDAPP /]# vncserver -kill :1
Killing Xvnc process ID 17371
5.客户端测试vnc连接
客户端是vncviewer,我这里是Windows系统,下载对应的vnc安装包HA-vnc-4.0-x86_win32-KC.exe(各个版本的vncviewer均可以)
安装选择只安装VNC Viewer即可。
6.注
如果要用非root用户连接vnc,则在该用户下启动vnc即可。
如果想用其他用户登录VNC则修改/etc/sysconfig/vncservers
VNCSERVERS="1:root 2:root 3:oracle"
VNCSERVERARGS[1]="-geometry 800x600 -alwaysshared -depth
VNCSERVERARGS[2]="-geometry 800x600 -alwaysshared -depth
VNCSERVERARGS[3]="-geometry 800x600 -alwaysshared -depth