CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問


CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問

原文鏈接: https://yq.aliyun.com/articles/484284

1. 准備工作


關閉selinux

  1. [root@localhost ~] # setenforce 0
  2. [root@localhost ~] # getenforce
  3. Permissive
  4. [root@localhost ~] #

關閉firewalld防火牆,並清空iptables規則:

  1. [ root@localhost ~]# systemctl stop firewalld
  2. [ root@localhost ~]# iptables -F
  3. [ root@localhost ~]# iptables -X
  4. [ root@localhost ~]# iptables -nvL
  5. Chain INPUT (policy ACCEPT 38 packets, 7291 bytes)
  6. pkts bytes target prot opt in out source destination
  7.  
  8. Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
  9. pkts bytes target prot opt in out source destination
  10.  
  11. Chain OUTPUT (policy ACCEPT 12 packets, 1208 bytes)
  12. pkts bytes target prot opt in out source destination
  13. [root@localhost ~]#

由於CentOS7默認安裝的是MariaDB,所以要添加MySQL的yum源,有些編譯需要的devel包只有epel擴展源有,所以我們需要把epel源也一並添加。因為是通過wget命令從下載地址中下載,但是最小化安裝的CentOS7不自帶wget命令,還需要先安裝這個命令:

  1. yum install -y wget
  2. wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  3. rpm -ivh mysql-community- release-el7-5.noarch.rpm
  4. wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  5. rpm -ivh epel- release-latest-7.noarch.rpm

2. 安裝postfix


首先需要安裝編譯環境及其他所需要的包,免得一會編譯過程中老報缺少包的錯誤,因為需要安裝的包有點多,所以這個過程有點慢:

yum install nginx vim 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 mail libicu-devel -y

安裝完以上所需的包后,開始編譯安裝postfix:

1.首先卸載系統自帶的postfix,並刪除postfix用戶,重新指定uid、gid創建新用戶postfix,postdrop,嫌一條條命令去執行有點麻煩就寫成腳本文件去執行:

  1. yum remove postfix -y
  2. userdel postfix
  3. groupdel postdrop
  4. groupadd -g 2525 postfix
  5. useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
  6. groupadd -g 2526 postdrop
  7. useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

2.下載源碼包並解壓編譯(如果下載地址失效就到官網去找下載連接):

  1. cd /usr/local/src/
  2. wget http: //cdn.postfix.johnriley.me/mirrors/postfix-release/official/postfix-3.0.11.tar.gz
  3. tar -zxvf postfix -3.0.11.tar.gz
  4. cd postfix-3.0.11
  5. make 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 -lrt -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
  6. make && make install
  7. echo $?

在make install環節的時候會有個交互式的界面,可以自定義一些目錄,我這里只更改了第二項臨時文件目錄,其他的都選擇了默認目錄:

  1. Please specify the prefix for installed file names. Specify this ONLY
  2. if you are building ready-to-install packages for distribution to OTHER
  3. machines. See PACKAGE_README for instructions.
  4. install_root: [/]
  5.  
  6. Please specify a directory for scratch files while installing Postfix. You
  7. must have write permission in this directory.
  8. tempdir: [/usr/ local/src/postfix-3.0.11] /tmp/extmail // 就只更改這一項為tmp目錄,其他的全部默認
  9.  
  10. Please specify the final destination directory for installed Postfix
  11. configuration files.
  12. config_directory: [/etc/postfix]
  13.  
  14. Please specify the final destination directory for installed Postfix
  15. administrative commands. This directory should be in the command search
  16. path of adminstrative users.
  17. command_directory: [/usr/sbin]
  18.  
  19. Please specify the final destination directory for installed Postfix
  20. daemon programs. This directory should not be in the command search path
  21. of any users.
  22. daemon_directory: [/usr/libexec/postfix]
  23.  
  24. Please specify the final destination directory for Postfix-writable
  25. data files such as caches or random numbers. This directory should not
  26. be shared with non-Postfix software.
  27. data_directory: [/ var/lib/postfix]
  28.  
  29. Please specify the final destination directory for the Postfix HTML
  30. files. Specify "no" if you do not want to install these files.
  31. html_directory: [ no]
  32.  
  33. Please specify the owner of the Postfix queue. Specify an account with
  34. numerical user ID and group ID values that are not used by any other
  35. accounts on the system.
  36. mail_owner: [postfix]
  37.  
  38. Please specify the final destination pathname for the installed Postfix
  39. mailq command. This is the Sendmail-compatible mail queue listing command.
  40. mailq_path: [/usr/ bin/mailq]
  41.  
  42. Please specify the final destination directory for the Postfix on-line
  43. manual pages. You can no longer specify "no" here.
  44. manpage_directory: [/usr/ local/man]
  45.  
  46. Please specify the final destination pathname for the installed Postfix
  47. newaliases command. This is the Sendmail-compatible command to build
  48. alias databases for the Postfix local delivery agent.
  49. newaliases_path: [/usr/ bin/newaliases]
  50.  
  51. Please specify the final destination directory for Postfix queues.
  52. queue_directory: [/ var/spool/postfix]
  53.  
  54. Please specify the final destination directory for the Postfix README
  55. files. Specify "no" if you do not want to install these files.
  56. readme_directory: [ no]
  57.  
  58. Please specify the final destination pathname for the installed Postfix
  59. sendmail command. This is the Sendmail-compatible mail posting interface.
  60. sendmail_path: [/usr/sbin/sendmail]
  61.  
  62. Please specify the group for mail submission and for queue management
  63. commands. Specify a group name with a numerical group ID that is
  64. not shared with other accounts, not even with the Postfix mail_owner
  65. account. You can no longer specify "no" here.
  66. setgid_group: [postdrop]
  67.  
  68. Please specify the final destination directory for Postfix shared-library
  69. files.
  70. shlib_directory: [ no]

