Home > Tiếng Việt > Hướng Dẫn (Tutorials) > Hướng dẫn cài đặt postfix, dovecot và squirrelmail trên centos(web mail)

Hướng dẫn cài đặt postfix, dovecot và squirrelmail trên centos(web mail)

Chuẩn bị 

1 vps thông số

DOMAiN=maxserver.net

IP=107.189.160.7

GATEWAY=107.189.160.1

NETMASK=255.255.255.192

Cài đặt thêm kho epel. Tham khảo link Click here

Cài đặt LAMP. Tham khảo link Click here Click here

Tắt tạm iptables 

# service iptables stop

Tắt selinux ,sửa file selinux

# nano /etc/sysconfig/selinux 

Sửa SELINUX=disabled

# reboot để khởi động lại máy

Cấu hình mạng

# nano /etc/sysconfig/network-scripts/ifcfg-eth0

# Generated by SolusVM
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=107.189.160.7
GATEWAY=107.189.160.1
NETMASK=255.255.255.192
DNS1=107.189.160.7
DNS2=107.189.160.1
DNS3=8.8.8.8

# service network restart

# chkconfig network on

Cấu hình file /etc/hosts, /etc/resolv.conf và hostname sửa nội dung như sau

# nano /etc/hosts

# Generated by SolusVM
127.0.0.1       localhost
107.189.160.7   mail.maxserver.net mail

 

# nano /etc/resolv.conf

# Generated by SolusVM
search maxserver.net
nameserver 107.189.160.7
nameserver 107.189.160.1
nameserver 8.8.8.8

 

Đổi tên hostname trong  /etc/sysconfig/network

# nano /etc/sysconfig/network

# Generated by SolusVM
NETWORKING=yes
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no
HOSTNAME=mail.maxserver.net

Khởi động lại server

# reboot

Cấu hình DNS Server

Cài đặt các gọi cần thiết

# yum -y install perl perl-core wget screenw3m elinks openssh-clients openssh-server bind bind-utils unzip nmap sednc sysstat libaio rsync telnet aspell

Chỉnh sửa file named.conf

# nano /etc/named.conf

Thêm chữ 'any'

