全部最新版postfix+dovecot+postgresql+centos7+amavisd+clamd+spamassassin源文件安装搭建完善的邮件服务器

首先系统环境:CentOS 7,2016年4月下载的最新版系统。

先安装数据库:postgresql9.5.2

去官网下载源码:postgresql.org

安装基本的编译工具:

yum install gcc make

目前最新版本zlibzlib1.2.8,安装开始;
$wget http://www.zlib.net/zlib-1.2.8.tar.gz
$tar -xvzf zlib-1.2.8.tar.gz
$cd zlib-1.2.8.tar.gz
$./configure
$make
$sudo make install

 

CentOS7 中,要yuminstall readline-devel

debian 中一般文件命名为:lib****

而CentOS中,一般文件命名为: ****-devel

好了言归正传

./configure --prefix=/usr/local/pgsql  

Make

make install

adduser postgres

mkdir/data/pgdata

chown postgres/data/pgdata

su  postgres

/usr/local/pgsql/bin/initdb–D /data/pgdata 

/usr/local/pgsql/bin/postgres-D /data/pgdata >logfile 2>&1 &


/usr/local/pgsql/bin/createdbwevvv

/usr/local/pgsql/bin/psqlwevvv

开机自启动,将源文件目录下

/data/software/postgresql-9.5.2/contrib/start-scripts/linux文件拷至/etc/init.d/下,并改名为:postgresql

cp /data/software/postgresql-9.5.2/contrib/start-scripts/linux/etc/init.d/postgresql   

并更改postgresql文件里相应的安装目录和加LBS

 

### BEGIN INIT INFO

# Provides: Postgresql

# Required-Start: $remote_fs $syslog

# Required-Stop:  $remote_fs $syslog

# Default-Start: 2 3 4 5

# Default-Stop: 1

# Short-Description: The Postgresql Server

### END INIT INFO



给相应的权限

chmod a+x /etc/init.d/postgresql


配置开机自启动

chkconfig --add postgresql

chkconfig postgresql on


****************************************************************************************************
在postfix配置文件夹下,配置虚拟用户的时候,千万不能再建文件夹。如果建文件夹会出现权限错误。
如/etc/postfix/下面配虚拟用户的话,有时为了目录清楚,在下面再建一下pgsql文件夹,会出现莫明错误。如这样的文件夹会出错。/etc/postfix/pgsql而只能在/etc/postfix文件夹下建配置文件。切记切记!!!!一个星期的时候才解决问题。
参照的文档如:http://wiki2.dovecot.org/HowTo/DovecotPostgresql
只安装了postgresql,postfix,dovecot三个软件。


****************************************************************************************************
*******************************       DOVECOT      *************************************************
****************************************************************************************************


编译dovecot
yum install openssl-devel
yum install pam-devel
yum install ssl-devel


不能用源OPENSSL安装,特别是从git上获取得。
 ./configure --with-ssl=openssl --with-pgsql --with-notify=inotify --with-sql --prefix=/usr/local  --with-pam --sysconfdir=/etc




****************************************************************************************************
******************************       POSTFIX        ************************************************
****************************************************************************************************


必需先安装这个db库
yum install libdb-devel


解压后直接在这个文件上加上Postgresql数据库的INCLUDE文件路径,要不然会出错。
出错找不到路径的C文件,加上这个,两个文件
/data/software/postfix-3.1.0/src/global/dict_pgsql.c
/usr/local/pgsql/include/


ln -s /usr/local/pgsql/lib/libpq.so.5 /usr/lib64/libpq.so.5




安装postfix,这个后装,还有其它配置
make tidy
make -f Makefile.init makefiles CCARGS='-DHAS_PGSQL -I/usr/local/pgsql -DUSE_TLS -I/usr/include/openssl -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"'  AUXLIBS='-lssl -lcrypto -lsasl2' AUXLIBS_PGSQL='-L/usr/local/pgsql/lib -lpq'




最好的是上面的,下面的这个就是pg和dovecot的SSL认证。
make -f Makefile.init makefiles 'CCARGS=-DHAS_PGSQL -I/usr/local/pgsql\
 -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"'\
 'AUXLIBS_PGSQL=-L/usr/local/pgsql/lib -lpq' 


make 
make install


安装完配置路径


install_root: [/] /
tempdir: [/usr/local/src/ postfix-3.1.0]    /tmp     //临时目录


config_directory: /etc/postfix /etc/postfix //配置目录
command_directory: /usr/sbin //命令目录
daemon_directory: /usr/libexec/postfix //守护进程
data_directory:/var/lib/postfix 
html_directory:  /var/www/html/postfix
mail_owner: [postfix]
mailq_path: /usr/bin/mailq.postfix
manpage_directory: /usr/share/man //man手册
newaliases_path: [/usr/bin/newaliases.postfix]
queue_directory: /var/spool/postfix
readme_directory:/usr/share/doc/postfix-3.1.0/README_FILES
sendmail_path: [/usr/sbin/sendmail.postfix]
setgid_group: [postdrop]
shlib_directory:[no]
meta_directory: /etc/postfix






****************************************************************************************************
****************************************************************************************************
****************************************************************************************************

***********************************************************************************************************

vim /etc/postfxi/main.cf

************************************************************************************************************


queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550


myhostname = mail.domain.com
mydomain = domain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks_style = subnet
mynetworks = 192.168.1.0/24, 127.0.0.0/8, 10.0.0.0/24
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
smtpd_banner = mail.domain.com mail service
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES




meta_directory = /etc/postfix
shlib_directory = no




local_recipient_maps =
compatibility_level = 2
smtputf8_enable = no
transport_maps = pgsql:/etc/postfix/transport.cf
virtual_uid_maps = pgsql:/etc/postfix/uids.cf
virtual_gid_maps = pgsql:/etc/postfix/gids.cf
virtual_mailbox_base = /home/mail
virtual_mailbox_maps = pgsql:/etc/postfix/mailboxes.cf
virtual_maps = pgsql:/etc/postfix/virtual.cf
#smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, reject_unauth_destination
#smtpd_sasl_auth_enable = yes
#smtpd_sasl_security_options = noanonymous
#smtpd_sasl_local_domain = domain.com
#smtp_sasl_auth_enable = no
smtpd_tls_key_file = /etc/postfix/certs/key.pem
smtpd_tls_cert_file = /etc/postfix/certs/cert.pem








***************************************************************************************************************
vim /etc/postfix/master.cf
***************************************************************************************************************
smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_wrappermode=no
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,defer_unauth_destination  
#  -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject 
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
pickup    unix  n       -       n       60      1       pickup
cleanup   unix  n       -       n       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       n       1000?   1       tlsmgr
rewrite   unix  -       -       n       -       -       trivial-rewrite
bounce    unix  -       -       n       -       0       bounce
defer     unix  -       -       n       -       0       bounce
trace     unix  -       -       n       -       0       bounce
verify    unix  -       -       n       -       1       verify
flush     unix  n       -       n       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       n       -       -       smtp
showq     unix  n       -       n       -       -       showq
error     unix  -       -       n       -       -       error
retry     unix  -       -       n       -       -       error
discard   unix  -       -       n       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil
scache    unix  -       -       n       -       1       scache
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=mailreader:mail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}






******************************************************************************************************
vim /etc/dovecot/dovecot.conf
******************************************************************************************************
protocols = imap
dict {
}
!include conf.d/*.conf
!include_try local.conf
ssl = yes
passdb {
    driver = sql
    args = /etc/dovecot/dovecot-sql.conf
}
userdb {
    driver = prefetch
}
userdb {
    driver = sql
    args = /etc/dovecot/dovecot-sql.conf
}
mail_uid = 600
mail_gid = 12
first_valid_uid = 600
disable_plaintext_auth = no
auth_mechanisms = plain
protocol imap {
    mail_plugins = $mail_plugins autocreate
}
plugin {
    autocreate = Trash
    autocreate2 = Sent
    autosubscribe = Trash
    autosubscribe2 = Sent
    sieve=~/
    global_script_path = /home/mail/default.sieve
}
service auth {
    unix_listener /var/spool/postfix/private/auth {
        mode = 0660
        user = postfix
        group = postfix
    }
}
service auth {
    unix_listener auth-userdb {
    mode = 0600
    user = mailreader
    }
}
#protocol lda {
#  mail_plugins = $mail_plugins
#  mail_plugins = $mail_plugins sieve
#}
postmaster_address = master@domain.com
hostname = mail.domain.com
mail_location = Maildir:~/




****************************************************************************************************


一定要按照先数据库,后DOVECOT 再postfix的顺序安装

下一篇进增加垃圾邮件和病毒防护


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值