CentOS6 安裝Sendmail + Dovecot + Roundcubemail


前言 

  本文是繼CentOS6 安裝Sendmail + Dovecot + Squirrelmail 關於郵箱服務器配置的第二篇文章,因為關於使用Sendmail進行相關配置的文章、資料等太老,而且資料也不全,而使用Postfix的比較容易找到完備的資料,此處不討論Sendmail和Postfix的優劣,僅僅是記錄配置過程,希望對你有幫助。

  此外,這里只是演示一個搭建本地郵箱環境,如果要投入真正使用,還需要搭建一個DNS,還得要有一個域名。這里會演示搭建本地環境的完整的一個過程,就不包括安裝虛擬機了,這篇文章跟前一篇在安裝Sendmail和Dovecot基本上是重復的,僅演示必要過程,不做過多解釋。

准備階段

1、基本命令使用

[lz@mail ~]$ sudo -i          【獲取系統root權限】
[root@mail ~]# cat /etc/issue     【查看系統發行版本】
CentOS release 6.9 (Final)
Kernel \r on an \m
[root@mail ~]# cat /etc/sysconfig/network      
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail.roundcubemail.com    【修改下主機名,重啟生效,不過不急於重啟】
[root@mail ~]# hostname
mail.roundcubemail.com         【改成你的主機名】
[root@mail lz]# cat /etc/hosts
127.0.0.1	mail.roundcubemail.com	localhost          【將主機名和域名添加到hosts文件中】
127.0.0.1	roundcubemail.com	localhost
127.0.0.1	localhost.localdomain	localhost
::1	localhost6.localdomain6	localhost6
[root@mail lz]# ping -c 1 mail.roundcubemail.com           【這樣就會自動解析成本地地址,這樣就能使用這個名字啦】
PING mail.roundcubemail.com (127.0.0.1) 56(84) bytes of data.
64 bytes from mail.roundcubemail.com (127.0.0.1): icmp_seq=1 ttl=64 time=0.073 ms
[root@mail lz]# ping -c 1 roundcubemail.com
PING roundcubemail.com (127.0.0.1) 56(84) bytes of data.
64 bytes from mail.roundcubemail.com (127.0.0.1): icmp_seq=1 ttl=64 time=0.015 ms

2、系統更新

[root@mail lz]# yum update
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Update Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.aliyun.com
No Packages marked for Update

關於系統更新就不演示過程,會比較耗時,只需一條命令即可更新。

3、關於root權限獲取

如果你在使用sudo -i獲取root權限失敗,顯示沒有sudo權限,可以通過如下方式獲取root權限

[lz@mail ~]$ su root
Password:                     【輸入lz的用戶密碼】
[root@mail lz]# vim /etc/sudoers

將你的用戶名添加到root后面,此處為lz, 保存文件之后就能正常使用sudo -i命令了。

安裝LAMP環境

1、安裝apache2

[root@mail lz]# yum install httpd 
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.aliyun.com
Package httpd-2.2.15-60.el6.centos.4.x86_64 already installed and latest version
Nothing to do
[root@mail lz]# service httpd status        【apache2默認應該是安裝好了的,但並沒有啟動】
httpd is stopped
[root@mail lz]# service httpd start         【啟動】
Starting httpd:                                            [  OK  ]
[root@mail lz]# chkconfig httpd on         【設置為開機自動啟動】

這個時候訪問虛擬機ip地址,應該就可以看到如下頁面

2、安裝PHP

因為Roundcubemail要求php > 5.3.7, 我們需要使用一個更新的源。原文參考:Centos 6.x/7.x yum安裝php5.6.X(最新版)

a) 檢查當前安裝的php包

[root@mail lz]# yum list installed | grep php

如果之前安裝過舊版本的php可以使用如下命令刪除

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64 

b) 配置yum源

追加CentOS 6.5的epel及remi源:

rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

CentOS 7.0的源:

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

查看可安裝的包:

yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

c) 安裝php5.6

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

d) 查看php版本

[root@mail lz]# php --version
PHP 5.6.31 (cli) (built: Jul  6 2017 08:16:47) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

e) 測試

[root@mail lz]# cd /var/www/html/
[root@mail html]# ls
[root@mail html]# vim info.php
[root@mail html]# cat info.php 
<?php
phpinfo();
?>

好像需要重啟一下apache

[root@mail html]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

3、安裝Mysql

一坨安裝,參考CentOS6.4+LAMP+Postfix+Dovecot+Postfixadmin+Roundcubemail 打造企業級郵件服務器 (1)  中第五步:五、安裝並配置LAMP環境

會顯示有一些錯誤,不過沒有關系...

