CentOS系统中VNC配置,检查VNC客户端和服务器端、将用户名加入到配置文件、启动VNC服务、修改VNC SERVER的窗口治理器等必要问题。
1.检查VNC客户端和服务器端是否已经安装
执行如下命令:
[root@localhost ~]# rpm -qa vnc vnc-server
package vnc is not installed
package vnc-server is not installed
表示系统没有安装VNC服务端,那我们就用yum安装VNC服务端。
[root@localhost ~]# yum -y install vnc vnc-server
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tigervnc.i686 0:1.0.90-0.10.20100115svn3945.el6 set to be updated
---> Package tigervnc-server.i686 0:1.0.90-0.10.20100115svn3945.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================
Installing:
tigervnc i686 1.0.90-0.10.20100115svn3945.el6 base 252 k
tigervnc-server i686 1.0.90-0.10.20100115svn3945.el6 base 1.1 M
Transaction Summary
=================================================================================================================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 1.3 M
Installed size: 3.6 M
Downloading Packages:
(1/2): tigervnc-1.0.90-0.10.20100115svn3945.el6.i686.rpm | 252 kB 00:00
(2/2): tigervnc-server-1.0.90-0.10.20100115svn3945.el6.i686.rpm | 1.1 MB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 137 kB/s | 1.3 MB 00:09
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tigervnc-1.0.90-0.10.20100115svn3945.el6.i686 1/2
Installing : tigervnc-server-1.0.90-0.10.20100115svn3945.el6.i686 2/2
Installed:
tigervnc.i686 0:1.0.90-0.10.20100115svn3945.el6 tigervnc-server.i686 0:1.0.90-0.10.20100115svn3945.el6
Complete!
启动VNC Server服务:使用vncserver命令(在当前用户主目录下生成.vnc文件夹)
[root@localhost ~]# vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
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
2. 在CentOS系统中将用户名加入到配置文件中
编辑vncservers的配置文件
[root@localhost ~]# vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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 this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
# VNCSERVERS="2:myusername"
VNCSERVERS="2:root" #用户名root
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERARGS[2]="-geometry 1024x768" #尺寸大小
3.设置 root用户的密码
使用如下命令设置密码:
[root@localhost ~]# vncpasswd
Password:abc123
Verify:abc123
当提示Verify时,再次输入密码确认。
4.启动VNC服务
使用如下命令启动VNC SERVER
[root@localhost ~]# /sbin/service vncserver start
正在启动 VNC 服务器:2:root
New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log
[确定]
[root@localhost ~]#
当显示如下信息时,表示启动成功.
5.修改VNC SERVER的窗口治理器
vnc server默认使用的窗口治理器是twn,这是一个非常简单的窗口治理器,我们可以改成常用的GNOME或者KDE。
先使用如下命令进入用户的home目录:cd /.vnc
编辑启动项:vi xstartup
按照如下方式修改启动项:
[root@localhost ~]# vi /root/.vnc/xstartup
#!/bin/sh
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session & #以GNOME作为VNC的窗口治理器
#startkde #kde desktop
#twm &
#twm # 注掉CentOS系统默认的窗口治理器
6.重启VNC SERVER
当CentOS系统提示如下信息时,表示重启成功
[root@localhost ~]# /sbin/service vncserver restart
关闭 VNC 服务器:2:root [确定]
正在启动 VNC 服务器:2:root
New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log
[确定]
查看VNC SERVER 监听的端口:
[root@localhost ~]# netstat -antulp |grep 59
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 3162/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 4193/Xvnc
tcp 0 0 0.0.0.0:59473 0.0.0.0:* LISTEN 1153/rpc.statd
tcp 0 0 :::5989 :::* LISTEN 1501/cimserver
tcp 0 0 :::5900 :::* LISTEN 3123/vino-server
tcp 0 0 ::ffff:192.168.0.124:5900 ::ffff:192.168.0.145:3072 ESTABLISHED 3123/vino-server
防火墙开放的端口:
[root@localhost ~]# /sbin/iptables -A INPUT -p tcp -m multiport -m state --state NEW,ESTABLISHED,RELATED --dport 5901,5900 -j ACCEPT
[root@localhost ~]# service iptables save
[root@localhost ~]# service iptables restart
从VNC view登录
VNC view 下载地址:
http://js1.mydown.yesky.com/48/soft/201105/RealVNC-v4.61.zip
在windows上安装vnc view,然后输入192.168.0.124:2,连接登录,输入密码即可。
备注:假如从vnc view登录时,提示connection refused(10061),则是因为linux防火墙的问题,登录centos系统,选择SystemPreferencesRemote Desktop,勾选sharing中的两项,Security两项不勾,点击关闭,然后再重新用vnc view登录即可。