3.更改目錄的屬主和屬組:

  1. chown - R postfix:postdrop /var/spool/postfix
  2. chown - R postfix:postdrop /var/lib/postfix/
  3. chown root / var/spool/postfix
  4. chown - R root /var/spool/postfix/pid

4.修改postfix的配置文件:

  1. [root@localhost ~] # vim /etc/postfix/main.cf
  2. myhostname = mail.everyoo.com //設置主機名
  3. mydomain = everyoo.com //指定域名
  4. myorigin = $mydomain //指明發件人所在的域名
  5. inet_interfaces = //all指定postfix系統監聽的網絡接口
  6. mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain //指定postfix接收郵件時收件人的域名 [使用虛擬域需要禁用]
  7. mynetworks_style = host //指定信任網段類型
  8. mynetworks = 192.168.77.1/24, 127.0.0.0/8 //指定信任的客戶端
  9. relay_domains = $mydestination //指定允許中轉郵件的域名
  10. alias_maps = hash:/etc/aliases //設置郵件的別名

5.然后需要在/etc/init.d/目錄下提供一個腳本來管理postfix的啟動與停止:

[root@localhost /var/www/extsuite/extman]# vim /etc/init.d/postfix

把下面的內容放在/etc/init.d/postfix里面:

  1. #!/bin/bash
  2. #
  3. # postfix Postfix Mail Transfer Agent
  4. #
  5. # chkconfig: 2345 80 30
  6. # description: Postfix is a Mail Transport Agent, which is the program \
  7. # that moves mail from one machine to another.
  8. # processname: master
  9. # pidfile: /var/spool/postfix/pid/master.pid
  10. # config: /etc/postfix/main.cf
  11. # config: /etc/postfix/master.cf
  12.  
  13. # Source function library.
  14. . /etc/rc.d/init.d/ functions
  15.  
  16. # Source networking configuration.
  17. . /etc/sysconfig/network
  18.  
  19. # Check that networking is up.
  20. [ $NETWORKING = "no" ] && exit 3
  21.  
  22. [ -x /usr/sbin/postfix ] || exit 4
  23. [ -d /etc/postfix ] || exit 5
  24. [ -d /var/spool/postfix ] || exit 6
  25.  
  26. RETVAL=0
  27. prog= "postfix"
  28.  
  29. start() {
  30. # Start daemons.
  31. echo -n $"Starting postfix: "
  32. /usr/bin/newaliases >/dev/null 2>&1
  33. /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $ "$prog start"
  34. RETVAL=$?
  35. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
  36. echo
  37. return $RETVAL
  38. }
  39.  
  40. stop() {
  41. # Stop daemons.
  42. echo -n $"Shutting down postfix: "
  43. /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $ "$prog stop"
  44. RETVAL=$?
  45. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
  46. echo
  47. return $RETVAL
  48. }
  49.  
  50. reload() {
  51. echo -n $"Reloading postfix: "
  52. /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $ "$prog reload"
  53. RETVAL=$?
  54. echo
  55. return $RETVAL
  56. }
  57.  
  58. abort() {
  59. /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $ "$prog abort"
  60. return $?
  61. }
  62.  
  63. flush() {
  64. /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $ "$prog flush"
  65. return $?
  66. }
  67.  
  68. check() {
  69. /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $ "$prog check"
  70. return $?
  71. }
  72.  
  73. restart() {
  74. stop
  75. start
  76. }
  77.  
  78. # See how we were called.
  79. case "$1" in
  80. start)
  81. start
  82. ;;
  83. stop)
  84. stop
  85. ;;
  86. restart)
  87. stop
  88. start
  89. ;;
  90. reload)
  91. reload
  92. ;;
  93. abort)
  94. abort
  95. ;;
  96. flush)
  97. flush
  98. ;;
  99. check)
  100. check
  101. ;;
  102. status)
  103. status master
  104. ;;
  105. condrestart)
  106. [ -f /var/lock/subsys/postfix ] && restart || :
  107. ;;
  108. *)
  109. echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
  110. exit 1
  111. esac
  112.  
  113. exit $?

為腳本添加執行權限,並將服務添加到開機啟動項中:

  1. [root@localhost / var/www/extsuite/extman]# chmod +x /etc/init.d/postfix
  2. [root@localhost / var/www/extsuite/extman]# chkconfig --add postfix
  3. [root@localhost / var/www/extsuite/extman]# chkconfig postfix on
  4. [root@localhost / var/www/extsuite/extman]# chown postfix.postfix -R /var/lib/postfix/
  5. [root@localhost / var/www/extsuite/extman]# chown postfix.postfix /var/spool/ -R

3. 安裝dovecot


yum安裝:

[root@localhost ~]# yum install -y dovecot dovecot-mysql

配置dovecot:

  1. [root@localhost ~] # cd /etc/dovecot/
  2. [root@localhost dovecot] # vim dovecot.conf //直接在配置文件最后添加即可
  3. protocols = imap pop3
  4. !include conf.d/*.conf
  5. listen = *
  6. base_dir = /var/run/dovecot/
  7. [root@localhost dovecot] # cd conf.d/
  8. [root@localhost conf.d] # vim 10-auth.conf
  9. disable_plaintext_auth = no
  10. [root@localhost conf.d] # vim 10-mail.conf
  11. mail_location = maildir:~ /Maildir
  12. mail_location = maildir:/var/mailbox/%d/%n/Maildir
  13. mail_privileged_group = mail
  14. [root@localhost conf.d] # vim 10-ssl.conf
  15. ssl = no
  16. [root@localhost conf.d] # vim 10-logging.conf
  17. log_path = /var/log/dovecot.log
  18. info_log_path = /var/log/dovecot.info
  19. log_timestamp = "%Y-%m-%d %H:%M:%S "
  20. [root@localhost conf.d] # cp auth-sql.conf.ext auth-sql.conf
  21. [root@localhost conf.d] # vim auth-sql.conf
  22. passdb {
  23. driver = sql
  24.  
  25. # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
  26. args = /etc/dovecot/dovecot-sql.conf.ext
  27. }
  28.  
  29. userdb {
  30. driver = sql
  31. args = /etc/dovecot/dovecot-sql.conf.ext
  32. }

編輯dovecot通過mysql認證的配置文件:

  1. [root@localhost conf.d] # vim /etc/dovecot-mysql.conf
  2. driver = mysql
  3. connect = host=localhost dbname=extmail user=extmail password=extmail
  4. default_pass_scheme = CRYPT
  5. password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'
  6. user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'

4. 安裝courier-authlib


下載解壓並編譯:

  1. [root@localhost ~] # cd /usr/local/src/
  2. [root@localhost /usr/ local/src]# wget https://sourceforge.net/projects/courier/files/authlib/0.66.2/courier-authlib-0.66.2.tar.bz2
  3. [root@localhost /usr/ local/src]# tar -jxvf courier-authlib-0.66.2.tar.bz2
  4. [root@localhost /usr/ local/src]# cd courier-authlib-0.66.2
  5. [root@localhost /usr/ local/src/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
  6. [root@localhost /usr/ local/src/courier-authlib-0.66.2]# make && makeinstall

編譯過程中發生了一個錯誤:

configure: error: The Courier Unicode Library 1.2 appears not to be installed. You may need to install a separate development subpackage, in addition to the main package

這是因為Courier Unicode Library沒有安裝,我們下載courier-unicode-1.2並編譯安裝:

  1. [root@localhost ~] # wget https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-1.2.tar.bz2
  2. [root@localhost ~] # tar jxvf courier-unicode-1.2.tar.bz2
  3. [root@localhost ~] # cd courier-unicode-1.2
  4. [root@localhost courier-unicode- 1.2]# ./configure
  5. [root@localhost courier-unicode- 1.2]# make && make install

完成Courier Unicode Library的安裝后,倒回去再次編譯courier-authlib就沒問題了

配置courier-authlib:

  1. [ root@localhost courier-authlib-0.66.2]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
  2. [ root@localhost courier-authlib-0.66.2]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
  3. [ root@localhost courier-authlib-0.66.2]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
  4. [ root@localhost courier-authlib-0.66.2]# vim /etc/authdaemonrc //配置文件里的驗證方法比較多,我們這里只使用authmysql
  5. authmodulelist= "authmysql"
  6. authmodulelistorig= "authmysql"
  7. [ root@localhost courier-authlib-0.66.2]# vim /etc/authmysqlrc //直接添加到配置文件尾部,然后去上面將響應系統默認的注視掉,或者刪除即可
  8. MYSQL_SERVER localhost
  9. MYSQL_USERNAME extmail
  10. MYSQL_PASSWORD extmail
  11. MYSQL_SOCKET / var/lib/mysql/mysql.sock
  12. MYSQL_PORT 3306
  13. MYSQL_DATABASE extmail
  14. MYSQL_USER_TABLE mailbox
  15. MYSQL_CRYPT_PWFIELD password
  16. DEFAULT_DOMAIN test.com
  17. MYSQL_UID_FIELD '2525'
  18. MYSQL_GID_FIELD '2525'
  19. MYSQL_LOGIN_FIELD username
  20. MYSQL_HOME_FIELD concat('/var/mailbox/',homedir)
  21. MYSQL_NAME_FIELD name
  22. MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)

courier-authlib添加服務啟動腳本及其他:

  1. [root@localhost courier-authlib- 0.66.2]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
  2. [root@localhost courier-authlib- 0.66.2]# chmod +x /etc/init.d/courier-authlib
  3. [root@localhost courier-authlib- 0.66.2]# chkconfig --add courier-authlib
  4. [root@localhost courier-authlib- 0.66.2]# chkconfig courier-authlib on
  5. [root@localhost courier-authlib- 0.66.2]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
  6. [root@localhost courier-authlib- 0.66.1]# ldconfig
  7. [root@localhost courier-authlib- 0.66.1]# service courier-authlib start
  8. Starting Courier authentication services: authdaemond

smtp以及虛擬用戶相關的設置:

  1. [ root@localhost ~]# vim /usr/lib64/sasl2/smtpd.conf //文件不存在,要自己創建
  2. pwcheck_method: authdaemond
  3. log_level: 3
  4. mech_list: PLAIN LOGIN
  5. authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
  6. [ root@localhost ~]# vim /etc/postfix/main.cf
  7. ##postfix支持SMTP##
  8. smtpd_sasl_auth_enable = yes
  9. smtpd_sasl_local_domain = ''
  10. smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
  11. broken_sasl_auth_clients=yes
  12. smtpd_client_restrictions = permit_sasl_authenticated
  13. smtpd_sasl_security_options = noanonymous
  14. ##postfix支持虛擬用戶##
  15. virtual_mailbox_base = / var/mailbox
  16. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf //這里的配置文件需在后面extman
  17. 里復制過來
  18. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
  19. virtual_alias_domains =
  20. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
  21. virtual_uid_maps = static:2525
  22. virtual_gid_maps = static:2525
  23. virtual_transport = virtual

安裝extmail


下載extmail和extman:

  1. [root@localhost ~] # cd /usr/local/src/
  2. [root@localhost /usr/ local/src]# wget http://7xivyw.com1.z0.glb.clouddn.com/extmail-1.2.tar.gz
  3. [root@localhost /usr/ local/src]# wget http://7xivyw.com1.z0.glb.clouddn.com/extman-1.1.tar.gz

創建站點目錄並解壓、重命名extmail包:

  1. [root@localhost /usr/ local/src]# mkdir -p /var/www/extsuite
  2. [root@localhost /usr/ local/src]# tar -zxvf extmail-1.2.tar.gz -C /var/www/extsuite/
  3. [root@localhost /usr/ local/src]# mv /var/www/extsuite/extmail-1.2/ /var/www/extsuite/extmail

更改extmail的配置文件:

  1. [ root@localhost ~]# cd /var/www/extsuite/extmail
  2. [ root@localhost extmail]# cp webmail.cf.default webmail.cf
  3. [ root@localhost extmail]# vim webmail.cf
  4. SYS_SESS_DIR = /tmp/extmail
  5. SYS_UPLOAD_TMPDIR = /tmp/extmail/upload
  6. SYS_USER_LANG = zh_CN
  7. SYS_MIN_PASS_LEN = 8
  8. SYS_MAILDIR_BASE = / var/mailbox
  9. SYS_MYSQL_USER = extmail
  10. SYS_MYSQL_PASS = extmail
  11. SYS_MYSQL_DB = extmail
  12. SYS_MYSQL_HOST = localhost
  13. SYS_MYSQL_SOCKET = / var/lib/mysql/mysql.sock
  14. SYS_MYSQL_TABLE = mailbox
  15. SYS_MYSQL_ATTR_USERNAME = username
  16. SYS_MYSQL_ATTR_DOMAIN = domain
  17. SYS_MYSQL_ATTR_PASSWD = password
  18. SYS_AUTHLIB_SOCKET = /usr/ local/courier-authlib/var/spool/authdaemon/socket

建立臨時文件目錄與session目錄,並更改權限:

  1. [root@localhost extmail] # mkdir -p /tmp/extmail/upload
  2. [root@localhost extmail] # chown -R postfix.postfix /tmp/extmail/

安裝extman


回到extman的下載目錄下,解壓extman包:

  1. [root@localhost ~] # cd /usr/local/src/
  2. [root@localhost /usr/ local/src]# tar -zxvf extman-1.1.tar.gz -C /var/www/extsuite/
  3. [root@localhost /usr/ local/src]# cd /var/www/extsuite/
  4. [root@localhost /var/www/extsuite] # mv extman-1.1/ extman

拷貝extman的配置文件:

  1. [ root@localhost /var/www/extsuite]# cd extman/
  2. [ root@localhost /var/www/extsuite/extman]# cp webman.cf.default webman.cf

更改cgi目錄的屬主屬組:

  1. [root@localhost / var/www/extsuite/extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
  2. [root@localhost / var/www/extsuite/extman]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/

導入數據庫:
由於數據庫不能識別TYPE=MyISAM,所以這里直接導入會出錯,需要先編輯extmail.sql數據庫文件,將文件中的TYPE=MyISAM更改為ENGINE=MyISAM,共有五處修改:

  1. [root@localhost /var/www/extsuite/extman] # vim docs/extmail.sql
  2. :% s/TYPE/ENGINE/g

我這里導入數據的時候發生了一個錯誤,提示找不到mysql.sock文件:

  1. [root@localhost / var/www/extsuite/extman]# mysql -uroot < docs/extmail.sql
  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  3. [root@localhost /var/www/extsuite/extman]# ls /var/lib/mysql/mysql.sock
  4. ls: 無法訪問/var/lib/mysql/mysql.sock: 沒有那個文件或目錄

解決:然后我去查看了一下/etc/my.cnf文件,發現沒問題,socket參數指向的也是 /var/lib/mysql/mysql.sock 這個路徑,於是我就重啟了mysql服務,然后再嘗試就沒有報找不到mysql.sock文件的錯誤了,但是報了另一個錯誤:

  1. [root@localhost /var/www/extsuite/extman] # mysql -uroot < docs/extmail.sql
  2. ERROR 1364 (HY000) at line 31: Field 'ssl_cipher' doesn't have a default value
  3. [root@localhost /var/www/extsuite/extman] #

這錯誤的意思是:字段 'ssl密碼' 沒有默認值

於是又得去查看一下/etc/my.cnf文件,然后把sql_mode參數給注釋掉:
CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問

接着重啟mysql服務后,繼續導入數據,這次就沒問題了:

  1. [root@localhost / var/www/extsuite/extman]# !service
  2. service mysqld restart
  3. Redirecting to /bin/systemctl restart mysqld.service
  4. [root@localhost / var/www/extsuite/extman]# mysql -uroot < docs/extmail.sql
  5. [root@localhost / var/www/extsuite/extman]# mysql -uroot < docs/init.sql

導入數據成功后再次修改/etc/my.cnf文件,把剛剛注釋的那行給去掉注釋,不去掉的話,mysql服務可能會出現不能啟動的問題:

CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問

數據導入成功后,登錄mysql,創建一個mysql數據庫用戶extmail並授予權限:

  1. [ root@localhost /var/www/extsuite/extman]# mysql -uroot
  2. mysql> GRANT ALL ON extmail.* to extmail@ '%' identified by 'extmail'; //我這里是直接授予全部權限在任意的IP地址上了,實際情況根據需求而定
  3. Query OK, 0 rows affected (0.00 sec)
  4.  
  5. mysql> FLUSH PRIVILEGES;
  6. Query OK, 0 rows affected (0.00 sec)
  7.  
  8. mysql>

復制之前提到的配置文件:

  1. [root@localhost ~] # cd /var/www/extsuite/extman/docs/
  2. [root@localhost /var/www/extsuite/extman/docs] # cp mysql_virtual_* /etc/postfix/

為extman創建臨時目錄:

  1. [root@localhost / var/www/extsuite/extman/docs]# mkdir /tmp/extman
  2. [root@localhost / var/www/extsuite/extman/docs]# chown -R postfix.postfix /tmp/extman/

啟動postfix、dovecot、saslauthd服務,並查看進程是否正常:

  1. [root@localhost /var/www/extsuite/extman] # service postfix start
  2. Starting postfix (via systemctl): [ 確定 ]
  3. [root@localhost /var/www/extsuite/extman] # ps aux |grep postfix
  4. root 63586 0.0 0.1 95392 2160 ? Ss 01:29 0:00 /usr/libexec/postfix/master -w
  5. postfix 63587 0.0 0.2 95448 3808 ? S 01:29 0:00 pickup -l -t unix -u
  6. postfix 63588 0.0 0.2 95496 3816 ? S 01:29 0:00 qmgr -l -t unix -u
  7. root 63592 0.0 0.0 112680 976 pts/0 S+ 01:33 0:00 grep --color=auto postfix
  8. [root@localhost /var/www/extsuite/extman] # ss -tnluo | grep :25
  9. tcp LISTEN 0 100 *:25 *:*
  10. [root@localhost /var/www/extsuite/extman] # service dovecot start
  11. Redirecting to /bin/systemctl start dovecot.service
  12. [root@localhost /var/www/extsuite/extman] # ps aux |grep dovecot
  13. root 63834 0.3 0.0 15652 1484 ? Ss 02:15 0:00 /usr/sbin/dovecot -F
  14. dovecot 63837 0.0 0.0 9320 1012 ? S 02:15 0:00 dovecot/anvil
  15. root 63838 0.0 0.0 9448 1164 ? S 02:15 0:00 dovecot/log
  16. root 63840 0.0 0.1 12464 2196 ? S 02:15 0:00 dovecot/config
  17. root 63842 0.0 0.0 112680 972 pts/0 S+ 02:15 0:00 grep --color=auto dovecot
  18. [root@localhost /var/www/extsuite/extman] # systemctl start saslauthd
  19. [root@localhost /var/www/extsuite/extman] # ps aux |grep saslauthd
  20. root 63131 0.0 0.0 69648 916 ? Ss 01:19 0:00 /usr/sbin/saslauthd -m /run/saslauthd -a pam
  21. root 63132 0.0 0.0 69648 676 ? S 01:19 0:00 /usr/sbin/saslauthd -m /run/saslauthd -a pam
  22. root 63133 0.0 0.0 69648 676 ? S 01:19 0:00 /usr/sbin/saslauthd -m /run/saslauthd -a pam
  23. root 63134 0.0 0.0 69648 676 ? S 01:19 0:00 /usr/sbin/saslauthd -m /run/saslauthd -a pam
  24. root 63135 0.0 0.0 69648 676 ? S 01:19 0:00 /usr/sbin/saslauthd -m /run/saslauthd -a pam
  25. root 63144 0.0 0.0 112680 972 pts/0 S+ 01:20 0:00 grep --color=auto saslauthd
  26. [root@localhost /var/www/extsuite/extman] # ps aux |grep courier-authlib
  27. root 61661 0.0 0.0 4316 444 ? S 00:07 0:00 /usr/local/courier-authlib/sbin/courierlogger -pid=/usr/local/courier-authlib/var/spool/authdaemon/pid -start /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  28. root 61662 0.0 0.0 35512 1796 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  29. root 61663 0.0 0.0 35512 468 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  30. root 61664 0.0 0.0 35512 468 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  31. root 61665 0.0 0.0 35512 468 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  32. root 61666 0.0 0.0 35512 468 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  33. root 61667 0.0 0.0 35512 468 ? S 00:07 0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
  34. root 63660 0.0 0.0 112680 980 pts/0 S+ 02:00 0:00 grep --color=auto courier-authlib

7. 測試


測試虛擬用戶:

  1. [root@localhost courier-authlib- 0.66.2]# /usr/local/courier-authlib/sbin/authtest -s login postmaster@extmail.org extmail
  2. Authentication succeeded. //顯示這個表示成功,測試時使用的是postmaster@extmail.org,因為我們導入的數據庫init.sql里面自帶了這個。
  3. Authenticated: postmaster@extmail.org (uid 2525, gid 2525)
  4. Home Directory: /var/mailbox/extmail.org/postmaster //這里需要注意/var/mailbox這個目錄現在我們還沒有創建,后面web訪問的時候如果沒有會報錯,所以提前創建。
  5. Maildir: /var/mailbox/extmail.org/postmaster/Maildir/
  6. Quota: (none)
  7. Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
  8. Cleartext Password: extmail
  9. Options: (none)
  10. [root@localhost courier-authlib- 0.66.2]# mkdir /var/mailbox
  11. [root@localhost courier-authlib- 0.66.2]# chown -R postfix.postfix /var/mailbox/

測試smtp發信:

  1. [ root@localhost ~]# printf "postmaster@extmail.org" | openssl base64
  2. cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
  3. [ root@localhost ~]# printf "extmail" | openssl base64
  4. ZXh0bWFpbA==
  5. [ root@localhost ~]# telnet localhost 25
  6. Trying :: 1...
  7. telnet: connect to address :: 1: Connection refused
  8. Trying 127.0.0.1...
  9. Connected to localhost.
  10. Escape character is '^]'.
  11. 220 mail.daen.com ESMTP Postfix
  12. auth login
  13. 334 VXNlcm5hbWU6
  14. cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
  15. 334 UGFzc3dvcmQ6
  16. ZXh0bWFpbA==
  17. 235 2.7.0 Authentication successful //成功
  18. quit
  19. 221 2.0.0 Bye
  20. Connection closed by foreign host.

8. 啟動nginx實現web訪問


nginx本身並不能解析cgi,extmail自帶了解析cgi的程序,但是有些地方需要修改下:

  1. [root@localhost ~] # vim /var/www/extsuite/extmail/dispatch-init
  2. SU_UID=postfix
  3. SU_GID=postfix

啟動dispatch-init:

  1. [root@localhost ~] # /var/www/extsuite/extmail/dispatch-init start
  2. Starting extmail FCGI server...
  3. [root@localhost ~] # /var/www/extsuite/extman/daemon/cmdserver -v -d
  4. loaded ok

添加nginx虛擬主機:

vim /etc/nginx/conf.d/extmail.conf

文件內容如下:

  1. server {
  2. listen 8080;
  3. server_name mail.everyoo.com;
  4. index index.html index.htm index.php index.cgi;
  5. root / var/www/extsuite/extmail/html/;
  6. location /extmail/cgi/ {
  7. fastcgi_pass 127.0.0.1:8888;
  8. fastcgi_index index.cgi;
  9. fastcgi_param SCRIPT_FILENAME / var/www/extsuite/extmail/cgi/$fastcgi_script_name;
  10. include fcgi.conf;
  11. }
  12. location /extmail/ {
  13. alias /var/www/extsuite/extmail/html/;
  14. }
  15. location /extman/cgi/ {
  16. fastcgi_pass 127.0.0.1:8888;
  17. fastcgi_index index.cgi;
  18. fastcgi_param SCRIPT_FILENAME / var/www/extsuite/extman/cgi/$fastcgi_script_name;
  19. include fcgi.conf;
  20. }
  21. location /extman/ {
  22. alias /var/www/extsuite/extman/html/;
  23. }
  24. access_log / var/log/extmail_access.log;
  25. }

創建fcgi.conf文件:

vim /etc/nginx/fcgi.conf

文件內容如下:

  1. fastcgi_param GATEWAY_INTERFACE CGI/ 1.1;
  2. fastcgi_param SERVER_SOFTWARE nginx;
  3. fastcgi_param QUERY_STRING $query_string;
  4. fastcgi_param REQUEST_METHOD $request_method;
  5. fastcgi_param CONTENT_TYPE $content_type;
  6. fastcgi_param CONTENT_LENGTH $content_length;
  7. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  8. fastcgi_param REQUEST_URI $request_uri;
  9. fastcgi_param DOCUMENT_ROOT $document_root;
  10. fastcgi_param SERVER_PROTOCOL $server_protocol;
  11. fastcgi_param REMOTE_ADDR $remote_addr;
  12. fastcgi_param REMOTE_PORT $remote_port;
  13. fastcgi_param SERVER_ADDR $server_addr;
  14. fastcgi_param SERVER_PORT $server_port;
  15. fastcgi_param SERVER_NAME $server_name;

安裝Unix::Syslog:

  1. [root@localhost ~] # cd /usr/local/src/
  2. [root@localhost /usr/ local/src]# wget http://www.cpan.org/authors/id/M/MH/MHARNISCH/Unix-Syslog-1.1.tar.gz
  3. [root@localhost /usr/ local/src]# tar zxvf Unix-Syslog-1.1.tar.gz
  4. [root@localhost /usr/ local/src]# cd Unix-Syslog-1.1
  5. [root@localhost /usr/ local/src/Unix-Syslog-1.1]# perl Makefile.PL
  6. [root@localhost /usr/ local/src/Unix-Syslog-1.1]# make && make install

啟動nginx,並檢查進程和監聽端口是否正常:

  1. [root@localhost ~] # service nginx start
  2. Redirecting to /bin/systemctl start nginx.service
  3. [root@localhost ~] # ps aux |grep nginx
  4. root 72338 0.0 0.1 122892 2296 ? Ss 03:22 0:00 nginx: master process /usr/sbin/nginx
  5. nginx 72339 0.0 0.1 123336 3192 ? S 03:22 0:00 nginx: worker process
  6. nginx 72340 0.0 0.1 123336 3192 ? S 03:22 0:00 nginx: worker process
  7. nginx 72341 0.0 0.1 123336 3192 ? S 03:22 0:00 nginx: worker process
  8. nginx 72342 0.0 0.1 123336 3192 ? S 03:22 0:00 nginx: worker process
  9. root 72344 0.0 0.0 112680 976 pts/0 S+ 03:22 0:00 grep --color=auto nginx
  10. [root@localhost ~] # netstat -lntp
  11. Active Internet connections (only servers)
  12. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  13. tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 63834/dovecot
  14. tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 63834/dovecot
  15. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 72338/nginx: master
  16. tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 72338/nginx: master
  17. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1482/sshd
  18. tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 64100/dispatch.fcgi
  19. tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 64328/master
  20. tcp6 0 0 :::3306 :::* LISTEN 62442/mysqld
  21. tcp6 0 0 :::80 :::* LISTEN 72338/nginx: master
  22. tcp6 0 0 :::22 :::* LISTEN 1482/sshd
  23. [root@localhost ~] #

然后到windows上訪問你服務器IP的8080端口:
CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問

extman的登錄賬戶為root@extmail.org密碼為extmail*123*,首次使用需要先添加域,添加之后再修改域,改為可自由注冊,再注冊用戶就可以登錄發郵件了:
CentOS7下搭建postfix郵箱服務器並實現extmail的web訪問

 

 

本文轉自 ZeroOne01 51CTO博客,原文鏈接:http://blog.51cto.com/zero01/2064693,如需轉載請自行聯系原作者


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM