吉佳 发表于 2018-5-12 08:41:50

RedHat 5.4+ Postfix +Extmail实现基于虚拟用户的邮件系统(一)

一、系统环境

1、Extmail架构

                                       
2、拓朴图
                                                   



系统
域名
服务器
客户端
RedHat 5.4
mail.postfix.org
172.16.1.254
172.16.1.10


所软件包:
postfix-2.8.6.tar.gz
extman-1.1.tar.gz
extmail-1.2.tar.gz
courier-authlib-0.63.0.tar.bz2
Unix-Syslog-1.1.tar.gz
Time-HiRes-1.9725.tar.gz
File-Tail-0.99.3.tar.gz
rrdtool-1.4.7.tar.gz
二、基本配置
1、配置IP
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=172.16.1.254
NETMASK=255.255.255.0
:wq
# service network restart

2、配置DNS文件
# vim /etc/resolv.conf
nameserver 172.16.1.254

3、配置hosts文件
# vim /etc/hosts
127.0.0.1       localhost.localdomain localhost
172.16.1.254    mail.postfix.org

4、配置主机名:mail.postfix.org
# vim /etc/sysconfig/network
HOSTNAME=mail.postfix.org
:wq保存
# hostname mail.postfix.org
断开终端,再次连接,这样就需要重新启动系统:ctrl+d
# hostname
mail.postfix.org

5、SELinux关闭、LINUX关闭防火墙
SELinux关闭
1 永久方法 – 需要重启服务器
修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启服务器。
2 临时方法 – 设置系统参数
使用命令setenforce 0

LINUX关闭防火墙
1 重启后永久性生效:
开启:chkconfig iptables on
关闭:chkconfig iptables off
2 即时生效,重启后失效:
开启:service iptables start
关闭:service iptables stop

三、配置YUM(略)
参考方案:http://yanghuawu.blog.51cto.com/2638960/886129
挂载光盘:本次挂载目录:/mnt
# mount -i /dev/cdrom /mnt

四、安装bind(DNS)
# yum install bind bind-chroot caching-nameserver
# cd /var/named/chroot/etc/
# ll
total 32
-rw-r--r-- 1 root root   405 Dec 18 09:17 localtime
-rw-r----- 1 root named 1230 Jul 302009 named.caching-nameserver.conf
-rw-r----- 1 root named955 Jul 302009 named.rfc1912.zones
-rw-r----- 1 root named113 Dec 18 14:30 rndc.key
# cp -p named.caching-nameserver.conf named.conf
# cp named.conf named.confbak#备份
# vim named.conf
修改:
行数
15         listen-on port 53 { any; };
27         allow-query   { any; };
28         allow-query-cache { any; };
37         match-clients      { any; };
38         match-destinations { any; };

:wq
# cd named.rfc1912.zones named.rfc1912.zonesbak #备份
# vim named.rfc1912.zones
复制修改以下内容:
21 zone "localhost" IN {
22         type master;
23         file "localhost.zone";
24         allow-update { none; };
25 };
修改如下:
27 zone "postfix.org" IN {
28         type master;
29         file "postfix.org.zone";
30         allow-update { none; };
31 };

:wq
# cd ../var/named/
# pwd
/var/named/chroot/var/named
# cp -p localhost.zone postfix.org.zone
# cp postfix.org.zone postfix.org.zonebak   #备份
# vim postfix.org.zone
$TTL    86400
@               IN SOAns.postfix.org.    root (
                                        42            ; serial (d. adams)
                                        3H            ; refresh
                                        15M             ; retry
                                        1W            ; expiry
                                        1D )            ; minimum

                IN NS         ns.postfix.org.
ns            IN A            172.16.1.254
mail            IN A            172.16.1.254
pop3            IN CNAME      mail
smtp            IN CNAME      mail
@               IN MX 10      mail

:wq

# service named restart
# chkconfig named on
# rndc reload
server reload successful
# dig -t mx postfix.org
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t mx postfix.org
;; global options:printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 663
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; QUESTION SECTION:
;postfix.org.                   IN      MX

;; ANSWER SECTION:
postfix.org.            86400   IN      MX      10 mail.postfix.org.

;; AUTHORITY SECTION:
postfix.org.            86400   IN      NS      ns.postfix.org.

;; ADDITIONAL SECTION:
mail.postfix.org.       86400   IN      A       172.16.1.254
ns.postfix.org.         86400   IN      A       172.16.1.254

;; Query time: 5 msec
;; SERVER: 172.16.1.254#53(172.16.1.254)
;; WHEN: Thu Dec 27 09:24:26 2012
;; MSG SIZErcvd: 99
五、关闭sendmail,并不随机启动或者卸载
# service sendmail status
sendmail (pid2754) is running...
# service sendmail stop
# chkconfig sendmail off

