linux學習之郵件服務器


一、服務器數據庫

[root@localhost ~]# yum install mysql-server -y
[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]# mysql_secure_installation 設置密碼爲westos
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# lftp 192.168.0.1
lftp 192.168.0.1:/pub/postfix> get extmail-1.2.tar.gz extman-1.1.tar.gz
[root@localhost ~]# tar zxf extman-1.1.tar.gz
[root@localhost ~]# tar zxf extmail-1.2.tar.gz 
[root@localhost ~]# cd extman-1.1/docs/
[root@localhost docs]# mysql -pwestos < extmail.sql 
[root@localhost docs]# vim init.sql 
INSERT INTO `mailbox` VALUES ('[email protected]','postmaster','westos','','PostMaster','','extmail.org/postmaster/Maildir/','extmail.org/postmaster','104857600S','52428800S','extmail.org',1000,1000,'2007-02-14 15:10:04','2010-11-08',1,0,0,0,0,0,0,0,'my question','my answer');
INSERT INTO `manager` VALUES ('[email protected]','westos','admin','root','Super User','my question','my answer','0','2007-02-14 15:10:04','2010-11-08',1);
[root@localhost docs]# mysql -pwestos < init.sql 
[root@localhost docs]# useradd -u 800 vmail
[root@localhost docs]# postconf -e virtual_mailbox_base=/home/vmail/
[root@localhost docs]# postconf -e virtual_uid_maps=static:800
[root@localhost docs]# postconf -e virtual_gid_maps=static:800
[root@localhost docs]# cp mysql_virtual_alias_maps.cf mysql_virtual_domains_maps.cf mysql_virtual_mailbox_maps.cf /etc/postfix/
[root@localhost postfix]# postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf
[root@localhost postfix]# postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql_virtual_domains_maps.cf
[root@localhost postfix]# postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
[root@localhost postfix]# postfix reload
[root@localhost postfix]# yum install mailx-12.4-6.el6.x86_64 -y
[root@localhost postfix]# mail [email protected]
Subject: test
qwertyuiop
asdfghjkl
EOT
[root@localhost postfix]# mailq
Mail queue is empty
這時候,在/home/vmail/extmail.org/postmaster/Maildir/new下會有一封新的郵件

二、3月30日 第二天從這裏開始

[root@localhost docs]# mkdir /var/www/extsuite
[root@localhost ~]# mv extman-1.1 /var/www/extsuite/extman
[root@localhost ~]# mv extmail-1.2 /var/www/extsuite/extmail
[root@localhost ~]# cd /var/www/extsuite/
[root@localhost extsuite]# chown vmail.vmail * -R
[root@localhost extsuite]# cp extmail/webmail.cf.default extmail/webmail.cf
[root@localhost extsuite]# cp extman/webman.cf.default extman/webman.cf
/etc/httpd/conf/httpd.conf 加入
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.extmail.org
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
SuexecUserGroup vmail vmail
</VirtualHost>
主機名修改爲mail.extmail.org
[root@localhost extsuite]# /etc/init.d/httpd restart
[root@localhost extsuite]# vi extmail/webmail.cf
修改配置文件extmail/webmail.cf
SYS_LOG_ON = 0
SYS_MAILDIR_BASE = /home/vmail
SYS_CRYPT_TYPE = plain
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
修改配置文件extman/webman.cf
SYS_CAPTCHA_ON = 0
SYS_MAILDIR_BASE = /home/vmail
SYS_SESS_DIR = /tmp/
SYS_CRYPT_TYPE = plain
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman

[root@localhost extsuite]# yum install perl-CGI -y
客戶端192.168.0.1做192.168.0.146 mail.extmail.org解析
訪問mail.extmail.org 用戶 uname:postmaster passwd:westos
http://mail.extmail.org/extman/cgi/index.cgi 管理員 passwd:westos
後臺運行,管理員可查看系統信息
[root@localhost extsuite]# /var/www/extsuite/extman/daemon/cmdserver &

三、接下來添加功能

