centos远程桌面vnc

来源:互联网 发布:原生js ajax请求 编辑:程序博客网 时间:2024/06/05 23:39

环境:

CentOS 6.3 Final,桌面安装了除KDE的所有组件

 

1、安装服务

 

[plain] view plaincopy
 
 
  1. yum install tigervnc-server  

 

名字有点怪哦,CentOS5前叫vnc-server

 

2、运行并设置密码

 

[plain] view plaincopy
 
 
  1. vncserver[:1]  

 

输入密码,会生成相关的文件

 

[plain] view plaincopy
 
 
  1. xauth:  creating new authority file /root/.Xauthority  
  2.   
  3. New 'centos6-244:1 (root)' desktop is centos6-244:1  
  4.   
  5. Starting applications specified in /root/.vnc/xstartup  
  6. Log file is /root/.vnc/centos6-244:1.log  

 

3、配置用户

 

[plain] view plaincopy
 
 
  1. vim /etc/sysconfig/vncservers  
最后一行加入:

 

VNCSERVERS="1:root" 多个用户用空格分开,并要先su - 到那个用户运行vncserver[:n]来设定配置文件和密码

 

4、实用命令

usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]
                 [-geometry <width>x<height>]
                 [-pixelformat rgbNNN|bgrNNN]
                 [-fp <font-path>]
                 [-fg]
                 <Xvnc-options>...


       vncserver -kill <X-display>
       vncserver -list

vncserver[:n] 开服务

vncserver -list 看有几个在运行

vncserver -kill :n   杀掉第几个x-display

vncpasswd           修改密码

 

5、服务管理

service vncserver restart

其它用法:/etc/init.d/vncserver {start|stop|restart|try-restart|status|force-reload}

chkconfig vncserver on 加入到自启动(chkconfig --level 35 vncserver on)

 

6、客户端连接

CentOS:使用TigerVNC Viewer 连接 ip:1

Windows:使用Real VNC Viewer 连接ip:1

输入密码即可访问


===============================================================================================

必须明白:
vncserver在调用的时候,会根据你的配置来启用server端的监听端口,
端口默认是从5900开始,再加上你的桌面号。
比如你的桌面号为1,则vnc的连接端口号为5900+1=5901
比如你的桌面号为10000,则vnc的连接端口号为5900+10000=15900
======================================================================
下面配置VNC服务器,使用户(root)能够通过vnc客户端远程连接到linux系统的图形界面(前提是你的服务器要安装桌面)

1、检查linux系统是否安装VNC
在终端窗口输入命令:

rpm -q vnc-server

返回信息如下

package vnc-server is not installed

说明vnc服务器没有安装
2、运行以下命令进行安装:

yum install vnc vnc-server

3、启动VNC服务

vncserver
You will require a password to access your desktops.
Password:
Verify:

会提示输入密码,这个密码是远程登录时所需要输入的密码,输入密码,回车
4、切换到root账号:su root然后输入root账号的密码

vi /etc/sysconfig/vncservers  #vnc配置文件
VNCSERVERS="10000:root"  # 把前面的#取消了   10000:root (桌面号:用户)
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

最后保存退出
5、配置防火墙,允许10000+5900=15900端口通过防火墙(否则远程连不上VNC服务器)

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 15900 -j ACCEPT(允许15900端口通过防火墙)

保存退出
6、重启vnc服务器

 /etc/init.d/vncserver restart
或者
service vncserver restart

7、重启防火墙,使刚才的端口配置生效

/etc/init.d/iptables restart
service iptables restart

8、 设置vnc服务器开机自动启动
第一种方法:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击确定,配置完成。
第二种方法:使用“chkconfig”在命令行模式下进行操作,命令使用如下

chkconfig vncserver on
chkconfig --list vncserver
vncserver       0:off   1:off   2:on    3:on    4:on    5:on    6:off

9、更改vnc连接密码
vncpasswd
到此,VNC服务端设置完成,用VNC客户端可以连接了
vnc服务器:你的ip:15900

注意:如果在连接上之后,出现灰屏,可以按照下面的方法设置
进入用户的home目录, cd /home/user
如果是用root账号登录的,那么当前目录就是用户根目录

cd ~/.vnc
vi xstartup  #编辑
#twm &    #注释掉这一行
gnome-session &   #添加这一行

保存退出即可正常连接!

做到这里,总算是大功告成了,接下来你可以用http://IP:port的方式来WEB登录比如说

http://IP:5801,也可以在vncviewer里用IP:1这种来登录。

0 0