[root@mail html]# yum -y install httpd mysql mysql-devel mysql-server php php-pecl-Fileinfo php-mcrypt php-devel php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc pcre pcre-devel

創建數據庫:roundcubemail

[root@mail html]# service mysqld start          【啟動mysql】
[root@mail html]# chkconfig mysqld on           【設置mysql開機啟動】
[root@mail html]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database roundcubemail;            【創建數據庫】
Query OK, 1 row affected (0.00 sec)

mysql> grant all on roundcubemail.* to roundcubemail@'localhost' identified by 'roundcubemail';      【賦予權限】
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

到這里LAMP安裝完成。

Sendmail 安裝和配置

1、安裝mail相關工具包 

[root@mail html]# yum install m4 telnet mailx

2、Sendmail安裝

[root@mail html]# yum install sendmail sendmail-cf

3、Sendmail配置

a) 下面將使用m4這個工具來創建sendmail.cf這個文件

[root@mail html]# netstat -an | grep :25 | grep tcp
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      
[root@mail html]# cd /etc/mail
[root@mail mail]# pwd
/etc/mail
[root@mail mail]# ls
access     aliasesdb-stamp  domaintable.db  local-host-names  mailertable.db  Makefile     sendmail.cf.bak  submit.cf  trusted-users  virtusertable.db
access.db  domaintable      helpfile        mailertable       make            sendmail.cf  sendmail.mc      submit.mc  virtusertable
[root@mail mail]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

b) 配置相關域名

在local-host-names增加域名項,表示的是可以用來發送/接收郵件的域名。

[root@mail mail]# vim /etc/mail/local-host-names 
[root@mail mail]# cat /etc/mail/local-host-names 
# local-host-names - include all aliases for your machine here.
roundcubemail.com
mail.roundcubemail.com
[root@mail mail]# service sendmail restart  
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]
[root@mail mail]# chkconfig sendmail on            [設置開機啟動]

4、Sendmail 發信測試:mail命令測試

先新建兩個用戶

[root@mail mail]# useradd user1
[root@mail mail]# useradd user2
[root@mail mail]# passwd user1
Changing password for user user1.
New password:                   【輸入密碼】
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@mail mail]# passwd user2           【輸入密碼
Changing password for user user2.
New password: 
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@mail mail]# gpasswd -a user1 mail     【加入mail用戶組】
Adding user user1 to group mail
[root@mail mail]# gpasswd -a user2 mail
Adding user user2 to group mail

用其中一個賬戶登陸,給另一個用戶發送郵件:

[root@mail mail]# su user1              【切換到user1】
[user1@mail mail]$ mail -s "hello user2" user2
This is test a mail from user1.       
.                             【.表示結束】     
EOT
[user1@mail mail]$ cat /var/mail/user2 
From user1@mail.roundcube.com  Mon Aug 14 22:28:15 2017
Return-Path: <user1@mail.roundcube.com>
Received: from mail.roundcube.com (mail.roundcubemail.com [127.0.0.1])
	by mail.roundcube.com (8.14.4/8.14.4) with ESMTP id v7EESF9P033866
	for <user2@mail.roundcube.com>; Mon, 14 Aug 2017 22:28:15 +0800
Received: (from user1@localhost)
	by mail.roundcube.com (8.14.4/8.14.4/Submit) id v7EESFmC033865
	for user2; Mon, 14 Aug 2017 22:28:15 +0800
From: user1@mail.roundcube.com
Message-Id: <201708141428.v7EESFmC033865@mail.roundcube.com>
Date: Mon, 14 Aug 2017 22:28:15 +0800
To: user2@mail.roundcube.com
Subject: hello user2
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is test a mail from user1.

5、Sendmail 發信測試: telnet方式測試

Sendmail安裝測試成功。

Dovecot安裝和配置

1、安裝相關工具包

[root@mail mail]# yum install telnet mailx mutt

2、Dovecot安裝

[root@mail mail]# yum install dovecot

3、Dovecot配置

[root@mail mail]# ls /etc/dovecot/
conf.d  dovecot.conf
[root@mail mail]# vim /etc/dovecot/dovecot.conf

[root@mail mail]# ls /etc/dovecot/conf.d/
10-auth.conf      10-master.conf  20-lmtp.conf    90-quota.conf                auth-master.conf.ext      auth-system.conf.ext
10-director.conf  10-ssl.conf     20-pop3.conf    auth-checkpassword.conf.ext  auth-passwdfile.conf.ext  auth-vpopmail.conf.ext
10-logging.conf   15-lda.conf     90-acl.conf     auth-deny.conf.ext           auth-sql.conf.ext
10-mail.conf      20-imap.conf    90-plugin.conf  auth-ldap.conf.ext           auth-static.conf.ext
[root@mail mail]# vim /etc/dovecot/conf.d/10-mail.conf