1.打開LOG功能記錄登錄狀況

修改配置文件extmail/webmail.cf
SYS_LOG_ON = 1
[root@localhost ~]# tar zxf Unix-Syslog-1.1.tar.gz 
[root@localhost Unix-Syslog-1.1]# perl Makefile.PL 
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
BEGIN failed--compilation aborted at Makefile.PL line 1.
[root@localhost Unix-Syslog-1.1]# yum install -y perl-ExtUtils-MakeMaker
[root@localhost Unix-Syslog-1.1]# yum install make gcc -y
[root@localhost Unix-Syslog-1.1]# perl Makefile.PL 
[root@localhost Unix-Syslog-1.1]# make install
[root@localhost ~]# tail -f /var/log/maillog 查看日誌

2.加入驗證碼防暴力註冊

修改配置文件extman/webman.cf
SYS_CAPTCHA_ON = 1
[root@localhost ~]# yum localinstall perl-GD-2.45-1.el6.rfx.x86_64.rpm -y

3.繪製圖表查看登錄頻率等信息

[root@localhost ~]# yum install rrdtool-perl-1.3.8-6.el6.x86_64.rpm -y
[root@localhost ~]# cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/
lftp 192.168.0.1:~> get pub/postfix/File-Tail-0.99.3.tar.gz 
[root@localhost ~]# tar zxf File-Tail-0.99.3.tar.gz 
[root@localhost ~]# cd File-Tail-0.99.3
[root@localhost File-Tail-0.99.3]# yum install perl-Time-HiRes -y
[root@localhost File-Tail-0.99.3]# perl Makefile.PL 
[root@localhost File-Tail-0.99.3]# make install
[root@localhost File-Tail-0.99.3]# /usr/local/mailgraph_ext/mailgraph-init start
刷新管理員頁面,點擊Graph Log

四、使用dovecot接收郵件

[root@mail ~]# yum install dovecot-mysql -y
[root@mail conf.d]# vim 10-mail.conf 
mail_location = maildir:/home/vmail/%d/%n/Maildir
first_valid_uid = 800
[root@mail conf.d]# vim 10-auth.conf 
#!include auth-system.conf.ext
!include auth-sql.conf.ext
[root@mail conf.d]# cp /usr/share/doc/dovecot-2.0.9/example-config/dovecot-sql.conf.ext /etc/dovecot/
[root@mail dovecot]# vim dovecot-sql.conf.ext 
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = PLAIN
password_query = \
  SELECT username, domain, password \
  FROM mailbox WHERE username = '%u' AND domain = '%d'
user_query = SELECT maildir, 800 AS uid, 800 AS gid FROM mailbox WHERE username = '%u'
[root@mail dovecot]# /etc/init.d/dovecot restart
[root@mail ~]# yum install telnet* -y
[root@mail dovecot]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user [email protected]
+OK
pass weifang
+OK Logged in.
list
+OK 0 messages:
.

五、使用雷鳥客戶端

在客戶端安裝thunderbird-17.0.2-1.el6.remi.x86_64
設置賬戶就好了
服務器
[root@mail ~]# vim /etc/postfix/main.cf 
inet_interfaces = all

爲使功能健全,在/etc/rc.local 添加
[root@localhost File-Tail-0.99.3]# vi /etc/rc.local 
/var/www/extsuite/extman/daemon/cmdserver &
/usr/local/mailgraph_ext/mailgraph-init start
[root@localhost ~]# chkconfig httpd on 
[root@localhost ~]# chkconfig mysqld on 
[root@mail ~]# chkconfig dovecot on

六、第二個周

1、postfix升級

