注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 百度转的,看了心痛呀,想..
 帮助

日志主机安装指南


2007-12-27 09:32:54
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。
                   日志主机安装指南
 
一.希望达到的目的
       1.服务器日志集中存放到MySQL数据库中;
       2.每天发送一封E-MAIL, 报告异常日志条目;
       3.实时报告异常系统事件;
       4WEB界面查询日志;
二.日志主机安装和配置
各个软件的功能及交互图
 
 
1.安装syslog-ng:
   http://www.balabit.com/downloads/syslog-ng下载 eventlog, libol, syslog-ng tarball.
   安装eventlog:   # ./configure  --prefix=/usr/local/eventlog && make && make install
   安装 libol:      # ./configure –prefix=/usr/local/libol &&make && make install
   安装 syslog-ng:  # export PKG_CONFIG_PATH=/usr/local/eventlog/pkgconfig/
                           # ./configure –prefix=/usr/local/syslog-ng --with-libol=/usr/local/libol
                           # make && make install
   配置 syslog-ng:  # vi /usr/local/syslog-ng/etc/syslog-ng/syslog-ng.conf
        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:  # /etc/init.d/syslog stop
                    # /usr/local/syslog-ng/sbin/syslog-ng
   验证:ps ef|grep syslog-ng
         查看文件:/var/log/syslog-ng/all-messages
2. 安装MySQL到 /usr/local/mysql 下,以存放日志。
3. 安装 SQLSyslogd, 以便将日志写入 MySQL 数据库中:
   安装:# ln s /usr/local/mysql/lib/mysql /usr/local/lib/mysql
         # ln s /usr/local/mysql/include/mysql \
              /usr/local/include/lib
         # make && cp sqlsyslogd /usr/local/sbin/
         # cat /usr/local/lib/mysql >> /etc/ld.so.conf && ldconfig
   验证 sqlsyslogd 能正常运行:# sqlsyslogd
        如果正常,你可以看到 sqlsyslogd 的帮助信息。
   修改 sqlsyslogd.sql 文件: # vi sqlsyslogd.sql
        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.sql
        # vi /usr/local/etc/sqlsyslogd.conf
          foo
   修改 syslog-ng.conf 文件,添加下面几行:
      destination mysql {
            program(/usr/local/sbin/sqlsyslogd u sqlsyslogd \
                      t logs sqlsyslogd p);
            };
      log {
            source(all);
            destination(mysql);
            };
   重启 syslog-ng: # pkill SIGHUP syslog-ng
   验证:现在你应该可以通过 MySQL 客户端软件查看日志了。
4.安装 logcheck 和 newlogcheck:
   http://sf.net/projects/sentrytools/ 下载 logcheck,
   http://www.campin.net/download/ 下载 newlogcheck.tgz
   安装:# mkdir p /usr/local/logcheck/bin \
           /usr/local/logcheck/etc/ /usr/local/logcheck/tmp
         # cd logcheck-<version>
           修改 Makefile 文件,将其中 /usr/local
           为 /usr/local/logcheck
          # make linux
          # cd newlogcheck-<version> && \
            cp *\.* /usr/local/logcheck/etc/
    配置:根据logcheck各个文件的位置修改 /usr/local/logcheck/etc/
          目录下的 newlogcheck.sh sort_logs.pl
          # mkdir /usr/local/logcheck/tmp/host
    测试:# /usr/local/logcheck/etc/newlogcheck.sh
     如果安装正常,你应该收到一封e-mail, 现在你可以安装一个
     crontab 来自动化logcheck日志
     检查: # crontab e
                
                10 2 * * * /usr/local/logcheck/etc/newlogcheck.sh
5.安装 swatch:
   按顺序安装下面的perl 模块:Carp-Clan, Bit-Vector, Date-Calc,
   Time-HiRes, File-Tail,TimeDate, swatch(使用3.0.8版本,
   不要用3.0.12)
   配置 swatch: #vi /etc/swatch.conf
    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: # /usr/bin/swatch --config-file=/etc/swatch.conf \
                   --tail-file=/var/log/syslog-ng/all-messages &
   验证:ps ef|grep swatch | grep v grep
         如果正常,你应该看到2个进程:
         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:
   http://www.splunk.com 下载 splunk tarball
   解压 splunk tarball 并将其移动到 /usr/local/splunk
   修改 /usr/local/splunk/bin/setSplunkEvn  
   和 /usr/local/splunk/etc/init.d/redhat/splunk,将
   其中的 $SPLUNK_HOME 设置为 /usr/local/splunk, 将  
   /usr/local/splunk/etc/init.d/redhat/splunk 拷贝到
   /etc/init.d/目录下,
   # chmod 700 /etc/init.d/splunk && chkconfig splunk on
   启动splunk: /etc/init.d/splunk start
   现在你可以通过 WEB 浏览器访问 splunk 了:http://localhost:8000/
 
   配置:
       
