树叶云linux教程:15.2.1 配置Postfix服务程序

Postfix是一款由IBM资助研发的免费开源电子邮件服务程序,能够很好地兼容Sendmail服务程序,可以方便Sendmail用户迁移到Postfix服务上。Postfix服务程序的邮件收发能力强于Sendmail服务,而且能自动增加、减少进程的数量来保证电子邮件系统的高性能与稳定性。另外,Postfix服务程序由许多小模块组成,每个小模块都可以完成特定的功能,因此可在生产工作环境中根据需求灵活搭配它们。

第1步:安装Postfix服务程序。这一步在RHEL7系统中是多余的。刘遄老师之所以还要写上这一步骤,其目的是让大家在学完本书之后不但能掌握RHEL系统,还能立即上手Fedora、CentOS等主流Linux系统。这样,既然这些系统没有默认安装Postfix服务程序,我们也可以自行搞定。在安装完Postfix服务程序后,需要禁用iptables防火墙,否则外部用户无法访问电子邮件系统。

    [root@linuxprobe ~]# yum install postfix
    Loaded plugins: langpacks, product-id, subscription-manager
    rhel7 | 4.1 kB 00:00
    (1/2): rhel7/group_gz | 134 kB 00:00
    (2/2): rhel7/primary_db | 3.4 MB 00:00
    Package 2:postfix-2.10.1-6.el7.x86_64 already installed and latest version
    Nothing to do
    [root@linuxprobe ~]# systemctl disable iptables

第2步:配置Postfix服务程序。大家如果是首次看到Postfix服务程序主配置文件(/etc/ postfix/main.cf),估计会被679行左右的内容给吓到。其实不用担心,这里面绝大多数的内容依然是注释信息。刘遄老师在本书中一直强调正确学习Linux系统的方法,并坚信“负责任的好老师不应该是书本的搬运工,而应该一名优质内容的提炼者”,因此在翻遍了配置参数的介绍,以及结合多年的运维经验后,最终总结出了7个最应该掌握的参数,如表15-1所示。

表15-1 Postfix服务程序主配置文件中的重要参数

参数作用
myhostname邮局系统的主机名
mydomain邮局系统的域名
myorigin从本机发出邮件的域名名称
inet_interfaces监听的网卡接口
mydestination可接收邮件的主机名或域名
mynetworks设置可转发哪些主机的邮件
relay_domains设置可转发哪些网域的邮件

在Postfix服务程序的主配置文件中,总计需要修改5处。首先是在第76行定义一个名为myhostname的变量,用来保存服务器的主机名称。请大家记住这个变量的名称,下边的参数需要调用它:

    [root@linuxprobe ~]# vim /etc/postfix/main.cf
    ………………省略部分输出信息………………
    68 # INTERNET HOST AND DOMAIN NAMES
    69 # 
    70 # The myhostname parameter specifies the internet hostname of this
    71 # mail system. The default is to use the fully-qualified domain name
    72 # from gethostname(). $myhostname is used as a default value for many
    73 # other configuration parameters.
    74 #
    75 #myhostname = host.domain.tld
    76 myhostname = mail.linuxprobe.com
    ………………省略部分输出信息………………

然后在第83行定义一个名为mydomain的变量,用来保存邮件域的名称。大家也要记住这个变量名称,下面将调用它:

    78 # The mydomain parameter specifies the local internet domain name.
    79 # The default is to use $myhostname minus the first component.
    80 # $mydomain is used as a default value for many other configuration
    81 # parameters.
    82 #
    83 mydomain = linuxprobe.com

在第99行调用前面的mydomain变量,用来定义发出邮件的域。调用变量的好处是避免重复写入信息,以及便于日后统一修改:

    85 # SENDING MAIL
    86 # 
    87 # The myorigin parameter specifies the domain that locally-posted
    88 # mail appears to come from. The default is to append $myhostname,
    89 # which is fine for small sites. If you run a domain with multiple
    90 # machines, you should (1) change this to $mydomain and (2) set up
    91 # a domain-wide alias database that aliases each user to
    92 # [email protected].
    93 #
    94 # For the sake of consistency between sender and recipient addresses,
    95 # myorigin also specifies the default domain name that is appended
    96 # to recipient addresses that have no @domain part.
    97 #
    98 #myorigin = $myhostname
    99 myorigin = $mydomain

第4处修改是在第116行定义网卡监听地址。可以指定要使用服务器的哪些IP地址对外提供电子邮件服务;也可以干脆写成all,代表所有IP地址都能提供电子邮件服务:

    103 # The inet_interfaces parameter specifies the network interface
    104 # addresses that this mail system receives mail on. By default,
    105 # the software claims all active interfaces on the machine. The
    106 # parameter also controls delivery of mail to user@[ip.address].
    107 #
    108 # See also the proxy_interfaces parameter, for network addresses that
    109 # are forwarded to us via a proxy or network address translator.
    110 #
    111 # Note: you need to stop/start Postfix when this parameter changes.
    112 #
    113 #inet_interfaces = all
    114 #inet_interfaces = $myhostname
    115 #inet_interfaces = $myhostname, localhost
    116 inet_interfaces = all

最后一处修改是在第164行定义可接收邮件的主机名或域名列表。这里可以直接调用前面定义好的myhostname和mydomain变量(如果不想调用变量,也可以直接调用变量中的值):

    133 # The mydestination parameter specifies the list of domains that this
    134 # machine considers itself the final destination for.
    135 #
    136 # These domains are routed to the delivery agent specified with the
    137 # local_transport parameter setting. By default, that is the UNIX
    138 # compatible delivery agent that lookups all recipients in /etc/passwd
    139 # and /etc/aliases or their equivalent.
    140 #
    141 # The default is $myhostname + localhost.$mydomain. On a mail domain
    142 # gateway, you should also include $mydomain.
    143 #
    144 # Do not specify the names of virtual domains - those domains are
    145 # specified elsewhere (see VIRTUAL_README).
    146 #
    147 # Do not specify the names of domains that this machine is backup MX
    148 # host for. Specify those names via the relay_domains settings for
    149 # the SMTP server, or use permit_mx_backup if you are lazy (see
    150 # STANDARD_CONFIGURATION_README).
    151 #
    152 # The local machine is always the final destination for mail addressed
    153 # to user@[the.net.work.address] of an interface that the mail system
    154 # receives mail on (see the inet_interfaces parameter).
    155 #
    156 # Specify a list of host or domain names, /file/name or type:table
    157 # patterns, separated by commas and/or whitespace. A /file/name
    158 # pattern is replaced by its contents; a type:table is matched when
    159 # a name matches a lookup key (the right-hand side is ignored).
    160 # Continue long lines by starting the next line with whitespace.
    161 #
    162 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
    163 #
    164 mydestination = $myhostname , $mydomain
    165 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    166 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,

第3步:创建电子邮件系统的登录账户。Postfix与vsftpd服务程序一样,都可以调用本地系统的账户和密码,因此在本地系统创建常规账户即可。最后重启配置妥当的postfix服务程序,并将其添加到开机启动项中。大功告成!

    [root@linuxprobe ~]# useradd boss
    [root@linuxprobe ~]# echo "linuxprobe" | passwd --stdin boss
    Changing password for user boss. passwd: all authentication tokens updated successfully.
    [root@linuxprobe ~]# systemctl restart postfix
    [root@linuxprobe ~]# systemctl enable postfix
    ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/182374.html<

(0)
运维的头像运维
上一篇2025-03-27 22:31
下一篇 2025-03-27 22:32

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注