VNC常用操作及常见问题解决办法汇总

 

VNC登录用户缺省是root,但在安装oracle时必须用oracle用户的身份登录,下面我们就以oracle为例说明如何配置VNC,从而可以使用不同的用户登录到主机。
步骤描述如下:
    步骤一:修改/etc/sysconfig/vncservers,添加oracle用户,修改后内容如下:
        VNCSERVERS="1:root 2:root 3:oracle"
        VNCSERVERARGS[1]="-geometry 1024x768"
        VNCSERVERARGS[2]="-geometry 1024x768"
        VNCSERVERARGS[3]="-geometry 1024x768"

    步骤二:在系统中新建oracle用户
        useradd oracle
        passwd oracle
        
    步骤三:将root用户下的路径复制到oracle用户的home路径下,并修改路径所属用户及组:
        cp -r /root/.vnc ~oracle/.vnc
        chown oracle ~oracle/.vnc/
        chown oracle.oinstall -R ~oracle/.vnc/
        chown oracle ~oracle/.vnc/*
        chown oracle.oinstall -R ~oracle/.vnc/*
       
    步骤四:重启VNC,观察id为3的端口是否启动
        service vncserver restart
        netstat -anlpt | grep 5903
        vnc的端口从5901开始,每增加一个用户,端口号就在5901上加1。如果要单独关闭指定id的端口,可以使用命令:
        vncserver -kill :id
        如:
        vncserver -kill :1
        vncserver -kill :2
        就将关闭5901和5902两个VNC端口

http://blog.sina.com.cn/s/blog_4a0a14170100f5lo.html

http://www.hackbase.com/tech/2012-03-21/66032.html





 

 

 

 

 

 

 

1、安装
yum install vnc*
2、启动
/etc/init.d/vncserver start
Starting VNC server: no displays configured                [  OK  ]
3、配置用户名
CODE:[root@localhost ~]#  vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# 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
# URL: http://www.uk.research.att.com/vnc/sshvnc.html
                                                                                            
# VNCSERVERS="1:myusername"
VNCSERVERS="1:root" (注意:root是CentOS用户名)
如果建2个,可以用VNCSERVERS="1:root 2:linglong"来配置
3.用vncpasswd创建一个vnc的口令

注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.
CODE:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]# ls -d .vnc
.vnc
[root@localhost ~]# ls .vnc
passwd
4.启动vnc服务.
CODE:[root@localhost ~]#  /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
察看一下.vnc这个目录的内容,应该类似于下面的东西.
注:在这里我刚开始出现“Warning: *****   is taken because of /tmp/.X1-lock”
在网上找了好多方法,终于找到解决办法了!
   我直接将: /tmp/.X1-lock 删除就可以 了 ,命令式: rm /tmp/.X1-lock
如果还出现其他的文件错误 也可照样操作!
CODE:[root@localhost ~]# cd .vnc
[root@localhost .vnc]# ls
localhost.localdomain:1.log localhost.localdomain:2.log passwd
localhost.localdomain:1.pid localhost.localdomain:2.pid xstartup
[root@localhost .vnc]#
编辑这个名为xstartup的脚本,
将这内容前面的注释符号去掉,否则你将只能得到一个什么都没有的灰屏。
#!/bin/sh
                                                                                            
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc                                                                                          
[ -x /etc/vnc/xstartup ] exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop"
twm

因为我们已经修改了启动脚本,现在来重新启动vncserver.
CODE:[root@localhost .vnc]#   /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
[root@localhost .vnc]#
5.防火墙端口设置
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901.
加入以下红色的部分,然后重启iptables服务。
[root@localhost ~]#   /sbin/service iptables restart
Flushing firewall rules:                               [   OK   ]
Setting chains to policy ACCEPT: filter                    [   OK   ]
Unloading iptables modules:                                [   OK   ]
Applying iptables firewall rules:                          [   OK   ]
[root@localhost ~]#

 

 

 

vim      /root/.vnc/xstartup   oracle用户 (/home/oracle/.vnc/xstartup)
twm &(默认文本类型桌面)修改为gnome-session(GNOME风格的桌面环境) startkde & (KDE风格桌面) 

 

 

 

Redhat下VNC SERVER的配置

1、启动VNC SERVER

输入vncserver,第一次启动会要求输入验证密码,完成后,VNC SERVER就启动了

    [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

    [root@localhost ~]#

2、编辑.vnc/xstartup

使用VI打开xstartup文件,如下:

    [root@localhost /]# cd /root/.vnc
    [root@localhost .vnc]# vi xstartup

删除全部内容,然后添加如下内容:

    unset SESSION_MANAGER
    exec /etc/X11/xinit/xinitrc


3、重启动VNC SERVER

    [root@localhost ~]# vncserver -kill :1
    Killing Xvnc process ID 21198

    [root@localhost ~]# vncserver

    New ‘localhost.localdomain:1 (root)’ desktop is localhost.localdomain:1

    Starting applications specified in /root/.vnc/xstartup
    Log file is /root/.vnc/localhost.localdomain:1.log

    [root@localhost ~]#

4、查看VNC的监听端口

如下,VNC用到了三个端口:5801、5901、6001。
    [root@localhost /]# netstat -nat
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State
    tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:5801                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:724                 0.0.0.0:*                   LISTEN
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN
    tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN
    tcp        0      0 172.200.102.3:5901          181.181.181.51:1669         ESTABLISHED
    tcp        0      0 :::6001                     :::*                        LISTEN
    tcp        0      0 :::22                       :::*                        LISTEN
    tcp        0   1364 ::ffff:172.200.102.3:22     ::ffff:181.181.181.51:1599  ESTABLISHED
    [root@localhost /]#
5、在防火墙上打开VNC用到的上面三个端口
    [root@localhost /]# cd /etc/sysconfig
    [root@localhost sysconfig]# vi iptables

添加如下三行:
    -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5801 -j ACCEPT
    -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5901 -j ACCEPT
    -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 6001 -j ACCEPT
重记动IPTABLES
    [root@localhost sysconfig]# /etc/rc.d/init.d/iptables restart
    Flushing firewall rules: [  OK  ]
    Setting chains to policy ACCEPT: filter [  OK  ]
    Unloading iptables modules: [  OK  ]
    Applying iptables firewall rules: [  OK  ]
    Loading additional iptables modules: ip_conntrack_netbios_ns ip_conntrack_ftp [  OK  ]



    [root@localhost sysconfig]#
6、使用VNC VIEW连接VNC SERVER
下载VNC VIEW,运行,然后输入IP:端口号,输入刚才设定的密码,进入REDHAT桌面。
http://www.aixchina.net/club/archiver/tid-27685.html

1、安装VNC

yum install vnc-server
2、添加多个用户
useradd user1  //添加用户user1
passwd user1  //设置用户的linux登录密码

su - user1          //切换到用户user1
vncpasswd      //设置用户的user1登录密码
exit

useradd user2  //添加用户user2
passwd user2  //设置用户的linux登录密码

su - user2         //切换到用户user2
vncpasswd     //设置用户的user2登录密码
exit
3、编辑vnc配置文件
vi /etc/sysconfig/vncservers
在最后加上:
VNCSERVERS="1:user1 2:user2"
VNCSERVERARGS[1]="-geometry 1024x768 -alwaysshared"  
VNCSERVERARGS[2]="-geometry 1024x768 -alwaysshared"
注意:-geometry 1024x768表示分辨率;-alwaysshared 表示允许多终端同时登陆

配置多个桌面
Linux下VNC配置多个桌面和修改密码

可以使用如下的方法启动多个桌面的VNC   
vncserver :1   vncserver :2   vncserver :3   ……   
但是这种手工启动的方法在服务器重新启动之后将失效,因此,下面介绍如何让系统自动管理多个桌面的VNC,
方法是将需要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中,先以桌面1为root用户桌面2为oracle用户为例进行配置如下:   
格式为:VNCSERVERS="桌面号:使用的用户名 桌面号:使用的用户名"   
[root@testdb ~]# vi /etc/sysconfig/vncservers   
VNCSERVERS="1:root 2:oracle"   
VNCSERVERARGS[1]="-geometry 1024x768"   
VNCSERVERARGS[2]="-geometry 1024x768"   
修改VNC访问的密码   
使用命令vncpasswd对不同用户的VNC的密码进行修改,一定要注意,如果配置了不同用户的VNC 需要分别到各自用户中进行修改,例如在我的这个实验中,root用户和oracle用户需要分别修改,修改过程如下:   
[root@testdb ~]# vncpasswd   
Password:   
Verify:
或vncpasswd oracle
vncpasswd root
 

 

4、打开对应的端口

打开5901至5902 端口用于vnc  //如果需要配置更多的桌面,增加端口即可

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值