Welove's Blog

January 12, 2011

ก้าวแรกสู่สังเวียน กับการเป็นพนักงาน True

Filed under: Life Style — harubiji @ 4:07 pm

วันนี้เป็นครั้งที่ 2 ที่ผมได้ขึ้นไปตึก true tower

แต่ครั้งนี้เป็นครั้งที่ผมนับว่าได้ย่างก้าว การเข้าเป็นพนักงานของบริษัท อย่างเต็มตัว

( ต้องขอขอบคุณ พี่อั๋น และ ต้น 350d ที่ให้โอกาสผมได้ร่วมงานในส่วนของ Welove ไว้ ณ.โอกาสนี้ด้วยครับ )

โดยวันนี้เป็นวันเซ็นสัญญาและถ่ายรูปทำบัตรพนักงานเพื่อเข้าเป็นพนักงาน

วันนี้ เข้าไปตอน 10.30 เพราะตอนเช้าต้องไปเปิดสมุดเงินฝากของ ธนาคาไทยพาณิชย์

(โดยเสียรู้นิดๆ เพราะไม่ทราบว่าด้านล่างของตึกก็มีสาขาของธนาคารไทยพาณิชย์อยู่ มาครั้งก่อนไม่ได้จำและไม่ได้สังเกตุซะงั้น แฮะๆๆ)

พอมาถึงก็ได้กลิ่นกาแฟอันหอมกรุ่นของร้านกาแฟด้านล่าง !! คิดในใจเดี๋ยวเราคงได้มาใช้บริการแน่ๆ อิอิ

แล้วไปแลกบัตรที่เคาน์เตอร์ เพื่อทำการผ่านประตูและขึ้นลิฟท์ ไปสู่ ชั้น 17 ฐานกองกำลังของ HR.True อิอิ

วันนี้บรรยากาศโดยร่วมคนเยอะมากๆ ทั้งถ่ายรูปทำบัตรพนักงานและสมัครงานกัน

โดยส่วนของผมดีหน่อย เข้าไปก็เลี้ยงขวาไปหาพี่ผู้หญิงชื่อ นภา โดยแยกส่วนออกไปจากตรงกลางห้องที่มีคนเยอะมาก

พี่นภา นำเอกสารมาให้เซ็นและอธิบายรายละเอียดในส่วนต่างๆให้ผมฟังอย่างละเอียด,ชัดเจนและเข้าใจ ดีมากๆ (ขอขอบคุณ พี่นภาด้วยครับในส่วนนี้)

พอเซ็นเอกสารและนำเอกสารต่างๆให้พี่นภาเรียบร้อยแล้ว ผมก็ไปรอเข้าคิวถ่ายรูปบัตรพนักงาน โดยผมไปอยู่ประมาณอันดับที่ 18 ได้

พอถึงตอนเซ็นชื่อเข้าถ่ายรูปในใบกลับไม่มีซื่อเราซะงั้น เลยต้องเขียนชื่อเพิ่มไปใหม่ในใบลงบันทึกนั้น (นึกในใจให้เรามาถ่ายใหม่วันหลังได้เปล่าหว่า วันนี้เตรียมตัวเสื้อผ้า หน้าตา ทรงผม มายังไม่หล่อเลย อิอิอิ)

ตากล้องสาว ถ่ายรูปผมไป 2 ภาพ พอเสร็จ ผมก็ลงจากตึกกะว่าจะมาอุดหนุนกาแฟอันหอมเย้ายวน ด้านล่างสักแก้ว

แต่ !! โอ้ว ลงมาคราวนี้คนรอซื้อกันอยู่ เยอะพอควร เลยตัดสินใจกลับ เอาไว้วันหน้าค่อยมาอุดหนุนล่ะกัน

สำหรับ วันนี้การไปตึก true ก็มีความภูมิใจอย่างมากและได้เห็นผู้คนอันหลากหลาย ที่ล้วนแต่จะได้เป็นครอบครัว true และเพื่อนร่วมงานกันในอนาคต สัปดาห์ หน้านี้

