20:33
0

Virtual Network Computing (VNC) คือ การแชร์ Desktop แบบ Graphical โดยใช้ Remote Frame Buffer protocol (RFB) ในการเข้าถึงเครื่องคอมพิวเตอร์ที่ต้องการ โดยบทความนี้จะสอนวิธีการติดตั้ง VNC Server บน Ubuntu ด้วยโปรแกรม tightvncserver

วิธีติดตั้ง VNC Server บน Ubuntu
1. เข้าสู่ Mode root privileges
1
sudo su
จากนั้นกรอกรหัสผ่านของ root ที่ติดตั้งบน Ubuntu

2. ก่อนทำการติดตั้งโปรแกรม ubuntu-desktop ให้ทำการ update และ upgrade ubuntu ให้เรียบร้อยก่อน
1
apt-get update & upgrade
* บางกรณีที่ไม่ได้ทำการ update และ upgrade จะทำให้เกิดปัญหาตอนติดตั้ง ubuntu-desktop ไม่สามารถแตกไฟล์บางไฟล์ได้ ซึ่งส่งผลทำให้เกิดปัญหาตอนติดตั้ง gdm ในขั้นตอนที่ 4

3. ติดตั้งโปรแกรม ubuntu-desktop
1
apt-get install ubuntu-desktop
* ขั้นตอนนี้ใช้เวลานาน แนะนำว่าระหว่างที่ Ubuntu กำลังติดตั้งอยู่ให้ผู้อ่านไปดาวน์โหลดโปรแกรม vnc client ไว้ก่อน เช่น TightVNC Viewer หรือ VNC-Viewer (ฟรี และสามารถใช้งานได้ทั้งคู่)

4. ติดตั้งโปรแกรม gdm (GNOME) 
1
apt-get intall gdm

4.1 กรณีที่มีหน้าต่าง Display Manager ขึ้นมาให้เลือกเป็น gdm แล้วกด OK

5. สั่งให้ gdm ทำงาน และ reconfigure
1
2
service gdm start
dpkg-reconfigure xserver-xorg
6. ติดตั้งโปรแกรม TightVNC Server
1
apt-get intall tightvncserver

7. เริ่มต้นทำงาน VNC และกำหนดรหัสผ่าน
1
vncserver

8. กำหนดรหัสผ่านสำหรับการใช้งาน vnc

9. หยุดการทำงานของ VNC ก่อนเพื่อกำหนดค่าต่อ (:1 คือ VNC ที่ 1 กล่าวคือ VNC นั้นจะถูกกำหนดเป็นหมายเลขเรียงลำดับจาก 1 ถึง n)
1
vncserver -kill :1

10. เปิดไฟล์ xstartup เพื่อกำหนดค่าการแสดงผลตอน VNC
1
2
cd
nano .vnc/xstartup

11. ใส่คำสั่งดังกล่าวไว้ที่บรรทัดล่างสุด
1
gnome-session &
12. สร้างไฟล์ service เพื่อสำหรับควบคุม และจัดการแต่ละ VNC ของ User (ตัวอย่างกำหนดเป็น vncserver1 คือ ย่อมากจาก :1)
1
nano /etc/init.d/vncserver1

13. ใส่ Code ดังนี้โดยแก้ไขตัวแปร USER ให้เป็น User ที่ต้องการเช่น USER="root" หรือ USER="administrator"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     3 4 5
# Default-Stop:      0 6
### END INIT INFO
PATH="$PATH:/usr/X11R6/bin/"
# The Username:Group that will run VNC
export USER="root"
#${RUNAS}
# The display that VNC will use
DISPLAY="1"
# Color depth (between 8 and 32)
DEPTH="16"
# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
#GEOMETRY="800x600"
GEOMETRY="1024x768"
#GEOMETRY="1280x1024"
# The name that the VNC Desktop will have.
NAME="my-vnc-server"
OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;
stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
* Thank You for Script from abdevelopment.ca *

14. เปลี่ยน access permissions ของไฟล์ที่สร้างจากขั้นตอนที่ผ่านมา
1
chmod +x /etc/init.d/vncserver1

15. กำหนดให้ Service vncserver1 ทำงานพร้อมกับตอนที่ OS Boot Process (เปิดเครื่อง)
1
update-rc.d vncserver1 defaults
จะได้ผลลัพธ์ดังรูป

17. สั่งให้ VNC Server :1 ทำงาน
1
vncserver

18. ทดสอบ Restart Server vncserver1
1
service vncserver start
หากดำเนินการถูกต้องจะแสดงผลประมาณดังรูป

19. ทดสอบ VNC Server โดยบทความนี้ใช้โปรแกรม TightVNC Viewer
19.1 กรอกหมายเลข IP Address:VNC-DISPLAY ตามตัวอย่าง แล้วกด Connect
19.2 กรอกรหัสผ่านที่กำหนดในขั้นตอนที่ 8 แล้วกดปุ่ม OK

20. หากไม่มีอะไรผิดพลาดจะพบว่าตอนนี้สามารถ VNC เข้าเครื่อง Ubuntu Server ได้เรียบร้อย

21. ทดสอบ Reboot Ubuntu เพื่อดูว่าหลังจาก Boot ขึ้นมาแล้ว Service VNC Server ยังทำงานอยู่รึเปล่า
21.1 Restart Ubuntu
1
reboot now -h

21.2 หลังจาก Boot ขึ้นมาแล้วให้ทดสอบตามขั้นตอนที่ 19 ใหม่อีกครั้งจะพบว่าสามารถ VNC Server ได้เหมือนเดิม

ขอบคุณ   http://amplysoft.com

0 ความคิดเห็น:

แสดงความคิดเห็น