Linux 安装postfix服务器
一、搭建内部DNS服务器
1、Bind包的安装
[root@magedu ~]# yum -y install bind bind-utils bind-libs
2、更改Bind主配置文件
[root@magedu ~]# ll /etc/named.conf -rw-r----- 1 root named 1008 7月 19 2010 /etc/named.conf [root@magedu ~]# mv /etc/named.conf /etc/named.conf.orig #主配置文件 [root@magedu ~]# cat /etc/named.conf options { directory "/var/named/"; }; zone "." IN { type hint; file "named.ca"; }; zone "allentuns.com" IN { type master; file "allentuns.com.zone"; }; zone "0.168.192.in-addr.arpa" IN { type master; file "192.168.0.16.zone"; }; [root@magedu ~]# chown root.named /etc/named.conf [root@magedu ~]# chmod 640 /etc/named.conf [root@magedu ~]# ll /etc/named.conf -rw-r----- 1 root named 240 10月 4 14:54 /etc/named.conf #添加正向解析 [root@magedu ~]# cat /var/named/allentuns.com.zone $TTL 600 @ IN SOA ns1.allentuns.com. admin.allentuns.com. ( 2013040101 1H 5M 2D 6H) IN NS ns1 IN MX 10 mail ns1 IN A 192.168.0.16 mail IN A 192.168.0.14 www IN A 192.168.0.16 ftp IN A 192.168.0.16 #添加反向解析 [root@magedu ~]# cat /var/named/192.168.0.16.zone $TTL 600 @ IN SOA ns1.allentuns.com. admin.allentuns.com. ( 2013040101 1H 5M 2D 6H) IN NS ns1.allentuns.com. 16 IN PTR ns1.allentuns.com. 14 IN PTR mail.allentuns.com. 16 IN PTR www.allentuns.com. 16 IN PTR ftp.allentuns.com.
3、修改配置文件的属主、属组和配置文件的权限
[root@magedu ~]# cd /var/named/ [root@magedu named]# chown root.named 192.168.0.16.zone allentuns.com.zone [root@magedu named]# chmod 640 192.168.0.16.zone allentuns.com.zone [root@magedu named]# ll *.zone -rw-r----- 1 root named 243 10月 4 15:08 192.168.0.16.zone -rw-r----- 1 root named 214 10月 4 15:03 allentuns.com.zone
4、检查配置文件的语法
[root@magedu ~]# named-checkconf [root@magedu ~]# named-checkzone "." /var/named/named.ca zone ./IN: has 0 SOA records zone ./IN: not loaded due to errors. [root@magedu ~]# named-checkzone "allentuns.com" /var/named/allentuns.com.zone zone allentuns.com/IN: loaded serial 2013040101 OK [root@magedu ~]# named-checkzone "0.168.192.in-addr.arpa" /var/named/192.168.0.16.zone zone 0.168.192.in-addr.arpa/IN: loaded serial 2013040101 OK
5、启动named服务
[root@magedu ~]# service named restart 停止 named: [确定] Generating /etc/rndc.key: [确定] 启动 named: [确定]
6、查看named的日志信息
[root@magedu ~]# tail -f /var/log/messages Oct 4 15:15:03 magedu named[1401]: starting BIND 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 -u named Oct 4 15:15:03 magedu named[1401]: built with ‘--build=x86_64-redhat-linux-gnu‘ ‘--host=x86_64-redhat-linux-gnu‘ ‘--target=x86_64-redhat-linux-gnu‘ ‘--program-prefix=‘ ‘--prefix=/usr‘ ‘--exec-prefix=/usr‘ ‘--bindir=/usr/bin‘ ‘--sbindir=/usr/sbin‘ ‘--sysconfdir=/etc‘ ‘--datadir=/usr/share‘ ‘--includedir=/usr/include‘ ‘--libdir=/usr/lib64‘ ‘--libexecdir=/usr/libexec‘ ‘--sharedstatedir=/var/lib‘ ‘--mandir=/usr/share/man‘ ‘--infodir=/usr/share/info‘ ‘--with-libtool‘ ‘--localstatedir=/var‘ ‘--enable-threads‘ ‘--enable-ipv6‘ ‘--with-pic‘ ‘--disable-static‘ ‘--disable-openssl-version-check‘ ‘--with-dlz-ldap=yes‘ ‘--with-dlz-postgres=yes‘ ‘--with-dlz-mysql=yes‘ ‘--with-dlz-filesystem=yes‘ ‘--with-gssapi=yes‘ ‘--disable-isc-spnego‘ ‘--with-docbook-xsl=/usr/share/sgml/docbook/xsl-stylesheets‘ ‘--enable-fixed-rrset‘ ‘build_alias=x86_64-redhat-linux-gnu‘ ‘host_alias=x86_64-redhat-linux-gnu‘ ‘target_alias=x86_64-redhat-linux-gnu‘ ‘CFLAGS= -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic‘ ‘CPPFLAGS= -DDIG_SIGCHASE‘ Oct 4 15:15:03 magedu named[1401]: ---------------------------------------------------- Oct 4 15:15:03 magedu named[1401]: BIND 9 is maintained by Internet Systems Consortium, Oct 4 15:15:03 magedu named[1401]: Inc. (ISC), a non-profit 501(c)(3) public-benefit Oct 4 15:15:03 magedu named[1401]: corporation. Support and training for BIND 9 are Oct 4 15:15:03 magedu named[1401]: available at https://www.isc.org/support Oct 4 15:15:03 magedu named[1401]: ---------------------------------------------------- Oct 4 15:15:03 magedu named[1401]: adjusted limit on open files from 4096 to 1048576 Oct 4 15:15:03 magedu named[1401]: found 1 CPU, using 1 worker thread Oct 4 15:15:03 magedu named[1401]: using up to 4096 sockets Oct 4 15:15:03 magedu named[1401]: loading configuration from ‘/etc/named.conf‘ Oct 4 15:15:03 magedu named[1401]: using default UDP/IPv4 port range: [1024, 65535] Oct 4 15:15:03 magedu named[1401]: using default UDP/IPv6 port range: [1024, 65535] Oct 4 15:15:03 magedu named[1401]: listening on IPv4 interface lo, 127.0.0.1#53 Oct 4 15:15:03 magedu named[1401]: listening on IPv4 interface eth1, 192.168.0.16#53 Oct 4 15:15:03 magedu named[1401]: generating session key for dynamic DNS Oct 4 15:15:03 magedu named[1401]: sizing zone task pool based on 3 zones Oct 4 15:15:03 magedu named[1401]: set up managed keys zone for view _default, file ‘dynamic/managed-keys.bind‘ Oct 4 15:15:03 magedu named[1401]: Warning: ‘empty-zones-enable/disable-empty-zone‘ not set: disabling RFC 1918 empty zones Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 0.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 127.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 254.169.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 2.0.192.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 100.51.198.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 113.0.203.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 255.255.255.255.IN-ADDR.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: D.F.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 8.E.F.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 9.E.F.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: A.E.F.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: B.E.F.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA Oct 4 15:15:03 magedu named[1401]: command channel listening on 127.0.0.1#953 Oct 4 15:15:03 magedu named[1401]: command channel listening on ::1#953 Oct 4 15:15:03 magedu named[1401]: zone 0.168.192.in-addr.arpa/IN: loaded serial 2013040101 Oct 4 15:15:03 magedu named[1401]: zone allentuns.com/IN: loaded serial 2013040101 Oct 4 15:15:03 magedu named[1401]: managed-keys-zone ./IN: loaded serial 0 Oct 4 15:15:03 magedu named[1401]: running
7、测试named是否能够正常工作
#Linux客户端测试
第一种情况: #在能够接通互联网的情况下,解析本地的区域NS、A等记录 [root@magedu ~]# ifconfig | grep "Bcast" |awk -F‘:‘ ‘{ print $2}‘ |cut -d ‘ ‘ -f1 192.168.0.16 [root@magedu ~]# grep -v "^#" /etc/resolv.conf nameserver 192.168.0.1 [root@magedu ~]# ping www.google.com.hk PING www-wide.l.google.com (173.194.72.199) 56(84) bytes of data. 64 bytes from tf-in-f199.1e100.net (173.194.72.199): icmp_seq=1 ttl=28 time=265 ms 64 bytes from tf-in-f199.1e100.net (173.194.72.199): icmp_seq=2 ttl=28 time=272 ms [root@magedu ~]# dig -t NS allentuns.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS allentuns.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 54172 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;allentuns.com. IN NS ;; AUTHORITY SECTION: com. 455 IN SOA a.gtld-servers.net. nstld.verisign-grs.com. 1412407069 1800 900 604800 86400 ;; Query time: 7 msec ;; SERVER: 192.168.0.1#53(192.168.0.1) ;; WHEN: Sat Oct 4 15:25:24 2014 ;; MSG SIZE rcvd: 104 第二种情况: #DNS设置本地的IP地址,通过本地的DNS服务解析区域NS、A等记录 [root@magedu ~]# ifconfig | grep "Bcast" |awk -F‘:‘ ‘{ print $2}‘ |cut -d ‘ ‘ -f1 192.168.0.16 [root@magedu ~]# grep -v "^#" /etc/resolv.conf nameserver 192.168.0.16 [root@magedu ~]# dig -t NS allentuns.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS allentuns.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64745 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;allentuns.com. IN NS ;; ANSWER SECTION: allentuns.com. 600 IN NS ns1.allentuns.com. ;; ADDITIONAL SECTION: ns1.allentuns.com. 600 IN A 192.168.0.16 ;; Query time: 1 msec ;; SERVER: 192.168.0.16#53(192.168.0.16) ;; WHEN: Sat Oct 4 15:34:19 2014 ;; MSG SIZE rcvd: 65 [root@magedu ~]# dig -t A ns1.allentuns.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A ns1.allentuns.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42959 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;ns1.allentuns.com. IN A ;; ANSWER SECTION: ns1.allentuns.com. 600 IN A 192.168.0.16 ;; AUTHORITY SECTION: allentuns.com. 600 IN NS ns1.allentuns.com. ;; Query time: 0 msec ;; SERVER: 192.168.0.16#53(192.168.0.16) ;; WHEN: Sat Oct 4 15:35:24 2014 ;; MSG SIZE rcvd: 65 [root@magedu ~]# dig -t MX allentuns.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t MX allentuns.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16584 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; QUESTION SECTION: ;allentuns.com. IN MX ;; ANSWER SECTION: allentuns.com. 600 IN MX 10 mail.allentuns.com. ;; AUTHORITY SECTION: allentuns.com. 600 IN NS ns1.allentuns.com. ;; ADDITIONAL SECTION: mail.allentuns.com. 600 IN A 192.168.0.14 ns1.allentuns.com. 600 IN A 192.168.0.16 ;; Query time: 0 msec ;; SERVER: 192.168.0.16#53(192.168.0.16) ;; WHEN: Sat Oct 4 15:36:06 2014 ;; MSG SIZE rcvd: 102
#Windows客户端测试
二、Postfix的安装
1、安装依赖包
[root@postfix ~]# yum -y install httpd openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect [root@postfix ~]# yum -y install openssl openssl-devel db4-devel [root@postfix ~]# yum -y install cyrus-sasl-devel [root@postfix ~]# yum -y install telnet mailx
2、创建用户
[root@postfix ~]# groupadd -g 2525 postfix [root@postfix ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix [root@postfix ~]# groupadd -g 2526 postdrop [root@postfix ~]# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
3、编译安装postfix
[root@postfix ~]# tar xf postfix-2.11.1.tar.gz [root@postfix ~]# cd postfix-2.11.1 [root@postfix postfix-2.11.1]# make makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ‘ ‘AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto‘ [root@postfix ~]# make [root@postfix ~]# make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] / tempdir: [/root/postfix-2.9.3] /tmp/postfix config_directory: [/etc/postfix] /etc/postfix daemon_directory: [/usr/libexec/postfix] command_directory: [/usr/sbin] queue_directory: [/var/spool/postfix] sendmail_path: [/usr/sbin/sendmail] newaliases_path: [/usr/bin/newaliases] mailq_path: [/usr/bin/mailq] mail_owner: [postfix] setgid_group: [postdrop] html_directory: [no]/var/www/html/postfix manpages: [/usr/local/man] readme_directory: [no]
4、启动postfix服务
[root@postfix ~]# service postfix restart 关闭 postfix: [确定] 启动 postfix: [确定]
5、查看postfix日志信息
[root@postfix ~]# tail -f /var/log/maillog Oct 4 16:06:47 localhost postfix/postfix-script[8119]: stopping the Postfix mail system Oct 4 16:06:47 localhost postfix/master[1488]: terminating on signal 15 Oct 4 16:06:47 localhost postfix/postfix-script[8194]: starting the Postfix mail system Oct 4 16:06:47 localhost postfix/master[8196]: daemon started -- version 2.11.1, configuration /etc/postfix
6、测试postfix的收发邮件
1、创建一个测试收发邮件的用户 [root@postfix ~]# useradd openstack 2、测试本地域的openstack发邮件 [root@postfix ~]# telnet localhost 25 Trying ::1... Connected to localhost. Escape character is ‘^]‘. 220 postfix.localdomain ESMTP Postfix helo postfix 250 postfix.localdomain mail from:[email protected] 250 2.1.0 Ok rcpt to:openstack 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> Subject:How are you these days? Guo Qing Kuai Le? . 250 2.0.0 Ok: queued as 62EBFA0570 quit 221 2.0.0 Bye Connection closed by foreign host. 3、查看postfix日志记录信息 [root@postfix ~]# tail -f /var/log/maillog Oct 4 16:11:12 localhost postfix/smtpd[8225]: connect from localhost[::1] Oct 4 16:12:52 localhost postfix/smtpd[8225]: 62EBFA0570: client=localhost[::1] Oct 4 16:13:33 localhost postfix/cleanup[8252]: 62EBFA0570: message-id=<[email protected]> Oct 4 16:13:33 localhost postfix/qmgr[8199]: 62EBFA0570: from=<[email protected]>, size=342, nrcpt=1 (queue active) Oct 4 16:13:33 localhost postfix/local[8253]: 62EBFA0570: to=<[email protected]>, orig_to=<openstack>, relay=local, delay=96, delays=95/0.01/0/0.06, dsn=2.0.0, status=sent (delivered to mailbox) Oct 4 16:13:33 localhost postfix/qmgr[8199]: 62EBFA0570: removed Oct 4 16:13:37 localhost postfix/smtpd[8225]: disconnect from localhost[::1] 4、openstack用户接收、查看邮件 [root@postfix ~]# su - openstack [openstack@postfix ~]$ mail Heirloom Mail version 12.4 7/29/08. Type ? for help. "/var/spool/mail/openstack": 1 message 1 new >N 1 [email protected] Sat Oct 4 16:13 14/473 "How are you these days?" & 1 Message 1: From [email protected] Sat Oct 4 16:13:33 2014 Return-Path: <[email protected]> X-Original-To: openstack Delivered-To: [email protected] Subject:How are you these days? Date: Sat, 4 Oct 2014 16:11:58 +0800 (CST) From: [email protected] Status: R Guo Qing Kuai Le? 5、openstack用户删除本地邮件 & d 1 & quit [openstack@postfix ~]$ mail No mail for openstack
本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1560598
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。