安装和配置VNC


1 安装vnc
# yum install -y  tigervnc-server tigervnc-server-module libXfont pixman xterm xorg-x11-twm   安装vnc及字体库
# chkconfig  vncserver on      设置开机自动启动
2 VNC配置
修改 /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"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp -depth 24"
# -alwaysshared代表允许多用户同时登录 -depth代为色深,参数有8,16,24,32  
#红色为新增内容
3 设置VNC密码
# vncpasswd
Password:  
Verify:  
连续两次输入同样的密码
设置的密码保存在  /root/.vnc/passwd
4 修改防火墙配置,修改/etc/sysconfig/iptables
# vi /etc/sysconfig/iptables    #编辑,添加以下代码,开启5901、5902端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT  
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT
:wq! 保存,退出
service iptables restart   # 重启
5 使用VNC连接CentOS主机
直接打开VNC,输入IP地址,冒号后面的1代表桌面号,这个要根据你的配置文件定义的桌面号
CentOS6.3下安装和配置VNC - zhm - 张传猛的运维博客
如果你是Root用户登陆,会有下面的警告提示
CentOS6.3下安装和配置VNC - zhm - 张传猛的运维博客
然后输入密码,就可登陆了
CentOS6.3下安装和配置VNC - zhm - 张传猛的运维博客
CentOS6.3下安装和配置VNC - zhm - 张传猛的运维博客
6 FAQ
6.1 VNC服务使用的端口号与桌面号的关系
   VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下
   桌面号为“1”  ―- 端口号为5901
   桌面号为“2”  ―- 端口号为5902
   桌面号为“3”  ―- 端口号为5903
基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下
   桌面号为“1”  ―- 端口号为5801
   桌面号为“2”  ―- 端口号为5802
   桌面号为“3”  ―- 端口号为5803
6.2 error1: VNC Fatal server error: could not open default font ‘fixed’  
Thu Jul 18 00:00:36 2013
vncext:      VNC extension running!
vncext:      Listening for VNC connections on all interface(s), port 5901
vncext:      created VNC server for screen 0
[dix] Could not init font path element /usr/share/X11/fonts/misc, removing from list!
[dix] Could not init font path element /usr/share/X11/fonts/100dpi, removing from list!
[dix] Could not init font path element /usr/share/X11/fonts/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/default/Type1, removing from list!
[dix] Could not init font path element built-ins, removing from list!
Fatal server error:
could not open default font 'fixed'
解决办法: yum -y install fontforge
                 yum update libXfont    
6.3  http://www.realvnc.com/download/binary/1293/    VNC下载地址
6.4 VNC的启动/停止/重启
# service vncserver start/stop/restart
关闭具体的vncserver命令:vncserver -kill:1       vncserver -kill:2
6.5  vncserver 不能重启
# service vncserver restart
Shutting down VNC server:                                  [  OK  ]
Starting VNC server: 1:root
Warning: hfracts01:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server hfracts01:1
A VNC server is already running as :1
解决办法:
# rm -rf /tmp/.X1-lock
# rm -rf /tmp/.X11-unix/
CentOS6.3下安装和配置VNC - zhm - 张传猛的运维博客
如果要杀掉 vncserver 进程,可执行 vncserver :1 kill ,1表示 display 的 ID 号


你可能感兴趣的:(安装和配置VNC)