>>  ไงพรุ่งนี้เป็นส่วนของการไปตรวจสุขภาพ ที่ตึกเมืองไทยภัทร (ต้น 350d แอบกระซิบมาว่า ที่นั้นเกย์เยอะมากมายไงระวังตัวให้ดีนะ 5555 )

April 19, 2010

ISPConfig3 On Ubuntu9.10

Filed under: Uncategorized — pat @ 2:41 pm

/etc/init.d/pure-ftpd-mysql restart

หลังจากที่ทำการติดตั้ง ubuntu เสร็จเรียบร้อยแล้วก็เริ่มติดตั้งกันเลย

เริ่มจากลง open ssh เพื่อความสะดวกในการทำงาน

#aptitude install ssh openssh-server
#aptitude install vim-nox

ทำการเพิ่มรายชื่อ host ให้เครื่องรู้จัก (more…)

March 31, 2010

การติดตั้ง Free Radius บน Debian

Filed under: Debian — pat @ 10:58 am

ทำการติดตั้งโปรแกรมด้วยคำสั่ง

#aptitude install freeradius freeradius-mysql

ทำการ add user ใหม่ด้วยคำสั่ง

#adduser chilli //password abcd1234
#passwd chilli //คำสั่งแก้พาสเวิร์ด

สั่งให้โปรแกรมทำงานด้วยคำสั่ง

#/etc/init.d/freeradius start

ทำการทดสอบระบบด้วยคำสั่ง (อาจเกิด error ได้เนื่องจาก Access-Reject เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ ก็ไม่เป็นไรครับ)

#radtest chilli abcd1234 localhost 0 testing123 //โดย testing123 คือ key เริ่มต้นของระบบ

แก้ไขแฟ้ม /etc/freeradius/radiusd.conf เพื่อทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
user = radiusd เป็น #user = radiusd
group = radiusd เป็น #group = radiusd

หมายเหตุ สามารถแก้ไข key ได้จากแฟ้ม /etc/freeradius/clients.conf  บรรทัด secret = testing123

หลังจากแก้ไขไฟล์ conf ต่างๆด้านบนแล้ว ให้สั่ง restart service และทดลองระบบ ด้วยคำัสั่ง

#/etc/init.d/freeradius restart
#radtest chilli abcd1234 localhost 0 testing123
ผลที่ได้

Sending Access-Request of id 78 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234″
NAS-IP-Address = 127.0.1.1
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=78, length=20

March 24, 2010

การ monitor Squid Proxy ด้วย Sarg

Filed under: Debian — pat @ 5:03 pm

วิธีการติดตั้ง Setup โปรแกรม SARG ( Squid Analysis Report Generator )

ต้องไป download file ที่ web http://sarg.sourceforge.net/sarg.php
จากนั้นทำการแตก ไฟล์ .tar.gz แล้วพิมพ์คำสั่งตามลำดับ
#tar xfz sarg-x.x.x.tar.gz
#cd sarg-x.x.x
#./configure
#make
#make install

ต่อมาทำการแก้ไข config ของ SARG
# vi /usr/local/etc/sarg.conf
หาบรรทัดต่าง ๆ ต่อไปนี้
# access_log /usr/local/squid/var/logs/access.log — เอา # ออก
# graphs yes — เอา # ออก
# graph_days_bytes_bar_color orange — เอา # ออก
# output_dir /usr/local/apache/htdocs/squid-reports — เอา # ออก และแก้ไขให้อยู่ใน directory ที่เก็บเว็บ

ต่อมาเราจะทดสอบการใช้งาน SARG โดยการสั่ง
# /usr/bin/sarg
จากนั้นเรียกผ่าน browser ตัวอย่าง จะำพบหน้าเว็บเพจสถิติดังกล่าว
http://202.57.163.xxx/squid-reports

ทำการตั้งค่า ให้ SARG ทำการ update การแสดงข้อมูลเป็นช่วงเวลาด้วย crontab
# crontab -e
ใส่ข้อความดังนี้เพิ่มเข้าไป
0 5 * * * /usr/bin/sarg

