当排查crontab 未按预期执行时,想要排查相关日志,发现/var/log/cron文件中输出(root) MAIL (mailed 81 bytes of output but got status 0x004b#012)

1
2
Jun 30 09:26:01 master172 CROND[6846]: (root) CMD (/bin/bash  /root/restart_cloudcore.sh)
Jun 30 09:26:01 master172 CROND[6845]: (root) MAIL (mailed 81 bytes of output but got status 0x004b#012)

查看/var/log/maillog文件发现

1
2
Jun 30 09:29:01 master172 postfix/sendmail[8262]: warning: valid_hostname: numeric hostname: 16.88.131
Jun 30 09:29:01 master172 postfix/sendmail[8262]: fatal: file /etc/postfix/main.cf: parameter mydomain: bad parameter value: 16.88.131

看上去hostname识别到了一个奇怪的地址16.88.131,联想到这台主机的hostname在安装k8s时修改过,可能posfix识别有问题,这块没找到具体的文章说明。

1
2
3
4
5
6
7
8
9
10
11
12
[root@master172 log]# hostnamectl
Static hostname: master172.16.88.131
Transient hostname: ctl
Icon name: computer-vm
Chassis: vm
Machine ID: 784df73b2b174ef09ba1249f781baf36
Boot ID: 646970e7f4494fcf9ea8b22ee9444299
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 5.16.8-1.el7.elrepo.x86_64
Architecture: x86-64

修改/etc/postfix/main.cf文件,增加myhostname和mydomain配置

1
2
3
[root@master172 mail]# cat /etc/postfix/main.cf|grep my
myhostname=master172.16.88.131
mydomain=master172.16.88.131

重启postfix

1
systemctl restart postfix

等crontab执行后,在/var/spool/mail 目录下看到了邮件

1
2
[root@master172 mail]# ls /var/spool/mail/
root sylink