迷彩 潜伏 隐蔽 伪装
分类: LINUX
2014-01-01 22:28:30
原文地址:linux下如何配置vnc 作者:hxl
环境:
Os: Red Hat Linux As 5
1.检查是否安装了vnc
[root@standby ~]# rpm -qa|grep vnc
vnc-server-4.1.2-9.el5
vnc-4.1.2-9.el5
vnc已经安装,可以继续如下步骤,否则需要安装vnc
2.切换到需要vnc的用户下执行(这里是在oracle用户下),设定密码
standby-> vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /u01/export/home/oracle/.Xauthority
New 'standby:1 (oracle)' desktop is standby:1
Creating default startup script /u01/export/home/oracle/.vnc/xstartup
Starting applications specified in /u01/export/home/oracle/.vnc/xstartup
Log file is /u01/export/home/oracle/.vnc/standby:1.log
3.停止vncserver:1
standby-> vncserver -kill:1
Warning: standby:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server standby:1
New 'standby:3 (oracle)' desktop is standby:3
Starting applications specified in /u01/export/home/oracle/.vnc/xstartup
Log file is /u01/export/home/oracle/.vnc/standby:3.log
这个时候需要将/tmp/.X11-unix/X1文件删除掉
4.编辑.vnc目录下的文件xstartup,添加如下内容
vi xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
[ -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 &
gnome-session &
#startkde kde
5.编辑vncservers文件(root下执行),添加如下内容
vi /etc/sysconfig/vncservers
VNCSERVERS="1:oracle"
VNCSERVERARGS[1]="-geometry 1024x768"
6.启动vncserver:1
standby-> vncserver :1
7.在客户端vnc viewer输入
192.168.50.150:1即可使用图形界面了,192.168.50.150是服务器的ip地址.
解决连接不上问题的方法
执行命令,查看VNC监听的端口是什么,在防火墙中开放端口即可.
# netstat -ntupl|grep vnc
返回列表如:
[root@node1 /]# netstat -ntupl|grep vnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 4593/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 3940/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 4593/Xvnc
tcp 0 0 0.0.0.0:6002 0.0.0.0:* LISTEN 3940/Xvnc
tcp 0 0 :::6001 :::* LISTEN 4593/Xvnc
tcp 0 0 :::6002 :::* LISTEN 3940/Xvnc
修改防火墙配置文件,开放5901端口即可
# more /etc/sysconfig/iptables
[root@node1 /]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
重新启动iptables
# service iptables restart
说明:
1.使用vnc viewer 登录的时候无法输入用户名的,若要想使用某个用户登录,需要在该用户的command下启动vncserver,具体指定桌面号,如[grid ~]$vncserver:1这样的话,再使用vnc viewer登录,登录进去的用户默认就是该用户了.
2.修改了用户的环境变量后,需要kill掉vnc进程重新启动后环境变量才会生效.
语法是 vncserver -kill :1
1这里是桌面号,注意kill和:之间需要空格,否则的话提示语法错误.
重新启动的命令是:
vncserver :1
-- The End