設置:mail_location = mbox:~/mail:INBOX=/var/mail/%u

[root@mail mail]# service dovecot start          【啟動】
Starting Dovecot Imap:                                     [  OK  ]
[root@mail mail]# chkconfig dovecot on           【設置開機dovecot啟動】

4、Dovecot 接收郵件測試: mutt命令

之前在測試Sendmail的時候,用user1這個賬戶向user2發送了一封郵件,通過查看本地文件進行驗證。

[root@mail ~]# mutt -f imap://user2:123456@localhost              【用戶user2  密碼:123456】

5、Dovecot接收郵件測試:telnet方式

Dovecot 安裝測試成功。

 

Roundcubemail安裝和配置

1、下載roundcubemail

roundcubemail 官網下載: https://roundcube.net/

下載完整版complete解壓到web根目錄:/var/www/html

[root@mail html]# pwd
/var/www/html
[root@mail html]# ls
info.php  roundcubemail-1.3.0
[root@mail html]# mv roundcubemail-1.3.0/ roundcubemail      【改下名字】

2、配置installer

Step 1: 

訪問地址: http://192.168.1.103/roundcubemail/installer/      【修改成你的ip】

有個小問題: 時區沒有設置,我們設置一下看看:

[root@mail html]# vim /etc/php.ini

apache服務器需要重啟一下,再次訪問正常:

但是在重啟apache的時候又會出現這樣一個問題:

可以根據提示,進行如下修改:

[root@mail html]# vim /etc/httpd/conf/httpd.conf

再次重啟正常:

Step2 :

點擊下一步,我們進入創建配置文件Create config這一步,內容項有很多,下面僅貼出重要的相關項

基本配置:

數據庫配置:roundcubemail (這個跟之前創建的數據庫相關,為了簡便,全部設置為roundcubemail)

IMAP設置: 默認即可

 SMTP設置: 默認即可

 

拉到頁面底部,點擊創建配置文件Create config

將創建好的配置文件config.inc.php放置在:/var/www/html/roundcubemail/config      【根據自己的實際情況進行相應的修改】

[root@mail html]# pwd
/var/www/html
[root@mail html]# ls
info.php  roundcubemail
[root@mail html]# cd roundcubemail/config/
[root@mail config]# ls
config.inc.php.sample  defaults.inc.php  mimetypes.php
[root@mail config]# cp /home/lz/temp/config.inc.php ./
[root@mail config]# ls
config.inc.php  config.inc.php.sample  defaults.inc.php  mimetypes.php
[root@mail config]# pwd
/var/www/html/roundcubemail/config

確定已經將配置文件放到config目錄下之后,點擊下一步:

下面一步步進行展示:

[root@mail html]# pwd
/var/www/html
[root@mail html]# ls
info.php  roundcubemail
[root@mail html]# cd roundcubemail/
[root@mail roundcubemail]# ls
bin        composer.json-dist  index.php  installer  logs     program      README.md  SQL   UPGRADING
CHANGELOG  config              INSTALL    LICENSE    plugins  public_html  skins      temp  vendor
[root@mail roundcubemail]# chmod a+w temp/       【賦予寫權限】
[root@mail roundcubemail]# chmod a+w logs/

點擊初始化按鈕之后,頁面會自動條狀成如下,要求已經ok了:

細心的同學可能會注意到在General configuration中temp_dir

temp_dir: /var/www/html/roundcubemail/temp/

和Logging & Debugging中log_dir

log_dir: /var/www/html/roundcubemail/logs/

 

測試一:

Sender: user1@mail.roundcubemail.com

Recipient: user2@mail.roundcubemail.com

主要是@后面的部分需要修改成你的配置...可以看到,這里測試ok了

測試二:

我們用user1:123456登陸測試, 驗證成功。

3、Roundcubemail 登陸測試

Webmail 登陸:

用戶名:密碼: user1/user2: 123456

發信測試:

user2給user1發送郵件:

切換成user1登陸查看郵件:

可以看到user1已經成功接收了user2發送的郵件。

至此,Sendmail + Dovecot + Roundcubemail 的環境搭建成功。 

 

References:

CentOS6 安裝Sendmail + Dovecot + Squirrelmail

Centos 6.x/7.x yum安裝php5.6.X(最新版)

CentOS6.4+LAMP+Postfix+Dovecot+Postfixadmin+Roundcubemail 打造企業級郵件服務器 (1) 


免責聲明!

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



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