CentOS 6.8 安装vnc

过一段时间就要安装,我写这里复制方便些。

1 查询是否安装了vnc

#rpm -qa |grep vnc

2 可以在yum 源上查看vnc软件

#yum list |grep vnc
tigervnc.x86_64                             1.1.0-24.el6                 @os    
tigervnc-server.x86_64                      1.1.0-24.el6                 @os

3 安装tigervnc软件

#yum install -y tigervnc
#yum install -y tigervnc-server

4 配置vnc服务器文件

vim /etc/sysconfig/vncservers

文件后面添加如下内容

VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1920x1080 -depth 32 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 1920x1080 -depth 32 -nolisten tcp"

解释:这里开启了2个vnc桌面,1号为root的,2号为oracle的,在这里配置的都必须是已有的用户.
下面的参数 就是分辨率,颜色深度,绑定ip等。

这里是vncservers文件: #cat /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:
# https://access.redhat.com/kNowledge/solutions/7027

# 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" (最多可以6个用户)
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1920x1080 -depth 32 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 1920x1080 -depth 32 -nolisten tcp"

5 使用root执行vncserver 会提示先输入密码,这个密码vnc的链接密码

则还会有
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
提示

我们这里还配置了oracle用户的,我们还需要切换到oracle用户,然后执行vncpasswd,为2号vnc的oracle用户生成vnc的链接密码

注:当然root下,也是只执行vncpasswd生成密码的,

然后统一执行service vncserver start。这样都同样会为root,和oracle用户在他们的家目录生成 .vnc/xstartup文件

6 修改 .vnc/xstartup文件(多个用户都需要修改,如果某个用户没有这个文件则是需要在改用户下启动一下vncserver ,或者 vncserver :2,或者利用 service vncserver start这样都会为用户创建认的xstartup文件

如果是gnome桌面,则把twm & 注释掉,添加gnome-session &
如果是KDE桌面,则把twm & 注释掉,添加startkde &

这里是xstartup文件: #cat .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 &

7 启动vncserver

service vncserver start
vncserver :1
vncserver -kill:1

vncserver -kill :桌面号 #关闭某个桌面号
vncserver :桌面号 #启动某个桌面号

8 添加开机启动和测试

chkconfigvncserver on
chkconfig vncserver --list

防火墙
service iptables status
添加容许通过的规则,或者直接关闭iptables,如果是添加规则别忘了 service iptables save保存下。

在测试有的是输入ip:加5901,5902这个端口,有的则是ip:1,ip:2这个vnc这个序号,也有因为vnc版本问题链接不成功的。

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native