1. 程式人生 > 實用技巧 >iredmail郵件系統離線搭建手冊-從零到無

iredmail郵件系統離線搭建手冊-從零到無

--時間:2020年10月20日

--作者:飛翔的小胖豬

概述

前言

iRedMail 是一個基於 Linux/BSD 系統的零成本、功能完備、成熟的郵件伺服器解決方案。iRedMail 是一個開源、免費的專案。以 GPL(v2)協議釋出。

文件初衷

在我實際生產環境中需要搭建一套郵件伺服器,百度了一下聽說iredmail不錯,一步一步來唄。大致流程如下:

1.先在自己環境下做測試,如果能成功再搞到生產環境中。

2.開啟其官方網站根據自己實際的裝置環境(作業系統)找到合適的安裝步驟。(儘量要英文手冊)

3.根據你所看到的步驟提示一步一步的走,然後就安裝好了。這有一個前提你的安裝環境必須與網際網路相通。

4.通過觀察iredmail的安裝實時提示資訊發現他會去網際網路中下載很多東西,可我的內網環境不能連通網際網路呀。看了一下官網上又沒有提供離線安裝包下載,好吧看來要消耗一波腦細胞了。

5.通過一整天的各種嘗試終於然我找到一套可行的離線安裝方式。

環境準備

系統及軟體:

資料準備:

安裝包下載:

該安裝包是由本人從iredmail官網上下載的檔案然後製作的離線安裝軟體包。現放在百度網盤中,該篇文件也是使用該包來完成安裝的。

連結:https://pan.baidu.com/s/1yaOS8CciAjFjeN5IHIW3-w
提取碼:wowb

ps:可能只適用與centos 7.6+iredmail-1.3.1的環境,其他作業系統及軟體版本也沒測過。

包檔案說明:

軟體包主要分為4塊。

.官網軟體包:iRedMail-1.3.1.tar.gz + misc

.安裝所需的epel源中的rpm檔案:yum_down_soft.tar.gz

.cvd病毒庫:cvd

.python2及3的各種必要模組:python

步驟

安裝配置作業系統

安裝作業系統

作業系統安裝這一步就不介紹了,請自行百度謝謝!!!切記我用的是Centos 7.6的系統,安裝軟體選擇最簡潔的最小化安裝即可。

配置系統

進入到作業系統過後需要關閉selinux及firewalld,同時要設定機器主機名、掛載本地repo映象。

(網路配置這些基礎配置自行百度)

.設定主機名

1.#使用名設定主機名為我們事先規劃好的名字
[root@test1 ~]# hostnamectl set-hostname test1.mail.com [root@test1 ~]#
hostname
test1.mail.com


2.修改/etc/hosts檔案把主機名新增到文字中,需要新增到最前面
[root@test1 ~]# vim /etc/hosts

127.0.0.1 test1.mail.com localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

.關閉selinux

1.命令臨時設定selinux為只記錄
[root@test1 ~]# setenforce 0 [root@test1 ~]# getenforce Disabled

2.修改/etc/selinux/config檔案中的SELINUX=enforcing為SELINUX=disabled
[root@test1 ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

.關閉firewalld

#停止firewalld服務同時設定其開機不自動啟動,設定不能被其他應用呼叫。
[root@test1 ~]# systemctl stop firewalld [root@test1 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@test1 ~]# systemctl mask firewalld

.掛載本地光碟映象

#掛載本地光碟到/mnt目錄中
[root@test1 ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
#刪除/etc/yum.repos.d/下系統自帶的repo檔案
[root@test1 ~]# cd /etc/yum.repos.d/
[root@test1 yum.repos.d]# rm -rf CentOS-*
#新建編輯一個名為local_yum.repo的yum原始檔
[root@test1 ~]# vim /etc/yum.repos.d/local_yum.repo
[yum_local]
name=yum_local
enabled=1
gpgcheck=0
baseurl=file:///mnt/
[root@test1 yum.repos.d]# yum clean all
[root@test1 yum.repos.d]# yum makecache
[root@test1 yum.repos.d]# yum repolist

準備安裝環境

解壓檔案

通過本人分享的百度連結下載得到安裝軟體包,然後解壓到根目錄下。

1.解壓總的安裝包
[root@test1 ~]# ll /iredmail.tar.gz -rw-r--r-- 1 root root 487738299 Oct 20 11:47 /iredmail.tar.gz [root@test1 ~]# [root@test1 ~]# [root@test1 ~]# tar -zxvf /iredmail.tar.gz -C / #解壓壓縮包到根目錄下
[root@test1 ~]# cd /soft
[root@test1 soft]# ll
total 194128
drwxr-xr-x 2 root root 59 Oct 20 11:42 cvd
-rw-r--r-- 1 root root 232203 Oct 16 08:47 iRedMail-1.3.1.tar.gz
drwxr-xr-x 2 root root 226 Oct 20 11:44 misc
drwxr-xr-x 4 root root 56 Oct 20 11:43 python
-rw-r--r-- 1 root root 198550344 Oct 19 16:50 yum_down_soft.tar.gz

2.解壓rpm軟體包。
[root@test1 soft]# tar -zxvf yum_down_soft.tar.gz

3.解壓iredmail檔案
[root@test1 soft]# tar -zxvf iRedMail-1.3.1.tar.gz
[root@test1 soft]# ll
total 194152
drwxr-xr-x 2 root root 59 Oct 20 11:42 cvd
drwxr-xr-x 10 root root 193 Sep 22 05:34 iRedMail-1.3.1
-rw-r--r-- 1 root root 232203 Oct 16 08:47 iRedMail-1.3.1.tar.gz
drwxr-xr-x 2 root root 226 Oct 20 11:44 misc
drwxr-xr-x 4 root root 56 Oct 20 11:43 python
drwxr-xr-x 3 root root 20480 Oct 18 23:32 yum_down_soft
-rw-r--r-- 1 root root 198550344 Oct 19 16:50 yum_down_soft.tar.gz

修改部分指令碼

在iredmail安裝指令碼中會自動生成一個sogo的repo檔案每次。在外網環境下他會通過自動生成的repo檔案去找到需要的包並進行下載。在內網中則會因為無法連線外網而安裝報錯。

我們需要修改其自動生成repo的語句改為我們本地的路徑。

在/soft/iRedMail-1.3.1/functions/packages.sh檔案中註釋掉baseurl=${SOGO_PKG_MIRROR}/SOGo/nightly/${SOGO_VERSION}/rhel/${DISTRO_VERSION}/\$basearch行(大概在檔案的408行左右),然後新增一行新資料指定生成的repo路徑為本地路徑。
[root@test1 soft]# vim /soft/iRedMail-1.3.1/functions/packages.sh
cat > ${YUM_REPOS_DIR}/sogo.repo <<EOF
[SOGo]
name=Inverse SOGo Repository
enabled=1
gpgcheck=0

# SOGo v3 stable release.
# WARNING: A proper support contract from Inverse is required:
# https://sogo.nu/support/index.html#support-plans
#baseurl=${SOGO_PKG_MIRROR}/SOGo/release/${SOGO_VERSION}/rhel/${DISTRO_VERSION}/\$basearch

# SOGo v3 nightly builds
#baseurl=${SOGO_PKG_MIRROR}/SOGo/nightly/${SOGO_VERSION}/rhel/${DISTRO_VERSION}/\$basearch #被註釋掉的行
baseurl=file:///soft/yum_down_soft #新新增的行,根據前文所知我的rpm包放在/soft/yum_down_soft目錄下
EOF

拷貝軟體到指定位置

拷貝安裝過程中的軟體到指定的位置,如果沒有相關資料夾請自行建立。
拷貝/soft/misc目錄到/soft/iRedMail-1.3.1/pkgs/
[root@test1 soft]# cp -rp /soft/misc /soft/iRedMail-1.3.1/pkgs/
[root@test1 soft]# ll /soft/iRedMail-1.3.1/pkgs/misc/ #確認複製成功
total 42972
-rw-r--r-- 1 root root 395656 Oct 20 11:44 iRedAdmin-1.0.tar.bz2
-rw-r--r-- 1 root root 102870 Oct 20 11:44 iRedAPD-4.3.tar.gz
-rw-r--r-- 1 root root 1849829 Oct 20 11:44 libsodium-1.0.18-stable.tar.gz
-rw-r--r-- 1 root root 40622 Oct 20 11:44 mlmmjadmin-3.0.tar.gz
-rwxr-xr-x 1 root root 34464172 Oct 20 11:44 netdata-v1.23.1.gz.run
-rw-r--r-- 1 root root 7031947 Oct 20 11:44 roundcubemail-1.4.7-complete.tar.gz
-rw-r--r-- 1 root root 105522 Oct 20 11:44 webpy-0.51.tar.gz

正式安裝iredmail

一切準備就緒那就可以安裝了,安裝的步驟和官網的一模一樣但有幾部又有不同。建議開啟兩個終端,一個用來安裝iredmail一個cd到/etc/yum.repos.d目錄下準備修改repo檔案。

[root@test1 ~]# cd /soft/iRedMail-1.3.1/
[root@test1 iRedMail-1.3.1]# bash iRedMail.sh
然後就是大帕拉的各種提示,此時應該會報錯如下:
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:

yum-config-manager --save --setopt=iRedMail.skip_if_unavailable=true

failure: repodata/repomd.xml from iRedMail: [Errno 256] No more mirrors to try.
https://dl.iredmail.org/yum/rpms/7/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: dl.iredmail.org; Unknown error"
[ INFO ] Checking configuration file: /soft/iRedMail-1.3.1/config ...[ INFO ] NOT FOUND. Launching installation wizard.
/soft/iRedMail-1.3.1/dialog/config_via_dialog.sh: line 44: dialog: command not found

修改/etc/yum.repos.d/iRedMail.repo為如下內容後再執行安裝。
[root@test1 ~]# vim /etc/yum.repos.d/iRedMail.repo
[iRedMail]
name=iRedMail
#baseurl=https://dl.iredmail.org/yum/rpms/$releasever/
baseurl=file:///soft/yum_down_soft
enabled=1
gpgcheck=0
#exclude=postfix*
priority=99
module_hotfixes=1
[root@test1 ~]# cd /soft/iRedMail-1.3.1/
[root@test1 iRedMail-1.3.1]# bash iRedMail.sh

直接滑鼠點選<Yes>進入下一步。

定義你的郵件儲存路徑,自定義的,如果儲存比較有空那麼可以掛一張新盤來作為郵件儲存。

選擇安裝郵件伺服器執行web服務。

郵件中的使用者管理使用mysql資料庫。

設定mysql的密碼,自定義的。

建立一個域名。

設定郵件管理員的密碼。

不管全選,具體選項功能看其後的英文註釋很清楚。

再次確認你的設定,確認無誤後輸入Y敲回車繼續安裝。

輸入了Y後,敲回車,系統會進行軟體包的安裝。

當安裝停在/etc/firewalld/zones/iredmail.xm,with SSHD ports:22. [Y|n] 行時先不要動。新開一個終端進行如下操作。

此處的命令請新開一個終端執行。
[root@test1 ~]# pip install --no-index --find-links  /soft/python/2  -r /soft/python/pip2.txt     #安裝python2的模組
[root@test1 ~]# pip3 install --no-index --find-links  /soft/python/3  -r /soft/python/pip3.txt    #安裝python3的模組


複製包內的cvd病毒庫檔案置/var/lib/clamav/下並修改所有者。
[root@test1 lib]# cp /soft/cvd/* /var/lib/clamav/ [root@test1 lib]# chown clamupdate:clamupdate /var/lib/clamav/* [root@test1 lib]# ll /var/lib/clamav/

以上的記憶體執行好了再回到之前的終端“Y”。

最後你可以類似如下的資訊,請從********************************************************************* URLs of installed web applications:處開始複製下來,或拍照,不然以後忘了。

然後根據提示重啟伺服器完成安裝。

.................................
Reading CVD header (daily.cvd): Giving up on https://database.clamav.net... ******************************************************************** * URLs of installed web applications: * * - Roundcube webmail: https://test1.mail.com/mail/ * - SOGo groupware: https://test1.mail.com/SOGo/ * - netdata (monitor): https://test1.mail.com/netdata/ * * - Web admin panel (iRedAdmin): https://test1.mail.com/iredadmin/ * * You can login to above links with below credential: * * - Username: [email protected] * - Password: 123456 * * ******************************************************************** * Congratulations, mail server setup completed successfully. Please * read below file for more information: * * - /soft/iRedMail-1.3.1/iRedMail.tips * * And it's sent to your mail account [email protected]. * ********************* WARNING ************************************** * * Please reboot your system to enable all mail services. * ********************************************************************

測試

* - Roundcube webmail: https://test1.mail.com/mail/ #郵件收發web介面,所有人可登入
* - SOGo groupware: https://test1.mail.com/SOGo/ #郵件收發web介面,所有人可登入
* - netdata (monitor): https://test1.mail.com/netdata/ #很酷炫的一個資源監控介面,使用域管理員登入。
* - Web admin panel (iRedAdmin): https://test1.mail.com/iredadmin/ #郵件管理web介面,使用域管理員登入。用作管理郵件系統,建立域、使用者什麼的。。。。

請逐一建議檢查以上這4個介面是否可用。有問題可以私信我。

總結

在內網環境無法連線網際網路時,想要在內網中部署一套需要需要各種外部包和資料的軟體及應用不是一件特別輕鬆的事。

針對這種情況一般有兩種方法。

.找到軟體的所有依賴包和所需的資料下載打包起來在安裝的過程中手動把需要的資料庫拷貝到指定的位置。

.搭建套Docker環境,在網際網路的環境中使用容器事先軟體安裝部署,然後打包容器為image,在內網環境中安裝docker環境,然後load一下之前打包好的映象,最後docker run一下就搞定了。

容器真香哈哈。

翻譯過來的中文操作文件全是坑。