配置CentOS邮件服务器通常涉及安装和配置Postfix作为邮件传输代理(MTA)、Dovecot作为邮件服务器软件(MDA)以及相关的数据库服务,如MariaDB。以下是配置CentOS邮件服务器的基本步骤:
准备工作:
安装邮件服务:
sudo yum install postfix dovecot mariadb-server
配置Postfix:
/etc/postfix/main.cf
,设置以下参数:myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
配置Dovecot:
/etc/dovecot/dovecot.conf
,设置以下参数:protocols = imap pop3
mail_location = maildir:~/Maildir
ssl = yes
ssl_cert = </etc/letsencrypt/fullchain.pem
ssl_key = </etc/letsencrypt/privkey.pem
/etc/dovecot/conf.d/10-auth.conf
,设置认证方式:auth_mechanisms = plain login
配置数据库:
sudo systemctl start mariadb
sudo mysql_secure_installation
CREATE DATABASE mail;
CREATE USER 'mail_admin'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON mail.* TO 'mail_admin'@'localhost';
FLUSH PRIVILEGES;
启动并启用服务:
sudo systemctl start postfix
sudo systemctl enable postfix
sudo systemctl start dovecot
sudo systemctl enable dovecot
配置防火墙:
sudo firewall-cmd --permanent --add-port=25/tcp
sudo firewall-cmd --permanent --add-port=143/tcp
sudo firewall-cmd --permanent --add-port=587/tcp
sudo firewall-cmd --permanent --add-port=993/tcp
sudo firewall-cmd --reload
验证设置: