參考資料: http://linuxu.blog.51cto.com/9471357/1641436
參考資料: http://www.cloudchinese.com/News/detail/id/51.html
運作流程:
e-mail --> [postifx (*:25)] -->[amavisd-new (127.0.0.1:10024)]
-->[SpamAssassine過濾垃圾郵件,ClamAV掃毒]
-->[postfix (127.0.0.1:10025)] -->[delivery agent (local/smtp/...)]
yum install -y http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install nginx vi gcc gcc-c++ openssl openssl-devel db4-devel ntpdate mysql mysql-devel mysql-server bzip2 php-mysql cyrus-sasl-md5 perl-GD perl-DBD-MySQL perl-GD perl-CPAN perl-CGI perl-CGI-Session cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel libtool-ltdl-devel telnet mailx libicu-devel -y
CentOS 套件安裝 :
yum grouplist
yum groupinstall 'Development Tools'
yum install -y pcre-devel perl-rrdtool amavisd-new perl-Time-HiRes perl-devel
wget ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-3.1.1.tar.gz
tempdir: [/root/postfix-3.1.1]
chown -R postfix:postdrop /var/spool/postfix
vi /etc/postfix/main.cf
#relay_domains = $mydestination //指定允許中轉郵件的域名
//指定postfix接收郵件時收件人的域名 [使用虛擬域需要禁用]
alias_maps = hash:/etc/aliases //設置郵件的別名
chmod +x /etc/rc.d/rc.local (加入啟動項目,須賦予執行的權限)
vi /etc/rc.local
/usr/sbin/postfix start
/usr/sbin/saslauthd -m /run/saslauthd -a pam
/var/www/extsuite/extmail/dispatch-init start
/var/www/extsuite/extman/daemon/cmdserver -v -d
安裝 dovecot:
yum install -y dovecot dovecot-mysql
cd /etc/dovecot/
vi dovecot.conf
protocols = imap pop3
!include conf.d/*.conf
listen = *
base_dir = /var/run/dovecot/
cd conf.d/
vi 10-auth.conf
disable_plaintext_auth = no
vi 10-mail.conf
mail_location = maildir:~/Maildir
mail_location = maildir:/var/mailbox/%d/%n/Maildir
mail_privileged_group = mail
vi 10-ssl.conf
ssl = no
vi 10-logging.conf
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot.info
log_timestamp = "%Y-%m-%d %H:%M:%S "
cp auth-sql.conf.ext auth-sql.conf
vi auth-sql.conf
passdb { driver = sql # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
args = /etc/dovecot/dovecot-sql.conf
}
userdb { driver = sql
args =/etc/dovecot/dovecot-sql.conf
}
vi /etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=localhost 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'
systemctl enable dovecot.service
systemctl start dovecot.service
安裝courier-unicode
wget https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-1.2.tar.bz2
tar xf courier-unicode-1.2.tar.bz2
cd courier-unicode-1.2
./configure
make && make install
安裝courier-authlib
wget https://sourceforge.net/projects/courier/files/authlib/0.66.2/courier-authlib-0.66.2.tar.bz2
tar xf courier-authlib-0.66.2.tar.bz2
cd courier-authlib-0.66.2
./configure \
--prefix=/usr/local/courier-authlib \
--sysconfdir=/etc \
--without-authpam \
--without-authshadow \
--without-authvchkpw \
--without-authpgsql \
--with-authmysql \
--with-mysql-libs=/usr/lib64/mysql \
--with-mysql-includes=/usr/include/mysql \
--with-redhat \
--with-authmysqlrc=/etc/authmysqlrc \
--with-authdaemonrc=/etc/authdaemonrc\
--with-mailuser=postfix
make && makeinstall
chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
cp /etc/authdaemonrc.dist /etc/authdaemonrc
cp /etc/authmysqlrc.dist /etc/authmysqlrc
vi /etc/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
vi /etc/authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_PORT 3306
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
DEFAULT_DOMAIN example.com
vi /etc/rc.local
/usr/sbin/saslauthd -m /run/saslauthd -a pam
/var/www/extsuite/extmail/dispatch-init start
/var/www/extsuite/extman/daemon/cmdserver -v -d
yum install -y dovecot dovecot-mysql
MYSQL_UID_FIELD '2525'
#MYSQL_UID_FIELD '2000' ( maildrop 安裝完後修改 )
MYSQL_GID_FIELD '2525'
#MYSQL_GID_FIELD '2000'( maildrop 安裝完後修改 )
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)
courier-authlib添加服務啟動腳本及其他:
cp courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod +x /etc/init.d/courier-authlib
chkconfig –add courier-authlib
chkconfig courier-authlib on
echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
ldconfig
systemctl enable courier-authlib
systemctl start courier-authlib
vi /usr/lib64/sasl2/smtpd.conf //文件不存在,要自己建立
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
vi /etc/postfix/main.cf
##一般 postfix SMTP 設定##
smtpd_sasl_auth_enable = yes
##一般 postfix SMTP 設定##
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
二選一:
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_unauth_destination
broken_sasl_auth_clients=yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
##postfix支持虛擬用戶## (沒用到虛擬主機,不須要以下設定)
virtual_mailbox_base = /var/mailbox
//這裡的設定檔需在後面extman裡複製過來
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:2000 (依建立 ExtMail vmail 帳號 id 修改)
virtual_gid_maps = static:2000(依建立 ExtMail vmail 帳號 id 修改)
virtual_transport = maildrop (安裝 maildrop 套件後修改)
SYS_MAILDIR_BASE = /var/mailbox
SYS_DEFAULT_UID = 2000
SYS_DEFAULT_GID = 2000
//將這行註釋掉,重啟mysql,這裡需要注意的是,等資料庫導入成功後,這行是不可以去掉注釋的,不然mysql就啟動不起來了。
mysql -uroot < docs/extmail.sql
mysql -uroot < docs/init.sql
建立資料庫使用者帳號 extmail 並授予權限,這裡直接在授權任何權限給任意位址
mysql> FLUSH PRIVILEGES;
將 vmail 帳號 ID update 到資庫內:
[root@Mail ~]# mysql -u root -p
mysql> use extmail;
mysql> update mailbox set uidnumber='2000';
mysql> update mailbox set gidnumber='2000';
mysql> flush privileges;
cd /var/www/extsuite/extman/docs/
cp mysql_virtual_* /etc/postfix/
mkdir /tmp/extman
chown -R postfix.postfix /tmp/extman/
啟動postfix、dovecot、saslauthd
確認服務有正常啟動:
ss -tnluo | grep :25
ps aux | grep dovecot
ps aux | grep saslauthd
測試運作:
/usr/local/courier-authlib/sbin/authtest -s login postmaster@extmail.org extmail
Authentication succeeded. //顯示這個表示成功,測試時使用的是postmaster@extmail.org,因為我們導入的資料庫init.sql裡面內建了這個postmaster@extmail.org。
Authenticated: postmaster@extmail.org (uid 2525, gid 2525)
Home Directory: /var/mailbox/extmail.org/postmaster //這裡需要注意/var/mailbox這個目錄現在我們還沒有建立,後面web連線的時候如果沒有會出現錯誤
Maildir: /var/mailbox/extmail.org/postmaster/Maildir/
Quota: (none)
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
mkdir /var/mailbox
chown -R postfix.postfix /var/mailbox/
測試smtp發信:
printf "postmaster@extmail.org" | openssl base64
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
printf "extmail" | openssl base64
ZXh0bWFpbA==
telnet localhost 25
啟動 nginx web 連線:
vi /var/www/extsuite/extmail/dispatch-init
SU_UID=postfix
SU_GID=postfix
啟動ExtMail、ExtMan服務:
/var/www/extsuite/extmail/dispatch-init start
/var/www/extsuite/extman/daemon/cmdserver -v -d
添加 nginx 虛擬主機:
vi /etc/nginx/conf.d/extmail.conf
server {
listen 8080;
server_name mail.everyoo.com;
index index.html index.htm index.php index.cgi;
root /var/www/extsuite/extmail/html/;
location /extmail/cgi/ {
fastcgi_pass 127.0.0.1:8888;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /var/www/extsuite/extmail/cgi/$fastcgi_script_name;
include fcgi.conf;
}
location /extmail/ {
alias /var/www/extsuite/extmail/html/;
}
location /extman/cgi/ {
fastcgi_pass 127.0.0.1:8888;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /var/www/extsuite/extman/cgi/$fastcgi_script_name;
include fcgi.conf;
}
location /extman/ {
alias /var/www/extsuite/extman/html/;
}
access_log /var/log/extmail_access.log;
}
生成fcgi.conf
vi /etc/nginx/fcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
systemctl enable nginx.service
systemctl start nginx.service
安裝 Unix-Syslog 套件:
wget http://www.cpan.org/authors/id/M/MH/MHARNISCH/Unix-Syslog-1.1.tar.gz
tar xf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL
make && make install
extman預設的登入帳號為 root@extmail.org 密碼為 extmail*123*,首次使用需要先增一個網域及管理員帳號(可進 MySQL 新增修改帳號類型),新增之後再刪除內建的 extmail.org 網域。
安裝clamav、clamd、amavisd
yum –y install amavisd-new spamassassin
yum install epel-release
yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd
修改 clamd.conf
cp /usr/share/clamav/template/clamd.conf /etc/clamd.d/clamd.conf
sed -i ‘/^Example/d’ /etc/clamd.d/clamd.conf
ss -tnluo | grep :25
Authenticated: postmaster@extmail.org (uid 2525, gid 2525)
Home Directory: /var/mailbox/extmail.org/postmaster //這裡需要注意/var/mailbox這個目錄現在我們還沒有建立,後面web連線的時候如果沒有會出現錯誤
Maildir: /var/mailbox/extmail.org/postmaster/Maildir/
Quota: (none)
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
wget http://www.cpan.org/authors/id/M/MH/MHARNISCH/Unix-Syslog-1.1.tar.gz
User clamscan
#User amavis ( Amavisd-new 安裝後修改 )
須註釋掉此行行
[Unit]
Description = freshclam scanner
After = network.target
Type = forking
ExecStart = /usr/bin/freshclam -d -c 4
Restart = on-failure
PrivateTmp = true
WantedBy=multi-user.target
systemctl enable clam-freshclam.service
systemctl start clam-freshclam.service
systemctl status clam-freshclam.service
修改 ClamAV 設定:
mv /usr/lib/systemd/system/clamd@.service /usr/lib/systemd/system/clamd.service
Description = clamd scanner daemon
After = syslog.target nss-lookup.target network.target
Type = simple
ExecStart = /usr/sbin/clamd -c /etc/clamd.d/clamd.conf --foreground=yes
Restart = on-failure
PrivateTmp = true
WantedBy=multi-user.target
mkdir -p /var/run/clamd.service
chown clamscan.clamscan /var/run/clamd.service
cd /usr/lib/systemd/system
systemctl enable clamd.service
systemctl start clamd.service
#systemctl enable clamd@scan.service (會與 clamd.service 衝突,messages log 一直出現 clamd.sock 被位用)
#systemctl start clamd@scan.service
下載最新版DCC http://www.rhyolite.com/dcc/source/dcc.tar.Z
loadplugin Mail::SpamAssassin::Plugin::Pyzor
loadplugin Mail::SpamAssassin::Plugin::Razor2
loadplugin Mail::SpamAssassin::Plugin::AWL
content_filter=amavisfeed:[127.0.0.1]:10024
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_unauth_destination
20 $mydomain = 'example.com';
154 $notify_method = $forward_method ;
$max_servers 設定同步執行的Amavisd-new進程數量,而且必須與/etc/postfix/master.cf內的amavisfeed服務的maxproc中相符合
20 $mydomain = 'example.com'; # a convenient default for other settings
152 $myhostname = 'vmail.example.com'; # must be a fully-qualified domain name!
381 - 385 行
### http://www.clamav.net/
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamd.amavisd/clamd.sock"],
qr/\bOK$/m, qr/\bFOUND$/m,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
安裝maildrop
useradd -u 2000 vmail
ln -sv /usr/local/courier-authlib/bin/courierauthconfig /usr/bin
ln -sv /usr/local/courier-authlib/include/* /usr/include
wget https://sourceforge.net/projects/courier/files/maildrop/2.8.4/maildrop-2.8.4.tar.bz2
tar xf maildrop-2.8.4.tar.bz2
cd maildrop-2.8.4
./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root vmail' --enable-syslog=1 --enable-maildrop-uid=2000 --enable-maildrop-gid=2000 && make && make install
vi /etc/ld.so.conf.d/courier-unicode.conf
/usr/local/lib
ldconfig -v
maildrop -v
修改相應文件的權限
chmod 700 /var/mailbox/ -R
chown vmail /tmp/extma* -R
chmod 777 /tmp/extma*
chgrp postdrop /var/spool/postfix/maildrop/
chown vmail.vmail -R /tmp/viewlog/
/usr/sbin/postfix restart
mysql -u root -p
mysql> use extmail;
mysql> update mailbox set uidnumber='2000';
mysql> update mailbox set gidnumber='2000';
mysql> flush privileges;
額外套件:
使用Opendkim為Postfix郵件服務器添加DKIM簽名
DKIM就是一種防垃圾郵件的機制!網域密鑰DomainKeys(DK)和域名密鑰標識郵件技朮(DKIM)是使用密碼的email驗證系統,它能用於防止網絡詐騙,而且,因為大多數的垃圾郵件都包含欺騙性的地址,DK/DKIM能從很大程度上減少垃圾郵件,盡管它們不是專門設計用於反垃圾郵件的工具。DK/DKIM還能用於確保收到郵件的完整性,或確保郵件在發件人服務器被發出直到到達接收者服務器的過程中,沒有被更改過。
DK/DKIM密碼驗證系統,收件人服務器能確信到達的郵件是來自發件人的并且沒有人用任何方式改變過郵件信息。為了確保郵件的有效性和完整性,DKIM使用一個公共和密碼的keypairs系統,一個加密的公鑰被發布到發送服務器的DNS記錄,然後每個發出的郵件都被服務器用相應的私鑰進行了簽名。對於收到的郵件,當收件服務器發現它是一個被做了DKIM簽名的郵件時,它將從發件服務器的DNS記錄中找回公鑰,然後將期與郵件中的簽名比對來確定郵件的合法性。如果收到的郵件不能通過驗證,那麼收件服務器就知道其包含了偽造的地址或曾被篡改
安裝配置Opendkim
wget -P /tmp http://mirror.pnl.gov/epel/7/x86_64/epel-release-7-7.noarch.rpm
rpm -Uvh /tmp/epel-release-7-7.noarch.rpm
yum -y install opendkim
opendkim-genkey -d example.com -s default
mv default.private /etc/opendkim/keys/
chown opendkim.opendkim /etc/opendkim/keys/default.private
cat default.txt
default._domainkey IN TXT ( "v=DKIM1; k=rsa; "
"p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuoxOw56mF5JBKD5GhQdf5KYuilyTOUgn9nrOCHbMosdjZ1lrJsN/ww+YANyI68dUhX2L6Z2Gk2bzclM74xdSq+KyjdNv4AhAabBeyV7wEu7s5Pl/9owdaLIpVEx4CFJKV+PbjASwn2lBiZmQ+OqM2Goa7s/p8Nd0M5ASQkNHOrwIDAQAB" ) ; ----- DKIM key default for example.com
這樣就為網域 example.com 生成了一對用於DKIM簽名的公鑰和私鑰,把私鑰放到了opendkim默認的存儲密鑰文件的目錄下.
上面default.txt裡面的內容是公鑰文件,需要把上面的內容在DNS服務器上新建一個TXT類型的記錄存儲起來.名字就是default._domainkey內容是Default是剛才生成密鑰的時候-S參數後面的名字,也就是一個selector,可以建立多個selector,不同域名使用不同的selector來做簽名的.
修改Opendkim的配置文件
[root@Mail ~]# cat /etc/opendkim/KeyTable
# OPENDKIM KEY TABLE
# To use this file, uncomment the #KeyTable option in /etc/opendkim.conf,
# then uncomment the following line and replace example.com with your domain
# name, then restart OpenDKIM. Additional keys may be added on separate lines.
qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
使用Opendkim為Postfix郵件服務器添加DKIM簽名
[root@Mail ~]# cat /etc/opendkim/KeyTable
default._domainkey.example.com example.com:default:/etc/opendkim/keys/default.private
Syslog yes
Socket inet:8891@localhost
KeyFile /etc/opendkim/keys/default.private
安裝postfix的時候,指定的postfix的libexec目錄是/usr/libexec/postfix/,這裡要根據自己的配置來確定放到哪個目錄.
vi /etc/postfix/main.cf
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_unauth_destination,
reject_sender_login_mismatch,
check_policy_service unix:private/policy,
reject_authenticated_sender_login_mismatch
Cannot add dependency job for unit clamd@amavisd.service, ignoring: Unit clamd@amavisd.service failed to load: No such file or directory.
Cannot add dependency job for unit postfix.service, ignoring: Unit postfix.service failed to load: No such file or directory.
原因:
因利用 tar 檔安裝,在 /usr/lib/systemd/system/amavisd.service 裡有連結上面兩個起動檔,但無此兩檔案,造成啟動錯誤。
/usr/lib/systemd/system/amavisd.service 裡面內容:
修改 Wants=clamd@amavisd.service --> Wants=clamd.service
Wants=postfix.service
[Unit]
Description=Postfix Mail Transport Agent
After=syslog.target network.target
Conflicts=sendmail.service exim.service
[Service]
Type=forking
PIDFile=/var/spool/postfix/pid/master.pid
EnvironmentFile=-/etc/sysconfig/network
ExecStartPre=-/usr/libexec/postfix/aliasesdb #看message log 如果還有錯訊息刪除
ExecStartPre=-/usr/libexec/postfix/chroot-update #看message log 如果還有錯訊息刪除
ExecStart=/usr/sbin/postfix start
ExecReload=/usr/sbin/postfix reload
ExecStop=/usr/sbin/postfix stop
[Install]
WantedBy=multi-user.target
ln -sf /usr/lib/systemd/system/postfix.service /etc/systemd/system/multi-user.target.wants/postfix.service
/var/log/message 錯誤訊息2:
postfix/smtpd[xxxx]: sql_select option missing
postfix/smtpd[xxxx]: auxpropfunc error no mechanism available
vi /usr/lib64/sasl2/smtpd.conf
新增:
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: localhost
sql_user: extmail
sql_passwd: extmail
sql_database: extmail
sql_select: select password from mailbox where username='%u'
如還有錯誤訊息:
解決方式:
查看是否有安裝
or
rpm -qa cyrus-sasl-sql
安裝 Fail2Ban:
yum install fail2ban
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
依照需求 啟用 policy (postfix, ssh, apache, named)
例:
cd /etc/fail2ban/jail.d/
vi sshd.local
findtime = 10800
vi postfix.local
[postfix-iptables]
enabled = true
filter = postfix
action = iptables[name=Postfix, port=smtp, protocol=tcp]
logpath = /var/log/maillog
maxretry = 3
findtime = 10800
bantime = 7200
vi named.local
[named-refused-udp]
enabled = false
filter = named-refused
action = iptables-multiport[name=named, port="domain,953", protocol=udp]
logpath = /var/named/chroot/var/log/named/security.log
maxretry = 3
findtime = 10800
bantime = 3600
vi dovecot.local
[dovecot-iptables]
#pop3(110),pop3s(995),imap(143),imaps(993)
enabled = true
filter = dovecot
action = iptables-multiport[name=Dovecot, port="pop3,imap", protocol=tcp]
#logpath = /var/log/maillog
logpath = /var/log/secure
maxretry = 3
findtime = 10800
bantime = 3600
測試過濾功能是否正常:
fail2ban-regex /var/log/secure /etc/fail2ban/jail.d/sshd.local
fail2ban-regex /var/log/maillog /etc/fail2ban/jail.d/postfix.local
fail2ban-regex /var/named/chroot/var/log/named/security.log /etc/fail2ban/jail.d/named-refused.local
fail2ban-regex /var/log/secure /etc/fail2ban/jail.d/dovecot.local
Description=Postfix Mail Transport Agent
After=syslog.target network.target
Conflicts=sendmail.service exim.service
Type=forking
PIDFile=/var/spool/postfix/pid/master.pid
EnvironmentFile=-/etc/sysconfig/network
ExecStartPre=-/usr/libexec/postfix/aliasesdb #看message log 如果還有錯訊息刪除
ExecStartPre=-/usr/libexec/postfix/chroot-update #看message log 如果還有錯訊息刪除
ExecStart=/usr/sbin/postfix start
ExecReload=/usr/sbin/postfix reload
ExecStop=/usr/sbin/postfix stop
WantedBy=multi-user.target
postfix/smtpd[xxxx]: sql_select option missing
postfix/smtpd[xxxx]: auxpropfunc error no mechanism available
新增:
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: localhost
sql_user: extmail
sql_passwd: extmail
sql_database: extmail
sql_select: select password from mailbox where username='%u'
#systemctl status slapd.service
auxpropfunc error invalid parameter supplied
ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin(): invalid parameter supplied
#systemctl status cyrus-imapd.service
ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin(): invalid parameter supplied
auxpropfunc error invalid parameter supplied
查看是否有安裝
rpm -qa cyrus-sasl-ldap
or
rpm -qa cyrus-sasl-sql
它是不需要的 RPM:
rpm -e cyrus-sasl-ldap
rpm -e cyrus-sasl-sql (如錯誤訊依舊再移除左側套件)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm
yum install fail2ban
依照需求 啟用 policy (postfix, ssh, apache, named)
例:
cd /etc/fail2ban/jail.d/
vi sshd.local
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
logpath = /var/log/secure
maxretry = 3
findtime = 10800
bantime = 3600
[postfix-iptables]
enabled = true
filter = postfix
action = iptables[name=Postfix, port=smtp, protocol=tcp]
logpath = /var/log/maillog
maxretry = 3
findtime = 10800
bantime = 7200
[named-refused-udp]
enabled = false
filter = named-refused
action = iptables-multiport[name=named, port="domain,953", protocol=udp]
logpath = /var/named/chroot/var/log/named/security.log
maxretry = 3
findtime = 10800
bantime = 3600
[dovecot-iptables]
#pop3(110),pop3s(995),imap(143),imaps(993)
enabled = true
filter = dovecot
action = iptables-multiport[name=Dovecot, port="pop3,imap", protocol=tcp]
#logpath = /var/log/maillog
logpath = /var/log/secure
maxretry = 3
findtime = 10800
bantime = 3600
fail2ban-regex /var/log/secure /etc/fail2ban/jail.d/sshd.local
fail2ban-regex /var/log/maillog /etc/fail2ban/jail.d/postfix.local
fail2ban-regex /var/named/chroot/var/log/named/security.log /etc/fail2ban/jail.d/named-refused.local
fail2ban-regex /var/log/secure /etc/fail2ban/jail.d/dovecot.local
沒有留言:
張貼留言