安装postfix前准备

首先查看本机有没有安装 sendmail
rpm -qa|grep sendmail 或者 alternatives --display mta
如果存在则删除或者停止
yum remove sendmail

安装postfix

yum -y install postfix*
vim /etc/postfix/main.cf
修改
myhostname = mail.flycoder.cn
mydomain = flycoder.cn
myorigin = $mydomain
inet_protocols = ipv4

启动服务

service postfix restart
chkconfig postfix on
alternatives --set mta /usr/sbin/sendmail.postfix 或者 alternatives --config mta 选择对应的/usr/sbin/sendmail.postfix

测试邮件

echo 'Hello world!' | mail -s 'Test Email' youremail@domain.com

监控脚本

nginx监控脚本,php mysql redis和此类似
vim nginx.sh

!/bin/bash
nginx.sh
nc -w2 localhost 80
if [ $? -ne 0 ]
then
        echo 'Nginx is down' | mail -s 'Nginx is down' youremail@domain.com
        /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
fi

disk监控脚本
vim dish.sh

!/bin/bash
disk.sh awk后面的具体跟随自身服务器显示的内容来写
num=df |awk 'NR==2{print int($5)}'
if [ $num -gt 80 ]
then
        echo "disk space is ${num}%" | mail -s 'disk space > 80' youremail@domain.com
fi