os :redhat as 5
1.确认VNC是否安装
确认是否已经安装VNC服务及查看安装的VNC版本
[root@testdb ~]# rpm -q vnc-server
vnc-server-4.1.2-9.el5
[root@testdb ~]#
若系统没有安装,可以到操作系统安装盘的Server目录下找到VNC服务的RPM安装包
vnc-server-4.1.2-9.el5.x86_64.rpm,安装命令如下 号”用“数字”的方式表示,每个用户连个需要占用1个桌面 用户主目录下的.vnc子目录(/root/.vnc/passwd)中;同时在用户主目录下的.vnc子目 录中为用户自动建立xstartup配置文件(/root/.vnc/xstartup),在每次启动VND服务 时,都会读取该文件中的配置信息。 后对应后天操作系统的进程号,用于停止VNC服务时准确定位进程号。 如下 vi /etc/sysconfig/vncservers VNCSERVERS="2:root" 5.设置防火墙 启桌面号为“1”相应的端口为例,命令如下 6.客户端连接问题 如果在客户端成功连接上VNC服务器(或者通过浏览器连接上)之后,看不到Linux主机的屏幕(不能显示桌面,而只有一个Terminal窗口),则可以修改.vnc文件夹中的xstartup文件。
[root@localhost ~]#vi .vnc/xstartup 去掉前面注释 ,保存。 unset SESSION_MANAGER
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
2.启动VNC服务
使用vncserver命令启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面
启动编号为1的桌面示例如下
[root@testdb ~]# vncserver :1
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
New ’testdb:1 (root)’ desktop is testdb:1
Creating default startup script. /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
以上命令执行的过程中,因为是第一次执行,需要输入密码,这个密码被加密保存在
BTW:/root/.vnc/目录下还有一个“testdb:1.pid”文件,这个文件记录着启动VNC
3.VNC服务使用的端口号与桌面号的关系
VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下
桌面号为“1” ---- 端口号为5901
桌面号为“2” ---- 端口号为5902
桌面号为“3” ---- 端口号为5903
……
基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系
桌面号为“1” ---- 端口号为5801
桌面号为“2” ---- 端口号为5802
桌面号为“3” ---- 端口号为5803
……
4.修改配置文件
VNCSERVERARGS[2]="-geometry 1024x728 -nolisten tcp -nohttpd -localhost"
基于上面的介绍,如果Linux开启了防火墙功能,就需要手工开启相应的端口,以开
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
exec /etc/X11/xinit/xinitrc
7.启动与关闭
重新启动vncserver服务的方法:
[root@testdb ~]# vncserver -kill :1
[root@testdb ~]# vncserver :1