link เพิ่มเติม
http://www.212cafe.com/boardvip/view.php?user=tondiary&id=36
http://www.uboninfo.net/board/index.php?topic=697.0

การติดตั้ง Proxy server ฉบับง่ายและรวดเร็ว

Filed under: Debian — luceon @ 4:30 pm

proxy server

proxy server เปรียบได้กับ cache ในคอมพิวเตอร์ นั่นคือเป็นทางผ่านก่อนเชื่อมต่อออก network จริง โดยเวลาเข้าเว็บเพจจากเครื่อง client ที่เชื่อมผ่าน proxy จะทำให้โหลดได้รวดเร็วกว่าปกติ ถ้าเว็บนั้นเคยเข้ามาก่อนแล้ว เพราะข้อมูลที่เคยเข้าถูกเก็บไว้ใน proxy server

เราได้ประโยชน์อะไรจาก proxy ?
– ระบบการจัดการการร้องขอแบบ caching คือ เวบใดเคยมีการเรียกใช้จากเครื่องลูกข่ายภายในเครือข่ายแล้ว Proxy จะเก็บข้อมูลของเวบนั้นไว้ใน caching ของ Proxy
– แล้วเมื่อมีการเรียกใช้อีกครั้งในภายหลังก็สามารถเรียกจาก caching ได้ทันทีโดยไม่ต้องเรียกจากเครื่องเซิร์ฟเวอร์ปลายทาง
– ประหยัดเวลาในการถ่ายโอนข้อมูล web page
– ประหยัด bandwidth ของเครือข่ายในการเข้าถึงข้อมูลใน caching
– การทำงานอื่นๆบนเครือข่ายจะเร็วขึ้น

Squid Proxy Server

Squid เป็นโปรแกรม Proxy caching server ที่อยู่ในระบบปฏิบัติการ Linux การให้บริการของ Squid ซึ่งเป็น Web caching server นั้นคือ จะคอยรับคำร้องขอบริการจากเครื่องลูกข่าย และส่งผ่านไปยังเซิร์ฟเวอร์ปลายทางที่เหมาะสม

การติดตั้ง Squid

1. โหลดไฟล์ เวอร์ชันล่าสุดจาก http://core.ring.gr.jp/archives/net/www/squid/ ในที่นี้จะใช้เวอร์ชัน 3.1.0.18 โดยใช้คำสั่ง

wget  http://core.ring.gr.jp/archives/net/www/squid/squid-3.1.0.18.tar.gz

โหลดมาไว้ที่ /root
2. จากนั้นแตกไฟล์ออกมาด้วยคำสั่ง

tar xvfx squid-3.1.0.18.tar.gz

3. จากนั้นเข้า โฟลเดอร์ โดยใช้ cd squid-3.1.0.18

4. ทำการ build โดยใช้คำสั่ง

  #./configure --prefix=/usr/local/squid
  #make all
  #make install

5. จากนั้นเข้าไปแก้ config ที่ /usr/local/etc/squid/squid.conf  ตามนี้

#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl localhost src ::1/128
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl to_localhost dst ::1/128

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
acl localnet src 172.16.0.0/12    # RFC1918 possible internal network
acl localnet src 192.168.0.0/16    # RFC1918 possible internal network
acl localnet src fc00::/7   # RFC 4193 local private network range
acl localnet src fe80::/10  # RFC 4291 link-local (directly plugged) machines
acl our_networks src 192.168.1.0/24 10.0.0.0/24

acl SSL_ports port 443
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow our_networks
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
#cache_peer, never_direct/always_direct

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128 transparent

# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?

# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /usr/local/squid/var/cache 1000 16 256
cache_mem 400 MB

#acl, http_access, icp_access
#cache_mgr
visible_hostname 192.168.1.132(ใส่ ip ของ server ที่ต้องการใช้เป้น proxy)
# Leave coredumps in the first cache dir
coredump_dir /usr/local/squid/var/cache

# Add any of your own refresh_pattern entries above these.

refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320

แก้ไฟล์ตาม สีแดง ที่ mark เอาไว้

6. ทำการสร้าง cache และตำแหน่งของ cache โดยตำแหน่งของ cache จะอยู่ที่ /usr/local/squid/var/cache โดยไดเร็คทอรี่ cache ในตอนนี้จะยังไม่มี แต่จะถูกสร้างขึ้นเมื่อเรารันคำสั่งต่อไปนี้

ก่อนอื่นเปลี่ยน permission ให้ directory var ก่อน

chmod 777 /usr/local/squid/var/

จากนั้นจึงใช้คำสั่ง

/usr/local/squid/sbin/squid -z

ทำการ start service ใช้คำสั่ง

/usr/local/squid/sbin/squid start

วิธีการทดสอบ

1. เข้า IE คลิ๊กที่ Tool > Internet option > Connecttions > Lan setting > ติ๊กหน้า Proxy แล้วเซ็ตเป็น

ip เครื่องเซิฟเวอร์ กับ port 3128

2. เข้าไปดู log file โดยใช้คำสั่ง

tail -f /usr/local/squid/var/logs/access.log


proxy

เพิ่มเติมครับ นอกจากเราจะทำการ set squid ของเราให้เป็น transparent proxy แล้ว เรายังต้องกำหนด iptables ให้ทำการ forward port ที่เข้ามาทาง port 80 ให้ไปใช้งานทาง port 3128 ด้วย โดยจะต้องรู้สองสิ่งคือ เครื่อง clients จะติดต่อเข้ามาที่เครื่อง gateway ทางไหน และ port ที่ squid รันอยู่ เราสามารถทำการส่งไปยัง proxy โดยพิมพ์คำสั่งว่า

#iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j REDIRECT –to-port 8080

เพียงเท่านี้ เมื่อมี client เรียกเว็บเข้ามาทาง eth0 ก็จะไปใช้ proxy ของเราแล้ว

การติดตั้งเครื่อง Gateway บน Debian :)

Filed under: Debian — pat @ 1:18 pm

ในการทำ Gateway เราต้องใช้ Network cards 2 อัน ซึ่งต้องมีอันหนึ่งเชื่อมต่อออก internet ได้

การทำ gateway เริ่มจาก การนำไฟล์ที่บรรจุคำสั่ง iptables ที่เราต้องการไปไว้ที่ directory /etc/network/if-up.d ซึ่งต้อง set file permission เป็น 755 ด้วยจึงจะสามารถทำงานได้ โดยทุกครั้งที่เราทำการ restart network จะมีการโหลดไฟล์ต่างๆที่อยู่ในโฟลเดอร์นี้ทุกๆครั้งมีผลทำให้ config iptables ของเรามีผลอยู่ตลอดเวลาที่รันเครื่องใหม่

กำหนดให้
eth0 เชื่อมต่อเครือข่ายภายใน
eth1 เชื่อมต่อเครือข่ายภายนอก

ไฟล์ iptables มีรายละเอียดดังนี้

#!/bin/sh
PATH=/usr/sbin:/sbin:/bin:/usr/bin
#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

# Don't forward from the outside to the inside.
iptables -A FORWARD -i eth1 -o eth1 -j REJECT

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward

หรือแบบเรียบๆง่ายๆ

#!/bin/sh
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Allow established connections, and those not coming from the outside
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

จากนั้นทำการ restart network ด้วยคำสั่ง

/etc/init.d/networking restart

หากทำการติดตั้งเรียบร้อย จะพบว่าเมื่อใส่คำสั่ง #iptables -L จะแสดงรายละเอียดของ iptables ที่เราใส่เข้าไปก็ถือว่าถูกต้องแล้วครับ :)

ส่วนรูปแบบคำสั่ง iptables สามารถอ่านทำความเข้าใจได้จาก link เพิ่มเติมด้านล่างครับ