现在你可以搜索日志了.
7.配置启动:vi /etc/rc.local
/usr/local/syslog-ng/sbin/syslog-ng
/usr/bin/swatch config-file=/etc/swatch.conf \
   tail-file=/var/syslog-ng/all-messages &
 
三.日志客户机配置
这里所说的日志客户机指需要把自己的日志传送给日志主机的服务器。
我们在日志客户机上的配置很简单,只需要两步:
1. 在 /etc/syslog.conf 文件添加一项,使日志客户机把自己的严重程度在.info以上的日志也发送给日志主机:
# cat /etc/syslog.conf
...
*.info                               @log_host
2. 在 /etc/hosts 文件里面添加一项,使日志客户机能解析上面的 log_host:
# cat /etc/hosts
...
x.x.x.x                              log_host
 
总结,配置一个日志主机,需要花费较大的功夫。但是,一旦你配置好了,它给你带来的益处也很大,比如,你能够随时查阅很久以前的日志,你能及时知道某台服务器的硬盘有问题了,如果有黑客入侵了你的服务器,不管他如何销毁自己的踪迹,你都能够他在入侵过程中留下的痕迹,等等等等。所以,花大力气建立这样一个日志主机还是明智的。

本文出自 “邹可见” 博客,转载请与作者联系!





    文章评论
 
2007-12-27 10:24:02
学习 安装一下

2008-01-02 14:33:12
非常感谢!


