【Linux】postfix大坑笔记
由于需要,想弄一个自动发送邮件的mailx或者sendmail
但是执行
echo "test" | mail -s "Worning mail !" xxxxx@qq.com;
的时候就会报错,提示使用ipv6,但是网卡没有配置ipv6的设置,所以需要强制然他默认为ipv4
vi /etc/main.cf
# Enable IPv4, and IPv6 if supported
inet_protocols = all #将这个修改为ipv4 记住是小写的 不要看他的注释,他的注释是错误的
但是修改完成后,还是不行,重启还是失败
# /etc/init.d/postfix restart
Shutting down postfix: [FAILED]
Starting postfix: [FAILED]
很难受,日志也没有相关的记载 日志的位置是/var/log/maillog
还是根据这个入手,结果看以前的日志,发现好多报警
Nov 27 22:46:43 xxx postfix/sendmail[24028]: warning: or the command is run from a set-uid root process
Nov 27 22:46:43 xxx postfix/sendmail[24095]: warning: or the command is run from a set-uid root process
Nov 27 22:46:43 xxx postfix/sendmail[24206]: warning: or the command is run from a set-uid root process
Nov 27 22:46:43 xxx postfix/sendmail[24028]: warning: the Postfix sendmail command must be installed without set-uid root file permissions
Nov 27 22:46:43 xxx postfix/sendmail[24095]: warning: the Postfix sendmail command must be installed without set-uid root file permissions
Nov 27 22:46:43 xxx postfix/sendmail[24206]: warning: the Postfix sendmail command must be installed without set-uid root file permissions
Nov 27 22:46:43 xxx postfix/sendmail[24095]: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
Nov 27 22:46:43 xxx postfix/sendmail[24028]: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
Nov 27 22:46:43 xxx postfix/sendmail[24206]: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
Nov 27 22:46:43 xxx postfix/sendmail[24095]: warning: inet_protocols: configuring for IPv4 support only
Nov 27 22:46:43 xxx postfix/sendmail[24206]: warning: inet_protocols: configuring for IPv4 support only
Nov 27 22:46:43 xxx postfix/sendmail[24028]: warning: inet_protocols: configuring for IPv4 support only
Nov 27 22:46:43 xxx postfix/sendmail[24206]: fatal: file /etc/postfix/main.cf: parameter mail_owner: unknown user name value: postfix
Nov 27 22:46:43 xxx postfix/sendmail[24095]: fatal: file /etc/postfix/main.cf: parameter mail_owner: unknown user name value: postfix
Nov 27 22:46:43 xxx postfix/sendmail[24028]: fatal: file /etc/postfix/main.cf: parameter mail_owner: unknown user name value: postfix
其中最后几行持续输入一个参数报错,mail_owner这个参数,提示没有用户,去mail.rc文件中找到这个参数,后面的是=postfix 于是在/etc/passwd中找这个用户,发现这个用户也被删掉
more /etc/passwd | grep postfix
echo "postfix:x:89:89::/var/spool/postfix:/sbin/nologin" >> /etc/passwd
由于系统日志没有记录,不知道是否添加成功,手动启动postfix进程,发现还是失败
于是尝试将postfix卸载重新安装
但是yum持续有问题,结果发现/etc/resolv.conf中nameserver 8.8.8.8被注释掉
打开注释,重新执行yum clean all; yum makecache
可以执行
再次执行yum remove postfix ,结果再卸载时候,需要将其他4个文件一并卸载,(但是用rpm -e 但是卸载报错,因为有其他服务以来postfix这个包,无法卸载),yum reinstall 也无法安装
这4个包分别是:
很难受,那也要卸载掉,于是点了y继续卸载,写在成功后,重新安装
yum install postfix -y 安装成功,但是只安装了他自己,没有其他的包呀!
安装完成后,将其他的包也重新装上,毕竟cron和sysstat是非常重要的东西
yum -y install vixie-cron
yum install sysstat -y
执行完上述的命令就可以将卸载的东西全部还原(这里如果原来的crontab中有执行计划的话,再次卸载安装的话,执行计划是不会丢失的,具体的位置在/var/spool/cron/下面,如果不放心可以备份)
全部弄完后,再吃重启,发现可以重启成功了,但是第一步中修改的ipv4变回了all,需要再次修改后,重启,
最后,postfix启动成功