Monday, August 25, 2008

VNC server with CentOS 4 ว่าด้วยการ config

สวัสดีครับพี่น้อง ผมได้อ่านและทำตามการติดตั้ง vncserver ด้วย CentOS 4.6 ของบทความนี้ และใช้งานได้
จึงเห็นสมควรอนุรักษ์ไว้ จึง copy มาทั้งดุ้นแบบนี้ เชิญท่านทัศนาได้แล้ว ณ บัดนี้


Contents

1. Installing the required packages
2. Configuring un-encrypted VNC
1. Create your VNC users
2. Set your users' VNC passwords
3. Edit the server configuration
4. Create xstartup scripts
5. Test each VNC user
1. Testing with a java enabled browser
2. Testing with a vnc client
3. Starting vncserver at boot
3. VNC encrypted through an ssh tunnel
4. Recovery from a logout
5. VNC-Sever setup with no hassles with vnc-ltsp-config
6. VNC-Server for an already logged in GUI console session

VNC is used to display an X windows session running on another computer. Unlike a remote X connection, the xserver is running on the remote computer, not on your local workstation. Your workstation ( Linux or Windows ) is only displaying a copy of the display ( real or virtual ) that is running on the remote machine.

There are several ways to configure the vnc server. This HOWTO shows you how to configure VNC using the 'vncserver' service as supplied by CentOS.

1. Installing the required packages

The server package is called 'vnc-server'. Run the command rpm -q vnc-server.

The result will be either package vnc-server is not installed or something like vnc-server-4.0-11.el4.

If the server is not installed, install it with the command: yum install vnc-server.

The client program is 'vnc'. You can use the command yum install vnc to install the client if rpm -q vnc shows that it is not already installed.

Make sure to install a window manager in order to get a normal GUI desktop. You can use the command yum groupinstall "GNOME Desktop Environment" to install the Gnome Desktop and requirements, for example. Other popular desktop environments are "KDE" and "XFCE-4.4". XFCE is more light-weight than Gnome or KDE and available from the "extras" repository.

ตรงนี้หากเราติดตั้ง CentOS และเลือก Xwindows พร้อมกับ KDE หรือ Gnome แล้วตั้งแต่แรกก็สามารถข้ามไปได้ อนึ่ง
ในลินุกซ์การติดตั้ง package เป็นขบวนแบบนี้ภายหลังยุ่งยากมาก เพราะไฟล์ที่ต้องการและขึ้นต่อกันมีเยอะเกินไป
จึงควรทำเสียให้เสร็จตั้งแต่ตอนแรกแล้ว....

2. Configuring un-encrypted VNC

We will be setting up VNC for 3 users. These will be 'larry', 'moe', and 'curly'.

You will perform the following steps to configure your VNC server:

1. Create your VNC users.
2. Set your users' VNC passwords.
3. Edit the server configuration.
4. Create xstartup scripts.
5. Test each VNC user.

2.1. Create your VNC users หรือ นัยหนึ่่งคือสร้าง user ในลินุกซ์ หากมี user อยู่แล้วให้ข้ามไปขั้นตอน
สร้าง password เลย

As root:

# useradd larry
# useradd moe
# useradd curly
# passwd larry
# passwd moe
# passwd curly

2.2. Set your users' VNC passwords

Login to each user, and run vncpasswd. This will create a .vnc directory. ให้ login
ด้วย user แต่ละคนก่อนในแต่ละคนนั้นให้สร้างพาสเวิร์ดด้วยคำสั่ง vncpasswd ซึ่งจะมีการสร้างไดเรกทอรี .vnc
ขึ้นในนั้นประกอบด้วยไฟล์ passwd ขึ้นมา

[~]$ cd .vnc
[.vnc]$ ls
passwd

2.3. Edit the server configuration
# เสร็จแล้วให้แก้ไขไฟล์ vncservers ใน /etc/sysconfig ด้วยการเพิ่มเข้าไปอีก 4 บรรทัด คงพอเดาได้หล่ะนะ
ว่าคืออะไร