六、安装所需依赖rpm包
yum install -y httpd php php-mysql mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect db* cyrus*

七、检查以上开发所有用到的RPM包组是否启动安装
# yum grouplist
   Development Libraries      开发言库
   Development Tools         开发工具
   Legacy Software Development传统软件开发
   X Software Development       图形开发组


方法安装:
# yum groupinstall &quot;FTP Server&quot;

八、启动mysql数据库,并给mysql的root用户设置密码
# service mysqld start
# chkconfig mysqld on
# mysqladmin -u root password 'redhat'    #为mysql的用户设置密码:redhat
或也可以以下操作:
---------------------------------授权本地用户
# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> set password for root@'localhost'=password('redhat');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@'127.0.0.1'=password('redhat');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
---------------------------------------------授权远程用户
mysql> grant all privileges on *.* to root@'%' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \q


九、安装postfix
1、创建postfix的执行用户postfix和属组postfix
# groupadd -g 2525 postfix
# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
# groupadd -g 2526 postdrop
# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
2、编译、安装postfix
# tar -zxvf postfix-2.8.6.tar.gz -C /usr/local/src/
# cd /usr/local/src/
# cd postfix-2.8.6/
# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl-DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto' makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl-DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto'
# make
# make install
如下配置:
install_root: [/]
tempdir: /tmp
config_directory:
command_directory:
daemon_directory:
data_directory:
html_directory:
mail_owner:
mailq_path:
manpage_directory:
newaliases_path:
queue_directory:
readme_directory:
sendmail_path:
setgid_group:


3、生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低
newaliases_path:
# newaliases
# postfix start#启动postfix
# netstat -anp |grep :25或# netstat -tupln |less
tcp    0    0 0.0.0.0:25   0.0.0.0:*    LISTEN13280/master

# postconf -m    #模块 mysql
btree
cidr
environ
hash
internal
mysql
nis
proxy
regexp
static
tcp
texthash
unix

实现用service 服务名 start 启动服务!
源代码没有控制同步,可借助于rpm包的控制同步
# mkdir /tmp/abc
# cd /tmp/abc/
# cp /mnt/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./
# ll
total 3656
-r--r--r-- 1 root root 3734257 Dec 18 17:31 postfix-2.3.3-2.1.el5_2.i386.rpm
# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
16333 blocks
# ll
total 3680
drwxr-xr-x 5 root root    4096 Dec 18 17:32 etc
-r--r--r-- 1 root root 3734257 Dec 18 17:31 postfix-2.3.3-2.1.el5_2.i386.rpm
drwxr-xr-x 7 root root    4096 Dec 18 17:32 usr
drwxr-xr-x 3 root root    4096 Dec 18 17:32 var
# cd etc/
# ll
total 24
drwxr-xr-x 2 root root 4096 Dec 18 17:32 pam.d
drwxr-xr-x 2 root root 4096 Dec 18 17:32 postfix
drwxr-xr-x 3 root root 4096 Dec 18 17:32 rc.d
# cd rc.d/
# ll
total 8
drwxr-xr-x 2 root root 4096 Dec 18 17:32 init.d
# cd init.d/
# ll
total 8
-rwxr-xr-x 1 root root 2404 Dec 18 17:32 postfix
# cp postfix /etc/init.d/
# vim /etc/init.d/postfix #查看代码,不用编辑(略)
# service postfix stop
# netstat -tupln |grep 25
tcp      0      0 172.16.1.253:53             0.0.0.0:*                   LISTEN      3486/named         
udp      0      0 172.16.1.253:53             0.0.0.0:*                               3486/named

# service postfix start
# netstat -tupln |grep 25
tcp      0      0 172.16.1.253:53             0.0.0.0:*                   LISTEN      3486/named         
tcp      0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      13429/master       
udp      0      0 172.16.1.253:53             0.0.0.0:*                               3486/named         
# chkconfig postfix on 或# chkconfig --add postfix #相同
# chkconfig --list |grep postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

4、创建账号
# useradd user1

5、发邮件测试
# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.postfix.org ESMTP Postfix
HELO mail.postfix.org
250 mail.postfix.org
mail from:root@localhost
250 2.1.0 Ok
rcpt to:user1@localhost
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
11111111111111111111111111111
.
250 2.0.0 Ok: queued as 48ABCE72F3
quit
221 2.0.0 Bye
Connection closed by foreign host.


6、查看邮件日志
# tail -f /var/log/maillog 或# tail /var/log/maillog
邮件发送成功!


                                                                     首页|下一页
页: [1]
查看完整版本: RedHat 5.4+ Postfix +Extmail实现基于虚拟用户的邮件系统(一)