19 กุมภาพันธ์ 2555

Udomsak

Story about Log and monitoring

this's short note for Log and monitoring solution. i use this weekend. for log and monitoring solution and summarize below


Apache Flume

- https://cwiki.apache.org/FLUME/

Logstash

- http://logstash.net/

OpenTSDB

- http://opentsdb.net/

EsperTech

- http://esper.codehaus.org/

Graylog2

- http://graylog2.org/

Extremon Project

- https://extremon.org/

Icinga Nagios fork

- https://www.icinga.org/


My plan is use logstash to extract log stream and keep it in MongoDB for 1th phase.

this solution will take small resource for running application. i use logstash + mongodb and not enable for elasticsearch ( search engine built on top of Apache Lucence )

--

โดย udomsakc (noreply@blogger.com) ณ 19 กุมภาพันธ์ 2555 16:31 +0700

14 กุมภาพันธ์ 2555

Neutron

Dynamic RAWNAT: Episode 2

Since I have blogged about the Dynamic RAWNAT that it's nearly 2 years ago. The problem that I could remember is it's always crash on the SMP system and at that time, I have no any experiences to solve the concurrent processing, eg. mutex lock, read/write lock, semaphore. Therefore, this code has not been used in any productions system yet, actually it is developed for the KKU Network (Khon Kaen University Network) but the quality is poor, thus should be pending.

Fortunately, there are big improvements in ipset which now leaps to the version 6.11. The code is easier to follow and the new redesigned userland tool is elegant. Thanks to Jozsef Kadlecsik and the people behind the ipset.

Hence, I have started to migrate the Dynamic RAWNAT code to ipset 6.x again.

First part: ipset hacked
I have to add the storage set. The first time, I have coded the hash:ipip which derived from hash:ipportip type and sent it to ipset team. I have got some advices that I could not use the hash:ipip for the purpose of lookup table since the hash code of ipset using both IP for the hash key calculation.

Therefore, I have started over again to create the hash:iplookup which modify the hash function of the original ipset. Then I have the storage set for both IPv4/IPv6.

# ipset -
ipset> create test hash:iplookup
ipset> list test
Name: test
Type: hash:iplookup
Header: family inet hashsize 1024 maxelem 65536 
Size in memory: 16504
References: 0
Members:
ipset> add test 192.168.11.165 map-to 192.168.11.64
ipset> add test 192.168.11.64 map-to 192.168.11.165
ipset> list test
Name: test
Type: hash:iplookup
Header: family inet hashsize 1024 maxelem 65536 
Size in memory: 16568
References: 0
Members:
192.168.11.165 map-to 192.168.11.64
192.168.11.64 map-to 192.168.11.165
ipset> test test 192.168.11.165
192.168.11.165 is in set test.

Second part: modify RAWNAT target
The SETRAWNAT was inspired by the RAWNAT target (RAWSNAT, RAWDNAT) which included in the xtables-addons package. I have also started to get the SETRAWNAT done by migrate the old code to new ipset APIs.
This time, ipset also provides the APIs to access the set data which I have no need to hack the core APIs anymore :).

# iptables -t raw -A PREROUTING -m set --match-set test dst -j SETRAWDNAT --bind-set test
# iptables -t rawpost -A POSTROUTING -m set --match-set test src -j SETRAWSNAT --bind-set test

Lab test:
In the lab test, I used farpd to spoof the arp reply for the router arp request for the IP 192.168.11.165 and it's work like a charm.

# farpd -i wlan0 192.168.11.0/24
# tcpdump -i wlan0 host 192.168.11.165
=== 8< ===
...
...
11:24:25.401992 IP channel-138-143.01.snc6.tfbnw.net.https > 192.168.11.165.35544: Flags [.], ack 127139, win 181, options [nop,nop,TS val 881459662 ecr 24205990], length 0
11:24:26.293708 IP 192.168.11.165.57338 > baymsg1010827.gateway.edge.messenger.live.com.msnp: Flags [P.], seq 1099:1104, ack 31585, win 64800, options [nop,nop,TS val 24206278 ecr 208471411], length 5
11:24:26.554042 IP baymsg1010827.gateway.edge.messenger.live.com.msnp > 192.168.11.165.57338: Flags [P.], seq 31585:31593, ack 1104, win 63683, options [nop,nop,TS val 208476039 ecr 24206278], length 8
11:24:26.554183 IP 192.168.11.165.57338 > baymsg1010827.gateway.edge.messenger.live.com.msnp: Flags [.], ack 31593, win 64800, options [nop,nop,TS val 24206343 ecr 208476039], length 0
...
...
=== >8 ===

