分类: 系统运维
2009-08-01 08:54:09
补充修改:哈密瓜
blog:
转自:http://zoukejian.blog.51cto.com/131276/56828
CODE:
openssl097a-0.9.7a-9.el5_2.1
openssl-0.9.8b-10.el5_2.1
openssl-devel-0.9.8b-10.el5_2.1
openssl-perl-0.9.8b-10.el5_2.1
安装glib:CODE:
options {
keep_hostname(yes);
long_hostnames(off);
sync(1);
log_fifo_size(1024);
create_dirs(yes); # if a dir does not exist create it
owner(root); # owner of created files
group(root); # group of created files
perm(0600); # permissions of created files
dir_perm(0700); # permissions of created dirs
};
source s_all {
udp(); # remote logs # arriving at 514/udp
unix-stream("/dev/log"); # local system logs
file("/proc/kmsg"); # local kernel logs
internal(); # internal syslog-ng logs
};
destination single-file {
file("/var/log/syslog-ng/all-messages");
};
log {
source(s_all);
destination(single-file);
};
启动 syslog-ng:
(2009-02-23 16:45:30, Size: 2.36 KB, Downloads: 22)
CODE:
/usr/local/src/mysql-5.0.51b/debian/libmysqlclientSLIB-dev.files.in
/usr/local/mysql/lib/mysql/libmysqlclient.so
/usr/local/mysql/lib/mysql/libmysqlclient_r.so.15
/usr/local/mysql/lib/mysql/libmysqlclient.so.15.0.0
/usr/local/mysql/lib/mysql/libmysqlclient.so.15
/usr/local/mysql/lib/mysql/libmysqlclient_r.la
/usr/local/mysql/lib/mysql/libmysqlclient_r.so.15.0.0
/usr/local/mysql/lib/mysql/libmysqlclient_r.a
/usr/local/mysql/lib/mysql/libmysqlclient.a
/usr/local/mysql/lib/mysql/libmysqlclient_r.so
/usr/local/mysql/lib/mysql/libmysqlclient.la
#ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.15 /usr/libCODE:
create database sqlsyslogd;
use sqlsyslogd;
create table logs (
Id int(10) NOT NULL auto_increment,
Timestamp varchar(16),
Host varchar(50),
Prog varchar(50),
Mesg text,
PRIMARY KEY (id)
);
use mysql;
create user sqlsyslogd@localhost identified by ‘foo’;
grant all on sqlsyslogd.* to sqlsyslogd;
flush privileges;
# sql –u root –p < sqlsyslogd.sqlCODE:
destination mysql {
program(“/usr/local/sbin/sqlsyslogd –u sqlsyslogd \
–t logs sqlsyslogd –p”);
};
log {
source(all);
destination(mysql);
};
重启 syslog-ng: CODE:
INSTALLDIR = /usr/local/etc
INSTALLDIR_BIN = /usr/local/bin
INSTALLDIR_SH = /usr/local/etc
TMPDIR = /usr/local/etc/tmp
改为:
CODE:
INSTALLDIR = /usr/local/logcheck/etc
INSTALLDIR_BIN = /usr/local/logcheck/bin
INSTALLDIR_SH = /usr/local/logcheck/etc
TMPDIR = /usr/local/logcheck/etc/tmp
# make linuxCODE:
LOGTAIL=/usr/local/bin/logtail
TMPDIR=/usr/local/etc/tmp
HACKING_FILE=/usr/local/etc/logcheck.hacking
VIOLATIONS_FILE=/usr/local/etc/logcheck.violations
VIOLATIONS_IGNORE_FILE=/usr/local/etc/logcheck.violations.ignore
IGNORE_FILE=/usr/local/etc/logcheck.ignore
改为:
CODE:
LOGTAIL=/usr/local/bin/logtail
TMPDIR=/usr/local/etc/tmp
HACKING_FILE=/usr/local/etc/logcheck.hacking
VIOLATIONS_FILE=/usr/local/etc/logcheck.violations
VIOLATIONS_IGNORE_FILE=/usr/local/etc/logcheck.violations.ignore
IGNORE_FILE=/usr/local/etc/logcheck.ignore
#tar zvxf newlogcheck.tgzCODE:
SYSADMIN=root,***@***.com //多个邮箱地址用逗号隔开
LOGTAIL=/usr/local/bin/logtail
BASEDIR=/usr/local/logcheck
# vi /usr/local/logcheck/etc/sort_logs.pl
CODE:
my $LOGCHECK_DIR = "/usr/local/logcheck";
# mkdir /usr/local/logcheck/tmp/hostCODE:
watchfor /Failed password/
mail address=root, subject=warning: Failed password
throttle 01:00
watchfor /Invalid user/
mail address=root, subject=warning: Invalid user
throttle 01:00
watchfor /authentication failure/
mail address=root, subject=warning: authentication failure
throttle 01:00
watchfor /iptables:/
mail address=root, subject=warning: iptables operation
throttle 01:00
watchfor /Duplicate address/
mail address=root, subject=warning: Duplicate address
throttle 01:00
watchfor /file system full/
mail address=root, subject=warning: file system full
throttle 01:00
watchfor /(panic|halt)/
mail address=root, subject=warning: panic or halt happened
throttle 01:00
watchfor /Media Error/
mail address=root, subject=warning: disk error happened
throttle 01:00
……
运行swatch: CODE:
root ...... /usr/bin/perl /usr/bin/swatch --config-file=/etc/swatch.conf --tail-file=/var/log/syslog-ng/all-messages
root ...... /usr/bin/perl /root/.swatch_script.17374 ß //你看到的将是其他数字
6.安装 splunk:CODE:
将其中的 $SPLUNK_HOME 设置为 /usr/local/splunk
将/usr/local/splunk/etc/init.d/redhat/splunk 拷贝到/etc/init.d/目录下
# chmod 700 /etc/init.d/splunk && chkconfig splunk onCODE:
……
/usr/local/syslog-ng/sbin/syslog-ng
/usr/bin/swatch –config-file=/etc/swatch.conf –tail-file=/var/syslog-ng/all-messages &
三.日志客户机配置CODE:
...
*.info @log_host
2. 在 /etc/hosts 文件里面添加一项,使日志客户机能解析上面的 log_host:CODE:
...
x.x.x.x log_host
总结,配置一个日志主机,需要花费较大的功夫。但是,一旦你配置好了,它给你带来的益处也很大,比如,你能够随时查阅很久以前的日志,你能及时知道某台服务器的硬盘有问题了,如果有黑客入侵了你的服务器,不管他如何销毁自己的踪迹,你都能够他在入侵过程中留下的痕迹,等等等等。所以,花大力气建立这样一个日志主机还是明智的。