วันจันทร์ที่ 31 พฤษภาคม พ.ศ. 2553

send e-mail with sSMTP


Ssmtp เป็นโปรแกรมส่งอีเมลแบบ CLI ที่ช่วยให้ Server สามารถส่งอีเมลได้โดยไม่ต้องตั้ง Mail Serverเอง คล้ายกับการใช้งาน Mail Client เช่น Outlook Express , ThunderBird
การ setup โดยใช้การส่งเมลผ่าน Thaicyberu Mail


ติดตั้งโปรแกรม
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
yum install ssmtp
service sendmail stop
chkconfig sendmail off
ใช้โปรแกรม ssmtp แทนการใช้ sendmail
ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

ติดตั้งเสร็จเปิดไฟล์ ssmtp.conf
nano /etc/ssmtp/ssmtp.conf
แก้ไข/เพิ่มบรรทัดต่อไปนี้
..........................

root=admin@thaicyberu.go.th
mailhub=smtp.gmail.com:587
AuthUser=xxx@thaicyberu.go.th (email)
AuthPass=mypassword
UseSTARTTLS=YES
...........................

nano /etc/ssmtp/revaliases.conf
root:admin@thaicyberu.go.th:smtp.gmail.com:587
nobody:username@thaicyberu.go.th:smtp.gmail.com:587





SSMTP ส่งเมลได้แล้ว ทดลองส่งด้วยคำสั่ง
ssmtp myemail@gmail.com
ทดสอบการส่งข้อความ
To: recipient_email@example.com
From: myemailaddress@thaicyberu.go.th
Subject: test email
hello world!
เวลาส่งเมลก็ใช้คำสั่ง
$echo "this is a test" |mail -s "test" xxx@thaicyberu.go.th

การใช้งานกับ php เข้าไปแก้ไขใน php.ini
........................................................
[mail function]
; For Unix only. you may supply arguments as well (default:"sendmail -t -i")

sendmail_path = /usr/sbin/ssmtp -t






secure cron


โปรแกรม cron เป็นโปรแกรมประเภท daemon ที่คอยเฝ้ารอการให้บริการจากคำขอของผู้ใช้เพื่อกำหนดให้โปรแกรมรันในเวลาที่ต้องการ ถึงแม้ว่าจะเป็นความสะดวกแต่ก็เป็นการเพิ่มความเสี่ยงในการที่ยอมให้ผู้ใช้งานทั่วไปทำเช่นนั้นได้ คำสั่ง crontab ใช้สำหรับสร้างรายการการจัดตารางเวลาการรันโปรแกรม ในการเพิ่มความปลอดภัยให้ระบบควรสร้างไฟล์ cron.deny และcron.allow เพื่อใช้ควบคุมการใช้งาน crontab คำสั่งต่อไปนี้จะกำหนดให้ผู้ใช้ root เท่านั้นที่จะสามารถใช้ crontab ได้
.....................
cat /etc/cron.d/cron.deny
daemon
bin
smtp
nuucp
listen
nobody
noaccess
.....................

วันอาทิตย์ที่ 30 พฤษภาคม พ.ศ. 2553

การรายงานผล Apache ด้วย server-status, server-info


server-status เป็นการแสดงสถานะของการทำงานของ Apache ผ่านทางเว็บเพจ ดูการ r/w connection เพื่อที่จะได้นำไปวิเคราะห์ปรับแต่งให้ apache ให้รองรับจำนวน connection ที่ Request เข้ามาได้มากขึ้น
server-info เป็นการแสดงรายละเอียดค่า config ต่างๆ ของ Apache เสดงเป็นหมวดหมู่ เช่น ค่ารหัสภาษา, ค่า Document root

วิธีการคอนฟิก server-status ,server-info

เข้าไปคอนฟิกไฟล์ httpd.conf
pico /etc/apache/httpd.conf
....................
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
....................

SetHandler server-info
Order deny,allow
Deny from all
Allow from .example.com
....................

เข้าดูสถานะของ server-status ได้ที่ http://www.thaicyberu.go.th/server-status



Server uptime: 10 hours 42 minutes 8 seconds

ระยะเวลาที่ apache ทำงานมานับตั้งแต่ start service

Total accesses: 30980 - Total Traffic: 2.0 GB

จำนวน request และ bandwidth ที่ใช้ไป

CPU Usage: u101.56 s11.56 cu0 cs0 - .294% CPU load

การใช้งาน CPU ของ apache ณ ปัจจุบัน .804 requests/sec - 53.9 kB/second - 67.1 kB/request

จำนวน request/s ที่ apache กำลังทำงาน 3 requests currently being processed, 29 idle workers จำนวน process ที่กำลังทำงานอยู่


เข้าดูสถานะของ server-info ได้ที่ http://www.thaicyberu.go.th/server-info

การ Setup Outlook Express เพื่อใช้กับ Thaicyberu Mail