Edit /etc/sysconfig/vncservers, and add the following to the end of the file.

VNCSERVERS="1:larry 2:moe 3:curly" # กำหนดว่าให้ใช้ได้ 3 คน
VNCSERVERARGS[1]="-geometry 640x480" # คนที่ 1 ได้รายละเอียดของภาพที่ 640x480
VNCSERVERARGS[2]="-geometry 640x480" # คนที่ 2 ได้รายละเอียดของภาพที่ 640x480
VNCSERVERARGS[1]="-geometry 800x600" # คนที่ 3 ได้รายละเอียดของภาพที่ 800x600

Larry will have a 640 by 480 screen, as will moe. Curly will have an 800 by 600 screen.

2.4. Create xstartup scripts # จะเป็นการสร้างไฟล์ xstartup ที่จะใช้รันเมื่อมีการ connect เข้ามา
จาก vncviewer ต่าง ๆ ไฟล์นี้จะถูกสร้างในไดเรกทอรี .vnc ของ user ทั้งสามคนที่กำหนดไว้ข้างต้น ไฟล์นี้
ให้สร้างด้วย scrip โดยรัน vncserver service จะสร้างให้โดยอัตโนมัติ ตามขั้นตอนสามบรรทัดถัดจากนี้ไป

We will create the xstartup scripts by starting and stopping the vncserver as root.

# service vncserver start
# service vncserver stop

Login to each user and edit the xstartup script. To use Larry as an example, first login as larry.

[~]$ cd .vnc
[.vnc] ls
mymachine.localnet:1.log passwd xstartup

Edit xstartup. Add the line indicated here, and uncomment the two lines as directed.
=============== อันนี้เป็นค่า default ที่สร้างจาก vncserver service เลย ===============
#!/bin/sh (-)
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# 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 แก้เป็น exec gnome-session
หากต้องการรัน kde แก้เป็น startkde ของผมใช้ kde จึงเป็น startkde &

2.5. Test each VNC user ทดสอบดูว่าแต่ละคนจะใช้ vncserver ที่ port ต่างกันตามลำดับ

ก่อนจะทดสอบ ให้รัน vncserver เสียก่อน ด้วยคำสั่ง #service vncserver start
เห็น vncserver โชว์หรือเปล่าพร้อมสำหรับ 3 คนแล้ว

2.5.1. Testing with a java enabled browser

Let us assume that mymachine has an IP address of 192.168.0.10. The URL to connect to each of the users will be:

Larry is http://192.168.0.10:5801
Moe is http://192.168.0.10:5802
Curly is http://192.168.0.10:5803

Connect to http://192.168.0.10:5801. A java applet window will pop-up showing a conection to your machine at port 1. Click the [ok] button. Enter larry's VNC password, and a 640x480 window should open using larry's default window manager.

2.5.2. Testing with a vnc client

For Larry: vncviewer 192.168.0.10:1
For Moe: vncviewer 192.168.0.10:2
For Curly: vncviewer 192.168.0.10:3

To test larry using vncviewer, vncviewer 192.168.0.10:1. Enter Larry's VNC password, and a 640x480 window sholud open using Larry's default window manager.

เมื่อ vncserver รันได้แล้ว และพร้อมสำหรับการคอนเนกแล้ว ก็ให้รัน vncserver ทุกครั้งที่ boot ซะ
2.5.3. Starting vncserver at boot

To start vncserver at boot, enter the command chkconfig vncserver on.

# chkconfig --level 35 vncserver on


=========== ต่อไปของ howto นี้เป็นการ config VNC ในแบบ encrypted โดยผ่าน ssh tunnel ก็หาอ่านต่อได้จากลิงค์ต้นฉบับครับ ===========================

ต้นฉบับลอกมาจาก: http://wiki.centos.org/HowTos/VNC-Server
TightVNC

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More