歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS下快速配置VNC Server

CentOS下快速配置VNC Server

日期:2017/2/28 16:09:08   编辑:Linux教程

一、啟動VNC Server服務

使用vncserver命令(會在當前用戶主目錄下生成.vnc文件夾)

[[email protected] ~]# vncserver

You will require a password to access your desktops. Password:<輸入密碼>
Verify:<輸入密碼>
xauth: creating new authority file /root/.Xauthority

New 'CPAYNET005:1 (root)' desktop is CPAYNET005:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/CPAYNET005:1.log 二、配置VNC Server啟動文件

首次創建 ~HOME/.vnc/xstartup 時,指定的窗口管理器是 twm ,它是一個極小的窗口管理器,幾乎每台 X Window 系統機器上都有 twm。twm 不具備完整“桌面管理器”(象 KDE、GNOME 或 WindowMaker)的大部分花哨功能。下面是修改過的示例:

#!/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 &
gnome-session &

在文件中,將倒數第二、三行注銷掉,增加倒數第一行,表示啟動GNOME桌面系統。

當然,倒數第一行也可以改為startkde &,表示啟動KDE桌面系統。

三、關閉VNC Server服務

vncserver -kill :桌面號
例如:關閉上面的vnc連接
vncserver -kill :1

四、VNC Server 高級設置

1.設置vncserver啟動腳本(/etc/init.d/vncserver)實現系統自啟動時啟動vncserver.

# 在/etc/rc.d/rc.local文件中加入下面行

/etc/init.d/vncserver start

#也可以用chkconfig命令實現系統自啟動時啟動vncserver
[[email protected] ~]# chkconfig --level 2345 vncserver on

2、編輯/etc/sysconfig/vncservers

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768"

在ARGS 中修改"1024x768"來適應自己的X桌面實際參數配置。可以在這裡添加任何其他VNC服務器參數配置。在VNCSERVERS中修改 root 為你希望運行VNC桌面的用戶。VNCSERVERS中的1表示VNC以桌面1運行,如果希望添加其他的桌面,可以修改配置如下:

VNCSERVERS="1:user1 2:user2 3:user3"

3.設置vnc server的訪問密碼

使用vncpasswd命令

4、在RedHat系統上,使用以下命令啟動VNC:

/etc/init.d/vncserver start

5、查看VNC Server啟動情況

[[email protected] ~]# netstat -tulnp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:5801 0.0.0.0:* LISTEN 5248/Xvnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 5248/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 5248/Xvnc
tcp 0 0 :::6001 :::* LISTEN 5248/Xvnc

注:如果在浏覽器中通過web方式訪問VNC則 端口為:5801,如果通過VNC客戶端(比如VNC Viewer)來訪問VNC則端口為:5901

Copyright © Linux教程網 All Rights Reserved