1.确认VNC是否安装
默认情况下,Red Hat Enterprise Linux安装程序会将VNC服务安装在系统上。 确认是否已经安装VNC服务及查看安装的VNC版本
[root@testdb ~]# rpm -q vnc-server
vnc-server-4.1.2-9.el5
[root@testdb ~]#
若系统没有安装,可以到操作系统安装盘的
[url=javascript:;]Server[/url]
目录下找到VNC服务的RPM安装包vnc-server-4.1.2-9.el5.x86_64.rpm,安装命令如下
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
2.启动VNC服务
使用vncserver命令启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面号”用“数字”的方式表示,每个用户连个需要占用1个桌面
启动编号为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
以 上命令执行的过程中,因为是第一次执行,需要输入密码,这个密码被加密保存在用户主目录下的.vnc子目录(/root/.vnc/passwd)中;同 时在用户主目录下的.vnc子目录中为用户自动建立xstartup配置文件(/root/.vnc/xstartup),在每次启动VND服务时,都会 读取该文件中的配置信息。
BTW:/root/.vnc/目录下还有一个“testdb:1.pid”文件,这个文件记录着启动VNC后对应后天操作系统的进程号,用于停止VNC服务时准确定位进程号。
3.VNC服务使用的端口号与桌面号的关系
VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下 桌面号为“1” ---- 端口号为5901
桌面号为“2” ---- 端口号为5902
桌面号为“3” ---- 端口号为5903
……
基于
[url=javascript:;]Java[/url]
的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下 桌面号为“1” ---- 端口号为5801
桌面号为“2” ---- 端口号为5802
桌面号为“3” ---- 端口号为5803
……
基于上面的介绍,如果Linux开启了防火墙功能,就需要手工开启相应的端口,以开启桌
面号为“1”相应的端口为例,命令如下
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
4.测试VNC服务
第一种方法是使用VNC Viewer软件登陆
[url=javascript:;]测试[/url]
,操作流程如下
启动VNC Viewer软件 --> Server输入“144.194.192.183:1” --> 点击“OK” --> Password输入登陆密码 --> 点击“OK”登陆到X-Window图形桌面环境 --> 测试成功 第二种方法是使用Web浏览器(如Firefox,IE,Safari)登陆测试,操作流程如下
地 址栏输入http://144.194.192.183:5801/ --> 出现VNC viewer for Java(此工具是使用Java编写的VNC客户端程序)界面,同时跳出VNC viewer对话框,在Server处输入“144.194.192.183:1”点击“OK” --> Password输入登陆密码 --> 点击“OK”登陆到X-Window图形桌面环境 --> 测试成功
(注:VNC viewer for Java需要JRE支持,如果页面无法显示,表示没有安装JRE,可以到/javase/downloads/index_jdk5.jsp这里下载最新的JRE进行安装)
5.配置VNC图形桌面环境为KDE或GNOME桌面环境
如果您是按照我的上面方法进行的配置的,登陆到桌面后效果是非常简单的,只有一个Shell可供使用,这是为什么呢?怎么才能看到可爱并且美丽的KDE或GNOME桌面环境呢?回答如下
之所以那么的难看,是因为VNC服务默认使用的是twm图形桌面环境的,可以在VNC的配置文件xstartup中对其进行修改,先看一下这个配置文件
[root@testdb ~]# cat /root/.vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & twm &
将这个xstartup文件的最后一行修改为“startkde &”,再重新启动vncserver服务后就可以登陆到KDE桌面环境
将这个xstartup文件的最后一行修改为“gnome-session &”,再重新启动vncserver服务后就可以登陆到GNOME桌面环境
重新启动vncserver服务的方法:
[root@testdb ~]# vncserver -kill :1
[root@testdb ~]# vncserver :1
6.配置多个桌面
可以使用如下的方法启动多个桌面的VNC
vncserver :1
vncserver :2
vncserver :3
……
但是这种手工启动的方法在服务器重新启动之后将失效,因此,下面介绍如何让系统自动
[url=javascript:;]管理[/url]
多个桌面的VNC,方法是将需要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中,先以桌面1为root用户桌面2为oracle用户为例进行配置如下:
格式为:VNCSERVERS="桌面号:使用的用户名 桌面号:使用的用户名"
[root@testdb ~]# vi /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1024x768"
7.修改VNC访问的密码
使用命令vncpasswd对不同用户的VNC的密码进行修改,一定要注意,如果配置了不同用户的VNC需要分别到各自用户中进行修改,例如在我的这个实验中,root用户和oracle用户需要分别修改,修改过程如下:
[root@testdb ~]# vncpasswd
Password:
Verify:
[root@testdb ~]#
8.启动和停止VNC服务
1)启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver start
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[ OK ]
2)停止VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver stop
Shutting down VNC server: 1:root
2:oracle
[ OK ]
3)重新启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver restart
Shutting down VNC server: 1:root
2:oracle
[ OK ]
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[ OK ]
4)设置VNC服务随系统启动自动加载
第一种方法:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击确定,配置完成。
第二种方法:使用“chkconfig”在命令行模式下进行操作,命令使用如下(预知chkconfig详细使用方法请自助式man一下)
[root@testdb ~]# chkconfig vncserver on
[root@testdb ~]# chkconfig --list vncserver
vncserver 0:off
1:off 2:on 3:on
4:on 5:on 6:off
第二篇:vnc的配置和vnc配合ssh
1.首先要确定被控机器是否已经安装VNCserver,一般都是安装了的。可以用命令查询: #rpm -q vnc vnc-server
2.把用户名加入到配置文件中:
[root@localhost ~]# vi /etc/sysconfig/vncservers
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost" VNCSERVERS="1:root" #新增部分
3.防火墙端口设置
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901,然后重启iptables服务。
[root@localhost ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT #新增部分
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
4.重启iptables服务
[root@localhost ~]# /sbin/service iptables restart
清除防火墙规则: [确定] 把 chains 设置为 ACCEPT 策略:nat filter [确定] 正在卸载 Iiptables 模块: [确定] 应用 iptables 防火墙规则: [确定] 载入额外 iptables 模块:ip_conntrack_netbios_ns ip_conntrac[确定]
5.启动vncserver,这时候通过VNC Viewer只能看到终端窗口
[root@localhost ~]# vncserver
You will require a password to access your desktops.
Password: #123456
Verify: #123456
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
5.设置图形界面登录
[root@localhost ~]# vi /root/.vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER #去掉注释符号‘#’
exec /etc/X11/xinit/xinitrc #去掉注释符号‘#’
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #twm & #注释掉
gnome-session & #新增
6.重启vncserver
[root@localhost ~]# service vncserver restart
关闭 VNC 服务器:1:root [确定] 启动 VNC 服务器:1:root xauth: creating new authority file /root/.Xauthority New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1 Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
[确定]
[root@localhost ~]#
7.这时再通过客户端就可以登录图形界面了. 在配置完之后我只能打开一个界面,界面上之
后什么图标也没有,什么操作也不能做。后来经过尝试发现,每次登录都要将用户当前的vncserver打开,并且会提示端口号,在windows下用vncview登录时将提示的端口号加在ip地址后面就可以了如:10.17.22.16:5902
VNC 配合putty 安全连接linux
1. 运行putty,输入服务器的ip地址,输入一个名字,这里以vmsup1(主机名)作为session的名字,按save保存。见下图
2. 单击对话框左边的tunnels来选择相关设置,在source port里输入5901(本地vpc客户端连接的端口,可任意修改),在Destination里输入localhost:5901,按Add添加,如下图
3. 单击左边session,回到session设置,按save重新保存。按open即可登录到服务器。
4. 运行vnc-viewer ,在Server里输入localhost:1或者输入localhost:5901(本地vpc客户端映射的端口,见下图, 输入口令后一个linux的桌面就会出现在windows里。