用alternatives --display mta 查看一下自己的默認MTA
- # alternatives --display mta
- mta - 狀態是自動。
- 鏈接目前指向 /usr/sbin/sendmail.sendmail
- /usr/sbin/sendmail.sendmail - 優先度 90
- 從 mta-mailq:/usr/bin/mailq.sendmail
- 從 mta-newaliases:/usr/bin/newaliases.sendmail
- 從 mta-rmail:/usr/bin/rmail.sendmail
- 從 mta-sendmail:/usr/lib/sendmail.sendmail
- 從 mta-pam:/etc/pam.d/smtp.sendmail
- 從 mta-sendmailman:/usr/share/man/man8/sendmail.sendmail.8.gz
- 從 mta-mailqman:/usr/share/man/man1/mailq.sendmail.1.gz
- 從 mta-newaliasesman:/usr/share/man/man1/newaliases.sendmail.1.gz
- 從 mta-aliasesman:/usr/share/man/man5/aliases.sendmail.5.gz
- 當前“最佳”版本是 /usr/sbin/sendmail.sendmail。
我的郵件系統默認爲sendmail,我們需要的是Postfix。
關閉sendmail服務。
因爲系統運行需要郵件服務,Postfix沒安裝啊前,暫時不用#rpm -e sendmail卸載此郵件服務
- # service sendmail stop
- 關閉 sm-client:[確定]
- 關閉 sendmail:[確定]
- # chkconfig sendmail off
Postfix最新版本爲 Postfix 2.9 experimental release,我們下載穩定版本Postfix 2.8 stable release
- # wget http://postfix.it-austria.net/releases/official/postfix-2.8.4.tar.gz
!!!安裝數據庫
在安裝Postfix2.8時,需要指定數據庫的位置,我們先來下載安裝最新的Mysql-5.5.14
- # wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.14.tar.gz/from/http://mysql.stu.edu.tw/
安裝一下Mysql所依賴的軟件gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool* expect
- # yum -y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool* expect
創建Mysql安裝目錄及數據存放目錄
- # mkdir /usr/local/mysql
- # mkdir /var/mysqldata
創建用戶和組
- # groupadd mysql
- # useradd -g mysql mysql
賦予數據存放的權限
- # chown mysql.mysql -R /var/mysqldata/
安裝cmake
我用的是最新的Mysql-5.5.14,Mysql5.5以後是用cmake來編譯的,我們下載並安裝cmake
- # wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
- # tar zxvf cmake-2.8.5.tar.gz
- # cd cmake-2.8.5
- # ./configure
- # make && make install
安裝Bison
看M4安裝的位置並寫入環境變量
- # whereis m4
- # vi /etc/exports
- PATH=$PATH:/usr/bin/m4
下載並安裝Bison
- # wget ftp://mirrors.kernel.org/gnu/bison/bison-2.5.tar.gz
- # tar zxvf bison-2.5.tar.gz
- # cd bison-2.5
- # ./configure --prefix=/usr/local/bison --with-libiconv-prefix=/usr/local/lib
- # make
- # make install
添加Bison到環境變量並刷新環境變量(或 yum -y install bison)
- # vi /etc/exports
- PATH=$PATH:/usr/bin/bison
- # source /etc/exports
安裝Mysql
- # tar zxvf mysql-5.5.14.tar.gz
- # cd mysql-5.5.14
- # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
- -DMYSQL_UNIX_ADDR=/var/mysqldata/mysql.sock \
- -DDEFAULT_CHARSET=utf8 \
- -DDEFAULT_COLLATION=utf8_general_ci \
- -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
- -DWITH_MYISAM_STORAGE_ENGINE=1 \
- -DWITH_INNOBASE_STORAGE_ENGINE=1 \
- -DWITH_READLINE=1 \
- -DENABLED_LOCAL_INFILE=1 \
- -DMYSQL_DATADIR=/var/mysqldata \
- -DMYSQL_TCP_PORT=3306
- # make
- # make install
複製配置文件
- # cp support-files/my-medium.cnf /etc/my.cnf
初始化數據
初始化前需要賦值給scripts/mysql_install_db執行權限
- # chmod 755 scripts/mysql_install_db
- # scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/mysqldata/
設置開機啓動Mysql
- # cp support-files/mysql.server /etc/init.d/mysql
- # chmod 755 /etc/init.d/mysql
- # chkconfig mysql on
爲Mysql添加環境變量並添加兩個別名方便開啓(#source /etc/profile 刷新後起效)
- # vi /etc/profile
- export PATH=/usr/local/mysql/bin:$PATH
- alias mysql_start="mysqld_safe &"
- alias mysql_stop="mysqladmin –u root -p shutdown"
啓動Mysql
- # /etc/init.d/mysql start
設置密碼
數據庫的密碼開始爲空
- # /usr/local/mysql/bin/mysqladmin -u root -p password
!!!安裝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
安裝以下開發所用到的rpm包組
- #yum groupinstall -y "Development Libraries" "Development Tools" "Legacy Software Development" "X Software Development"
啓動saslauth認證並加入自動啓動中
- # service saslauthd start
- # chkconfig saslauthd on
安裝Postfix
- # tar zxvf postfix-2.8.4.tar.gz
- # cd postfix-2.8.4
- # make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
- # make
- # make install
在安裝的時候如果報 bin/postconf: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
- # vi /etc/ld.so.conf
- /usr/local/mysql/lib
- # ldconfig
我的安裝選項 默認也行
- install_root: [/] /
- tempdir: [/usr/local/src/postfix-2.8.4] /tmp
- config_directory: [/etc/postfix]
- command_directory: [/usr/sbin]
- daemon_directory: [/usr/libexec/postfix]
- data_directory: [/var/lib/postfix]
- html_directory: [no]
- mail_owner: [postfix]
- mailq_path: [/usr/bin/mailq]
- manpage_directory: [/usr/local/man]
- newaliases_path: [/usr/bin/newaliases]
- queue_directory: [/var/spool/postfix]
- readme_directory: [no]
- sendmail_path: [/usr/sbin/sendmail]
- setgid_group: [postdrop]
(注意)生成別名二進制文件,這個步驟如果忽略,會造成postfix效率極低:
- # newaliases
已經安裝好postfix了,修改一下配置選項並啓動測試
- # vi /etc/postfix/main.cf
- myhostname = mail.test.com
- myorigin = test.com
- mydomain = test.com
- mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
- mynetworks = 192.168.1.0/24, 127.0.0.0/8
說明:
myorigin參數用來指明發件人所在的域名;
mydestination參數指定postfix接收郵件時收件人的域名,即您的postfix系統要接收到哪個域名的郵件;
myhostname 參數指定運行postfix郵件系統的主機的主機名,默認情況下,其值被設定爲本地機器名;
mydomain參數指定您的域名,默認情況下,postfix將myhostname的第一部分刪除而作爲mydomain的值;
mynetworks 參數指定你所在的網絡的網絡地址,postfix系統根據其值來區別用戶是遠程的還是本地的,如果是本地網絡用戶則允許其訪問;
inet_interfaces 參數指定postfix系統監聽的網絡接口;
啓動postfix
- # /usr/sbin/postfix start
連接Postfix,驗證服務狀況
- #netstat -tnlp | grep :25
- tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 15497/master
- # telnet localhost 25
- Trying 127.0.0.1...
- Connected to localhost.localdomain (127.0.0.1).
- Escape character is '^]'.
- 220 mail.test.com ESMTP Postfix
- ehlo mail.test.com //本postfix的hostname字段;
- 250-mail.test.com
- 250-PIPELINING
- 250-SIZE 10240000
- 250-VRFY
- 250-ETRN
- 250-ENHANCEDSTATUSCODES
- 250-8BITMIME
- 250 DSN
- mail from:[email protected] //輸入發信人郵箱
- 250 2.1.0 Ok
- rcpt to:[email protected] //輸入收信人郵箱
- 250 2.1.5 Ok
- data //輸入郵件數據信息
- subject:Mail test! //輸入郵件主題
- hello hanfeng!!! //輸入郵件內容
- . //輸入結束符.
- 250 2.0.0 Ok: queued as C55863E016D
- quit //輸入quit退出郵件系統
- 221 2.0.0 Bye
- Connection closed by foreign host.
- [root@station123 ~]#grep C55863E016D /var/log/maillog //查找發信狀態
爲postfix開啓cyrus-sasl認證
使用一下命令驗證Postfix是否支持cyrus-sasl認證,如果輸出結果如下,則是支持的:
- # /usr/sbin/postconf -a
- cyrus
- dovecot
# vi /etc/postfix/main.cf
添加一下內容
- ############################CYRUS-SASL############################
- broken_sasl_auth_clients = yes
- 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
- smtpd_sasl_auth_enable = yes
- smtpd_sasl_local_domain = $myhostname
- smtpd_sasl_security_options = noanonymous
- smtpdsmtpd_sasl_application_name = smtpd
- smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
#vi /usr/lib/sasl2/smtpd.conf
添加如下內容:
- pwcheck_method: saslauthd
- mech_list: PLAIN LOGIN
重新加載Postfix
- # /usr/sbin/postfix reload
下載並安裝courier-authlib(CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations" 這個選項放在後面就錯,沒加載不知道有什麼影響)
- # wget http://downloads.sourceforge.net/project/courier/authlib/0.63.0/courier-authlib-0.63.0.tar.bz2?r=http%3A%2F%2Fwww.courier-mta.org%2Fdownload.php&ts=1311251851&use_mirror=ncu
- # tar jxvf courier-authlib-0.63.0.tar.bz2
- # cd courier-authlib-0.63.0
- # ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/local/mysql/lib --with-mysql-includes=/usr/local/mysql/include --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc
- # make
- # make install
- # 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"
- daemons=10
- # vi /etc/authmysqlrc 爲以下內容,其中2525,2525 爲postfix 用戶的UID和GID。
- MYSQL_SERVER localhost
- MYSQL_PORT 3306 (指定你的mysql監聽的端口,這裏使用默認的3306)
- MYSQL_USERNAME extmail (這時爲後文要用的數據庫的所有者的用戶名)
- MYSQL_PASSWORD extmail (密碼)
- MYSQL_SOCKET /var/mysqldata/mysql.sock
- MYSQL_DATABASE extmail
- MYSQL_USER_TABLE mailbox
- MYSQL_CRYPT_PWFIELD password
- MYSQL_UID_FIELD '2525'
- MYSQL_GID_FIELD '2525'
- MYSQL_LOGIN_FIELD username
- MYSQL_HOME_FIELD concat('/var/mailbox/',homedir)
- MYSQL_NAME_FIELD name
- MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)
- !!!保證此文件的內容不能有錯,否則不能啓用postfix與mysql的連接;
- # cp courier-authlib.sysvinit /etc/init.d/courier-authlib
- # chmod 755 /etc/init.d/courier-authlib
- # chkconfig --add courier-authlib
- # chkconfig --level 2345 courier-authlib on
- #echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf
- # ldconfig -v
- # service courier-authlib start (啓動服務)
- Starting Courier authentication services: authdaemond (可信的, 可靠的)