สามารถอ่านและทำความเข้าใจกับการใช้คำสั่ง iptables และ NAT ได้ที่
http://linux.sra.cattelecom.com/view.php?page=IPTABLES
http://linux.sra.cattelecom.com/view.php?page=NAT
link เพิ่มเติม
http://www.debian-administration.org/articles/23

มาทำ DHCP server บน Debian กันเถอะ

Filed under: Debian — pat @ 11:49 am

ในขั้นตอนการค้นห้า package เราใช้คำสั่ง #apt-cache search dhcp ซึ่งเราจะเจอ package ต่างๆที่เกียวข้อง

# apt-cache search dhcp
...
dhcp - DHCP server for automatic IP address assignment
dhcp-client - DHCP Client
dhcp-dns - Dynamic DNS updates for DHCP
dhcp-relay - DHCP Relay
dhcp3-client - DHCP Client
dhcp3-common - Common files used by all the dhcp3* packages.
dhcp3-dev - API for accessing and modifying the DHCP server and client state
dhcp3-relay - DHCP Relay
dhcp3-server - DHCP server for automatic IP address assignment
...

การติดตั้ง DHCP server ในบทความนี้ใช้ตัว dhcp3-server นะครับ
ลงมือติดตั้ง package ด้วยคำสั่ง

#aptitude install dhcp3-server

หลังจากการติดตั้งเรียบร้อยแล้ว โปรแกรมจะทำการรัน service dhcp เอง แต่เนื่องจากเรายังไม่ได้ config ค่าใดๆให้กับโปรแกรม จึงมีข้อความฟ้องขึ้นมาว่า fail
ให้เราทำการเข้าไปแก้ไฟล์ config ของตัว DHCP server ที่ /etc/dhcp3/dhcpd.conf โดยมีโครงประมาณนี้

ddns-update-style none; # ไม่ใช้ dynamic DNS
option domain-name "bank.com"; # ชื่อโดเมนของระบบเครือข่าย
option domain-name-servers ns1.bank.com, ns2.bank.com; # ชื่อหรือ IP ของ DNS เซิร์ฟเวอร์
default-lease-time 600; # จำนวนวินาทีที่ให้ใช้ IP ที่แจกจ่าย
max-lease-time 7200; # จำนวนวินาที (maximum) ที่ให้ใช้ IP ที่แจกจ่าย
authoritative; # บอกว่าเครื่องเซิร์ฟเวอร์นี้เป็น authoritative
log-facility local7; # เก็บล็อกแบบ local7

host Bank { #เป็นเครื่องที่ลงทะเบียนไว้และเจาะจง ip address
 hardware ethernet 00:15:17:cb:b2:c9;
 fixed-address 10.0.0.1;
}
host pat { #เป็นเครื่องที่ลงทะเบียนไว้แต่ได้ ip ไม่เจาะจง
 hardware ethernet 00:15:17:cb:b0:2f;
 #fixed-address 10.0.0.2;
}
subnet 10.0.0.0 netmask 255.255.255.0 {
 option routers 10.0.0.1;
 pool {
 range 10.0.0.30 10.0.0.50;
 deny unknown clients;
 }
 pool {
 range 10.0.0.100 10.0.0.200;
 allow unknown clients;
 }
}

สุดท้ายนี้ให้เราทำไปใส่ interface ที่ให้ทำการแจก ip ที่ /etc/defaults/dhcp3-server เช่นให้ INTERFACES=”eth0″

หลังจากนั้น ให้ resart service เพื่อให้ค่า config file มีผลด้วยคำสั่ง

# /etc/init.d/dhcp3-server start

หากต้องการดู log file ในการรัน service สามารถดูได้ที่ /var/log/syslog
และไฟล์ืั้เก็บข้อมูลการแจกจ่าย IP สามารถดูได้ที่ /var/lib/dhcp3

link เพิ่มเติม
http://www.mm.co.th/poonlap/node/117
http://www.crazysquirrel.com/computing/debian/servers/dhcp.jspx

March 22, 2010