And also the packets pass-through the iptables rules

# watch -n5 'iptables -t raw -nvL PREROUTING; iptables -t rawpost -nvL POSTROUTING'
Every 5.0s: iptables -t raw -nvL PREROUTING; iptabl...  Tue Feb 14 11:26:19 2012

Chain PREROUTING (policy ACCEPT 560K packets, 297M bytes)
 pkts bytes target     prot opt in     out     source               destination

 226K  233M SETRAWDNAT  all  --  *      *       0.0.0.0/0            0.0.0.0/0
          match-set test dst bind-set test
Chain POSTROUTING (policy ACCEPT 483K packets, 71M bytes)
 pkts bytes target     prot opt in     out     source               destination

 198K   26M SETRAWSNAT  all  --  *      *       0.0.0.0/0            0.0.0.0/0
          match-set test src bind-set test

I have to review the code before commit to git.rahunas.org as it should be included in the RahuNAS 2.0 development.

There are a lot of works to get the RahuNAS 2.0 done but it's a good starting point to get the old problem solved :P

โดย neutron ณ 14 กุมภาพันธ์ 2555 11:38 +0700

13 กุมภาพันธ์ 2555

Neutron

I was in NLC12 last week

I was in NLC12 (National Linux Compettition) last week, It's a round-2 compettition that the organizer (OSSL NECTEC - Open Source Software Lab) brings me into the Linux minicamp. There are around 100 - 120 persons which almost fill up the auditorium room of Sirindhorn Science Home as it's a good place for the camp as I remember for a few years.

