centos 6.8 VNC 搭建(詳細)

 centos 6.8 VNC 搭建(詳細)

 

背景:考慮有些情況下,需要用到圖形化界面操作(如:配置KVM虛擬化),但是又不想去機房,針對這種情況,我們可以配置vnc服務,使得何時何處都可以輕鬆的辦公(只要網絡可達)


首先檢查是否安裝相應的軟件包

redhat@opman ~]$ rpm -qa |grep tigervnc

[redhat@opman ~]$

[redhat@opman ~]$

 

 沒有,則安裝!

yum -y install tigervnc

已加載插件:fastestmirror, refresh-packagekit, security

設置安裝進程

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

 

再次檢查是否安裝上

 

[root@opman ~]# rpm -qa |grep tigervnc

tigervnc-1.1.0-24.el6.x86_64

tigervnc-server-1.1.0-24.el6.x86_64

 

 

 啓動vnc,首次會生成/root/.vnc/xstartup 文件,後面要配置相關參數


[root@opman ~]# vncserver

 

You will require a password to access your desktops.

 

Password:

Verify:

Passwords don't match - try again

Password:

Verify:

xauth:  file /root/.Xauthority does not exist

 

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

 

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/opman:1.log

 

vim  /root/.vnc/xstartup

 

#twm &  //註釋該行

gnome-session &  //添加該行 如果爲KDE桌面,則修改爲:startkde &

 

啓動服務,發現報錯,需要修改配置文件

[root@opman ~]# /etc/init.d/vncserver  start

正在啓動 VNC 服務器:no displays configured                [失敗]

 

 

vim   /etc/sysconfig/vncservers ;添加末尾3行;作用是設定vnc用戶和對應界面的設置。我設置了兩個用戶分別是redhat 和root

 image.png


最後啓動vncserver 並設置爲開機啓動,執行以下

# service vncserver start

# chkconfig vncserver on

 

 檢查vnc服務的端口

[root@opman ~]# netstat -tunlp |grep vnc

tcp        0      0 0.0.0.0:5801                0.0.0.0:*                   LISTEN      3744/Xvnc          

tcp        0      0 0.0.0.0:5802                0.0.0.0:*                   LISTEN      4481/Xvnc          

tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      3744/Xvnc          

tcp        0      0 0.0.0.0:5902                0.0.0.0:*                   LISTEN      4481/Xvnc          

tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      3744/Xvnc          

tcp        0      0 :::6001                     :::*                        LISTEN      3744/Xvnc

 

 查看vnc 進程

[root@opman ~]#  ps -ef |grep vnc

root       3744      1  0 16:56 pts/0    00:00:00 /usr/bin/Xvnc :1 -desktop opman:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn

root       3754   3753  0 16:56 pts/0    00:00:00 vncconfig -iconic

root       4481      1  0 17:09 pts/0    00:00:00 /usr/bin/Xvnc :2 -desktop opman:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 800x600 -depth 32 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn -nolisten tcp

root       4492   4490  0 17:09 pts/0    00:00:00 vncconfig -iconic

root       5090   4787  0 17:25 pts/0    00:00:00 grep vnc

 

用vncview 連接測試效果:

發現連接超時,在一切都正常的情況下,關閉防火牆。

image.png

service iptables stop

[root@opman .vnc]# service iptables stop

iptables:將鏈設置爲政策 ACCEPTnat mangle filter         [確定]

iptables:清除防火牆規則:                                 [確定]

iptables:正在卸載模塊:                                   [確定]

[root@opman .vnc]#

再次連接,ip+:2(ip + 端口)

image.png


image.png


 



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