Microsoft Outlook Express เป็นโปรแกรม mail client ที่ใช้ในการรับส่ง E-mail ซึ่งมาพร้อมกับระบบปฏิบัติการ Windows และ Internet Explorer สำหรับการตั้งค่าทำได้ดังนี้
1. เปิดโปรแกรม Microsoft Outlook Express ขึ้นมา โดยไปที่ Start >> Programs >> Outlook Express


2. คลิกที่เมนู Tools >> Account
3. หน้าจอจะปรากฏหน้าต่าง Internet Account ดังภาพ


4. คลิกที่ Tab Mail แล้วคลิก ปุ่ม Add แล้วเลือก Mail


5. จะปรากฏหน้าต่าง Internet Connection Wizard ที่ช่อง Display name พิมพ์ ชื่อ-นามสกุล ลงไป แล้วคลิกปุ่ม Next


6. ที่ช่อง E-mail Address พิมพ์ E-mail ลงไป แล้วคลิกปุ่ม Next


7. ที่ช่อง My incoming mail server
- ช่อง My incoming mail server เลือก POP3
- ช่อง Incoming mail พิมพ์ pop.gmail.com
- ช่อง Outgoing mail พิมพ์ smtp.gmail.com


8. ที่ช่อง Account name พิมพ์ชื่อ E-mail ช่อง Password พิมพ์ รหัสผ่านของ E-mail ลงไป (หน้าจอจะไม่แสดงรหัสผ่านที่พิมพ์ลงไป)
จากนั้นคลิกที่ Remember Password แล้วคลิกปุ่ม Next


9. คลิกที่ปุ่ม Finish


10. ภายใต้ Tab Mail จะปรากฏ Account ที่เราใส่เข้ามาเมื่อสักครู่ ให้ดำเนินการดังนี้
(1) คลิกที่ Account นั้น
(2) คลิกที่ปุ่ม Properties


11. จะปรากฏหน้าต่างขึ้นมา ดังภาพให้ท่านดำเนินการดังนี้
(1) ช่อง Mail Account พิมพ์ mail.thaicyberu.go.th
(2) ช่อง Name พิมพ์ ชื่อ-นามสกุล
(3) ช่อง Organization พิมพ์ TCU หรือ Thaicyber University
(4) ช่อง Reply address จะใส่หรือไม่ใส่ก็ได้ ถ้าไม่ใส่จะถือว่าเป็นตัวเดียวกันกับ E-mail address


12.ไปที่แถบ Servers แล้วคลิกเลือก "My outgoing server (SMTP) requires authentication"

13. ไปที่แถบ Advanced คลิกเลือก SSL ทั้งสองช่อง และตรงช่องใส่กรอกเลข SMTP เป็น 465 ส่วน POP เป็น 995

14. คลิกเลือก Leave a copy of messages on sever (เพื่อเก็บสำเนาไว้ใน server)
15. ok
16. คลิกที่ปุ่ม Sent/Recv หรือ Ctrl+m (เพื่อดึง mail เข้ามาใน Outlookexpress)

วันเสาร์ที่ 29 พฤษภาคม พ.ศ. 2553

การ Monitor server ด้วย munin




Munin คือ web monitoring ที่เอาไว้สำรับตรวจสอบสถานะของ server และเครื่อข่าย โดยการทำงานแล้ว Munin แยกการทำงานออกเป็นสองส่วนคือ คือ Munin ซึ่งเป็นตัวรวบรวมของมูล และตัวจัดการกราฟ เปรียบเทียบแล้วเหมือน Server และ munin-node เป็น monitoring client Munin สามารถรวบรวมข้อมูลจาก Munin-node หลายๆ โหนดมาไว้ที่ Server ได้ Munin ติดต่อกับ munin node ผ่าน Port 4949




การติดตั้ง munin CentOS
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install munin munin-node
ระบบจะทำการติดตั้ง packet ต่างๆให้เอง gawk, libio-multiplex-perl, libnet-cidr-perl, libnet-server-perl, libnet-snmp-perl, librrd4, librrds-perl, munin, munin-node,rrdtool

chkconfig munin-node on
service munin-node start
chown -R munin:munin /var/www/munin
ln -s /var/www/munin/ /var/www/html/munin
service httpd restart && service crond restart
ln -s /usr/share/munin/plugins/apache_* /etc/munin/plugins/
service munin-node restart


เพิ่ม Alias

Alias /munin "/var/www/html/munin"

AllowOverride None

Options None

Order allow,deny

Allow from all




หลังจากติดตั้ง แล้ว สามารถเข้าไปดูได้ Report ได้เลย ตัวอย่าง Report Munin http://support.thaicyberu.go.th/monitor




สำหรับ การติดตั้งบน win2003
สามารถ Download Munin-node for win ได้ที่ http://www.jory.info/serendipity/archives/21-Munin-Node-for-Windows-v1.4.html