2019-03-21 CentOS 更改默认Sendmail为Postfix

大家都说Sendmail设置起来比较烦,还是postfix用起来简单省事。我这里设置邮件是用来发送告警邮件,邮件服务器什么的回头抽空再专门写一篇。
1、Centos安装时默认的是sendmail,所以要先卸载,再安装postfix。

yum remove sendmail
yum install postfix -y

2、更改默认MTA为postfix

[root@master axing]# /usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix
[root@master axing]# alternatives --display mta
mta - status is manual.
 link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix - priority 30
 slave mta-pam: /etc/pam.d/smtp.postfix
 slave mta-mailq: /usr/bin/mailq.postfix
 slave mta-newaliases: /usr/bin/newaliases.postfix
 slave mta-rmail: /usr/bin/rmail.postfix
 slave mta-sendmail: /usr/lib/sendmail.postfix
 slave mta-editmap: (null)
 slave mta-makemap: (null)
 slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
 slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
 slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
 slave mta-editmapman: (null)
 slave mta-makemapman: (null)
 slave mta-rmailman: (null)
 slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
Current `best' version is /usr/sbin/sendmail.postfix.

3、修改postfix配置文件/etc/postfix/main.cf
主要修改几项

myhostname = xxx.xxx.co.uk
#主机名,要和etc/hostname对应,否则可能出错
mydomain = xxx.co.uk
#指定域名
myorigin = $myhostname #可选,缺省配置
myorigin = $mydomain   #使用域名作为发件人邮箱@后面的部分,推荐使用
inet_interfaces = all #指定postfix监听的网络接口
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relay_domains = $mydomain    
#仅转发本域的邮件,以避免被利用到垃圾邮件转发
home_mailbox = Maildir/

4、重启并设置开机启动。另, log文件在/var/log/maillog

systemctl restart postfix
systemctl enable postfix
[root@master log]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-03-20 12:00:23 GMT; 12h ago
 Main PID: 3816 (master)
   CGroup: /system.slice/postfix.service
           ├─3816 /usr/libexec/postfix/master -w
           ├─3822 qmgr -l -t unix -u
           └─5000 pickup -l -t unix -u

发个邮件测试一下,这时postfix应该已经OK,如果收不到邮件去检查下垃圾邮箱,再看下log文件。

你可能感兴趣的:(2019-03-21 CentOS 更改默认Sendmail为Postfix)