Postfix 简单安装与配置

1.安装apache

postfix stop
systemctl disable postfix
yum erase postfix   //卸载系统自带的postfix
userdel postfix
groupdel postdrop
groupadd -g 1000 postfix
groupadd -g 1001 postdrop
useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
useradd -M -s /sbin/nologin www

yum -y install gcc gcc-c++ pcre-devel make libxml2-devel perl perl-devel perl-CPAN perl-Data-Dumper libtool libtool-devel libtool-ltdl-devel sqlite-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel fontconfig fontconfig-devel gd gd-devel openssl-devel libcurl-devel openldap-devel cyrus-sasl-devel libicu-devel cyrus-sasl-plain cyrus-sasl-lib rrdtool rrdtool-perl pam-devel bzip2 perl-GD
tar zxvf httpd-2.4.4.tar.gz -C /usr/src
tar zxvf apr-1.5.1.tar.gz -C /usr/src
tar zxvf apr-util-1.5.4.tar.gz -C /usr/src
cd /usr/src/httpd-2.4.4/
mv /usr/src/apr-1.5.1 srclib/apr
mv /usr/src/apr-util-1.5.4 srclib/apr-util
#./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache/htdocs --with-include-apr --enable-mods-shared=most
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-cgi --enable-suexec  --with-suexec-docroot=/usr/local/apache/htdocs --with-include-apr --enable-mods-shared=most
make && make install

2.安装mysql

参照http://qikangwei.blog.51cto.com/2282397/646679

3.安装php

#yum -y install libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel fontconfig fontconfig-devel gd gd-devel openssl-devel libcurl-devel openldap-devel
#cp -frp /usr/lib64/libldap* /usr/lib/

tar zxvf libmcrypt-2.5.8.tar.gz -C ./
cd libmcrypt-2.5.8
./configure
make && make install
tar zxvf mhash-0.9.9.9.tar.gz -C ./
cd mhash-0.9.9.9
./configure
make && make install

vi /etc/ld.so.conf
添加/usr/local/lib/
ldconfig

tar zxvf mcrypt-2.6.8.tar.gz -C ./
cd mcrypt-2.6.8
./configure
make && make install

tar zxvf php-5.3.13.tar.gz -C /usr/src
cd /usr/src/php-5.3.13
./configure --prefix=/usr/local/php --enable-mbstring --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-mysqli --with-zlib-dir --with-openssl --with-libxml-dir --with-mcrypt --enable-bcmath --with-curl --enable-shmop --with-pdo-mysql=mysqlnd --enable-soap --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir  --enable-gd-native-ttf --enable-sysvsem --with-mhash --with-xmlrpc --enable-zip
make && make install

cp php.ini-production /usr/local/php/etc/php.ini

4.配置apache支持php

vi /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html
ServerName localhost:80
User www
Group www

启动Apache
/usr/local/apache/bin/apachectl -t
/usr/local/apache/bin/apachectl start

5.安装postfix

#userdel postfix
#groupdel postfix
#groupdel postdrop
#groupadd -g 1200 postdrop
#groupadd -g 1000 postfix
#useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
#yum -y install cyrus-sasl-devel libicu-devel

/*注释掉的这几行不一定需要执行
yum -y install db*-devel   
vi /etc/ld.so.conf
/usr/loca/mysql/lib    //添加这一行
ldconfig
*/

mv /etc/postfix /usr/src/oldpostfix    //如果存在系统自带的postfix文件,将它移到别处

tar zxvf postfix-3.0.0.tar.gz -C /usr/src
cd /usr/src/postfix-3.0.0/

/*注释掉的为版本2的配置参数
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/ -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2'
*/

make makefiles CCARGS="-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -I/usr/include/openssl" AUXLIBS="-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64 -lsasl2 -L/usr/lib64 -lssl -lcrypto"
make
make install    //运行后会要求输入安装路径,直接默认就行

6.配置postfix

cd /etc/postfix
postconf -n > main2.cf
mv main.cf main.cf.bak
mv main2.cf main.cf
vi main.cf      //添加如下项
inet_interfaces = 192.168.10.6,127.0.0.1
myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
#mydestination = $mydomain, $myhostname
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
#mydestination     //文件中原来的这一行加#号注释掉

7.配置dovecot

#yum -y install pam-devel
useradd -M -s /sbin/nologin dovecot
tar zxvf dovecot-2.2.1.tar.gz -C /usr/src/
cd /usr/src/dovecot/
./configure --with-mysql --with-pam -sysconfdir=/etc
make
make install
cp -rf /usr/local/share/doc/dovecot/example-config/* /etc/dovecto/
vi /etc/dovecot/dovecot.conf
listen = *
cd /etc/dovecot
vi conf.d/10-auth.conf
disable_plaintext_auth = no
vi conf.d/10-ssl.conf
ssl = no
ssl_cert 和 ssl_key 两行加#号注释掉
vi conf.d/10-mail.conf
mail_location = maildir:~/Maildir
/*
vi /etc/pam.d/dovecot
auth required pam_nologin.so
auth include  system-auth
account include system-auth
session include system-auth
*/
useradd -M -s /sbin/nologin dovenull

7.配置SMTP认证

vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
#service saslauthd start
chkconfig --level 35 saslauthd on
vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.1,192.168.10.6
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

8.启动postfix、dovecot

postfix做到这已经可以支持用系统用户来收发邮件了...

chown -R postfix /var/lib/postfix/
chown -R postfix /var/spool/postfix/
cd /var/lib/postfix/
chown postfix:postfix *
chown root /var/spool/postfix/
chown -R root /var/spool/postfix/pid/
chown -R postfix:postdrop /var/spool/postfix/public/
postfix check
#postfix start
#dovecot

9.配置postfix支持虚拟用户,首先建立用户数据库

tar zxvf extman-1.1.tar.gz -C /usr/src/
cd /usr/src/extman-1.1/docs/
mysql -u root -p < extmail.sql 
这一步如果出现错误,解决办法:http://qikangwei.blog.51cto.com/2282397/866233 
mysql -u root -p < init.sql

10.修改postfix配置

vi /etc/postfix/main.cf
#mydestination = $mydomain, $myhostname  //注释掉这一行
virtual_mailbox_base = /mailbox
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
cp /usr/src/extman-1.1/docs/mysql_virtual_* /etc/postfix/
打开复制的所有mysql_virtual_开头的文件,将localhost改为127.0.0.1

11.为虚拟用户配置SMTP认证

#yum -y install libtool libtool-devel libtool-ltdl-devel sqlite-devel
useradd courier
tar jxvf courier-authlib-0.65.0.tar.bz2 -C /usr/src/
cd /usr/src/courier-authlib-0.65.0/
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib --with-mysql-includes=/usr/local/mysql/include --with-mailuser=courier --with-mailgroup=courier
make
make install
make install-configure
vi /etc/ld.so.conf
/usr/local/courier-authlib/lib/courier-authlib
ldconfig
cd /usr/local/courier-authlib/etc/authlib/
#cp authdaemonrc.dist authdaemonrc
vi authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
#cp authmysqlrc.dist authmysql
vi authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD uidnumber
MYSQL_GID_FIELD gidnumber
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/mailbox/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)
cp /usr/src/courier-authlib-0.65.0/courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod 755 /etc/rc.d/init.d/courier-authlib
chkconfig --level 35 courier-authlib on
service courier-authlib start
vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket

12.配置dovecot支持虚拟用户

vi /etc/dovecot/conf.d/10-auth.conf
#!include auth-system.conf.ext
!include auth-sql.conf.ext
vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/mailbox/%d/%n/Maildir
vi /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
connect = host=127.0.0.1 dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = select username as user, password as password from mailbox where username = '%u'
user_query = select maildir, uidnumber as uid, gidnumber as gid from mailbox where username = '%u'

13.安装extmail

#yum -y install perl-devel gd-devel
tar zxvf extmail-1.2.tar.gz -C /usr/src/
#/usr/src/extmail-1.2/tools/pkg-stats.sh  //执行这条命令后会列出需要安装的软件包,使用
下面的perl命令将没有的安装包安装即可
#perl -MCPAN -e shell
#>install  安装包的名字
#>exit
yum -y install perl-CGI perl-DB_File perl-DBD-MySQL perl-Crypt-PasswdMD5
tar zxvf Unix-Syslog-1.1.tar.gz -C ./
cd Unix-Syslog-1.1
perl Makefile.PL
make test
make install

mv /usr/src/extmail-1.2/ /usr/local/apache/htdocs/extmail
cd /usr/local/apache/htdocs/extmail
chown -R postfix:postfix cgi
cp webmail.cf.default webmail.cf
vi webmail.cf
SYS_CONFIG = /usr/local/apache/htdocs/extmail
SYS_LANGDIR = /usr/local/apache/htdocs/extmail/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extmail/html
SYS_MAILDIR_BASE = /mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
vi /usr/local/apache/conf/httpd.conf
#LoadModule suexec_module ......
#LoadModule cgi_module ......     //去掉这两行前面的#
ServerName mail.test.com:80
#DocumentRoot ......              //这行前面加#
#Include conf/extra/httpd-vhosts.conf  //去掉这行前面的#
mkdir -p /mailbox/extmail.org/postmaster/Maildir/
chown -R postfix:postfix /mailbox
vi /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot /usr/local/apache/htdocs/extmail/html
    ServerName mail.test.com
    ScriptAlias /extmail/cgi/ /usr/local/apache/htdocs/extmail/cgi/
    Alias /extmail /usr/local/apache/htdocs/extmail/html
    ScriptAlias /extman/cgi/ /usr/local/apache/htdocs/extman/cgi/
    Alias /extman /usr/local/apache/htdocs/extman/html
    SuexecUserGroup postfix postfix
</VirtualHost>

14.安装extman

#yum -y install rrdtool rrdtool-perl
perl -MCPAN -e shell
install File::Tail
install Time::HiRes
exit
mv /usr/src/extman-1.1 /usr/local/apache/htdocs/extman
cd /usr/local/apache/htdocs/extman
chown -R postfix:postfix cgi
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman
cp webman.cf.default webman.cf
vi webman.cf
SYS_CONFIG = /usr/local/apache/htdocs/extman/
SYS_LANGDIR = /usr/local/apache/htdocs/extman/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extman/html
SYS_MAILDIR_BASE = /mailbox
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock

15.配置邮件系统的图形化日志信息

perl -MCPAN -e shell
install Carp
install Symbol
install Time::Local
install Getopt::Long
exit
mkdir /usr/local/mailgraph_ext
cp /usr/local/apache/htdocs/extman/addon/mailgraph_ext/* /usr/local/mailgraph_ext/
/usr/local/mailgraph_ext/mailgraph-init start
/usr/local/apache/htdocs/extman/daemon/cmdserver -d

16.重新加载所有服务

service mysqld restart
/usr/local/apache/bin/apachectl restart
postfix reload
doveadm reload

17.登录

前台:http://mail.test.com

默认账户:postmaster  密码:extmail

后台:http://mail.test.com/extman

默认管理员账户:[email protected]  密码:extmail*123*



如果出现错误:
DBD::mysql::st execute failed: Incorrect integer value: '' for column 'can_signup' at row 1 at /usr/
解决办法:
关闭mysql安全选项

如果用webmail发送邮件一直显示正在发送请稍等,需要在main.cf里给inet_interfaces、mynetworks添加127.0.0.1


注意事项:

(1) 配置本机指向正确的DNS服务器,并在DNS服务器上添加对应的MX记录和A记录

(2)上面的perl和rrdtool都是用yum安装的,如果使用源码安装,参考下面的步骤

tar jxvf perl-5.16.3.tar.bz2 -C /usr/src
cd /usr/src/perl-5.16.3/
./Configure -des -Dprefix=/usr/local/perl
make
make test
make install
mv /usr/bin/perl /usr/bin/perl.bak
ln -s /usr/local/perl/bin/perl /usr/bin/perl
tar xvf rrdtool.tar.tar -C /usr/src
./configure --prefix=/usr/local/rrdtool
make
make install
cd /usr/local/perl/lib/site_perl/5.16.3/i686-linux/
ln -s /usr/local/rrdtool/lib/perl/5.16.3/i686-linux/RRDs.pm ./
ln -s /usr/local/rrdtool/lib/perl/5.16.3/i686-linux/auto/RRDs/RRDs.so ./
perl -MCPAN -e shell
>install  安装上文中所有需要的安装包


你可能感兴趣的:(postfix)