centos VNC服务器与VNC客户端配置

来源:互联网 发布:影楼网络销售赚钱吗 编辑:程序博客网 时间:2024/06/04 20:25

服务器端

1. 首先查看服务器有没有安装vncserver

rpm -q vnc vnc-server


2.安装vncserver

yum install vnc vnc-server


之后会设置vnc的登录密码,如果是多个用户,则每个用户都需要设置一个vnc密码。过程是切换到每一个用户,

然后输入vncserver,vnc进程则会要求输入当前用户的vnc密码


3.配置桌面类型

vim ~/.vnc/xtartup  (每一个vnc用户都会有一个这样的文件,每个用户都需要配置)

#!/bin/shvncconfig -iconic &unset SESSION_MANAGERunset DBUS_SESSION_BUS_ADDRESSOS=`uname -s`if[ $OS = 'Linux']; then  case"$WINDOWMANAGER"in    *gnome*)      if[ -e /etc/SuSE-release ]; then        PATH=$PATH:/opt/gnome/bin        export PATH      fi      ;;  esacfiif[ -x /etc/X11/xinit/xinitrc ]; then  exec /etc/X11/xinit/xinitrcfiif[ -f /etc/X11/xinit/xinitrc ]; then  exec sh /etc/X11/xinit/xinitrcfi[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresourcesxsetroot -solid greyxterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &twm &

注释掉最后两行,

然后添加一行启用gnome桌面,则文件变成


#!/bin/shvncconfig -iconic &unset SESSION_MANAGERunset DBUS_SESSION_BUS_ADDRESSOS=`uname -s`if[ $OS = 'Linux']; then  case"$WINDOWMANAGER"in    *gnome*)      if[ -e /etc/SuSE-release ]; then        PATH=$PATH:/opt/gnome/bin        export PATH      fi      ;;  esacfiif[ -x /etc/X11/xinit/xinitrc ]; then  exec /etc/X11/xinit/xinitrcfiif[ -f /etc/X11/xinit/xinitrc ]; then  exec sh /etc/X11/xinit/xinitrcfi[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresourcesxsetroot -solid grey#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &#twm &gnome-session

4.配置登录账号

vim /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 2:ue13 3:user3"VNCSERVERARGS[1]="-geometry 1024×768"VNCSERVERARGS[2]="-geometry 1024×768"VNCSERVERARGS[3]="-geometry 800×600 -depth 24 -nolisten tcp -nohttpd -localhost"

第三个用户不允许TCP连接,只用于本地的测试


客户端连接到某一用户的VNC命令为: vncserver:1   (连接到1号显示(root))


5.配置防火墙

vim /etc/sysconfig/iptables

添加允许 vnc 的tcp连接

在文件 中加入

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT  #这个是root
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT  #这个是ue13

注意: 如果如果有多个display,则端口号递增,


6.设置完iptables后需要重启  service iptables restart

7.设置vncserver 开机自动启动 chkconfig vncserver on


8.重启vncserver服务  service vncserver restart



客户端

1.客户端需要安装vncview才可以vnc服务器,

yum install tigervnc 

2.安装完成后

命令行输入  vncviewer

则会要求输入vnc服务器的IP与display的号码  => 192.168.0.13:2  

则可成功连接



遇到的错误

当尝试关掉1号display的进程时会有you'll have to mannually kill vnc process错误。

解决方法

1. ps -ef|grep -i vnc  显示出display 的进程号

2.kill 进程号, 关掉该进程


参考资料

常见错误:

http://blog.csdn.net/russle/article/details/4757888

http://down.chinaz.com/server/201109/1061_1.htm

http://www.cnblogs.com/ljjphysics/archive/2011/10/18/2216820.html

0 0
原创粉丝点击