我没啥基础,问问高手。
按你说方法在centos5里面装到 syslog-ng的时候./configure都是提示错误没找到eventlog 2.0以上版本 可是之前已经装了啊,目录都是按写的做的   :`(


2008-01-02 15:06:45
你把错误提示贴出来看看吧

2008-01-03 01:25:39
[root@tongxl syslog-ng-2.0.5]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for gcc option to accept ANSI C... none needed
checking for bison... no
checking for byacc... no
checking for flex... no
checking for lex... no
checking whether make sets $(MAKE)... (cached) yes
checking for ranlib... ranlib
checking how to enable static linking for certain libraries... GNU or Solaris
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dmalloc.h usability... no
checking dmalloc.h presence... no
checking for dmalloc.h... no
checking for strings.h... (cached) yes
checking openssl/ssl.h usability... yes
checking openssl/ssl.h presence... yes
checking for openssl/ssl.h... yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking stropts.h usability... yes
checking stropts.h presence... yes
checking for stropts.h... yes
checking sys/strlog.h usability... no
checking sys/strlog.h presence... no
checking for sys/strlog.h... no
checking door.h usability... no
checking door.h presence... no
checking for door.h... no
checking tcpd.h usability... yes
checking tcpd.h presence... yes
checking for tcpd.h... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_gmtoff... yes
checking for I_CONSLOG... no
checking for O_LARGEFILE... yes
checking for struct sockaddr_storage... yes
checking for struct sockaddr_in6... yes
checking for door_create in -ldoor... no
checking for socket in -lsocket... no
checking for nanosleep in -lrt... yes
checking for gethostbyname in -lnsl... yes
checking for regexec in -lregex... no
checking for res_init in -lresolv... no
checking for strdup... yes
checking for strtol... yes
checking for inet_aton... yes
checking for inet_ntoa... yes
checking for getopt_long... yes
checking for getaddrinfo... yes
checking for getutent... yes
checking for TCP wrapper library... -lwrap
checking for LIBNET... which: no libnet-config in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin)
no
checking whether to enable Sun STREAMS support... no
checking whether to enable Sun door support... no
checking whether to enable TCP wrapper support... yes
checking whether to enable spoof source support... no
checking whether to enable IPv6 support... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for GLIB... yes
checking for EVTLOG... no
configure: error: Cannot find eventlog version >= 0.2: is pkg-config in path?
[root@tongxl syslog-ng-2.0.5]#  




2008-01-03 01:29:16
错误如上面
最开始按你写的来做的。出现上面问题后来又如下面办法指定目录装一次还不行。
eventlog:   # ./configure --prefix=/usr/local/eventlog && make && make install
libol:     # ./configure –prefix=/usr/local/libol &&make && make install
syslog-ng: # export PKG_CONFIG_PATH=/usr/local/eventlog/pkgconfig/
                      # ./configure –prefix=/usr/local/syslog-ng --with-libol=/usr/local/libol
                      # make && make install

2008-01-03 09:28:16
我当时是在RHEL4上装的,CentOS 5我没有试过。
我会尽快在CentOS上试试,然后回复你。

2008-01-03 14:09:49
谢谢老大~

2008-01-03 16:53:07
你好。
不好意思,我今天在自己的电脑上装了VMWARE(因为手头暂时没有测试机),然后装上了CentOS 5,安装的过程挺慢的,尤其是在确认选择的安装包的依赖关系的时候。好不容易装完了。心想总算可以测试一下了吧。可是,启动的时候起不来,读入启动配置之后,就挂在加载内核的地方了,反复多次都启动不起来。没办法,暂时做不了了,也不能回复你了。请谅解。
如果你方便,可以在RHEL下测试测试吧。我的机器在VMWARE下跑多个RHEL没问题的。
抱歉。

2008-01-03 20:28:42
好。一会试试VM装rhel 不管怎么样都非常感谢老大热心帮忙。

写的都不错,实用性比较强``今后还得多向你学学这些技术。


2008-01-03 20:49:21
不客气。
谢谢夸奖,其实我就是把我实际工作中的一些东西写出来了而已,
因为我们是大型网站,还是有比较多的技术值得去研究的。
谢谢你对我的文章的支持,以后多交流吧。^_^

2008-02-26 11:47:08
错误如上面
最开始按你写的来做的。出现上面问题后来又如下面办法指定目录装一次还不行。
eventlog:   # ./configure --prefix=/usr/local/eventlog && make && make install
libol:   # ./configure –prefix=/usr/local/libol &&make && make install
syslog-ng: # export PKG_CONFIG_PATH=/usr/local/eventlog/pkgconfig/
              # ./configure –prefix=/usr/local/syslog-ng --with-libol=/usr/local/libol
              # make && make install


应该是 :
PKG_CONFIG_PATH=/usr/local/eventlog/lib/pkgconfig/

愿意是路径不对

我也遇到这个问题 修改以后解决

但是也遇到一个问题

问一下此博客主人是否遇到过此问题 如何解决

错误信息
checking for GLIB - version >= 2.4.0... no
configure: error: Cannot find GLib library version >= 2.4.0: is pkg-config in path?

环境 centos 5.1
glib版本 2.10



2008-03-14 18:21:01
3. 安装 SQLSyslogd, 以便将日志写入 MySQL 数据库中:
  从 http://www.frasunek.com/sources/security/sqlsyslogd/ 下载SQLSyslogd
  安装:# ln –s /usr/local/mysql/lib/mysql /usr/local/lib/mysql
      # ln –s /usr/local/mysql/include/mysql \
        /usr/local/include/lib
      # make && cp sqlsyslogd /usr/local/sbin/

此步骤make是出错,我安装mysql --prefix=/usr/local/mysql-5.0.51,ln建立软链接也使用的是/usr/local/mysql-5.0.51/lib


2008-04-29 16:37:12
我也遇到楼上的问题,SQLSyslogd怎么是解压后的,好象文件不全哦.所以make时出错。有没有完整的SQLSyslogd下载啊

2008-04-29 16:42:01
多好的构思,强烈推荐.但我在安装SQLSyslogd就止步了.期待!!!

2008-05-08 16:36:54
loggen.c: In function `main':
loggen.c:229: `AI_ADDRCONFIG' undeclared (first use in this function)
loggen.c:229: (Each undeclared identifier is reported only once
loggen.c:229: for each function it appears in.)
make[2]: *** [loggen.o] Error 1
make[2]: Leaving directory `/usr/software/syslog-ng-2.0.9/tests/loggen'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/usr/software/syslog-ng-2.0.9/tests'
make: *** [install-recursive] Error 1
编译syslog-ng时出错,是什么问题啊?

2008-05-09 22:33:10
各位博友大家好:
  由于我刚进入信诺瑞得从事技术支持工作,而且负责几个产品的售前和售后工作,确实没有时间和精力回复大家,抱歉。等有时间了,一定好好研究并及时回复大家的问题。

                            邹可见

2008-05-09 23:58:40
可见也跳槽啦?

2008-05-15 13:36:37
安装 SQLSyslogd,make出错问题终于解决了,改一下Makefile文件的-I参数为-I /usr/local/include/lib 就通过了

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: