手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux System Administrator攻略详解

[日期:2012-02-22] 来源:Linux社区  作者:李万鹏 [字体:大 中 小]

VNC server搭建

Red Hat Enterprise Linux Server 6.2

一.VNC安装

1.首先将ISO镜像mount到一个目录下:

sudo mount -t iso9660 RHEL6.2-20111117.0-Server-x86_64-DVD1.iso /mnt

2.将RHEL6.2-20111117.0-Server-x86_64-DVD1/Packeges的下列包拷出来:

gtk-vnc-0.3.10-3.el6.i686.rpm

libvncserver-0.9.7-4.el6.x86_64.rpm

tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64.rpm

tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64.rpm

xorg-x11-fonts-misc-7.2-9.1.el6.noarch.rpm

3.由于在server上镜像里的各个包都不能安装,提示失败之类的,所以这里先把包放在本地,然后上传服务器:

scp tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64.rpm root@9.186.9.18:/root/

4.使用命令rpm安装各个包

rpm -ivh xxxx

5.rpm -qa | grep vnc

[root@chinaltcdragon ~]# rpm -qa | grep vnc

tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64

gtk-vnc-Python-0.3.10-3.el6.x86_64

tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64

gtk-vnc-0.3.10-3.el6.x86_64

libvncserver-0.9.7-4.el6.x86_64

可以看到已经成功安装vnc了。

二.VNC配置

1.配置/etc/sysconfig/vncserver文件,在最下边添加:

VNCSERVERS="1:root"

VNCSERVERARGS[1]="-geometry 1400x1000"

这里的1400*1000是你通过vncviewer看到的窗口的大小。

2.配置当前用户目录下的.vnc/xstartup文件:

如果是gnome的desktop,则添加:

gnome-session&

去掉startkde&一行

如果是kde desktop则相反。

3.配置防火墙开启vnc desktop使用的端口,默认防火墙是开启的,所以在终端输入;

vncviewer 9.186.9.18:1

是登不上去的,显示:

hacker@hacker:~$ vncviewer 9.186.9.18:1

vncviewer: ConnectToTcpAddr: connect: No route to host

Unable to connect to VNC server

如果完全关闭防火墙:

[root@chinaltcdragon ~]# /etc/rc.d/init.d/iptables stop

iptables:清除防火墙规则:                                 [确定]

iptables:将链设置为政策 ACCEPT:filter           [确定]

iptables:正在卸载模块:                                     [确定]

则可以通过vncviewer正常访问,当然完全关闭防火墙是不安全的,这里重新开启防火墙,只打开vnc desktop使用的端口:

[root@chinaltcdragon ~]# /etc/rc.d/init.d/iptables start

iptables:应用防火墙规则:                                 [确定]

[root@chinaltcdragon ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT

现在就可以使用vncviewer正常访问了。

VNC服务使用的端口号与桌面号的关系:

VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下:

桌面号为“1” ---端口号为5901

桌面号为“2” ---端口号为5902

桌面号为“3”---端口号为5903

4.手动启动和关闭vncserver:

启动:

[root@chinaltcdragon ~]# vncserver :1

New 'chinaltcdragon.cn.ibm.com:1 (root)' desktop is chinaltcdragon.cn.ibm.com:1

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/chinaltcdragon.cn.ibm.com:1.log

[root@chinaltcdragon ~]# ps -e | grep vnc

31681 pts/1    00:00:00 Xvnc

31687 pts/1    00:00:00 vncconfig

关闭:

[root@chinaltcdragon ~]# ps -e | grep vnc

4887 ?        00:01:14 Xvnc

4893 ?        00:00:00 vncconfig

[root@chinaltcdragon ~]# vncserver -kill :1

Killing Xvnc process ID 4887

[root@chinaltcdragon ~]# ps -e | grep vnc

4.自启动vncserver

各个runlevel:

# 0 - 停机(千万不能把initdefault 设置为0 )# 1 - 单用户模式 # 2 - 多用户,没有 NFS # 3 - 完全多用户模式(标准的运行级) # 4 - 没有用到 # 5 - X11 (xwindow) # 6 - 重新启动

这里我们要在runlevel 3和5自启动vncserver服务,使用chkconfig(用来更新(启动或停止)和查询系统的运行级信息):

[root@chinaltcdragon ~]# ls -l /etc/rc*.d/*vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc0.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc1.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc2.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc3.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc4.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc5.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 17 12:57 /etc/rc6.d/K35vncserver -> ../init.d/vncserver

[root@chinaltcdragon ~]# chkconfig --level 35 vncserver on

[root@chinaltcdragon ~]# ls -l /etc/rc*.d/*vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc0.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc1.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc2.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc3.d/S91vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc4.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc5.d/S91vncserver -> ../init.d/vncserver

lrwxrwxrwx. 1 root root 19  2月 21 09:24 /etc/rc6.d/K35vncserver -> ../init.d/vncserver

6.开机自动打开端口

在/etc/sysconfig/iptables文件中添加:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

service iptables restart生效

效果如下:

Linux System Administrator

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款