แจ้งเตือน Serverdown ผ่านทาง SMS ด้วย ShellScript

Filed under: Debian,ShellScript — pat @ 5:04 pm

การทำงานของ Script ตัวนี้ เป็นการตรวจสอบ port ของ host ที่เรากำหนดไว้เป็นระยะๆเพื่อดูว่า port นั้นทำงานอยู่หรือไม่ ถ้าพบว่า port นั้นไม่สามารถติดต่อได้ ก็จะทำการเรียกใช้ API ในการส่ง SMS ไปแจ้งเตือน(ในตัวอย่างนี้ใช้ http://smsgateway.packetlove.com/index.php)

หลังจากที่ได้ทราบหลักการทำงานของโปรแกรมแล้ว เรามาดูวิธีทำกันเลย

  1. สร้างไฟล์ test.sh ขึ้นมาเพื่อทำการเขียน ShellScript (ในที่นี้สรา้างไว้ที่ vi /root/test.sh)
  2. ใส่ code ลงไปตามนี้#!bin/bash
    USR=”your username
    PSW=”your password
    SNDR=”sender telephone
    TONUMBER=”receiver telephone
    flag=0
    MESS=”"
    for host in 192.168.1.131 192.168.1.132 #หมายเลย ip ของ host ที่จะทำการตรวจสอบสถานะ
    do
    hm=”Server $host ”
    pm=”Port: ”
    for port in 22 80 #หมายเลข port ที่ต้องการตรวจสอบ
    do
    if netcat -z $host $port # ทำการตรวจสอบสถานะของ port
    then
    echo port $port is up
    else
    echo port $port is down
    flag=1
    pm=”$pm$port ”
    fi
    done
    MESS=”$MESS$hm$pm              ” #เก็บข้อความแจ้งเตือนไว้
    done
    if flag==1
    then
    #ทำการส่ง SMS ผ่านทาง URL ซึ่งเป็นบริการของ SMS Gateway http://smsgateway.packetlove.com/index.php
    wget “http://smsgateway.packetlove.com/api_sms.jsp?user_id=$USR&passwd=$PSW&sender=$SNDR&mobile_no=$TONUMBER&msg=$MESS” &
    fi
  3. หลังจากนั้นต้องสั่งให้ crontab ทำการรัน script ทุกๆ 10 นาที โดยการพิมพ์ crontab -e ใน shell
    #crontab -e
    จะพบหน้าจอ crontab list ให้เพิ่มลงไปท้ายสุดดังนี้
    # m h  dom mon dow   command
    0-59/10 * * * * /root/test.sh > /dev/null
    โดย /root/test.sh คือไฟล์ที่เราเก็บ ShellScript ไว้
    ทีนี้โปรแกรมของเราก็จะถูกรันทุกๆสิบนาทีเพื่อตรวจสอบสถานะแล้ว

เป็นอันเสร็จสิ้นการทำโปรแกรมเพื่อส่ง SMS เตือนเมื่อ server ล่มครับ :)
นอกจากนี้ถ้าเราต้องการตรวจสอบ port ของแต่ละเครื่องที่ต่างกัน ก็สามารถปรับแต่งโดยการเพิ่ม code ให้ทำงานไว้ในส่วนของตรวจสอบสถานะเข้าไปได้เรื่อยๆ ด้วยครับ

link เพิ่มเติม
การใช้งาน crontab http://adminschoice.com/crontab-quick-reference
SMS Gateway API ของ Packetlove http://smsgateway.packetlove.com/index.php

การติดตั้ง webserver บน Debian และการทำ Virtual host

Filed under: Apache,Debian — pat @ 5:03 pm

ก่อนอื่นเราต้องทำการติดตั้งโปรแกรม ให้กับเครื่องของเราก่อน ประกอบไปด้วย Apache Mysql PHP phpmyadmin

#apt-get install mysql-server-5.0
#apt-get install apache2-mpm-prefork
#apt-get install libapache2-mod-php5 php5-mysql
#apt-get install php5-cli php5-common php5-cgi
#apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi
#apt-get install phpmyadmin

