Linux System Administrator攻略(二)

来源:岁月联盟 编辑:exp 时间:2012-02-22
作者  李万鹏
 
 上一篇:Linux System Administrator攻略(一)
 
 
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 <defunct>
[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生效
 
 
 
 
效果如下:
 
 

 

/