options {
        listen-on port 53 { 127.0.0.1;
any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost;
any; };
        recursion yes;

 

Tạo đoạn ở dưới cùng của file named.conf như sau

zone "maxserver.net" IN {
type master;
file "db.maxserver.net";
allow-update { none; };
};

 

Tạo 1 thư mục và thêm quyền sử dụng nhóm

# touch /var/named/db.maxserver.net
# chgrp named /var/named/db.maxserver.net
# nano /var/named/db.maxserver.net

Tạo nội dung như sau

$TTL 1D
@       IN SOA  ns1.maxserver.net. root.maxserver.net. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      ns1.maxserver.net.
@       IN      MX      0 mail.maxserver.net.
ns1     IN      A       107.189.160.7
mail    IN      A       107.189.160.7

 

Khởi động lại dịch vụ & Kiểm tra cấu hình kết quả của DNS Server

# service named restart
# chkconfig named on

Dùng lệnh nslookup và dig để kiểm tra

# nslookup mail.maxserver.net

Server:         107.189.160.7
Address:        107.189.160.7#53

Name:   mail.maxserver.net
Address: 107.189.160.7

 

# dig maxserver.net mx

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <<>> maxserver.net mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29090
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; QUESTION SECTION:
;maxserver.net.             IN      MX

;; ANSWER SECTION:
maxserver.net.      86400   IN      MX      0 mail.maxserver.net.

;; AUTHORITY SECTION:
maxserver.net.      86400   IN      NS      ns1.maxserver.net.

;; ADDITIONAL SECTION:
mail.maxserver.net. 86400   IN      A       107.189.160.7
ns1.maxserver.net.  86400   IN      A       107.189.160.7

;; Query time: 0 msec
;; SERVER: 107.189.160.7#53(107.189.160.7)
;; WHEN: Tue Mar 15 23:16:50 2016
;; MSG SIZE  rcvd: 106

Tiến hành

1.Cài đăt postfix

Thường postfix đã đc cài dặt sẵn, nếu chưa có ta dùng lệnh 

# yum install postfix -y

# nano /etc/postfix/main.cf

Ấn ctrl+w để tìm chữ

Tìm chữ 'myhostname' và thêm dòng sau

#myhostname = host.domain.tld
#myhostname = virtual.domain.tld

myhostname = mail.maxserver.net

Tìm chữ 'mydomain' và thêm dòng sau

#mydomain = domain.tld
mydomain = maxserver.net
 

Tìm chữ 'myoirgin' và bỏ dấu '#' ở dòng sau

#myorigin = $myhostname
myorigin = $mydomain
 

Tìm chữ 'inet_interfaces' và sửa các dòng như sau

inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
inet_protocols = all

Tìm chữ 'mydestination' thêm dấu '#' và bỏ dấu '#' như sau

#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

Tìm chữ 'mynetworks' bỏ dấu'#' và sửa ip

mynetworks = 107.189.160.7, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table

Tìm chữ 'home_mailbox' bỏ dấu '#' 

#home_mailbox = Mailbox
home_mailbox = Maildir/

Khởi động lại postfix và cho chạy cùng hệ thống

# service postfix restart
# chkconfig postfix on


Kiểm tra postfix

Tạo user và đặt mật khẩu cho user đó 

# useradd maxserver
# passwd maxserver

Dùng lệnh telnet để kiểm tra kết nối
# telnet localhost smtp


[root@mail ~]# telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.maxserver.net ESMTP Postfix

ehlo localhost            (gõ lệnh này)
250-mail.maxserver.net.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

mail from:<maxserver>                ( Địa chỉ email người gửi)
250 2.1.0 Ok
rcpt to:<maxserver>                    (Địa chỉ email người nhận)
250 2.1.5 Ok
data                                                (Bắt đầu vào nội dung tin nhắn email)
354 End data with <CR><LF>.<CR><LF>
test thanh cong                                 (Nội dung tin nhắn email)
.                                                          (Nội dung tin nhắn email kết thúc bằng dấu '.' )
250 2.0.0 Ok: queued as EB82554E2
quit                                                (lệnh thoát)
221 2.0.0 Bye
Connection closed by foreign host.

Bây giờ điều hướng đến user "maxserver" thư mục mail và kiểm tra thư mới:

# ls /home/maxserver/Maildir/new/

root@mail ~]# ls /home/maxserver/Maildir/new/
1459484457.Vfc01I209f3M150354.mail.maxserver.net.net

Một thư mới cho user "maxserver". Để đọc mail, nhập vào lệnh sau đây:

# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net

[root@mail ~]# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net
Return-Path: <[email protected]>
X-Original-To: maxserver
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
        by mail.maxserver.net.net (Postfix) with ESMTP id EB82554E2
        for <maxserver>; Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
Message-Id: <[email protected]>
Date: Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
From: [email protected]
To: undisclosed-recipients:;

test thanh cong

 

2.Cài đặt dovecot

Dovecot là một mã nguồn mở IMAP và POP3 mail server cho các hệ thống Unix / Linux. Để cài đặt:

# yum install dovecot -y

Chỉnh sửa cấu hình dovecot

# nano /etc/dovecot/dovecot.conf

Tìm chữ 'Protocols' và bỏ dấu '#' ở dòng sau

# Protocols we want to be serving.
protocols = imap pop3 lmtp

# nano /etc/dovecot/conf.d/10-mail.conf

Tìm chữ 'mail_location' và bỏ dấu '#' ở dòng sau

# See doc/wiki/Variables.txt for full list. Some examples:
#
 
 mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n


 # nano /etc/dovecot/conf.d/10-auth.conf

Tìm chữ 'disable_plaintext_auth' và bỏ dấu '#'

# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.

disable_plaintext_auth = yes

Tìm chữ 'auth_mechanisms' thêm chữ 'login' vào dòng đó

# Space separated list of wanted authentication mechanisms:
#   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
#   gss-spnego
# NOTE: See also disable_plaintext_auth setting.

auth_mechanisms = plain login
 

# nano /etc/dovecot/conf.d/10-master.conf

Tìm chữ 'mode = 0600' bỏ dấu '#' và thêm user = postfix , group = postfix

unix_listener auth-userdb {
    #mode = 0600

    user = postfix
    group = postfix

  }

Khởi động dovecot và cho chạy cùng hệ thống