หลังจากที่ลงโปรแกรมต่างๆครบถ้วนแล้ว ก็เกือบเสร็จแล้วล่ะครับ เพราะว่าการติดตั้งบน Debian นั้นง่ายจริงๆ
ต่อมาให้เราำทำการทดสอบโดยการสร้าง page phpinfo เข้าไปไว้ในเว็บ แล้วลองเปิดเข้าไปดูรายละเอียดว่าทำงานได้อย่างถูกต้องหรือไม่

ทำการสร้างไฟล์ phpinfo.php ไว้ที่ /var/www
#vi /var/www/phpinfo.php
โดยข้างในมีข้อความดังนี้
<?php
phpinfo();
?>

จากนั้นทำการบันทึกและลองเรียก page นี้ผ่านทาง web browser ถ้าผลที่ได้เป็นหน้า รายละเอียดของ php แล้วล่ะก็ถือว่าถูกต้อง :)

สิ่งที่ควรรู้หลังจากติดตั้ง viagra เสร็จแล้ว

  • path /var/www เป็นที่อยู่เริ่มต้นของ website
  • config ต่างๆของ apache แก้ได้ที่ #vi /etc/apache2/apache2.conf เช่น root path
  • config ต่างๆของ php แก้ได้ที่ #vi /etc/php5/apache2/php.ini เช่น register_global = On
  • เข้า phpmyadmin ได้ที่ http://localhost/phpmyadmin
  • สามารถสั่ง service start stop restart ฯลฯ ด้วยคำสั่ง #/etc/init.d/apache2 restart

การ Config Virtual host

เราสามารถจำลองให้เซิฟเวอร์เครื่องเดียว มีได้หลายเว็บด้วยกัน โดยกำหนด path เริ่มต้นที่แตกต่างกันให้กับแต่ละ Virtual host โดยการสร้างไฟล์ขึ้นมาใหม่ เช่น #vi /etc/apache2/sites-available/pat.com โดยมีข้อมูลดังนี้

<VirtualHost *:80>
DocumentRoot /var/www/blog
ServerName pat.com
ServerAlias www.pat.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www
ServerName info.pat.com
</VirtualHost>

หลังจากนั้นให้ทำการบันทึกและพิมพ์คำสั่ง # a2ensite pat.com จะพบว่ามี link pat.com เพิ่มขึ้นที่ /etc/apache2/sites-enable

จากตัวอย่างด้านบน เราสามารถพิมพ์ url http://pat.com และ http://info.pat.com ซึ่งจะเชื่อมโยงไปยัง /var/www/blog และ /var/www ตามลำดับ

link เพิ่มเติม
Webserver
http://techpatterns.com/forums/about390.html
http://www.zulfanruri.com/th/install-web-server-debian.htm
http://221.128.105.95/manualdebian/manual-linux.pdf
http://web.ofebia.com/contents/view/241.htm
Virtual host
http://www.itmanage.info/technology/linux/apache_vhost.html
http://web.ofebia.com/contents/view/241.htm

การติดตั้ง MRTG

Filed under: Debian — luceon @ 4:49 pm

MRTG นั้นเป็นตัว Monitor Router เพื่อไว้ทำการดู traffic ต่าง ๆ ในเครื่อง ซึ่งสามารถ config ได้และสามารถเลือกดูได้หลาย ๆ อย่าง โดยมีขั้นตอนคือ

1. ทำการดาวโหลด package ต่างๆที่จำเป็นดังนี้

# apt-get install mrtg ตัวลง mrtg

#apt-get install gcc make g++ โหลดตัวที่ใช้ในการทำ compiler

#apt-get install apache2 ลง Apache ซึ่งจะทำหน้าที่เป็น Webserver

หลังจากลงเสร็จต่อไปจะเป็นการโหลดตัว MRTG มาใช้

#apt-get install mrtg snmpd snmp

โดยที่ ตัวโปรแกรมจะ create subdirectory ไว้ที่ /var/www/

