Author Topic: config logrotate + syslog-ng + ntp support mail.log on debian  (Read 11974 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
config logrotate + syslog-ng + ntp support mail.log on debian
« on: มกราคม 23, 2011, 12:54:18 AM »
### ถ้าจะใช้ syslog-ng ต้องลบ syslog ออกน่ะครับผมเพราะไม่งั้น os จะสับสนกันเองครับ

install syslog-ng
#apt-get install syslog-ng

ลบ script syslog ออกไม่ให้รัน ตอน reboot server
#update-rc.d -f syslog remove

ต่อไป เริ่ม config syslog-ng.conf
#vi /etc/syslog-ng/syslog-ng.conf

หาว่ามี config mail.log หรือไม่
destination df_mail { file("/var/log/mail.log"); };

#mail.* -/var/log/mail.log
log {
source(s_all);
filter(f_mail);
destination(df_mail);
};

ถ้ามีครบ ก็ ไป config logrotate ได้เลยครับ
#vi /etc/logrotate.d/syslog-ng

/var/log/mail.info {
rotate 90
daily
missingok
notifempty
compress
}

/var/log/mail.log {
rotate 90
daily
missingok
notifempty
compress
# delaycompress
}

/var/log/mail.warn {
rotate 90
daily
missingok
notifempty
compress
}

แค่นี้ ครับ

ข้อแม้ ห้ามมีไฟล์ที่ เขียน config อย่างงี้ซ้ำกันใน path "/etc/logrotate.d/"

น่ะครับไม่งั้น เวลาสั่ง logrotate มันจะขึ้นว่า log file มัน duplicate กัน

เสร็จแล้วการ test สั่งให้ logrotate ทำงาน

#logrotate /etc/logrotate.conf

รอสักพัก แล้วไปดูใน path /var/log ก็จะเห็นมัน lorate log ให้ครับผม

ส่วน log file ตัวอื่นก็ทำในลักษณะเดียวกันน่ะครับ

ส่วนการรัน log rotate จะทำงานใน cron.daily ทุกวันอยู่แล้ว ไม่ต้องไป set crontab เพิ่มน่ะครับผม
ถ้าจะเช๊คก็ดูได้ที่
#more /etc/cron.daily/logrotate




ถ้ามีข้อสงสัยก็โฟสไว้ได้น่ะครับผม
golfreeze[at]packetlove.com
« Last Edit: มกราคม 23, 2011, 01:08:54 AM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: config logrotate + syslog-ng support mail.log on debian
« Reply #1 on: มกราคม 23, 2011, 01:08:24 AM »
Install SYSLOG-ng + NTP server + MRTG + http

ปิด seLinux ก่อนใน CentOS 5
#vi /etc/selinux/config
SELINUX=disabled

หรือจะเข้าไปแก้ใน คำสั่ง setup ก็ได้ครับ
#setup

เลือก
Security Level: ( ) Enabled (*) Disabled

SELinux: Enforcing
Permissive
Disabled เลือกเป็นตัวนี้

แค่นี้ครับ Selinux ก็จะไม่มากวนใจท่าน อีก แล้วเราค่อย set iptables ของเราเองครับ

ลง mrtg + net-snmp + httpd
#yum install httpd net-snmp net-snmp-utils net-snmp-libs

ก่อนจะลง mrtg ควรที่จะลง perl module ของ net-IO ก่อนครับดังนี้
#perl –MCPAN –e shell
cpan>install Bundle::CPAN
ถ้าไม่ได้ทำการ update config ใหม่ แล้วเลือก site ใหม่โดย
Cpan>o conf init
แล้วสั่งให้ลง
cpan>install Bundle::CPAN

เสร็จแล้ว
#yum install mrtg

ลง syslog-ng ต้องทำการลบ sysklog ออกก่อนดังนี้
#rpm –e –nodeps sysklog
ลง eventlog ด้วย
#wget
ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/x86_64/RPMS/eventlog-0.2.5-6.el5.kb.x
86_64.rpm
#rpm –Uvh eventlog-0.2.5-6.el5.kb.x86_64.rpm
#wget http://www.silfreed.net/download/repo/packages/syslog-ng/syslog-ng-2.0.9-3.el5.x86_64.rpm
#rpm –Uvh syslog-ng-2.0.9-3.el5.x86_64.rpm
ฝั่ง server วาง config ไว้ที่
/etc/syslog-ng/syslog-ng.conf
มีดังนี้
# syslog-ng configuration file.
#
# This should behave pretty much like the original syslog on RedHat. But
# it could be configured a lot smarter.
#
# See syslog-ng( and syslog-ng.conf(5) for more information.
#

options {
sync (0);
# time_reopen (10);
log_fifo_size (1000);
long_hostnames (off);
use_dns (no);
#use_fqdn (no);
create_dirs (no);
#keep_hostname (yes);
};

#source s_sys {
# file (\"/proc/kmsg\" log_prefix(\"kernel: \"));
# unix-stream (\"/dev/log\");
# internal();
# udp(ip(0.0.0.0) port(514));
#};

########Syslog-ng keep apache from 192.168.1.155 #########
source sys_apache_test { tcp(ip(192.168.1.155) port(212)); };
destination d_apache { file(\"/var/log/apache_test/access.log\"
create_dirs(yes)
dir_owner(root) dir_group(root) dir_perm(700)) ; };
log { source(sys_apache_test); destination(d_apache); };

########Syslog-ng keep apache from 192.168.1.155 #########
source sys_apachelog { tcp(ip(192.168.1.155) port(299)); };
destination d_apachelog { file(\"/var/log/apache_test/access_log\"
create_dirs(yes)
dir_owner(root) dir_group(root) dir_perm(700)); };
log { source(sys_apachelog); destination(d_apachelog); };

############# Keep Log from Router ########################
#source info_src { internal(); udp();};
#destination d_info_src { file(\"/var/log/apache_test/access_hw.log\"); };
#log { source(info_src); destination(d_info_src); };


เมื่อลอง netstat ดูจะเห็นว่ามี socket เปิดรออยู่แล้วดังนี้
tcp 0 0 192.168.1.155:299 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.155:212 0.0.0.0:* LISTEN
ฝั่ง client ก็ทำการลง syslog-ng ดังนี้
#rpm –e –nodeps sysklog
ลง eventlog ด้วย
#wget
ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/x86_64/RPMS/eventlog-0.2.5-6.el5.kb.x
86_64.rpm
#rpm –Uvh eventlog-0.2.5-6.el5.kb.x86_64.rpm
#wget http://www.silfreed.net/download/repo/packages/syslog-ng/syslog-ng-2.0.9-3.el5.x86_64.rpm
#rpm –Uvh syslog-ng-2.0.9-3.el5.x86_64.rpm
Config syslog-ng.conf โดย
options {
sync (0);
#time_reopen (10);
#log_fifo_size (1000);
long_hostnames (off);
use_dns (no);
#use_fqdn (no);
create_dirs (no);
#keep_hostname (yes);
};
source apachelog { file (\"/var/log/httpd/access_log\"); };
destination d_apachelog { tcp(\"10.0.1.155\" port(299)); };
log { source(apachelog); destination(d_apachelog); };
source sys_apache { unix-dgram(\"/dev/log\"); file
(\"/proc/kmsg\" );
unix-stream (\"/dev/log\"); create_dirs (no); };
destination d_apache_internal {
file(\"/var/log/httpd/access.log\");
};
destination d_apache { tcp(\"10.0.1.155\" port(212)); };
log { source(sys_apache); destination(d_apache_internal); };
log { source(sys_apache); destination(d_apache); };

แค่นี้ครับ
ต่อไป config ntp server ครับ
#yum install ntpd

# vi /etc/ntp.conf
สำหรับบันทัดนี้ มันจะเป็นแหล่งที่เรา ไป sync กับตัว หลัก
server clock.nectec.or.th prefer
บันทัดนี้ สำหรับ server รอง
server 202.142.213.175
อนุญาติให้ ทุกๆ client ติดต่อสั่ง ntpdate ได้
restrict 0.0.0.0 mask 0.0.0.0 nomodify
หรือใส่เป็น ให้ ip=202.142.213.175 เป็น ntp server
restrict 202.142.213.175 mask 255.255.255.245


แล้วแก้ ให้ รัน ntpd ทุกครั้งตอน reboot เครื่อง
# chkconfig ntpd on
#/etc/init.d/ntpd restart
# vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
(write the sync time to CMOS)
เสร็จแล้วสั่ง เช๊ค ntp ว่าให้ sync ได้หรือไม่โดย
#/usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*nucleus.nectec. 133.100.9.2 2 u 78 256 377 4.690 -1.600 2.723
LOCAL(0) .LOCL. 5 l 59 64 377 0.000 0.000 0.001
0.0.0.0 .BCST. 16 l - 64 0 0.000 0.000 0.001

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: config logrotate + syslog-ng support mail.log on debian
« Reply #2 on: มกราคม 23, 2011, 01:08:35 AM »
ทำการ ntpdate ที่ client โดย
#ntpdate 202.142.213.175

เรียบร้อยครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: config logrotate + syslog-ng + ntp support mail.log on debian
« Reply #3 on: มกราคม 23, 2011, 01:08:58 AM »
check ntp server ว่าทำงานหรือเปล่า ดูได้ว่า port 123 เปิดหรือเปล่า
[root@xxx etc]# netstat -nlp | grep 123
udp 0 0 202.142.213.175:123 0.0.0.0:*
27039/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 27039/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 27039/ntpd
udp 0 0 fe80::213:f7ff:fe00:123 :::* 27039/ntpd
udp 0 0 ::1:123 :::* 27039/ntpd
udp 0 0 :::123 :::* 27039/ntpd

Anokiiz9

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: config logrotate + syslog-ng + ntp support mail.log on debian
« Reply #4 on: กันยายน 05, 2013, 06:34:24 PM »
เป็นข้อมูบที่ดีมากครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: config logrotate + syslog-ng + ntp support mail.log on debian
« Reply #5 on: สิงหาคม 31, 2021, 01:29:41 PM »
ในกรณีเจอเครื่อง centos ไม่ให้ใช้งาน port อื่นนอกจาก 514 เพื่อรับ log สามารถตรวจเชคได้ ติด selinux หรือเปล่านะครับ

semanage port --list | grep syslog
syslogd_port_t                 tcp      601, 20514
syslogd_port_t                 udp      514, 601, 20514

ถ้าขึ้นมาเป็น 20514 สามารถใช้ตัวนี้ได้นะครับผม