# service dovecot start
# chkconfig dovecot on

Kiểm tra dovecot

# telnet localhost pop3​
 

[root@mail ~]# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.

user maxserver                     (đăng nhập user maxserver)
+OK
pass matkhau                         (mật khẩu của usre maxserver là matkhau)
+OK Logged in.
retr 1
+OK 475 octets
Return-Path: <[email protected]>
X-Original-To: maxserver
Delivered-To: [email protected]
Received:
from localhost (localhost [127.0.0.1])
        by mail.maxserver.net (Postfix) with ESMTP id EB82554E2
        for <maxserver>; Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
Message-Id: <[email protected]>
Date: Fri,  1 Apr 2016 00:19:24 -0400 (EDT)
From: [email protected]
To: undisclosed-recipients:;

test thanh cong
.
quit
+OK Logging out.

Connection closed by foreign host.
 

3.Cài đặt squirrelmail

Cài đặt SquirreMail sử dụng lệnh sau đây:

# yum install squirrelmail -y

Điều hướng đến thư mục / usr / share / SquirreMail / config / và chạy lệnh conf.pl lệnh:

# cd /usr/share/squirrelmail/config/
# ./conf.pl

Trình hướng dẫn sau đây sẽ mở ra. Nhập lựa chọn "1" để thiết lập chi tiết tổ chức của bạn:

[root@mail ~]# cd /usr/share/squirrelmail/config/
[root@mail config]# ./conf.pl
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color off
S   Save data
Q   Quit

Command >> 1

Trình hướng dẫn sau đây sẽ mở ra. Nhập "1" một lần nữa thay đổi các chi tiết tổ chức của bạn:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : SquirrelMail
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           : 
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : SquirrelMail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 1

Đặt tên  Organization của bạn và nhấn Enter:

We have tried to make the name SquirrelMail as transparent as
possible.  If you set up an organization name, most places where
SquirrelMail 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 that
must be defined before the $org_name is printed.
$version, for example, is included by default, and will print the
string representing the current SquirrelMail version.

[SquirrelMail]: maxserver

Bằng cách này, thiết lập tất cả các chi tiết như tên tổ chức, logo, tên nhà cung cấp trong chương trình trên. Khi bạn làm xong, nhấn "S" để lưu các thay đổi và nhấn "R" để trở lại menu chính của bạn:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : maxserver
2.  Organization Logo      : ../images/sm_logo.png
3.  Org. Logo Width/Height : (308/111)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           :
6.  Top Frame              : _top
7.  Provider link          : http://squirrelmail.org/
8.  Provider name          : MaxserverMail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> s

Bây giờ nhập "2" để cài đặt thiết lập mail Server như tên miền và đại lý email ....

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color off
S   Save data
Q   Quit

Command >> 2

Nhập "1", Nhập tên miền mail của bạn  và nhấn phím Enter.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1.  Domain                 : localhost
2.  Invert Time            : false
3.  Sendmail or SMTP       : sendmail

A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 1

The domain name is the suffix at the end of all email addresses.  If
for example, your email address is [email protected], then your domain
would be example.com.

[nguyenvietduc.net]: maxserver.net

Nhập "3" và thay đổi từ sendmail sang SMTP

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1.  Domain                 : maxserver.net
2.  Invert Time            : false
3.  Sendmail or SMTP       : Sendmail

A.  Update IMAP Settings   : localhost:143 (uw)
B.  Change Sendmail Config : /usr/sbin/sendmail

R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit

Command >> 3

Nhập "2" để chuyển đổi

You now need to choose the method that you will use for sending
messages in SquirrelMail.  You can either connect to an SMTP server
or use sendmail directly.

  1.  Sendmail
  2.  SMTP
Your choice [1/2] [1]: 2

Bây giờ nhập "S" tiếp theo là "Q" để lưu lại cấu hình và thoát SquirreMail.

Cấu hình httpd

# nano /etc/httpd/conf/httpd.conf

Sửa những dòng sau 

DocumentRoot "/usr/share/squirrelmail"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory
/usr/share/squirrelmail>
   
Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all

</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "
/usr/share/squirrelmail">
 

Khởi động lại httpd

# service httpd restart

Bây giờ bạn có thể truy cập vào  địa chỉ http://ip-vps