Hướng dẫn cài đặt mail server zimbra trên centos 7

Bài hướng dẫn này sẽ giới thiệu đến các bạn cách setup một local mail server sử dụng Postfix, hoặc Dovecot hoặc Squirrelmail trên nền tảng CentOS 7. Và ở nội dung bài lab này, chúng ta chỉ setup “ local mail server “. Bạn sẽ không thể dùng mail server này để gửi hoặc nhận mail ra ngoài giống Yahoo Mail hoặc Gmail. Để gửi hoặc nhận mail ra ngoài, bạn cần cấu hình mail server với một IP Public, yêu cầu ISP cấu hình MX Record của mail server của bạn trên DNS của họ.

Bạn đang xem: Hướng dẫn cài đặt mail server zimbra trên centos 7

Bài Lab được thực hiện trên hệ điều hành CentOS 64 bit. Trước tiên chúng ta cần chuẩn bị hệ thống máy :


Hệ điều hành : CentOS 7 64bit minimal serverĐịa chỉ IP : 192.168.1.150/24Hostname : server1.cheohanoi.vn.local

Nào chúng ta cùng bắt đầu.

Đầu tiên, chúng ta cần phải remove bất kì MTA ( Mail Transfer Agent ) nào đang có sẵn trên máy. Với bản minimal thì mặc định sendmail không được cài đặt sẵn, vì vậy bạn có thể bỏ qua bước này.

yum remove sendmail3. Add thêm các thông tin vào file /etc/hosts :


vi /etc/hostsAdd tên miền đầy đủ ( FQDN )

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.1.150 server1.cheohanoi.vn.local server1Tiếp tục Disable SELinux để giảm độ phức tạp cấu hình postfix.Sử dụng lệnh :

vi /etc/sysconfig/selinuxĐổi SELINUX=enforcing thành SELINUX=disabled

SELINUX=disabledCài đặt Repel Repository :Squirrelmail webmail client không có sẵn trên các repository của CentOS. Vì vậy chúng ta cần enable EPEL repository :

yum install epel-releaseMở port Apache cổng 80 trên firewall/router :firewall-cmd --permanent --add-port=80/tcpSử dụng lệnh Restart Firewall :


 firewall-cmd –reloadTiến hành restart server để toàn bộ thay đổi có hiệu lực.

Cài đặt Postfix :

Postfix là một chương trình mail transfer agent miễn phí ( MTA ), opensource và hoàn toàn miễn phí. Chương trình có tốc độ nhanh, bảo mật và dễ quản trị. Trên hệ điều hành Red Hat, đây là MTA mặc định.

Tiến hành cài đặt Postfix sử dụng lệnh :

yum install postfixCấu hình Postfix :

Edit file /etc/postfix/main.cf :

vi /etc/postfix/main.cfTìm và chỉnh sửa những dòng sau :

## Line no 77 - Bỏ comment và đặt lại FQDN ##myhostname = server1.cheohanoi.vn.local## Line 85 - Bỏ comment và Set domain name ##mydomain = cheohanoi.vn.local## Line 101 - Bỏ comment ##myorigin = $mydomain## Line 115 - Bỏ comment và Set ipv4 ##inet_interfaces = all## Line 121 – chuyển thành all ##inet_protocols = all## Line 166 - Comment ###mydestination = $myhostname, localhost.$mydomain, localhost,## Line 167 - Bỏ comment ##mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain## Line 266 - Bỏ comment và add IP range ##mynetworks = 192.168.1.0/24, 127.0.0.0/8## Line 421 - Bỏ comment ##home_mailbox = Maildir/Lưu và thoát file.

Start/ Restart dịch vụ Postfix :

systemctl enable postfixsystemctl restart postfixTiến hành Test Mail server Postfix :


Đầu tiên, tạo user với tên “sk” :

 useradd skSet Password cho user :

passwd skTruy cập Server thông qua Telnet và nhập lệnh thủ công :

telnet localhost smtpLưu ý nếu máy không truy cập được Telnet thì chúng ta cần tiến hành cài thêm Telnet.

Kết quả trả về :


Trying ::1...Connected to localhost.Escape character is "^>".220 server1.cheohanoi.vn.local ESMTP Postfixehlo localhost ## nhập dòng này ##250-server1.cheohanoi.vn.local250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSNmail from: ## nhập vào địa chỉ mail gửi ##250 2.1.0 Okrcpt to: ## nhập vào địa chỉ mail nhận##250 2.1.5 Okdata ## nhập vào để chuyển đến nội dung của mail ##354 End data with .Welcome to cheohanoi.vn mail server ## nội dung của mail ##. ## đặt dấu (.) sau khi hoàn thành email ##250 2.0.0 Ok: queued as E2B522032F93quit  ## Gõ quit để thoát khỏi trình soạn##221 2.0.0 ByeConnection closed by foreign host.Tiếp theo chuyển sang hộp thư của user sk để kiểm tra xem mail đã được chuyển đến chưa.

ls /home/sk/Maildir/new/Kết quả trả về :

1437722056.Vfd01I203e3e7M938078.server1.cheohanoi.vn.localNhư vậy là chúng ta đã gửi nhận mail thành công với user “ sk ”.

