快捷搜索:   nginx

电子邮件监控Centos5服务器

今天照着一位大侠的blog成功实现了使用邮件监控我的centos虚拟机,

[@centos5 ~]# wget
--19:47:37--
Resolving blog.s135.com... 72.249.146.214
Connecting to blog.s135.com|72.249.146.214|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1095 (1.1K) [application/octet-stream]
Saving to: `servmon-1.1.linux.tar.gz'

100%[=======================================>] 1,095       --.-K/s   in 0s

19:47:38 (16.1 MB/s) - `servmon-1.1.linux.tar.gz' saved [1095/1095]

[root@centos5 ~]# tar -zxvf servmon-1.1.linux.tar.gz
servmon-1.1/
servmon-1.1/src/
servmon-1.1/src/data/
servmon-1.1/src/cron/
servmon-1.1/src/cron/servmon
servmon-1.1/src/bin/
servmon-1.1/src/bin/swapstat_send
servmon-1.1/src/bin/diskstat_send
servmon-1.1/src/bin/loadstat_send
servmon-1.1/install
[root@centos5 ~]# cd servmon-1.1
[root@centos5 servmon-1.1]# ./install -i 123456

> Installing ServMon client to /usr/local/servmon/ & /etc/cron.d/servmon ...
> OK

[root@centos5 /]# /usr/sbin/sendmail -bd -q30m
[root@centos5 /]# vi /etc/php.ini

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from =

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i

[root@centos5 /]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [ OK ]

[root@centos5 /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database servmon;
Query OK, 1 row affected (0.00 sec)

mysql> use servmon;
Database changed

mysql> CREATE TABLE `tb_diskstat` (
    -> `ip` varchar(128) NOT NULL default '',
    -> `date` int(10) NOT NULL default '0',
    -> UNIQUE KEY `ip` (`ip`)
    -> ) TYPE=MyISAM;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> \q
Bye

[root@centos5 conf]# cd /var/www/html/
[root@centos5 html]# ls
index.php
[root@centos5 html]# mkdir servmon
[root@centos5 html]# vi servmon/interface.php

[root@centos5 html]# ps -ef |grep sendmail
root      2163     1 0 19:59 ?        00:00:00 sendmail: accepting connections
smmsp     2171     1 0 19:59 ?        00:00:00 sendmail: Queue for /var/spool/clientmqueue
root      4144 2460 0 20:49 pts/0    00:00:00 grep sendmail

[root@centos5 html]# mail -s "test linux" < /etc/php.ini

[root@centos5 /]# cd /etc/cron.d/
[root@centos5 cron.d]# ls
servmon

[root@centos5 cron.d]# cat servmon
0-30/30 * * * * root /bin/sh /usr/local/servmon/bin/diskstat_send 123456
*/20 * * * * root /bin/sh /usr/local/servmon/bin/swapstat_send 123456
1,16,31,46 * * * * root /bin/sh /usr/local/servmon/bin/loadstat_send 123456

[root@centos5 cron.d]# service crond restart
Stopping crond:                                            [ OK ]
Starting crond:                                            [ OK ]

From Sat May 2 22:53:14 2009
Return-Path: <>
Received: from localhost.localdomain (centos5 [127.0.0.1])
        by localhost.localdomain (8.13.8/8.13.8) with ESMTP id n42ErD6s006782
        for <>; Sat, 2 May 2009 22:53:13 +0800
Received: (from )
        by localhost.localdomain (8.13.8/8.13.8/Submit) id n42Er3xH006777;
        Sat, 2 May 2009 22:53:03 +0800
Date: Sat, 2 May 2009 22:53:03 +0800
Message-Id: <>
From: (Cron Daemon)
To:
Subject: Cron <> /bin/sh /usr/local/servmon/bin/diskstat_send 123456
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

% Total    % Received % Xferd Average Speed   Time    Time     Time Current
                                 Dload Upload   Total   Spent    Left Speed
0    21    0    21    0     0      1      0 --:--:-- 0:00:11 --:--:--     4
已成功发送报警邮件!

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论