Linux VNC server 安裝配置


VNC運行的工作流程如下:

1、VNC客戶端通過瀏覽器或VNC Viewer連接至VNC Server。

2、VNC Server傳送一對話窗口至客戶端,要求輸入連接密碼,以及存取的VNC Server顯示裝置。

3、在客戶端輸入聯機密碼后,VNC Server驗證客戶端是否具有存取權限。

4、若是客戶端通過VNC Server的驗證,客戶端即要求VNC Server顯示桌面環境。

5、VNC Server通過X Protocol 要求X Server將畫面顯示控制權交由VNC Server負責。

6、VNC Server將來由 X Server的桌面環境利用VNC通信協議送至客戶端,並且允許客戶端控制VNC Server的桌面環境及輸入裝置。

1.安裝vnc server
[ root@pxe ~]# yum install tigervnc-server -y
 
2.設置 vnc server 開機啟動
[ root@pxe ~]# chkconfig vncserver on
 
3.修改vncserver 配置文件
[ root@pxe ~]# vi /etc/sysconfig/vncservers
在配置文件后添加以下內容
VNCSERVERS="2:root"
VNCSERVERARGS[2]="-geometry 1366x768 -nolisten tcp"
 
設置vncserver 的密碼
[ root@pxe ~]# vncpasswd 
Password:
Verify:
 
4.啟動sncserver 服務
[ root@pxe ~]# /etc/init.d/vncserver start
 
5.使用VNC Viewer 遠程連接
 
 
 
CentOS7配置VNC
centos7配置vnc遠程.pdf
 
一.安裝
以root用戶運行以下命令來安裝vncserver;
yum install tigervnc-server 
同樣運行以下命令來安裝vncviewer;
yum install vnc
停止並禁用防火牆;
systemctl stop firewalld.service
systemctl disable firewalld.service
 
二.配置
vncviewer基本上不用配置;
vncserver的配置,創建一個新的配置文件,以開啟1號窗口為例(也可以同時開啟多個窗口,修改數字即可),方法如下:
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
或者再增加一個窗口:
 
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service

 

編輯/lib/systemd/system/vncserver@:1.service,設置用戶root相關參數
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l  root -c "/usr/bin/vncserver %i -geometry 800x600"
PIDFile= /root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
 
三.應用
更新systemctl以使其生效;
systemctl daemon-reload 
設置vncserver的密碼;
 vncpasswd root
按提示輸入密碼以及確認密碼
啟動該服務用來啟用vnc的1號窗口;
systemctl start vncserver@:1.service  或者  vncserver :1
關閉1號窗口:
systemctl stop vncserver@:1.service   或者  vncserver -kill :1
設置為開機自動啟動;
systemctl enable vncserver@:1.service
End.
 
一, 確認及安裝VNCSERVER。
1,首先確認你服務器是否配置了VNCSERVER,可以在命令行下敲入以下命令查看:
[root@localhost: ~]#rpm -qa |grep vnc
vnc-server-4.1.2-14.el5_3.1.i386.rpm     #返回VNCSEVER服務器端版本說明你已經安裝了VNCSERVER。

2,如果沒有安裝VNCSEVER,那么從光盤找到安裝包進行安裝。
首先將光盤掛載(也叫解壓)到某個目錄這里是在/var/ftp/pub/下面建立了rhel5-64目錄
mount -o loop rhel-server-5.3-x86_64-dvd.iso /var/ftp/pub/rhel5-64/
然后在/var/ftp/pub/rhel5-64/Server目錄下找到 vnc-server-4.1.2-14.el5.x86_64.rpm安裝包(也可以使用地址:
http://centos.ustc.edu.cn/centos/5.5/os/i386/CentOS/vnc-server-4.1.2-14.el5_3.1.i386.rpm下載),使用

RPM命令直接安裝;
rpm -ivh vnc-server-4.1.2-14.el5_3.1.i386.rpm


或者使用yum安裝:
# yum install vnc


二,開始配置VNCSERVER
1,啟動VNCSERVER,第一次啟動VNCSERVER會提示輸入密碼,這里分為管理員賬戶及普通賬戶,啟動方式略有所不同。
管理員:
[root@localhost /]# vncserver
You will require a password to access your desktops.
Password: 123456            #輸入vnc 連接密碼
Verify: 123456                 #確認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 ceboy    #ceboy 是用戶名
[ceboy@localhost /]$ vncserver
You will require a password to access your desktops.
Password: 123456            #輸入vnc 連接密碼
Verify: 123456                 #確認vnc密碼
xauth: creating new authority file /home/ceboy/.Xauthority
New ‘localhost.localdomain:2 (ceboy)’ desktop is localhost.localdomain:2
Creating default startup script /home/ceboy/.vnc/xstartup
Starting applications specified in /home/ceboy/.vnc/xstartup
Log file is /home/ceboy/.vnc/localhost.localdomain:2.log

#這里要注意:每個用戶都可以啟動自己的VNCSERVER遠程桌面,同時每個用戶可以啟動多個VNCSERVER遠程桌面,它們用ip加端口號:ip:1、ip:2、ip:3 來標識、區分,使用同一端口會使另外登錄的用戶自動退出。另,VNCSERVER的大部分配置文件及日志文件都在用戶home目錄下.vnc目錄下。
用戶可以自定義啟動號碼如:
[ceboy@localhost /]$ vncserver :2        #注意:2前面一定要有空格。
A VNC server is already running as :2

三,相關桌面配置,RedHat Linux支持兩種圖形模式:KDE模式和gnome模式。

1,你的RH使用的什么圖形模式這個一般只有登錄到圖形界面查看一下才能知道,或者通過ps -A命令列出所有當前運行的程序,看看有沒有KDE或者gnome字樣來判斷一下。如果你是gnome桌面,那么你需要修改/root/.vnc/xstartup的配置文件。

[root@localhost .vnc]# vi 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" &
gnome-session gnome           #添加這一句是連接時使用gnome 桌面環境
twm &

設置修改完畢最好是重啟一次系統,否則設置不會生效。我采用的方法是殺死VNCSERVER進程再重運行VNCSERVER。
[root@localhost .vnc]#vncserver -kill :1      #這里你啟動vncserver時是什么端口號要對應上。
[root@localhost .vnc]#vncserver :1           #重啟VNCSERVER,注意:1前面一定要有空格。

2,設置用戶信息及分辨率。

[root@localhost: ~]#vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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/archive/vnc/sshvnc.html >.
# Use “-nolisten tcp” to prevent X connections to your VNC server via TCP.
# Use “-nohttpd” to prevent web-based VNC clients connecting.
# Use “-localhost” to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the “-via” option in the
# `man vncviewer’ manual page.

VNCSERVERS="1:root 2:ceboy"            #此處添加用戶,一般只添加一個1:root也就行了。
VNCSERVERARGS[1]="-geometry 800×600 -nolisten tcp -nohttpd -localhost"
VNCSERVERARGS[2]="-geometry 1024×768 -nolisten tcp -nohttpd -localhost"
#注意:上面是分別設置的root和ceboy兩個用戶的分辨率,注意是用端口號區分的。

另外也可以通過命令行臨時修改分辨率及色深,這種方式重啟后就會丟失,這里暫時用不到,命令如下:
[root@localhost: ~]#vncserver -geometry 800×600        #設置vncserver的分辨率   
[root@localhost: ~]#vncserver -depth 16           #設置vncserver的色深

到這里VNCSERVER服務器端就配置完成了。

四,客戶端連接及使用。
1,訪問方式
a、在linux下,運行vncviewer命令即可,服務器地址的寫法形如192.168.1.11:1
b、在windows下,運行windows版本的vncviewer即可,用法與linux下相近。
c、用瀏覽器(平台無關),作為java applet來實現,以形如http://192.168.1.11:5801 的方式來啟動
(vnc 端口從5800 開始依次類推,一般會是5800,5900)


以下為一些常識:
2,修改密碼
運行vncpasswd即可

3,停止vncserver
#vncserver -kill :1
#vncserver -kill :2
注意到vncserver只能由啟動它的用戶來關閉,即時是root也不能關閉其它用戶開啟的vncserver,只能用
kill命令暴力殺死進程。

4,穩定性設置
vncserver默認在多個客戶機連接同一個vncserver的顯示端口時,vncserver端口舊連接,而為新連接服
務,可通過-dontdisconnect拒絕新連接請求而保持舊的連接。

5,同一個顯示器可以連接多個客戶機
#vncserver -alwaysshared

6,重啟服務
service vncserver restart

7,讓系統啟動時自動啟動VNCSERVER。
使用VNC連接登錄到RedHat Linux圖形界面,點擊“系統”——“管理”——“服務器設置”——“服務
”,在“后台服務”中找到VNCSERVER后勾選它,點擊保存即可。
 

3、配置分辨率和用戶登錄信息

# vim /etc/sysconfig/vncservers

參考最后兩行添加自己的配置
VNCSERVERS="2:root"
VNCSERVERARGS[2]="-geometry 1024x768"

4、配置 VNC 登錄密碼

執行下列命令
# vncserver
首次執行提示設置密碼,根據提示輸入兩次密碼即可

5、配置 VNC 登錄桌面模式
Centos Linux支持兩種圖形模式:KDE模式和gnome模式,如果是gnome桌面則需修改 /root/.vnc/xstartup 的配置相關項
# vim /root/.vnc/xstartup

個人理解上面的意思是用戶目錄下需要.vnc目錄因為我的不需要配置就可以直接通過vnc viewver直接連接linux

VNC的啟動/停止/重啟

# service vncserver start/stop/restart

關閉具體的vncserver命令:vncserver -kill :1       vncserver -kill :2

如果沒有安裝采用yum安裝
yum -y install vnc
2.
配置VNC用戶如果以root登錄的話,輸入
vncpasswd
Password:
Verify:
設置root用戶的VNC登錄用戶名和密碼
3.配置vnc-server的配置文件

/etc/sysconfig/vncservers
內容如下:
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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/archive/vnc/sshvnc.html>.
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-nohttpd" to prevent web-based VNC clients connecting.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.
VNCSERVERS="1:root"
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
VNCSERVERARGS[1]="-geometry 800x600"
1.VNCSERVERS=后面可以支持多用戶,以空格隔開。如:
VNCSERVERS="1:myusername 15:otheruser"--->這里的1 和15是端口號,用於連接時的端口
2.VNCSERVERARGS后面的[]里面的數據要與VNCSERVERS后面對應用戶的值要一致。好像不一致也沒有關系
VNCSERVERARGS基本參數有:
-geometry 桌面大小,缺省是1024x768
-nohttpd 不監聽HTTP端口
-nolisten tcp 不監聽X端口
-localhost 只允許從本機訪問
-AlwaysShared 默認的, 同時只能有一個vncviewer連接(跟客戶端配置也有關), 一旦第2個連上去, 第1個就被斷開了. 此參數允許同時連多個vncviewer
-SecurityTypes None登錄不需要密碼認證 VncAuth默認值,要密碼認證
啟動vncserver
/sbin/nvcserver start
如果沒有出錯的話,就會啟動vnc服務了
4.修改默認桌面設置
在root的用戶目錄下面的.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 & ---把這兩行注釋掉,加上
#exec startxfce4
gnome-session
重新啟動vncserver
netstat -antpl查看可以發現有三個端口在監聽。
5901 5801 6001
這三個端口:
默認的, vnc 服務監聽3個TCP端口
RFB(Remote FrameBuffer)協議 默認端口 : 5900 顯示器號
HTTP協議默認端口 : 5800 顯示器號
X協議 默認端口 : 6000 顯示器號
vncserver使用的顯示器編號默認從1開始, 依次使用, 也可以參數指定端口號
我們只需要RFB協議就可以了,所以我們把5800 6000這兩種端口關掉。
需要修改/etc/sysconfig/vncservers
在參數后面加上:
-nohttpd 不監聽HTTP端口

-nolisten tcp 不監聽X端口

5. Windows登陸到VNC Server

(1).從IE登錄
直接從IE瀏覽器中輸入如下地址:
http://xxx.xxx.xxx.xxx:5801
輸入密碼即可使用。
(2).從VNC view登錄
在windows上安裝vnc view,然后輸入xxx.xxx.xxx.xxx:1,連接登錄,輸入密碼即可。
備注:如果從vnc view登錄時,提示connection refused(10061),則是因為linux防火牆的問題,登錄centos系統,選擇 System-->Preferences-->Remote Desktop,勾選sharing中的兩項,Security兩項不勾,點擊關閉,然后再重新用vnc view登錄即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM