1. 检查是否已经安装了VNC server
[root@localhost ~]# rpm -qa | grep vnc
如果已经安装,则返回相关的版本信息
2.安装相应桌面环境与vnc服务端和客户端,相关命令如下:
# yum groupinstall "X Window System" "Desktop" # yum install tigervnc # yum install tigervnc-server
2、Vncserver的配置:
执行命令: vim /root/.vnc/xstartup
在打开的配置文件中,注释掉以下两行
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
之后,在最后添加一行:
gnome-session &
3、以centOS6.5为例,修改后的配置文件为:
[root@GUOKE ~]# vi /root/.vnc/xstartup #!/bin/sh [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n export LANG export SYSFONT 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" & #twm & gnome-session &
修改后,直接保存,然后修改/etc/sysconfig/vncservers用户配置文件:
执行命令: vim /etc/sysconfig/vncservers
在打开的配置文件中,把下面两行的“#”去掉
VNCSERVERS="……"
VNCSERVERARGS[1]="……"
以centOS6.5为例,修改后的用户配置文件为:
[root@GUOKE ~]# 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="1:root" VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -localhost"
4、启动vncserver
第一次启动vncserver需要输入密码两次,下面是切换到pms.cc用户,并设置密码
启动vncserver命令: vncserver
设置为开机启动的命令: chkconfig vncserver on
重启的命令:service vncserver restart
xauth: (stdin):1: bad display name "bogon:15" in "add" command New 'bogon:15 (root)' desktop is bogon:15 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/bogon:15.log
如上显示的,已经启动成功,看其提示“New 'bogon:15 (root)' desktop is bogon:15”,
表示远程连接的路径为:”ip:15”,既:主机IP或域名+端口号。
远程连接的工具使用”UltraVNC Viewer”
如果是第一次启动,会要求设置vnc访问密码。
如果需要修改密码命令行输入:vncpasswd
5、防火墙配置
如果这时候连接不上,可能是防火墙的问题。防火墙设置如下:
防火墙命令:
关闭防火墙:service iptables stop
重启防火墙: service iptables restart
启动vnc服务后,你可以用netstat –tunlp命令来查看vnc服务所使用的端口,使用下面命令开启这些端口:
[root@localhost ~]# netstat -tulnp | grep X tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 14319/Xvnc tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 14319/Xvnc tcp 0 0 :::6001 :::* LISTEN 14319/Xvnc
iptables防火墙默认会阻止vnc远程桌面,所以需要在iptables允许通过。
开始配置防火墙命令:vim /etc/sysconfig/iptables
进入vim模式后,可以添加相关的规则,如下:
-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 6001 -j ACCEPT
本文版权所有,转载须注明:来源 https://www.qvdv.net/qvdv-zhuji-646.html