crontab
Linux crontab是用来定期执行程序的命令
检查Cronta工具是否安装:crontab -l
检查crond服务是否启动:service crond status
crontab安装
yum install vixie-cron
yum install crontabs
service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看crontab服务状态
chkconfig --level 345 crond on // 设置开机启动
tail -f /var/log/cron //查看cron日志
crontab 格式
* * * * * command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
**例子:**
*/5 * * * * root ab -n 2000 http://60.217.229.252/250k.jpg
上面例子表示每5分钟模拟用户访问http://60.217.229.252/250k.jpg 2000次
postfix
postfix是一个邮件服务器
postfix安装
可以通过命令检查posfix是否安装
lee.guo rpm -qa postfix
postfix-2.6.6-8.el6.x86_64
服务是否启动可以使用命令检查
➜ lee.guo lsof -i:25
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
master 10932 root 12u IPv4 179399 0t0 TCP *:smtp (LISTEN)
如果没有安装执行安装命令
yum install -y postfix
postfix配置
编辑postfix配置文件,把 inet_interfaces 设置为 all vim /etc/postfix/main.cf
inet_interfaces = all
以163邮箱为例。vim /etc/mail.rc
在文件末尾增加,注意: 阿里云服务器必须使用465端口
set from=leeguoo@163.com
set smtp=smtps://smtp.163.com:465
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth-user=leeguoo@163.com
set smtp-auth-password=你的163生成随机码
set smtp-auth=login
必须配置证书, 不然发送邮箱会失败
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -L -d /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/ -i ~/.certs/163.crt
启动postfix
➜ lee.guo service postfix start
Starting postfix: [ OK ]
设置postfix开机启动
➜ lee.guo chkconfig postfix on
测试
echo "test" |mail -v -s "test" leeguoo@163.com
测试通过OK