NỘI DUNG
⚠️ Lưu ý: CentOS 7 đã ngừng hỗ trợ CentOS 7 đã chính thức ngừng hỗ trợ vào ngày 30 tháng 6 năm 2024 và không còn nhận bản vá bảo mật. Bạn không nên cài đặt hệ thống mới trên CentOS 7. Giải pháp thay thế là chuyển sang AlmaLinux, Rocky Linux hoặc Ubuntu LTS, xem chi tiết tại CentOS 7 End of Life: Lựa chọn nào sẽ thay thế?. Nội dung bên dưới vẫn giữ nguyên để tham khảo cho hệ thống cũ đang chạy CentOS 7. |
Mail Server là một trong những Máy chủ quan trọng và quan trọng đối với mọi tổ chức vì hầu hết các giao tiếp kinh doanh chỉ được thực hiện qua email. Trong thế giới nguồn mở có một vài máy chủ email miễn phí nhưng Zimbra là một trong những máy chủ thư hàng đầu. Máy chủ thư Zimbra a.k.a ZCS (Bộ cộng tác Zimbra) có hai phiên bản, Nguồn mở và phiên bản doanh nghiệp.
Và bài viết này mình sẽ hướng dẫn bạn thực hiện cài đặt một máy chủ mail riêng cho công ty, doanh nghiệp của bạn.

Bước 1: Cập nhật bản ghi mail
Để phục vụ cho việc cài đặt. Bạn hãy trỏ bản ghi mail như sau trước nhé. Bên dưới là 2 bản ghi và mẫu của mình.
| Type | Name | Value | TTL |
| MX | @ or domain | mail.domain | Auto |
| A | ip-server | Auto |

Bước 2: Kiểm tra và cập nhật hệ thống
Bước đầu tiên bạn cần kiểm tra SELINUX xem có đang bật không, nếu đang bật thì bạn tắt đi.
# vi /etc/selinux/config SELINUX=disabled
[root@mail ~]# sestatus
SELinux status: disabled

Thực hiện stop postfix và remove postfix.
Postfix là một phầm mềm nguồn mở được dùng để gửi mail (Mail Transfer Agent-MTA). Được phát hành bởi IBM với mục tiêu thay thế trình gửi mail phổ biến là sendmail. Nó được trang bị trên hệ điều hành do đó bạn hãy xoá bỏ để sử dụng dịch vụ riêng của Zimbra.
[root@mail ~]# systemctl stop postfix [root@mail ~]# yum remove postfix -y

Sau đó bạn cập nhật hệ thống bằng lệnh sau và reboot lại máy chủ để áp dụng
[root@mail ~]# yum update -y ; reboot
Bước 3: Kiểm tra và set hostname
Bạn thực hiện kiểm tra hostname và set lại hostname tương ứng
[root@mail ~]# hostnamectl set-hostname mail.dotrungquan.site [root@mail ~]# exec bash

Sau khi set hostname xong bạn thêm dòng sau vào file hosts bạn nhớ thay đổi IP bằng IP của bạn nha.
[root@mail ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
103.221.220.187 mail.dotrungquan.site
Bước 4: Cài đặt Zimbra
Bạn thực hiệ chạy lệnh sau để install Zimbra & ZCS dependencies
[root@mail ~]# yum install unzip net-tools sysstat openssh-clients perl-core libaio nmap-ncat libstdc++.so.6 wget -y
Bước tiếp theo bạn cần Download Zimbra và cài đặt. Và bạn cần tạo một thư mục zimbra để cài vào đó. Bạn cũng có thể xem các phiên bản Zimbra ở trang chủ để download nhé.
[root@mail ~]# mkdir zimbra && cd zimbra [root@mail zimbra]# wget https://files.zimbra.com/downloads/8.8.15_GA/zcs-8.8.15_GA_3869.RHEL7_64.20190918004220.tgz --no-check-certificate

Sau khi download về hoàn tất bạn tiến hành giải nén file ra
[root@mail zimbra]# tar zxpvf zcs*.tgz
Truy cập vào thư mục vừa giải nén và chạy lệnh ./install
[root@mail zimbra]# cd zcs* && ./install.sh

[root@mail zimbra]# cd zcs* && ./install.sh Operations logged to /tmp/install.log.SJIMGleG Checking for existing installation... ... zimbra-license-tools...NOT FOUND ... Do you agree with the terms of the software license agreement? [N] y Use Zimbra's package repository [Y] y Importing Zimbra GPG key Configuring package repository Checking for installable packages Found zimbra-core (local) Found zimbra-ldap (local) Found zimbra-logger (local) Found zimbra-mta (local) Found zimbra-dnscache (local) Found zimbra-snmp (local) Found zimbra-store (local) Found zimbra-apache (local) Found zimbra-spell (local) Found zimbra-memcached (repo) Found zimbra-proxy (local) Found zimbra-drive (repo) Found zimbra-imapd (local) Found zimbra-patch (repo) Select the packages to install Install zimbra-ldap [Y] y Install zimbra-logger [Y] y Install zimbra-mta [Y] y Install zimbra-dnscache [Y] y Install zimbra-snmp [Y] y Install zimbra-store [Y] y Install zimbra-apache [Y] y Install zimbra-spell [Y] y Install zimbra-memcached [Y] y Install zimbra-proxy [Y] y Install zimbra-drive [Y] y Install zimbra-imapd (BETA - for evaluation only) [N] y Install zimbra-chat [Y] y Checking required space for zimbra-core Checking space for zimbra-store Checking required packages for zimbra-store zimbra-store package check complete. Installing: ... zimbra-dnscache zimbra-snmp zimbra-store zimbra-apache zimbra-spell ... The system will be modified. Continue? [N] y Beginning Installation - see /tmp/install.log.SJIMGleG for details... ... zimbra-snmp will be installed. zimbra-store-components will be downloaded and installed. zimbra-jetty-distribution will be downloaded and installed. zimbra-mbox-conf will be installed. ... Downloading packages (11): zimbra-core-components zimbra-ldap-components zimbra-mta-components zimbra-dnscache-components zimbra-snmp-components zimbra-store-components zimbra-jetty-distribution zimbra-apache-components zimbra-spell-components zimbra-memcached zimbra-proxy-components ... Installing extra packages (3): zimbra-drive zimbra-patch zimbra-chat ...done Running Post Installation Configuration: Operations logged to /tmp/zmsetup.20191218-041840.log Installing LDAP configuration database...done. Setting defaults... DNS ERROR resolving MX for mail.dotrungquan.site It is suggested that the domain name have an MX record configured in DNS Change domain name? [Yes] Yes Create domain: [mail.dotrungquan.site] dotrungquan.site MX: mail.dotrungquan.site (103.221.220.204) Interface: 127.0.0.1 Interface: ::1 Interface: 103.221.220.187 done. Checking for port conflicts Port conflict detected: 25 (zimbra-mta) Port conflict detected: 25 (zimbra-mta) Port conflicts detected! - Press Enter/Return key to continue # Enter Main menu 1) Common Configuration: 2) zimbra-ldap: Enabled 3) zimbra-logger: Enabled 4) zimbra-mta: Enabled 5) zimbra-dnscache: Enabled 6) zimbra-snmp: Enabled 7) zimbra-store: Enabled +Create Admin User: yes +Admin user to create: admin@dotrungquan.site ******* +Admin Password UNSET ## Chưa set password nên hiện UNSET +Anti-virus quarantine user: virus-quarantine.eu5lddmo4o@mail.dotrungquan.site +Enable automated spam training: yes +Spam training user: spam.9zr3tkfgx@mail.dotrungquan.site +Non-spam(Ham) training user: ham.xppyw1ac0x@mail.dotrungquan.site +SMTP host: mail.dotrungquan.site +Web server HTTP port: 8080 +Web server HTTPS port: 8443 +Web server mode: https +IMAP server port: 7143 +IMAP server SSL port: 7993 +POP server port: 7110 +POP server SSL port: 7995 +Use spell check server: yes +Spell server URL: http://mail.dotrungquan.site:7780/aspell.php +Enable version update checks: TRUE +Enable version update notifications: TRUE +Version update notification email: admin@dotrungquan.site +Version update source email: admin@dotrungquan.site +Install mailstore (service webapp): yes +Install UI (zimbra,zimbraAdmin webapps): yes 8) zimbra-spell: Enabled 9) zimbra-proxy: Enabled 10) zimbra-imapd: Enabled 11) Default Class of Service Configuration: s) Save config to file x) Expand menu q) Quit Address unconfigured (**) items (? - help) 7 Store configuration 1) Status: Enabled 2) Create Admin User: yes 3) Admin user to create: admin@dotrungquan.site ** 4) Admin Password UNSET 5) Anti-virus quarantine user: virus-quarantine.eu5lddmo4o@mail.dotrungquan.site 6) Enable automated spam training: yes 7) Spam training user: spam.9zr3tkfgx@mail.dotrungquan.site 8) Non-spam(Ham) training user: ham.xppyw1ac0x@mail.dotrungquan.site 9) SMTP host: mail.dotrungquan.site 10) Web server HTTP port: 8080 11) Web server HTTPS port: 8443 12) Web server mode: https 13) IMAP server port: 7143 14) IMAP server SSL port: 7993 15) POP server port: 7110 16) POP server SSL port: 7995 17) Use spell check server: yes 18) Spell server URL: http://mail.dotrungquan.site:7780/aspell.php 19) Enable version update checks: TRUE 20) Enable version update notifications: TRUE 21) Version update notification email: admin@dotrungquan.site 22) Version update source email: admin@dotrungquan.site 23) Install mailstore (service webapp): yes 24) Install UI (zimbra,zimbraAdmin webapps): yes Select, or 'r' for previous menu [r] 4 Password for admin@dotrungquan.site (min 6 characters): [n4JFxQ8fNn] n4JFxQ8fNn 1) Status: Enabled 2) Create Admin User: yes 3) Admin user to create: admin@mail.dotrungquan.site 4) Admin Password set # Đã set password 5) Anti-virus quarantine user: virus-quarantine.eu5lddmo4o@mail.dotrungquan.site 6) Enable automated spam training: yes 7) Spam training user: spam.9zr3tkfgx@mail.dotrungquan.site 8) Non-spam(Ham) training user: ham.xppyw1ac0x@mail.dotrungquan.site 9) SMTP host: mail.dotrungquan.site 10) Web server HTTP port: 8080 Select, or 'r' for previous menu [r] r *** CONFIGURATION COMPLETE - press 'a' to apply Select from menu, or press 'a' to apply config (? - help) a Save configuration data to a file? [Yes] yes The system will be modified - continue? [No] yes ....... The VERSION of zcs installed (8.8.10_GA_3039_RHEL7_64) The ADMIN EMAIL ADDRESS created (admin@dotrungquan.site) Notify Zimbra of your installation? [Yes] yes Notifying Zimbra of installation via http://www.zimbra.com/cgi-bin/notify.cgi?VER=8.8.10_GA_3039_RHEL7_64&MAIL=admin@mail.dotrungquan.site Notification complete Checking if the NG started running...done. Setting up zimbra crontab...done. Moving /tmp/zmsetup.20191218-041840.log to /opt/zimbra/log Configuration complete - press return to exit [root@mail zcs-8.8.10_GA_3039.RHEL7_64.20180928094617]#
Khi cài đặt xong bạn hãy khởi động lại dịch vụ Zimbra bằng lệnh sau
[root@mail ~]# su zimbra [zimbra@mail root]$ zmcontrol restart

Bước 5: Mở Port Firewall
Như vậy là đã hoàn tất rồi nhé, nếu máy chủ bạn có cài Firewall bạn cần mở các port sau ra để email hoạt động
- Dưới đây là các Port bạn cần mở
25,80,110,143,443,465,587,993,995,5222,5223,9071,7071
firewall-cmd --permanent --add-port={25,80,110,143,443,465,587,993,995,5222,5223,9071,7071}/tcp
firewall-cmd --reloadSau đó bạn truy cập admin zimbra bằng IP:port qua giao thức https nhé
- VD: https://103.221.220.187:7071/


Chúc bạn thực hiện thành công. Nếu cần triển khai hệ thống mail hãy liên hệ với mình nhé.
Nếu bạn phát hiện nội dung cũ, sai lệch hoặc cần cập nhật, vui lòng cho chúng tôi biết.
Báo cáo của bạn đã được gửi. Quản trị viên sẽ xem xét và cập nhật bài viết.
Với kinh nghiệm thực chiến từ việc tiếp xúc hàng ngày với vô vàn vấn đề về Website, Hosting, VPS, Server tại Phòng Kỹ thuật AZDIGI, mình luôn ấp ủ niềm đam mê chia sẻ kiến thức.
Mình xây dựng các blog không chỉ để tự trau dồi kỹ năng mà còn để cung cấp những tài liệu, hướng dẫn hữu ích nhất đến cộng đồng. Rất mong nhận được sự quan tâm của các bạn!
Để lại thông tin, mình sẽ phản hồi ngay.


27 comments
Đang tìm hiểu cài đặt thằng này cho công ty bên mình, cảm ơn bạn
Hi, chúc bạn thành công. Việc cài đặt không khó lắm đâu bạn. Kiểm soát vận hành vài trăm user mới khó thôi.
Mình cài xong rồi, chạy rồi. Nhưng không hiểu gửi ra và gửi vào không được.
Check port thấy ko có mở port 25. Mặc dù đã mở port trên firewall
*** CONFIGURATION COMPLETE – press ‘a’ to apply
Select from menu, or press ‘a’ to apply config (? – help) a
Save configuration data to a file? [Yes] yes
Save config in file: [/opt/zimbra/config.11467] yes
Saving config in yes…done.
The system will be modified – continue? [No] yes
Operations logged to /tmp/zmsetup.20210826-091413.log
Setting local config values…done.
Initializing core config…Setting up CA…failed.
[root@mail zcs-8.8.10_GA_3039.RHEL7_64.20180928094617]#
Select, or ‘r’ for previous menu [r] 4
Password for admin@ji-pi.vn (min 6 characters): [QH9Wb2rdEm] 123Abc!@#
Store configuration
1) Status: Enabled
2) Create Admin User: yes
3) Admin user to create: admin@ji-pi.vn
4) Admin Password set
5) Anti-virus quarantine user: virus-quarantine.swxwf7xe4m@ji-pi.vn
6) Enable automated spam training: yes
7) Spam training user: spam.2mm2qafuxl@ji-pi.vn
8) Non-spam(Ham) training user: ham.ivwujec5z@ji-pi.vn
9) SMTP host: mail.ji-pi.vn
10) Web server HTTP port: 8080
11) Web server HTTPS port: 8443
12) Web server mode: https
13) IMAP server port: 7143
14) IMAP server SSL port: 7993
15) POP server port: 7110
16) POP server SSL port: 7995
17) Use spell check server: yes
18) Spell server URL: http://mail.ji-pi.vn:7780/aspell.php
19) Enable version update checks: TRUE
20) Enable version update notifications: TRUE
21) Version update notification email: admin@ji-pi.vn
22) Version update source email: admin@ji-pi.vn
23) Install mailstore (service webapp): yes
24) Install UI (zimbra,zimbraAdmin webapps): yes
Select, or ‘r’ for previous menu [r] r
Main menu
1) Common Configuration:
2) zimbra-ldap: Enabled
3) zimbra-logger: Enabled
4) zimbra-mta: Enabled
5) zimbra-dnscache: Enabled
6) zimbra-snmp: Enabled
7) zimbra-store: Enabled
8) zimbra-spell: Enabled
9) zimbra-proxy: Enabled
10) zimbra-imapd: Enabled
11) Default Class of Service Configuration:
s) Save config to file
x) Expand menu
q) Quit
*** CONFIGURATION COMPLETE – press ‘a’ to apply
Select from menu, or press ‘a’ to apply config (? – help) a
Save configuration data to a file? [Yes] yes
Save config in file: [/opt/zimbra/config.5348] /opt/zimbra/config.5348
Saving config in /opt/zimbra/config.5348…done.
The system will be modified – continue? [No] yes
Operations logged to /tmp/zmsetup.20210826-134900.log
Setting local config values…done.
Initializing core config…Setting up CA…failed.
[root@mail zcs-8.8.10_GA_3039.RHEL7_64.20180928094617]#
Giờ mới thấy cmt của bạn. Lỗi này bạn chỉ cần xoá bỏ gói zimbra-openjdk sau đó chạy cài lại là được nha.
rpm -e zimbra-openjdk
Cám ơn bạn rất nhiều
Mình đã tạo xong mỗi tội gửi thư ko thấy nhận, mình không mở duy nhất 1 port 80, do trùng port và mình chỉ có 1 miền free duy nhất khi mua firewall hãng tặng
Nguyên nhân không nhận được thư có phải do port80 không mở hoặc sai múi giờ trên cent0s7 ko nhỉ.
Bạn vào admin zimbra xem dịch vụ MTA có chạy k nha. Đồng thời bạn mở các port như bài viêtd mình HD. Nếu nhà cung cấp có fire riêng bạn cần nhờ họ mở thì mới gửi nhận thư được.
Song song ở tên miền phải cấu hình MX. SPF,DKIM nữa nhé.
Mình chuyển sang IP mới thì bị báo lỗi như vầy khi khởi động lại zimbra: Failed to start slapd. Attempting debug start to determine error.
61c96b9c daemon: bind(7) failed errno=99 (Cannot assign requested address)
61c96b9c slap_open_listener: failed on ldap
Bạn xem HD này để fix thử nhé.
https://dotrungquan.info/fix-loi-unable-to-start-tls-ssl-connect-attempt-failed-error1416f086-tren-zimbra/
Chào Quân, mình không thể vào được web UI cho admin, mình không rõ bị lỗi gì mặc dù các status dịch vụ đều ok cả
Bạn hãy gửi ảnh lỗi để em xem thử nhé. Ngoài ra bạn netstat xem port 7071 có chạy không nha.
Mình gửi ảnh lỗi nhé, ngoài ra đây là kết quả netstat
[root@mail phuva]# netstat -an|grep 7071|grep LISTEN
tcp 0 0 0.0.0.0:7071 0.0.0.0:* LISTEN
Kiểm tra lại DNS thử bạn
mình check không ra DNS: https://www.dnswatch.info/dns/dnslookup?la=en&host=mail.servertest.com&type=A&submit=Resolve
cái mail.servertest.com này không phải DNS public, mình để nội bộ bn ạ
mình mới kiểm tra lại, hoá ra là thiếu https, cảm ơn bạn nhiều nhé
mình có thể xin info facebook, zalo, tele … của bạn để tiện trao đổi không, cảm ơn bạn
Mình setup thì đã nhận dc email ok rồi, nhưng send email thì báo lỗi blocked
<thanhtung1308@gmail.com>: host gmail-smtp-in.l.google.com[142.251.10.27] said:
550-5.7.1 [103.160.84.21 12] Our system has detected that this message
is 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to
Gmail, 550-5.7.1 this message has been blocked. Please visit 550-5.7.1
https://support.google.com/mail/?p=UnsolicitedMessageError 550 5.7.1 for
more information. d127-20020a636885000000b003fd8a0059a5si7249115pgc.316 –
gsmtp (in reply to end of DATA command)
Bác cấu hình thêm PTR nữa là được nhé.
Mình có thể cài nhiều mail server cho nhiều domain trên cùng 1 VPS được không bạn?
Được bạn nhé. Bạn có thể sử dụng nhiều domain trên cùng 1 máy chủ mail zimbra
Bạn ơi cho mình hỏi: Hiện mình đã cấu hình được Mail Server và có thể gửi mail qua lại với nhau trong Domian đã tạo. Giờ mình muốn có thể gửi mail ra ngoài như sang gmail hay nhiều mail khác thì giờ mình cần tiếp tục cấu hình gì ạ?
Mình cảm ơn
Điều kiện để gửi ra ngoài ổn định thì bạn cần kiểm tra các phần này nha
Cho mình hỏi thêm chút là: Mô hình hệ thống bên mình là có 1 firewall đứng giữa mọi kết nối internet, mọi thiết bị muốn ra mạng đều phải đi qua nó. Giờ con mail server của mình đứng sau con firewall này thì làm sao để cấu hình đúng IP record DNS trỏ về đúng Mail Server đó ( IP Public thì nó sẽ trỏ về IP của firewall, mình không biết NAT như thế nào để có thể trỏ đúng, đi qua firewall để tới Mail Server)
Mình cảm ơn
Xin chào bạn Quân. Mình làm theo hướng dẫn của bạn nhưng đang bị lỗi ở đoạn này, nhờ bạn chỉ giúp. Ip Mail Server mình là 222.252.8.99.
———
Create domain: [mail.fccvn.click] fccvn.click
MX: mail.fccvn.click (222.252.8.99)
Interface: 127.0.0.1
Interface: ::1
Interface: 192.168.88.61
Interface: 192.168.122.1
DNS ERROR – none of the MX records for fccvn.click
resolve to this host
———-
File /etc/hosts mình đã cấu hình:
———-
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
222.252.8.99 mail.fccvn.click
———
Mình cũng gặp lỗi này, không biết bạn đã có các khắc phục chưa ạ
Có thể chia sẻ cách giải quyết không ạ
mình cảm ơn
Bạn xem HD này cài thử nhé. Cài trên Ubuntu 20.04 ấy. Với cách này sẽ sử dụng dnsmasq nên không gặp lỗi trên nữa.
https://dotrungquan.info/huong-dan-cai-dat-zimbra-tren-ubuntu-20-04/