VNC

轉自:http://hi.baidu.com/daniel_tu/blog/item/aaf8ad1cd63c2c8e87d6b60b.html

1.查看VNC是否已經安裝:
$ rpm -q vnc vnc-server
vnc-4.1.2-24.fc8
vnc-server-4.1.2-24.fc8


我們一般用的是Tigervnc.

yum install -y tigervnc tigervnc-server

vnc是客戶端,vnc-server是服務器端

2.把用戶名加入到配置文件中:

CODE:
[root@localhost ~]# sudo 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"

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 ~]# sudo /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這個目錄的內容,應該類似於下面的東西.

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]# sudo /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 ~]# sudo vi /etc/sysconfig/iptables

# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT - [0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

[root@localhost ~]# sudo /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 ~]#
================================
其他:
================================

1. 讓vncserver接受兩個不同的用戶:

CODE:
VNCSERVERS="1:root 2:yanyp"

當然你要爲兩個用戶分別運行vncpasswd來設置口令. 並且在你的防火牆修改中,你應該明白VNC使用端口5901給連接1用,如果象上面一樣要支持兩個用戶,應同時打開5901和5902.

2. 如果安裝了用客戶端vncviewer可以使用 vncviewer命令來遠程連接vncserver

[root@localhost ~]$ vncviewer localhost(或者用IP地址):1

輸入你的vnc口令,就可以了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章