Để đọc mail, nhập lệnh :

cat/home/sk/Maildir/new/1437722056.Vfd01I203e3e7M938078.server1.cheohanoi.vn.localKết quả trả về :


Return-Path: >X-Original-To: skDelivered-To: Received: from localhost (localhost )by server1.cheohanoi.vn.local (Postfix) with ESMTP id E2B522032F93for ; Fri, 24 Jul 2015 12:42:36 +0530 (IST)Message-Id: >Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST)From: Welcome to cheohanoi.vn mail serverDone. Như vậy là chúng ta đã hoàn thành cài đặt và cấu hình, gửi nhận mail thành công trên Postfix.

Cài đặt Dovecot :

Dovecot cũng là chương trình Open Source mail server POP3 và IMAP dùng cho hệ thống Linux/Unix System.

Xem thêm: 168 Ảnh Doremon Chế Hài Hước, Xem Cười Bể Bụng, Tổng Hợp Ảnh Chế Doremon Hay Nhất

Để cài đặt, chạy dòng lệnh :

yum install dovecot

Cấu hình Dovecot :

Edit file /etc/dovecot/dovecot.conf :

vi /etc/dovecot/dovecot.confBỏ comment những dòng sau :

## Line 24 – bỏ comment ##protocols = imap pop3 lmtpEdit file /etc/dovecot/conf.d/10-mail.conf :

vi /etc/dovecot/conf.d/10-mail.confThay đổi dòng :

## Line 24 – bỏ comment ##mail_location = maildir:~/MaildirEdit file /etc/dovecot/conf.d/10-auth.conf :

vi /etc/dovecot/conf.d/10-auth.confThay đổi những dòng sau :

## line 10 – bỏ comment##disable_plaintext_auth = yes## Line 100 – thêm từ: "login" ##auth_mechanisms = plain loginEdit file /etc/dovecot/conf.d/10-master.conf :

vi /etc/dovecot/conf.d/10-master.confTiến hành thay đổi dòng :

## Line 91, 92 – bỏ comment và thêm "postfix"#mode = 0600 user = postfix group = postfix<...>Tiến hành dịch vụ Dovecot :

systemctl enable dovecotsystemctl start dovecotTest Dovecot service :Nhập lệnh telnet :

telnet localhost pop3Thêm lần lượt những dòng lệnh khu vực được tô đậm :

Trying ::1...Connected to localhost.Escape character is "^>".+OK Dovecot ready.user sk ## nhập vào mail username ##+OKpass centos ## nhập vào password ##+OK Logged in.retr 1 ## nhập lệnh để xem mail ##+OK 415 octetsReturn-Path: >X-Original-To: skDelivered-To: Received: from localhost (localhost )by server1.cheohanoi.vn.local (Postfix) with ESMTP id E2B522032F93for ; Fri, 24 Jul 2015 12:42:36 +0530 (IST)Message-Id: >Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST)From: Welcome to cheohanoi.vn mail server.quit ## Type "quit" to exit ##+OK Logging out.Connection closed by foreign host.Với kết quả bên trên, Dovecot đã hoạt động.

Install Squirrelmail :

Đối với người dùng bình thường, thì việc gửi và nhận mail bằng command line xem ra rất khó khăn. Sẽ dễ dàng hơn cho họ nếu có giao diện đồ họa. Squirrelmail được xem là giải pháp hoàn hảo khắc phục những nhược điểm của việc gửi nhận mail bằng command line.

Trước tiên, đảm bảo rằng bạn đã cài đặt và enable EPEL repository.

Sau đó, cài đặt Squirrelmail bằng dòng lệnh :

yum install squirrelmail

Cấu hình Squirrelmail :

Di chuyển đến thư mục /usr/share/squirrelmail/config/

cd /usr/share/squirrelmail/config/và chạy dòng lệnh để mở và cấu hình Squirrelmail :

./conf.plBảng lựa chọn sẽ hiển thị, nhấn phím “1” để thiết lập chi tiết :

SquirrelMail Configuration : Read: config.php (1.4.0)---------------------------------------------------------Main Menu --Organization PreferencesServer SettingsFolder DefaultsGeneral OptionsThemesAddress BooksMessage of the Day (MOTD)PluginsDatabaseLanguagesSet pre-defined settings for specific IMAP serversC Turn color offS Save dataQ QuitCommand >> 1Bảng Wizard kế tiếp sẽ hiển thị, chọn “ 1 “ tiếp tục để thiết lập thông tin tổ chức :

SquirrelMail Configuration : Read: config.php (1.4.0)

———————————————————

Organization Preferences

Organization Name : SquirrelMailOrganization Logo : ../images/sm_logo.pngOrg. Logo Width/Height : (308/111)Organization Title : SquirrelMail $versionSignout Page :Top Frame : _topProvider link : http://squirrelmail.org/Provider name : SquirrelMailR Return to Main MenuC Turn color offS Save dataQ QuitCommand >> 1Đặt tên tổ chức của bạn và chọn Enter :

We have tried to make the name SquirrelMail as transparent aspossible. If you set up an organization name, most places whereSquirrelMail would take credit will be credited to your organization.If your Organization Name includes a "$", please precede it with a \.Other "$" will be considered the beginning of a variable thatmust be defined before the $org_name is printed.$version, for example, is included by default, and will print thestring representing the current SquirrelMail version.: cheohanoi.vnTương tự, thiết lập tiếp các thông tin khác như Title, Logo, nhà cung cấp tên miền ở bảng bên dưới. Một khi đã hoàn thành, bấm nút “ S “ để lưu lại thay đổi, và bấm “ R “ để trở về menu chính :

SquirrelMail Configuration : Read: config.php (1.4.0)---------------------------------------------------------Organization PreferencesOrganization Name : cheohanoi.vnOrganization Logo : ../images/sm_logo.pngOrg. Logo Width/Height : (308/111)Organization Title : SquirrelMail $versionSignout Page :Top Frame : _topProvider link : http://squirrelmail.org/Provider name : cheohanoi.vn MailR Return to Main MenuC Turn color offS Save dataQ QuitCommand >> STiếp theo, bấm “ 2 “ , để setup cho mail server các thông số như domain name, mail agent…

SquirrelMail Configuration : Read: config.php (1.4.0)---------------------------------------------------------Main Menu --Organization PreferencesServer SettingsFolder DefaultsGeneral OptionsThemesAddress BooksMessage of the Day (MOTD)PluginsDatabaseLanguagesSet pre-defined settings for specific IMAP serversC Turn color offS Save dataQ QuitCommand >> 2Chọn “ 1 “, nhập vào domain name của bạn ( VD : cheohanoi.vn.local ), và bấm Enter :

SquirrelMail Configuration : Read: config.php (1.4.0)---------------------------------------------------------Server SettingsGeneral-------Domain : localhostInvert Time : falseSendmail or SMTP : SendmailUpdate IMAP Settings : localhost:143 (uw)Change Sendmail Config : /usr/sbin/sendmailR Return to Main MenuC Turn color offS Save dataQ QuitCommand >> 1The domain name is the suffix at the end of all email addresses. Iffor example, your email address is , then your domainwould be example.com.: cheohanoi.vn.localChọn “ 3 “ để chuyển từ Sendmail sang Postfix MTA :

SquirrelMail Configuration : Read: config.php (1.4.0)---------------------------------------------------------Server SettingsGeneral-------Domain : cheohanoi.vn.localInvert Time : falseSendmail or SMTP : SendmailUpdate IMAP Settings : localhost:143 (uw)Change Sendmail Config : /usr/sbin/sendmailR Return to Main MenuC Turn color offS Save dataQ QuitCommand >> 3Nhấn “ 2 “ để chuyển từ sendmail MTA sang Postfix :

You now need to choose the method that you will use for sendingmessages in SquirrelMail. You can either connect to an SMTP serveror use sendmail directly.SendmailSMTPYour choice <1/2> <1>: 2Xong chúng ta nhấn “ S “ tiếp theo là “ Q “ để save và exit bảng cấu hình Squirrelmail.

Tạo một squirrelmail vhost trong file httpd.conf

vi /etc/httpd/conf/httpd.conftại cuối file, thêm vào những dòng này :

Alias /webmail /usr/share/squirrelmailOptions Indexes FollowSymLinksRewriteEngine OnAllowOverride AllDirectoryIndex index.phpOrder allow,denyAllow from allRestart lại Apache Server :

systemctl restart httpdTạo mail user :

Chúng ta cần tạo user để test thử mail server. Ở đây người viết tạo 2 user “senthil“ và “kumar“.

useradd senthilpasswd senthiluseradd kumarpasswd kumar

Truy cập Webmail :

Vào trình duyệt gõ http://ip-address/webmail hoặc http://domain-name/webmail :

Trang đăng nhập sẽ hiển thị. Nhập vào Username và Password của User mà chúng ta đã tạo ở trên :

*

Vậy là bây giờ bạn đã có thể truy cập được vào mail box :

*

Gửi thử mail :

Chúng ta sẽ tiến hành gửi mail từ user “senthil“ đến User “kumar“. Click vào link Compose ở trên đầu menu. Nhập vào địa chỉ Mail nhận (), tạo nội dung, chủ đề cho mail và gửi.

*

Tiếp theo, log out khỏi user “senthil“ và Logon vào user “kumar“ để check mail đã đến chưa.

*

Như đã thấy, vậy là đã có mail từ user nằm trong inbox

Để đọc mail, bấm vào nó. Chúng ta có thể đọc, trả lời, xóa, hoặc gửi một mail mới.

*

Như vậy là chúng ta đã hoàn thành xong việc cài đặt và cấu hình gửi nhận mail trên hệ điều hành CentOS 7. Mail server này sẽ phục vụ cho việc gửi nhận mail của User trong hệ thống mạng Lan. Hy vọng bài viết sẽ giúp ích được cho bạn.

cài mail server trên centoscài mail server cho localhostcài đặt mail servercài đặt mail server trên centos 7cài đặt mail server nội bộmail server freemail server postfix dovecot squirrelmailmail server postfix centos 7