在CentOS5下安装配置VNC的过程

 

在CentOS5下安装配置VNC的过程

1.查看VNC是否已经安装:
$ rpm -q vnc vnc-server
vnc-4.1.2-24.fc8
vnc-server-4.1.2-24.fc8

vnc是客户端,vnc-server是服务器端   

注:a. 如果想卸载VNC,可用命令 yum remove vnc-server

b.yum安装可用命令: yum install vnc-server ,然后在配置
2.把用户名加入到配置文件中:
CODE:[root@localhost ~]#  vi /etc/sysconfig/vncservers

# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# as my ‘myusername’ (adjust this to your own).   You will also
# need to set a VNC password; run ‘man vncpasswd’ to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!   For a secure way of using VNC, see
# URL:http://www.uk.research.att.com/vnc/sshvnc.html

# VNCSERVERS=”1:myusername”
VNCSERVERS=”1:root” (注意:root是CentOS用户名)
如果建2个,可以用VNCSERVERS=”1:root 2:linglong”来配置
3.用vncpasswd创建一个vnc的口令

注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.
CODE:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]# ls -d .vnc
.vnc
[root@localhost ~]# ls .vnc
passwd
4.启动vnc服务.
CODE:[root@localhost ~]#  /sbin/service vncserver restart

Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = “zh_EN.UTF-8″
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).

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

[ OK ]

察看一下.vnc这个目录的内容,应该类似于下面的东西.
注:在这里我刚开始出现“Warning: *****   is taken because of /tmp/.X1-lock”
在网上找了好多方法,终于找到解决办法了!
我直接将: /tmp/.X1-lock 删除就可以 了 ,命令式: rm /tmp/.X1-lock
如果还出现其他的文件错误 也可照样操作!
CODE:[root@localhost ~]# cd .vnc
[root@localhost .vnc]# ls
localhost.localdomain:1.log localhost.localdomain:2.log passwd
localhost.localdomain:1.pid localhost.localdomain:2.pid xstartup
[root@localhost .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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop”
twm

因为我们已经修改了启动脚本,现在来重新启动vncserver.

 

CODE:[root@localhost .vnc]#   /sbin/service vncserver restart

Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = “zh_EN.UTF-8″
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).

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

[ OK ]
[root@localhost .vnc]#

 

5.防火墙端口设置
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901.
加入以下红色的部分,然后重启iptables服务。

[root@localhost ~]#   vi /etc/sysconfig/iptables

# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT – [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 -m state –state ESTABLISHED,RELATED -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 tcp -p tcp –dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT
[root@localhost ~]#   /sbin/service iptables restart
Flushing firewall rules:                               [   OK   ]
Setting chains to policy ACCEPT: filter                    [   OK   ]
Unloading iptables modules:                                [   OK   ]
Applying iptables firewall rules:                          [   OK   ]
[root@localhost ~]#
================================
其他:
================================

1. 让vncserver接受两个不同的用户:
CODE:VNCSERVERS=”1:root 2:yanyp”
当然你要为两个用户分别运行vncpasswd来设置口令. 并且在你的防火墙修改中,你应该明白VNC使用端口5901给连接1用,如果象上面一样要支持两个用户,应同时打开5901和5902.

2. 如果安装了用客户端vncviewer可以使用 vncviewer命令来远程连接vncserver

[root@localhost ~]$ vncviewer localhost(或者用IP地址):1

输入你的vnc口令,就可以了

 

原创文章,转载请注明: 转载自灵龙-技术 实验室

本文链接地址: 在CentOS5下安装配置VNC的过程

文章的脚注信息由WordPress的wp-posturl插件自动生成

关于 linlonx

灵龙,业余喜欢钻研各种计算机知识,包括计算软件、硬件、编程、SEO等。现就职于广州某软件公司,对未来充满自信,相信我的人生会很美好!

你可能感兴趣的:(Linux)