จากนั้นจะทำการ config snmpd เพื่อให้เราสามารถดูกราฟที่หลากหลายยิ่งขึ้น โดยคำสั่ง
#vi /etc/snmp/snmpd.conf

ให้แก้ไขตามนี้

# sec.name source community
#com2sec paranoid default public
com2sec readonly default public
#com2sec readwrite default private

ทำการรีสตาท #/etc/init.d/snmpd restart

2. หลังจากมี package ต่างๆครบ เราจะทำการ config ไฟล์กัน โดยจะสร้างไฟล์ดังนี้

#cfgmaker -global “options[_]:bits,growright” –global “workdir:/var/www/mrtg” public@127.0.0.1 > /etc/mrtg.cfg

#vi /etc/mrtg.cfg จาก นั้นเข้าไปทำการแก้ไข mrtg.cfg เพิ่มเติม เืพื่อให้มีสามารถ mornitor process อื่น ๆ ได้ีอีกเช่น CPU Load, Memory Usage, Disk Usage ฯลฯ

แล้วเพิ่มคำสั่งนี้เข้าไป (แล้วแต่ต้องการเช็คส่วนใด)

### Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:public@127.0.0.1
MaxBytes[cpu]: 100
Unscaled[cpu]: dwmy
Options[cpu]: gauge, absolute, growright, noinfo, nopercent
YLegend[cpu]: CPU Load(%)
ShortLegend[cpu]: (%)
LegendI[cpu]: &nbsp; CPU System
LegendO[cpu]: &nbsp; CPU User
Title[cpu]: CPU Analysis
PageTop[cpu]: <H1>CPU Analysis</H1>

### Memory Free ###
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@127.0.0.1
MaxBytes1[mem]: 1030288
MaxBytes2[mem]: 1052216
Unscaled[mem]: dwmy
Options[mem]: gauge, absolute, growright, noinfo
YLegend[mem]: Memory Free
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: (MBytes)
Legend2[mem]: (MBytes)
Title[mem]: Memory Analysis
PageTop[mem]: <H1>Memory Analysis</H1>

### New TCP Connection Monitoring (per minute) ###
Target[server.newconns]: tcpPassiveOpens.0&tcpActiveOpens.0:public@127.0.0.1
Title[server.newconns]: Newly Created TCP Connections
PageTop[server.newconns]: <H1>New TCP Connections</H1>
MaxBytes[server.newconns]: 10000000000
ShortLegend[server.newconns]: c/s
YLegend[server.newconns]: Conns / Min
LegendI[server.newconns]: In
LegendO[server.newconns]: Out
Legend1[server.newconns]: New inbound connections
Legend2[server.newconns]: New outbound connections
Options[server.newconns]: growright,nopercent,perminute

### Established TCP Connections ###
Target[server.estabcons]: tcpCurrEstab.0&tcpCurrEstab.0:public@127.0.0.1
Title[server.estabcons]: Currently Established TCP Connections
PageTop[server.estabcons]: <H1>Established TCP Connections</H1>
MaxBytes[server.estabcons]: 10000000000
ShortLegend[server.estabcons]:
YLegend[server.estabcons]: Connections
LegendI[server.estabcons]: In
LegendO[server.estabcons]:
Legend1[server.estabcons]: Established connections
Legend2[server.estabcons]:
Options[server.estabcons]: growright,nopercent,gauge

3. ทำการสร้าง crontab ดังนี้
# crontab -e

เพิ่มคำสั่งนี้เข้าไป
0-59/5 * * * * root /usr/bin/mrtg /etc/mrtg.cfg

# /etc/init.d/cron reload จากนั้นรีโหลดซะครั้ง

ปล สำหรับรุ่นใหม่ๆ ไม่ต้องสร้าง crontab ก็สามารถรันได้ทุกกี่นาทีที่กำหนดได้เอง โดยไม่ต้องเซ็ต

ได้ผลดังนี้ครับ ;)

mrtg1



Older Posts »

Powered by WordPress