Saturday, 28 August 2010

การตั้งค่า iptables

การตั้งค่า iptables

  1. ดาวโหลด script iptables
  2. # wget -O /etc/init.d/firewall.iptables http://syslogserver.googlecode.com/files/firewall.iptables
  3. เริ่มต้นการทำงาน iptables ด้วย config ใหม่
  4. # cd /etc/init.d/
    # chmod +x firewall.iptables 
    # ./firewall.iptables 
  5. สั่งให้ start firewall ทุกครั้งที่บูต server ด้วยคำสั่งนี้
  6. # echo "/etc/init.d/firewall.iptables"  >> /etc/rc.local

ติดตั้ง NTP Server

ติดตั้ง NTP Server

ติดตั้งระบบ เทียบเวลาเพื่อให้แต่ server ที่ให้บริการอยู่ในองค์กร และเครื่องลูกข่าย มีเวลาที่ตรงกัน ตามพรบระบุว่า ต้องตั้งนาฬิกาให้ต้องกับเวลาอ้างอิงสากล (Stratum 0)

ขั้นตอนการติดตั้ง

  1. ตรวจสอบ package
  2. การทำงานจะทำงานผ่าน port UDP  123 ดังนั้นต้องให้  firewalls ACCEPT port 123 ด้วย
    #rpm -qa | grep ntp*
    หากไม่พบ ก็สามารถติดตั้งได้โดย
    #yum install  ntp  -y
    เปิดพอร์ต สามารถทำได้โดยการ update filewall#vi  /etc/sysconfig/iptables
    ...
    ...
    -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTแทรก สองบรรทัดนี้ ต่อ จากบรรทัดตรงนี้
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
    
    restart iptable อีกครั้ง #service iptables restart
    #netstat  -tulpn
  3. ตรวจสอบ remote server
  4. สถาบันมาตรวิทยาแห่งชาติ           [203.185.69.60]   กรมอุทกศาสตร์ กองทัพเรือ            [time.navy.mi.th]  National Institute of Standards and Technology     [time.nist.gov]   
    #ntpdate  -b  203.185.69.60
    #ntpdate  -b  time.navy.mi.th
    #ntpdate  -b  time.nist.gov
  5. แก้ไขค่า config
  6. ตัวอย่างที่ใช้
    192.168.2.1    คือ  CentOs/Redhat server ของเรา
    203.185.69.60    คือ หมายเลข ip ของ NTP server192.168.2.0/24   คือ วง  network ของเครื่องลูกข่าย
    
    backup config#cp  /etc/ntp.conf   /etc/ntp.conf.ori
    #vi  /etc/ntp.conf
    เพิ่มเติม โดย แทนค่า 192.168.2.0 ด้วย วง network ของคุณเอง
    restrict 192.168.2.0  mask 255.255.255.0 nomodify notrap
    server   time1.nimt.or.th 
    server   time.navy.mi.th
    server   clock.nectec.or.th
  7. restart NTP server
  8. #service ntpd  restart
    #chkconfig ntpd on
    check อีกครั้่ง ด้วยวิธีดังต่อไปนี้
    #chkconfig --list  | grep ntp   
    #ps -ef  | grep ntp        
    #pgrep ntpd                         /*check process id
    #netstat  -ntlup                   /*check synce status
  9. check ตรวจสอบการทำงาน
  10. #ntpq  -pn                            /*firewalls rule  ต้องเปิดรับ UDP port 123
    หลักจาก start รอเวลาให้ time server ของคุณ sync ก่อน ประมาณ 5 นาที
    หลังจากนั้นก็ตรวขสอบ การ sync โดย
    #ntpstat
    #ntpdc
    ntpdc>sysinfo                     /*ระบบจะแสดงข้อมูลของ Time Server
  11. check การทำงานผ่านทาง Logfile ได้ที่
  12. #grep  ntpd   /var/log/messages
    แยก ntp log ออกมาไปเก็บไว้ที่  /var/log/ntp.log โดยการไปเพิ่ม ข้อความด้านล่างนี้ ใน /etc/ntp.conf ที่บรรทัดสุดท้าย
    #vi /etc/ntp.conf
    logfile   /var/log/ntp.log
  13. สั่งให้เครื่อง Client มา sync เวลาที่เครื่อง Timeserver (192.168.2.1)
  14. ต่อไปนี้ทำในเครื่อง server ในลูกข่ายไม่ได้ทำที่ เครื่อง time server#ntpdate  192.168.2.1
    #vi  /etc/ntp.conf
    server 192.168.2.1                        /* ip ของ NTP server
    restrict default  ignore                  /* deny all access จากเครื่องใด
    restrict   127.0.0.1
    
    ให้เครื่องลูกมา update ทุกๆๆ  30 นาที
    #crontrab -e
    30  * * * *  ntpdate 192.168.2.1   > /dev/null  2  > &1
    
    หมายเหตุ   ntpdate ใช้กับ client
  15. lient เป็น window ให้ใช้ nettime โดยสามารถไป Download ได้ที่
  16. http://nettime.sourceforge.net
  17. est result ผลการทำงาน
  18. #service ntpd restart
    #tail -f /var/log/ntp.log
    11 Feb 00:37:49 ntpd[2743]: ntpd exiting on signal 15
    11 Feb 00:41:03 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 00:41:03 ntpd[2764]: kernel time sync enabled 0001
    11 Feb 00:43:10 ntpd[2764]: synchronized to 118.175.67.83, stratum 1
    11 Feb 00:46:26 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 00:48:37 ntpd[2764]: synchronized to 118.175.67.83, stratum 1
    11 Feb 00:52:53 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
    11 Feb 01:03:47 ntpd[2764]: time reset +0.794279 s11 Feb 01:07:31 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 01:08:36 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
    11 Feb 01:12:01 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 01:13:47 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
  19. ตั้งค่าให้เริ่มการทำงานทุกครั้งที่เปิดเครื่อง
  20. # chkconfig ntpd on

การ config syslog-ng

ยังไม่สมบูรณ์

ขั้นตอนการ config

การ config syslog-ng.conf สำหรับรับ-ส่ง log ลงเครื่องตัวเอง

  1. ย้าย config files เก็บไว้
  2. # mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.ori
  3. ดาวโหลด config files ใหม่
  4. # wget -O /etc/syslog-ng/syslog-ng.conf http://syslogserver.googlecode.com/files/syslog-ng.conf.standalone
  5. restart syslog-ng เพื่อรับค่า config ใหม่
  6. # service syslog-ng restart

การ config syslog-ng.conf สำหรับส่ง log ไปหา centralized log server

เครื่อง client (ส่ง log)

  1. ย้าย config files เก็บไว้
  2. # mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.ori
  3. ดาวโหลด config files ใหม่
  4. # wget -O /etc/syslog-ng/syslog-ng.conf http://syslogserver.googlecode.com/files/syslog-ng.conf.send.conf
  5. restart syslog-ng เพื่อรับค่า config ใหม่
  6. # service syslog-ng restart

เครื่อง server (รับ log)

# mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.ori
  1. ดาวโหลด config files ใหม่
  2. # wget -O /etc/syslog-ng/syslog-ng.conf http://syslogserver.googlecode.com/files/syslog-ng.conf.send.conf
  3. restart syslog-ng เพื่อรับค่า config ใหม่
  4. # service syslog-ng restart

ติดตั้ง Syslog-ng

ติดตั้ง Syslog-ng

ติดตั้ง Syslog-ng แทน sysklogd

ขั้นตอนการติดตั้ง

  1. ตรวจสอบ sysklogd ว่ายังทำงานอยุ่ในระบบหรือไม่
  2. #rpm -qa  | grep sysklogd
    #rpm -ql  sysklog                       /* ดูรายละเอียดของ file  ที่ติดตั้ง
  3. ถ้าหากยังทำงานอยู่ ให้ทำการถอน sysklogd ออกจาก server ก่อน
  4. #rpm -e --nodeps  sysklogd
    (หากไม่ต้องการลบออก ก็สามารถทำได้โดยการ คำสั่งต่อไปนี้ แทน)
    *chkconfig syslog off*/etc/init.d/syslog stop
  5. ตรวจ สอง GLIB2.0 เนื่องจาก Syslog-ng ต้องการ Library นี้
  6. #rpm  -qa  | grep glib2
  7. ให้ทำการการ Download file ทั้งหมดและทำการติดตั้ง
  8. #cd /root
    #mkdir   /src
    #wget http://syslogserver.googlecode.com/files/syslog-ng-2.1.4-1.el5.i386.rpm
    #wget http://syslogserver.googlecode.com/files/eventlog-devel-0.2.7-3.el5.i386.rpm
    #wget http://syslogserver.googlecode.com/files/eventlog-0.2.7-3.el5.i386.rpm
    ติดตั้ง
    #rpm -Uvh  eventlog-0.2.7-3.el5.i386.rpm
    #rpm -Uvh  eventlog-devel-0.2.7-3.el5.i386.rpm
    #rpm -Uvh  syslog-ng-2.1.4-1.el5.i386.rpm
    #service syslog-ng start
    #chkconfig syslog-ng  on
    #rpm  -ql  syslog-ng
    ผลลัพท์
    /etc/init.d/syslog-ng                                    /* start script
    /etc/logrotate.d/syslog                                 /* log rotation
    /etc/sysconfig/syslog-ng
    /etc/syslog-ng
    /etc/syslog-ng/syslog-ng.conf                  /*file config
    /sbin/syslog-ng
    ...
    ...
# ทำการทดสอบ Syslog-ng config
เพื่อให้เห็นการทำงานที่ชัดเจน ให้ตุณทำการทดลองเปลี่ยน  path ที่เก็บ จาก /var/log เป็น  /var/logtestทำการ backup#cp /etc/syslog-ng/syslog-ng.conf  /etc/syslog-ng/syslog-ng.conf.ori
#mkdir  /var/logtest
#vi   /etc/syslog-ng/syslog-ng.conf

 27 destination d_cons { file("/dev/console"); };
 28 destination d_mesg { file("/var/logtest/messages"); };
 29 destination d_auth { file("/var/logtest/secure"); };
 30 destination d_mail { file("/var/logtest/maillog" sync(10)); };
 31 destination d_spol { file("/var/logtest/spooler"); };
 32 destination d_boot { file("/var/logtest/boot.log"); };
 33 destination d_cron { file("/var/logtest/cron"); };
 34 destination d_kern { file("/var/logtest/kern"); };
 35 destination d_mlal { usertty("*"); };
...
#service syslog-ng  restart
ตรวจสอบผล
#cd /var/logtest

การติดตั้ง โปรแกรม Squid (Proxy Server

การติดตั้ง โปรแกรม Squid (Proxy Server)

  1. ดาวโหลด โปรมแกรม Squid version 3 stable
  2. # cd /root
    # wget http://syslogserver.googlecode.com/files/squid-3.0.STABLE20-1.el5.i386.rpm
  3. ลบโปรแกรม squid เวอร์ชั่นเก่า 2.6 ออกก่อนด้วยคำสั่ง
  4. # rpm -qa | grep squid
    # yum remove squid -y
  5. ติดตั้งโปรแกรม squid เวอร์ชั่นใหม่ด้วยคำสั่ง
  6. # rpm -ivh squid-3.0.STABLE20-1.el5.i386.rpm
  7. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
  8. # chkconfig squid on
  9. สำรอง config file ของ Squid
  10. # mv /etc/squid/squid.conf /etc/squid/squid.conf.ori
  11. ดาวโหลด config file ของ Squid
  12. # wget -O /etc/squid/squid.conf  http://syslogserver.googlecode.com/files/squid.conf
  13. สั่งให้ squid เริ่มทำงานด้วยคำสั่ง
  14. # service squid start
  15. สั่ง restrart syslog-ng เพื่อรับค่าการส่ง log จาก squid ด้วยคำสั่ง
  16. # service syslog-ng restart

การติดตั้ง LogZilla/PHP Syslog-ng

การติดตั้ง LogZilla/PHP Syslog-ng

  1. ทำการดาวน์โหลดไฟล์ติดตั้ง โดยใช้คำสั่งดังต่อไปนี้
  2. # cd /root
    # wget http://syslogserver.googlecode.com/files/logzilla.tgz
    # tar xvfz logzilla.tgz
    # cd logzilla
    # ./install.sh
  3. หลังจากติดตั้งเสร็จ จะสามารถเรียกเข้า LogZilla ได้ดังนี้
http://ip-address/logserver Username = admin Password = logserver

Comment by kergritJun 01, 2010

การติดตั้งโปรแกรม Freeradius

การติดตั้งโปรแกรม Freeradius

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
  2. # yum install freeradius  freeradius-mysql -y
  3. แก้ไขให้ freeradiusทำงานโดยอัตโนมัติทุกครั้งที่บูทเครื่อง
  4. # chkconfig radiusd on
  5. แก้ไข secret ของ freeradius
  6. # nano /etc/raddb/clients.conf
     เดิม secret = testing123
     แก้ไขเป็น secret = mykey 
     โดยสามารถปรับเปลี่ยนได้ตามความต้องการ
  7. สร้าง database ชื่อ radius เพื่อให้ทำงานร่วมกับ freeradius
  8. # mysqladmin -uroot -psipalogserver create radius
  9. ดาวโหลดไฟล์ที่จำเป็นต้องใช้งาน และ import ข้อมูลขั้นต้นลงไป
  10. # cd /root
    # wget http://syslogserver.googlecode.com/files/freeradius.tar.gz
    # tar  zxvf  freeradius.tar.gz
    # cd  freeradius_webui
    # mysql -u root -psipalogserver radius < radius.sql
  11. ทำการสำเนาไฟล์ sql.conf โดยใช้งานคำสั่งดังนี้
  12. # cp /etc/raddb/sql.conf /etc/raddb/sql.conf.ori
  13. ทำการแก้ไข password ของ radius เพื่อให้ทำการเชื่มต่อกับฐานข้อมูลได้โดยใช้งานคำสั่งดังนี้
  14. # cd /etc/raddb/
    # sed -i 's/password = "rootpass"/password = "sipalogserver"/g' sql.conf
  15. สำรองไฟล์ /etc/raddb/radiusd.conf โดยใช้งานคำสั่งดังนี้
  16. # mv /etc/raddb/radiusd.conf /etc/raddb/radiusd.conf.ori
    # cp /root/freeradius_webui/radiusd.conf /etc/raddb/
    # service  radiusd restart
  17. ทำการสร้าง user โดยใช้งานคำสั่งดังนี้
  18. # echo "INSERT INTO radcheck(UserName,Attribute,Value) VALUES ('user','Password','123456');" | mysql -uroot -psipalogserver radius;
  19. ทำการทดสอบการทำงานโดยใช้งานคำสั่งดังนี้
  20. # radtest user 123456 localhost 0 mykey
  21. คำสั่ งด้านบนจะได้ผลลัพธ์ คล้ายๆข้อความด้านล่าง
  22. # radtest user 123456 localhost 0 testing123
    Sending Access-Request of id 112 to 127.0.0.1 port 1812
    User-Name = "user"
    User-Password = "123456"
    NAS-IP-Address = 255.255.255.255
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=112, length=20

การติดตั้งและใช้งานระบบจัดการพิสูจน์ตัวตนผู้ใช้งานอินเทอร์เน็ต

การติดตั้งฐานข้อมูลผู้ใช้งาน

  1. ทำการคัดลอกโฟลเดอร์ที่ชื่อว่า admin ไปใส่ใน path ของ apache โดยใช้คำสั่ง
  2. # cd  /root/freeradius_webui/            
    # cp -r admin /var/www/html/
  3. ทำการเรียกใช้งานระบบจัดการพิสูจน์ตัวตนผู้ใช้งานอินเทอร์เน็ตโดยเปิด Browserพิมพ์
  4. http://ip address/admin/
  5. หลังจากเข้าหน้าระบบจัดการพิสูจน์ตัวตน ทำการ login โดยมี
ชื่อผู้ใช้ : admin รหัสผ่าน : 123456