In this camp, I played a role of the committee with the others that have awarded in the last final compettition and also the persons whose invited by NECTEC. We have added the extra examinations which some of them have been chosen for this round compettion. (I didn't talk about the level of exams as it's from a bitter taste of the admin's life as they solve those problems in real life, therefore, you could imagine of it :P).

In this camp, I feel like to join the family as it's happy and a warm welcome. I could remember the most of the committees and for the participants which many of them have joined the camp for many years, otherwise are the new comers.

I have got more experience as I could setup the clonezilla for the multicast clone with the Debian based system from scratch (without the DRBL setup helper scripts). We (me, Phondanai, Suriya) use this system to clone the system image to the 33 laptops which we unicast clone for 29 laptops as we don't know how to clone with multicast yet, until the 4am of that night, the last 4 laptops are cloned by multicast technique. We have to review the clonezilla scripts and consult the google then found that the clonezilla using the "UDPCast" for send and receive the multicast data. Fortunately, the lab network switch supports the multicast packet and it's work like a charm, we finish cloning the 4 laptops with the times that we spent for only 1 laptops. Many thanks to the good project "CloneZilla".

I love Open Source Software.
Happy Hacking.

โดย neutron ณ 13 กุมภาพันธ์ 2555 10:55 +0700

12 กุมภาพันธ์ 2555

Thep

Thai and Lao script history

ช่วงนี้ก่อนนอนจะทยอยอ่านหนังสือ ความเป็นมาของชนชาติลาว เขียนโดย บุนมี เทบสีเมือง นักวิชาการ สปป. ลาว แปลเป็นไทยโดย ไผท ภูธา เป็นมุมมองประวัติศาสตร์ของลาวที่น่าสนใจ

ประวัติศาสตร์ลาวตามแบบฉบับนั้น เขานับเนื่องมาตั้งแต่อ้ายลาว มาน่านเจ้า ก่อนจะถูกคนเชื้อสายจีน (เข้าใจว่าหมายถึงชนชาติไป๋) ยึดอำนาจ ตั้งเป็นอาณาจักรต้าหลี่ ทำให้คนลาว (ซึ่งเป็นชนชาติเดียวกับที่ไทยเรียกว่าไท หรือ ไทย) ทางใต้โดยรอบประกาศตัวเป็นอิสระ เกิดเป็นอาณาจักรต่าง ๆ

หนังสือเล่มนี้เสนอทฤษฎีว่าชนชาติไทย-ลาวมีแหล่งกำเนิดที่เทือกเขาภูเลยในเขตประเทศลาวปัจจุบัน แล้วจึงมีการเคลื่อนย้ายออกไปทุกทิศทาง ทั้งลงมาลุ่มเจ้าพระยาตลอดจนแหลมมลายู และขึ้นเหนือไปทางจีนตอนใต้ ไปก่อตั้งนครลุง ปา เงี้ยว จนถึงอาณาจักรอ้ายลาว น่านเจ้า แล้วพวกที่ขึ้นเหนือจึงถอยร่นลงใต้มาอีกภายหลัง โดยในระหว่างนั้นที่บริเวณประเทศลาวปัจจุบันมีการตั้งอาณาจักรโคตรบูรหรือที่จีนเรียกว่า ฟูเลียว ร่วมสมัยกัน ซึ่งถ้าว่าตามทฤษฎีนี้ คนไทย-ลาวถือเป็นชนชาติที่เก่าแก่กว่าขอมและมอญซึ่งเพิ่งอพยพมาจากอินเดียในช่วงสมัยพระเจ้าอโศกมหาราช

แนวคิดเช่นนี้เป็นพื้นฐานของทฤษฎีว่าอักษรลาวเกิดขึ้นที่ลาวก่อน ไม่ใช่รับมาจากสุโขทัย โดยได้อ้างหลักฐาน ศิลาจารึกวัดวิชุน หลวงพระบาง ซึ่งระบุศักราช จ.ศ. ๕๓๒ ซึ่งตรงกับ พ.ศ. ๑๗๑๓ ก่อนศิลาจารึกพ่อขุนรามถึง ๑๑๓ ปี และยังมีหลักฐานศิลาจารึกที่ระเบียงคต พระธาตุหลวงนครเวียงจันทน์ ที่กำลังอยู่ระหว่างตรวจสอบว่าอาจจะสร้างใน จ.ศ. ๓๔๑ (พ.ศ. ๑๕๒๒) ซึ่งถ้าถูกต้องก็จะมีอายุถึงกว่า ๑ พันปี!


จารึกวัดวิชุน

เรื่องนี้ทำให้กลับไปคิดต่อ หลังจากที่ผมเคยเขียนถึง ทฤษฎีต้นกำเนิดอักษรไทย ที่ว่าอักษรไทยไม่ได้เพิ่งประดิษฐ์ขึ้นโดยพ่อขุนรามคำแหง แต่ควรจะมีใช้ก่อนหน้านั้นนานแล้ว โดยในหนังสือของ อ. สุจิตต์ วงษ์เทศ นั้นระบุว่ามีอักษรไทยใช้ในรัฐอโยธยา-ละโว้มาตั้งแต่ พ.ศ. ๑๗๗๘ เป็นอย่างช้า จากหลักฐานกฎหมายลักษณะเบ็ดเสร็จ (ตอนท้าย) และโองการแช่งน้ำ

นอกจากนี้ ยังมีการเปิดประเด็นมาก่อนหน้านี้โดย จิตร ภูมิศักดิ์ ในบทความ อักษรไทยก่อนสมัยพ่อขุนรามคำแหง ที่ได้รวบรวมไว้ใน ศัพท์สันนิษฐานและอักษรวินิจฉัย ว่ามีจารึกในอุโมงค์วัดศรีชุมเป็นอย่างน้อยที่น่าจะสลักอักษรไทยไว้ก่อนสมัยพ่อขุนรามคำแหง โดยอักขรวิธีเป็นแบบเดียวกับสมัยพญาลิไทย คือมีการเขียนสระไว้ข้างบน-ข้างล่างพยัญชนะ โดยพ่อขุนรามคำแหงอาจจะพยายามปฏิรูปการเขียนให้สระเข้ามาอยู่ในบรรทัด แล้วปรากฏว่าไม่ฮิต พอสิ้นท่านแล้วจึงกลับไปใช้อักขรวิธีแบบเดิม (คล้าย ๆ กับที่ในหลวง ร.๔ เคยทรงประดิษฐ์ อักษรอริยกะ, ในหลวง ร.๖ เคยทรงเสนอ อักขรวิธีแบบใหม่ หรือจะเป็นตัวสะกดสมัยจอมพล ป. ก็ตาม ล้วนไม่เป็นที่นิยมทั้งสิ้น)

เมื่อเปรียบเทียบตัวเขียนในจารึกวัดศรีชุมกับจารึกวันวิชุนแล้ว ดูคล้ายกันมาก ถ้าเชื่อตามจิตรแล้วตัดลายสือไทยพ่อขุนรามฯ ที่เป็นสิ่งชั่วคราวออก ประวัติศาสตร์อักษรไทย-ลาวก็จะดูคลี่คลายลงมากในเรื่องลำดับปีและวิวัฒนาการ

อย่างไรก็ดี ข้อโต้แย้งเรื่องอายุของจารึกวัดวิชุน ก็ยังเป็นคำถามที่ต้องตอบ ไม่ว่าจะเป็นข้อสังเกตเรื่องการใช้จุลศักราช ซึ่งท่านบุนมีตอบไว้เพียงว่า ไม่ใช่มหาศักราชแน่นอน เพราะอิทธิพลขอมยังแผ่มาไม่ถึง แต่ก็ไม่ได้เคลียร์ว่าทำไมต้องเป็นจุลศักราชตามพม่า ส่วนเรื่องการใช้ไม้หันอากาศนั้น ถ้าวินิจฉัยตามจิตรก็จะตอบได้ว่า จารึกวัดศรีชุมที่เก่ากว่าจารึกพ่อขุนรามฯ ก็มีไม้หันอากาศใช้แล้ว การใช้ตัวสะกดสองตัวซ้อนกัน เช่น อัน = อนน เป็นเพียงประดิษฐกรรมของพ่อขุนรามฯ เพื่อให้เขียนได้ในบรรทัดเท่านั้น

หากจะสรุปประเด็นที่ยังเปิดอยู่เกี่ยวกับจารึกวัดวิชุน ก็คงแยกเป็นสองเรื่องหลัก:

  1. อายุที่แท้จริงของจารึกวัดวิชุนเอง ยังต้องอธิบายให้แน่นหนายิ่งขึ้น ปีที่กล่าวถึงในจารึก เป็น จ.ศ. จริงหรือ? และถ้าจริง จำเป็นไหมว่าต้องเป็นปีที่จารึก ไม่ใช่การเขียนบันทึกเรื่องเก่า?
  2. ถึงแม้จารึกวัดวิชุนจะเก่ากว่าจารึกพ่อขุนรามฯ ก็ยังไม่ใช่ข้อสรุปว่าอักษรลาวเกิดก่อนอยู่ดี เพราะอักษรไทยก็มีใช้มาก่อนสมัยพ่อขุนรามฯ นานแล้วเหมือนกัน

ประเด็นข้างเคียงที่อาจต้องตรวจสอบต่อ คืออักษรอื่น ๆ ในภาษาตระกูลไท-ลาว เช่น อักษรถั่วงอกของไทมาว, อักษรไทอาหม, อักษรไทดำ ซึ่งมีอักขรวิธีคล้ายอักษรไทย-ลาวนั้น ได้รับอิทธิพลจากไหน ใครเกิดก่อนใคร

โดย noreply@blogger.com (Thep) ณ 12 กุมภาพันธ์ 2555 17:37 +0700

8 กุมภาพันธ์ 2555

Udomsak

Fix Ubuntu 11.10 kernel 3.0.15 WI-FI can't activate

หลังจากหายไปพักนึง พอดีตอนนี้พอมีเวลามานั่งแก้ปัญหา ์Notebook ของผมเองที่ใช้อยู่ IBM Lenovo S205 เกิดปัญหา upgrade kernel แล้วมีปัญหา wifi on ไม่ได้  จาก blog ก่อนหน้าที่ post วิธีแก้ปัญหาไป แต่คราวนี้เกิดปัญหาอีก โดย error จะขึนว่า


Feb  8 00:26:34 wolf NetworkManager[923]: <info> (wlan0): bringing up device.
Feb  8 00:26:34 wolf kernel: [64948.070554] ADDRCONF(NETDEV_UP): wlan0: link is not ready
Feb  8 00:26:34 wolf NetworkManager[923]: <info> WiFi hardware radio set enabled
Feb  8 00:26:34 wolf NetworkManager[923]: <info> WiFi now enabled by radio killswitch
Feb  8 00:26:34 wolf NetworkManager[923]: <info> (wlan0): supplicant interface state: starting -> ready
Feb  8 00:26:34 wolf NetworkManager[923]: <info> (wlan0): device state change: unavailable -> disconnected (reason 'supplicant-available') [20 30 42]
Feb  8 00:26:35 wolf NetworkManager[923]: <info> (wlan0): supplicant interface state: ready -> inactive
Feb  8 00:26:35 wolf NetworkManager[923]: <info> WiFi now disabled by radio killswitch
Feb  8 00:26:35 wolf NetworkManager[923]: <info> (wlan0): device state change: disconnected -> unavailable (reason 'none') [30 20 0]
Feb  8 00:26:35 wolf NetworkManager[923]: <info> (wlan0): deactivating device (reason 'none') [0]
Feb  8 00:26:35 wolf NetworkManager[923]: <info> Policy set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS.
Feb  8 00:26:35 wolf NetworkManager[923]: <info> Policy set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS.
Feb  8 00:26:35 wolf NetworkManager[923]: <info> (wlan0): taking down device.
Feb  8 00:28:34 wolf NetworkManager[923]: <info> radio killswitch /sys/devices/platform/acer-wmi/rfkill/rfkill5 disappeared
Feb  8 00:28:34 wolf NetworkManager[923]: <info> WiFi now enabled by radio killswitch
Feb  8 00:28:34 wolf NetworkManager[923]: <info> (wlan0): bringing up device.
Feb  8 00:28:34 wolf kernel: [65067.769716] acer_wmi: Acer Laptop WMI Extras unloaded




รุ่น kernel ที่มีปัญหา 


แก้โดยใช้คำสั่ง

  rmmod acer_wmi

  activate ได้เหมือนเดิม

โดย udomsakc (noreply@blogger.com) ณ 8 กุมภาพันธ์ 2555 00:48 +0700

4 กุมภาพันธ์ 2555

Thep

Thanks (2012-02-04)

ขอขอบคุณ พี่โดม (โดม เจริญยศ), คุณ Donga (ถนอมทรัพย์ นพบูรณ์), คุณ เริงฤทธิ์ (Rerngrit Rakkanittakorn), และคุณ kenggg (ปฏิพัทธ์ สุสำเภา) ที่ได้หย่อนสตางค์สนับสนุนการทำงานซอฟต์แวร์เสรีของผม

แต่ละท่านต่างก็กำลังร่วมเดินในเส้นทางซอฟต์แวร์เสรีและโอเพนซอร์สด้วยกัน ขอให้ประสบความสำเร็จตามที่มุ่งหวังนะครับ

ขอขอบคุณเป็นพิเศษสำหรับพี่โดมที่ได้เชิญชวนใน Facebook ให้ร่วมกัน donate ให้ผมครับ

โดย noreply@blogger.com (Thep) ณ 4 กุมภาพันธ์ 2555 12:33 +0700

1 กุมภาพันธ์ 2555

LookHin

การทำ Virtual Host บน Apache Web Server

โดยปกติแล้ว Web Server เครื่องๆ หนึ่งจะใช้สำหรับเว็บไซต์หลายเว็บ ซึ่งสามารถทำได้โดยการทำ Virtual Host โดยบน Apache สามารถทำได้ 2 แบบ คือ

1. IP Based Virtual Host คือการทำ Virtual Host โดยใช้ IP Address เป็นตัวแบ่ง ซึ่งวิธีนี้เราจะต้องมี IP สำหรับทุกๆ เว็บไซต์ที่จะทำ

2. Name Based Virtual Host วิธีนี้จะใช้ชื่อ domain name เป็นตัวแบ่ง โดยทุกๆ เว็บไซต์จะใช้ IP เดียวกันหมด ซึ่ง Hosting ส่วนใหญ่นิยมใช้แบบนี้ และวันนี้เราก็จะมาลองทำแบบนี้กัน ^^

ตัวอย่างที่เราจะทดสอบกันต่อไปนี้ Client เราจะใช้ Windows ส่วน Apache Web Server เราจะใช้ Linux CentOS ที่เราได้ทำการติดตั้งกันไปแล้วจากบทความก่อนๆ ส่วน DNS Server เราจะพูดถึงอีกทีในบทความต่อๆ ไป

เข้าเรื่องกันเลย อย่างแรกที่เราต้องทำก่อนก็คือกำหนดให้ domain name ของเรา point ไปยัง IP ของ Web Server ซึ่งในทีนี้ก็คือ 192.168.10.10 และเนื่องจากว่าเราเองยังไม่มี DNS Server ฉะนั้นในการทดสอบ ให้เราเข้าไปแก้ไข /etc/hosts ของเครื่องไคลเอนต์กันก่อน เพื่อกำหนดค่า ip ให้กับ domain แบบตรงๆ กันก่อน โดยถ้าใช้ windows ให้เข้าไปแก้ไขที่ไฟล์ c:\Windows\System32\drivers\etc\hosts และสำหรับ Linux ให้แก้ไขที่ไฟล์ /etc/hosts โดยให้เพิ่มบรรทัดต่อไปนี้

1
2
192.168.10.10 vhost1.unzeen.com
192.168.10.10 vhost2.unzeen.com

เมื่อเพิ่มข้อมูลลงไปแล้ว ให้ทดสอบทำการ ping vhost1.unzeen.com ว่าได้ IP กลับมาถูกต้องหรือไม่ ถ้าได้แล้วก็ไปขั้นตอนถัดไปได้เลย

apache-virtual-host

ขั้นตอนถัดไปให้เข้าไปที่ Linux Server และทำการสร้างโฟลเดอร์ /var/www/vhost1/ และ /var/www/vhost2/ เพื่อเอาไว้เก็บไฟล์ของเว็บไซต์

1
2
# mkdir /var/www/vhost1/
# mkdir /var/www/vhost2/

apache-virtual-host

จากนั้นทำการสร้างไฟล์ index.html ไว้ที่ /var/www/vhost1/ และ /var/www/vhost2/

# index.html ใน vhost1

1
2
3
4
5
6
7
8
<HTML>
 <HEAD>
  <TITLE>VHOST1</TITLE>
 </HEAD>
 <BODY>
  VHOST1
 </BODY>
</HTML>

# index.html ใน vhost2

1
2
3
4
5
6
7
8
<HTML>
 <HEAD>
  <TITLE>VHOST2</TITLE>
 </HEAD>
 <BODY>
  VHOST2
 </BODY>
</HTML>

เนื่องจากเราทำการล๊อกอินเข้าระบบด้วย root ฉะนั้นเพื่อความแน่ใจทำการเปลียน Permission ของ vhost1 และ vhost2 เล็กน้อย

1
2
# chmod -R 755 /var/www/vhost1/
# chmod -R 755 /var/www/vhost2/

apache-virtual-host

ต่อไปทำการแก้ไขไฟล์ /etc/httpd/conf/httpd.conf โดยให้เอา # หน้า NameVirtualHost ออก และเพิ่มบรรทัดในส่วนของ VirtualHost ลงไปตามตัวอย่าง

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NameVirtualHost *:80
 
<VirtualHost *:80>
    ServerAdmin webmaster@unzeen.com
    DocumentRoot /var/www/vhost1
    ServerName vhost1.unzeen.com
    ErrorLog logs/vhost1.unzeen.com-error_log
    CustomLog logs/vhost1.unzeen.com-access_log common
</VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin webmaster@unzeen.com
    DocumentRoot /var/www/vhost2
    ServerName vhost2.unzeen.com
    ErrorLog logs/vhost2.unzeen.com-error_log
    CustomLog logs/vhost2.unzeen.com-access_log common
</VirtualHost>

apache-virtual-host

จากนั้นสั่ง restart service ของ apache ด้วยคำสั่ง

1
# service httpd restart

apache-virtual-host

เท่านี้ก็เป็นอันว่าเราทำการสร้าง VirtualHost เป็นที่เรียบร้อย ทดสอบเปิดจาก Web Browser ดูได้

apache-virtual-host

วันนี้เท่านี้ก่อน รอบหน้าเราจะมาต่อกันที่เรื่อง SSL กันจริงๆ หละ

โดย LookHin ณ 1 กุมภาพันธ์ 2555 01:48 +0700

22 มกราคม 2555

LookHin

ขั้นตอนการติดตั้ง Apache Web Server และ PHP บน CentOS

หลังจากได้เรียนรู้วิธีการติดตั้งโปรแกรมในแบบต่างๆ ไปแล้ว วันนี้เรามาต่อกันที่การติดตั้ง Web Server โดยเราจะทำการติดตั้ง apache ให้ทำหน้าที่เป็น Web Server (http) และติดตั้ง mod_ssl เพื่อเอาไว้ใช้ทำ Secure Web Server (https) จากนั้นจะทำการติดตั้ง php และ php extension ต่างๆ เพื่อเอาไว้ใช้กับโปรแกรมที่เขียนด้วย php ซึ่งในบทความนี้ จะไม่ได้พูดถึงการใช้งานภาษา Perl, Python หรือโปรแกรมภาษาอื่นๆ หากผู้อ่านสนใจ ก็ตามไปศึกษาจากแหล่งข้อมูลอื่นๆ กันตามสะดวก และถ้าหากมีโอกาสในคราวหน้าก็อยากจะลองใช้ nginx ซึ่งเป็น Web Server ที่กำลังมาแรงตัวหนึ่งเหมือนกัน ^^

เริ่มจากติดตั้ง httpd และ mod_ssl โดยใช้คำสั่ง

1
# yum install httpd mod_ssl

ระบบจะแสดงข้อมูลและแพกเก็จต่างๆที่ต้องติดตั้ง ให้กด y เพื่อทำการติดตั้งต่อไป

เปิดไฟล์ /etc/httpd/conf/httpd.conf และเพิ่มหรือแก้ไขบรรทัด ServerName ลงไป โดยให้ใส่เป็นชื่อของเซอเวอร์ของเราลงไป

1
# nano /etc/httpd/conf/httpd.conf

จากนั้นทำการ start service httpd ด้วยคำสั่ง

1
# service httpd start

ทดสอบเปิดเว็บไซต์ดูได้เลย

1
http://192.168.10.10/

เมื่อติดตั้ง apache เรียบร้อยแล้วเราก็มาติดตั้ง php และ php extension ต่างๆกันต่อ อย่างแรกใช้คำสั่ง yum list php* เพื่อดูว่ามี php extension อะไรบ้างที่น่าสนใจ ให้จดหรือจำชื่อของ extension ต่างๆที่ต้องการเอาไว้

1
# yum list php*

ทำการติดตั้ง php และ php extension ต่างๆ ที่ต้องการ

1
# yum install php-common php-cli php-devel php-mysql php-gd php-imap php-mbstring php-mhash php-pear php-xml php-xmlrpc

ต่อไปทำการสร้างไฟล์ info.php ในโพลเดอร์ /var/www/html/ ด้วยคำสั่ง

1
# nano /var/www/html/info.php

และพิมพ์ Source Code ของ PHP ลงไปดังนี้

1
2
3
4
5
<?php
 
phpinfo();
 
?>

สั่ง restart service httpd สักหนึ่งรอบ ด้วยคำสั่ง

1
# service httpd restart

เมื่อทุกอย่างเรียบร้อย ให้ทดสอบเปิด info.php ผ่าน web browser ดูนะครับ ^^

1
http://192.168.10.10/info.php

ก่อนจบเราต้องเพิ่มให้ service httpd ทำงานทุกครั้งที่เปิดเครื่องด้วยคำสั่ง

1
# chkconfig httpd on

รอบหน้าเราจะต่อกันด้วยการทำ https ให้กับ web server ของเรากันต่อ

โดย LookHin ณ 22 มกราคม 2555 17:58 +0700

Chatsiri

Deli.cio.us

วันนี้ไปถึง BITEC บางนา แบบไม่ต้องพึ่งแท็กซี่ที่สถานนี้ออนนุชอีกแล้ว เพราะไปถึงสถานีบางนาแล้วเดินลงมาก็แทบเจอเลย. แว๊บแรกผ่าน อ่านเป็น "Del.icio.us" ทีไหนได้กลับมาดูในกล้องตัวเองมันเขียนเป็น "Deli.cio.us".
deli.cio.us

โดย chatsiri ณ 22 มกราคม 2555 01:17 +0700