[root@mail postfix-2.11.0]# /etc/init.d/postfix stop
[root@mail postfix-2.11.0]# yum install -y cyrus-sasl-*
[root@mail postfix-2.11.0]# yum install openssl-devel.x86_64 -y
[root@mail postfix-2.11.0]# yum install mysql-devel.x86_64 -y
[root@mail postfix-2.11.0]# yum install db4-devel-4.7.25-17.el6.x86_64 -y
[root@mail postfix-2.11.0]# make tidy
[root@mail postfix-2.11.0]# make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS' 'AUXLIBS=-L/usr/lib64/mysql/ -lmysqlclient -lz -lm -L/usr/lib64 -lsasl2 -lssl -lcrypto'
[root@mail postfix-2.11.0]# make upgrade
[root@mail ~]# postconf mail_version
mail_version = 2.11.0查看版本
[root@mail certs]# postconf -A
cyrus
[root@mail certs]# postconf -a
cyrus
dovecot
帶上mysql
[root@mail certs]# postconf -m

2、發信身份驗證,使用統一密碼

[root@mail ~]# yum localinstall -y cyrus-sasl-sql-2.1.23-13.el6.x86_64.rpm 注意版本

yum localinstall cyrus-sasl-sql-2.1.23-13.el6_3.1.x86_64.rpm
[root@mail sasl2]# vim /etc/sasl2/smtpd.conf 
pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5 NTLM
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: extmail
sql_passwd: extmail
sql_database: extmail
sql_select: SELECT password FROM mailbox WHERE username = '%u@%r'
[root@mail sasl2]# postconf -e smtpd_sasl_auth_enable=yes
[root@mail sasl2]# postfix reload
[root@mail sasl2]# perl -MMIME::Base64 -e 'print encode_base64("\0weifang\@extmail.org\0weifang");'
AHdlaWZhbmdAZXh0bWFpbC5vcmcAd2VpZmFuZw==
[root@mail sasl2]# telnet localhost 25
ehlo mail.extmail.org
auth plain AHdlaWZhbmdAZXh0bWFpbC5vcmcAd2VpZmFuZw==
使用雷鳥outgoing server 
編輯
connection none
authentication password,transmitted insecurely
username [email protected]
之後,用戶[email protected]發送郵件就會進行身份驗證
登錄需要身份驗證,發信也需要驗證身份,防止身份僞造或者非郵箱本人發信

3、加密發送

[root@mail sasl2]# postconf -e smtpd_tls_auth_only=yes
[root@mail sasl2]# postfix reload
[root@mail sasl2]# telnet localhost 25
ehlo localhost
沒有這個250-AUTH LOGIN CRAM-MD5 DIGEST-MD5 PLAIN
改成no,就會有250-AUTH LOGIN CRAM-MD5 DIGEST-MD5 PLAIN
[root@mail certs]# postconf -e smtpd_tls_auth_only=no
[root@mail sasl2]# postconf -e smtpd_tls_security_level=may可以不加密發送
就會多一條這個,表示開啓TLS加密
250-STARTTLS
生成加密驗證文件
[root@mail sasl2]# cd /etc/pki/tls/certs/
[root@mail certs]# make postfix.pem
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:LINUX
Common Name (eg, your name or your server's hostname) []:mail.extmail.org
Email Address []:[email protected]
[root@mail certs]# cp postfix.pem /etc/postfix/
[root@mail certs]# postconf -d | grep ^smtpd_tls
[root@mail certs]# postconf -e smtpd_tls_cert_file=/etc/postfix/postfix.pem 
[root@mail certs]# postconf -e 'smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache'
[root@mail certs]# postconf -n加上這四條
smtpd_tls_auth_only = no
smtpd_tls_cert_file = /etc/postfix/postfix.pem
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache
這時,雷鳥設置outgoing爲
連接加密 connection STARTTLS 使用加密或者none不使用加密都可以正常發送
認證方法 authentication normal password
用戶信息 username [email protected]
weifang發送郵件的話,需要確認網絡環境安全,並得到驗證文件,可以發送
修改爲強制加密
[root@mail certs]# postconf -e smtpd_tls_security_level=encrypt
[root@mail certs]# postconf -e smtpd_tls_auth_only=yes
[root@mail certs]# postfix reload

如果不使用加密,就不能發送,這樣就保證了安全
連接加密 connection STARTTLS 使用加密
認證方法 authentication normal password
用戶信息 username [email protected]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章