Linux 可以通过使用SSH 远程连接来进行控制,也可以在主机执行以下命令进行投射。
[root@localhost ~]# export DISPLAY=ipaddress:0
[root@localhost ~]# xhost +这个命令要求ipaddress 的机器装有X Server(比如Xmanager),但有时需要将远程整个的Linux 桌面投射到本地,这时仍可通过安装配置Xmanager 来实现。
本文主要介绍VNC Server 的配置方法,需配置好yum 源,文中的“主机”指安装Linux 的机器。
1. 首先验证主机上是否安装VNC Server,使用
[root@localhost ~]# yum list | grep vnc的命令。返回
tigervnc.x86_64 1.0.90-0.10.20100115svn3945.el6 @local
tigervnc-server.x86_64 1.0.90-0.10.20100115svn3945.el6 @local就代表已经存在,否则就通过
[root@localhost ~]# yum install "*vnc*"的命令进行安装。
2. 随后启动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这里要注意:每个用户都可以启动多个VNC Server 远程桌面,它们用ip 加端口号:ip:1、ip:2、ip:3 来标识区分,使用同一端口会使另外登录的用户自动退出。另,VNC Server 的大部分配置文件及日志文件都在用户home 目录的.vnc 目录下。
用户可以自定义启动号码如:
[root@localhost ~]# vncserver :2 #注意:2前面一定要有空格。
A VNC server is already running as :23. Red Hat Linux 支持两种图形模式:KDE 模式和gnome 模式。
你的Redh Hat 使用的什么图形模式这个一般只有登录到图形界面查看一下才能知道,或者通过
[root@localhost ~]# ps -aux | grep gnome这样的命令来判断。
如果是gnome 桌面,那么需要修改/root/.vnc/xstartup的配置文件。
使用vi 打开xstartup 文件,如下:
[root@localhost /]# cd /root/.vnc
[root@localhost .vnc]# vi xstartup删除全部内容,然后添加如下内容:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc4. 重启动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.log5. 在防火墙上打开VNC Server 的监听端口
VNC Server 用到了三个端口:5801、5901、6001。
[root@localhost /]# cd /etc/sysconfig
[root@localhost sysconfig]# vi iptables添加如下三行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5801 -j ACCEPT
-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注意,一定要在
-A INPUT -j REJECT --reject-with icmp-host-prohibited的前面,否则不会生效。
6. 重新启动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 ]7. 在Windows 机器上使用VNC Viewer 连接VNC Server
下载 VNC Viewer,运行然后输入IP:5901,输入刚才设定的密码,进入 RHEL 桌面。