Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2734750
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: LINUX

2012-06-27 13:55:23

原文出处:http://blog.sina.com.cn/s/blog_6e9052260100vuni.html


使用SSH连接远程通过字符界面来操作Linux,但是对于更多熟悉图形人来说是很不方便的,因此开启Linux的远程桌面还是很有必要的。目前有两种比较流行的方式:XDM(X display manager)方案和VNC方案,而我比较倾向于VNC方案,一是因为VNC方案配置起来相对比较容易,二是VNC方案支持多种连接方式,比如通过浏览器访问Linux桌面,免去需要安装客户端的麻烦.

VNC软件主要由两个部分组成:VNC SERVERVNC VIEWER。将VNC SERVER安装在被控制的主机上,才能在主控端执行VNC VIEWER控制被控端。

1、 确认及安装VNCSERVERVNCSERVERRPM包:tigervnc-server; 如果没有安装VNCSEVER,那么从光盘找到安装包进行安装,可以通过YUM来安装

rpm –q tigervnc-server

2、 开始配置VNCSERVER:可以使用vncserver命令来启动VNC服务:命令格式为:vncserver :桌面号,其中桌面号用数字的方式表示,每个用户连接要占用一个桌面,VNC服务使用的端口号与桌面号相关,VNC服务使用的TCP端口号从5900开始,例如桌面号是1,则使用的端口号是5901,桌面号是2,则端口号为5902

启动VNCSERVER,第一次启动VNCSERVER会提示输入密码,这里分为管理员账户及普通账户,启动方式略有所不同

管理员帐户:
[root@localhost /]# vncserver :1
You will require a password to access your desktops.
Password:
输入vnc 连接密码
Verify:
确认vnc密码
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 /]#su - chenyinghong
[chenyinghong @localhost /]$ vncserver :2
You will require a password to access your desktops.
Password:
输入vnc 连接密码
Verify:
确认vnc密码
xauth: creating new authority file /home/ chenyinghong /.Xauthority
New 'localhost.localdomain:2 (chenyinghong)' desktop is localhost.localdomain:2
Creating default startup script /home/chenyinghong /.vnc/xstartup
Starting applications specified in /home/chenyinghong /.vnc/xstartup
Log file is /home/ chenyinghong/.vnc/localhost.localdomain:2.log
*
注意到每个用户都可以启动自己的 vncserver,每个用户可以启动多个 vncserver
ip加端口号 ip:1ip:2ip:3 来标识、区分,使用同一端口会使另外登录的用户自动退出。另,VNCSERVER的大部分配置文件及日志文件都在用户home目录下.vnc目录下
用户可以自定义启动号码如

例:
[chenyinghong@localhost /]$ vncserver :2
#注意:2前面一定要有空格
A VNC server is already running as :2

相关桌面配置,RHEL支持两种图形模式:KDE模式和gnome模式,你的RHEL使用的什么图形模式这个一般只有登录到图形界面查看一下才能知道,或者通过ps -A命令列出所有当前运行的程序,看看有没有KDE或者gnome字样来判断一下。
编辑/home/user1/.vnc/xstartup(如果不存在的话,可以手动创建一个,并给予可执行权限),内容如下:

1. #!/bin/sh

2. vncconfig -iconic &

3. unset SESSION_MANAGER

4. unset DBUS_SESSION_BUS_ADDRESS

5. OS=`uname -s`

6. if [ $OS = 'Linux' ]; then

7. case "$WINDOWMANAGER" in

8. *gnome*)

9. if [ -e /etc/SuSE-release ]; then

10. PATH=$PATH:/opt/gnome/bin

11. export PATH

12. fi ;;

13. esac

14. fi

15. if [ -x /etc/X11/xinit/xinitrc ]; then

16. exec /etc/X11/xinit/xinitrc

17. fi

18. if [ -f /etc/X11/xinit/xinitrc ]; then

19. exec sh /etc/X11/xinit/xinitrc

20. fi

21. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

22. xsetroot -solid grey

23. xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

24. #twm &

配置防火墙以及SELinux

运行system-config-firewall启动防火墙配置界面,在Other Ports里面添加端口5901,协议选择tcp.如果启用了SELinux的话,需要运行chcon -t unconfined_exec_t /usr/bin/vncserver 改变vncserverSecurity Context,否则在使用VCN连接的时候会碰到很多问题,比如点击桌面的图标没有反应,程序不能被启动等等

编辑/etc/sysconfig/vncservers,内容如下:添加用户名机设置用户登陆的桌面环境信息
VNCSERVERS="1:user1 2:user2"
VNCSERVERARGS[1]="-geometry 800x600
-alwaysshared " -alwaysshared代表允许多用户同时登录

VNCSERVERARGS[2]="-geometry 800x600"
然后运行sudo chkconfig --level 345 vncserver on ,让VNC Server随系统自动启动最后,运行sudo /etc/init.d/vncserver start 来启动VNC Server

测试连接

使用VNC客户端连接:1 ,使用上面设置的密码。Linux上可以使用TigerVNC的客户端;Windows上推荐使用UltraVNC ( )

密码修改:
运行:
#vncpassword
即可:

停止vnc server
#vncserver -kill :1
#vncserver -kill :2

阅读(2168) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~