Cấu hình Mail Server trên CentOS 6.5

Mail Server là gì ?
Mail Server là một máy chủ dùng để nhận và gửi mail

Chức năng của Mail Server
- Quản lý account
- Nhận mail của người gửi (của những người có account) và gửi cho người nhận hoặc mail server của người nhận.
- Nhận mail từ mail server của người gửi (từ bên ngoài) và phân phối mail cho người trong hệ thống.
- Tùy thuộc vào việc cài đặt mà mail-server cho phép người dùng sử dụng web-mail (web) để nhận mail (giống yahoo), hay cho phép sử dụng outlook (application), hay cả 2 (giống như gmail)
Mục đích của việc quản trị hệ thống Mail Server
Ngày nay thư điện tử là một công cụ giúp việc rất hiệu quả để chuyển tải tâm tư tình cảm của con người cũng như trong kinh doanh. Ngoài ra tên miền của của địa chỉ thư điện cũng là một thương hiệu đại diện cho giá trị của một cơ quan, tổ chức hoạt động cho bất cứ một lĩnh vực nào. Do vậy nhu cầu xây dựng một hệ thống thư điện tử cho riêng mình là rất cần thiết với một tổ chức hay cơ quan.
Nó còn cho phép các đơn vị có thể tự mình quản lý hệ thống máy chủ thư điện tử của chính mình điều đó đồng nghĩa với việc chủ động trong việc quản trị máy chủ thư điện tử cũng như đảm bảo an toàn cao hơn cho thông tin của doanh nghiệp
Trong bài viết này mình xin hướng dẫn các bạn cấu hình một hệ thống Mail nội bộ trên môi trường CentOS với , Postfix – dùng để gửi mail , Dovecot -dùng để nhận mail và Squirrelmail – là webmail client . Mình xin bắt đầu
Chuẩn bị
- Máy CentOS – Mail Server
- Máy Client
Trên máy CentOS
IP : 172.16.1.254
Hostname : server.adminvietnam.org
1. Preliminary Note
Tải và cài 2 gói EPEL và RHEL
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh epel-release-6-8.noarch.rpm remi-release-6.rpm
Remove SENDMAIL
# yum remove sendmail
2. Installing Postfix
yum install postfix
Cấu hình Postfix
nano /etc/postfix/main.cf
Bỏ # dòng 75,83 và sửa lại hostname , domain
# from gethostname(). $myhostname is used as a default value for many myhostname = server.adminvietnam.org #myhostname = virtual.domain.tld # The mydomain parameter specifies the local internet domain name. # The default is to use $myhostname minus the first component. # $mydomain is used as a default value for many other configuration # parameters. # mydomain = adminvietnam.org
Bỏ # dòng 99,113
Thêm # dòng 116
myorigin = $mydomain # RECEIVING MAIL # The inet_interfaces parameter specifies the network interface # addresses that this mail system receives mail on. By default, # the software claims all active interfaces on the machine. The # parameter also controls delivery of mail to user@[ip.address]. # # See also the proxy_interfaces parameter, for network addresses that # are forwarded to us via a proxy or network address translator. # # Note: you need to stop/start Postfix when this parameter changes. # inet_interfaces = all #inet_interfaces = $myhostname #inet_interfaces = $myhostname, localhost #inet_interfaces = localhost
Bỏ # dòng 165
Thêm # dòng 164
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". # #mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, # mail.$mydomain, www.$mydomain, ftp.$mydomain
Bỏ # dòng 264 thêm địa chỉ đường mạng
#
mynetworks = 172.16.1.0/24, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
Bỏ # dòng 419
#home_mailbox = Mailbox
home_mailbox = Maildir/
Sau khi đã cấu hình xong Postfix ta lưu lại và khởi động lại dịch vụ
service postfix restart chkconfig postfix on
Tạo User để test Postfix
useradd adminvn passwd adminvn telnet localhost smtp
Lưu ý : Những phần được in đậm là do bạn nhập vào
[root@server /]# telnet localhost smtp
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 server.adminvietnam.org ESMTP Postfix
ehlo
501 Syntax: EHLO hostname
mail from:<adminvn>
250 2.1.0 Ok
rcpt to:<adminvn>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello
.
250 2.0.0 Ok: queued as 157B0416B6
quit
221 2.0.0 Bye
Connection closed by foreign host.
3. Installing Dovecot
yum install dovecot
Chỉnh sửa file dovecot.conf
vi /etc/dovecot/dovecot.conf
Bỏ # dòng 20
# Protocols we want to be serving.
protocols = imap pop3 lmtp
Chỉnh sửa file 10-mail.conf
vi /etc/dovecot/conf.d/10-mail.conf
Bỏ # dòng 24
#
mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
Chỉnh sửa file 10-auth.conf
vi /etc/dovecot/conf.d/10-auth.conf
Bỏ # dòng 9 chuyển disable_plaintext_auth = no
# connection is considered secure and plaintext authentication is allowed.
disable_plaintext_auth = no
# Authentication cache size (e.g. 10M). 0 means it's disabled. Note that
Bỏ # dòng 97 thêm auth_mechanisms = plain login
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login
Chỉnh sửa file 10-master.conf
vi /etc/dovecot/conf.d/10-master.conf
Bỏ # dòng 83 ,84
#mode = 0600 user = postfix group = postfix }
Khởi động lại dịch vụ và test
service dovecot restart telnet localhost pop3
Lưu ý : Những dòng được in đậm là do bạn nhập vào
[root@server /]# telnet localhost pop3 Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user adminvn +OK pass 123456 +OK Logged in. list +OK 1 messages: 1 453 . retr 1 +OK 453 octets Return-Path: <[email protected]> X-Original-To: adminvn Delivered-To: [email protected] Received: from localhost (localhost [IPv6:::1]) by server.adminvietnam.org (Postfix) with SMTP id 157B0416B6 for <adminvn>; Thu, 28 Apr 2016 19:10:20 +0700 (ICT) Message-Id: <[email protected]> Date: Thu, 28 Apr 2016 19:10:20 +0700 (ICT) From: [email protected] To: undisclosed-recipients:; hello . quit +OK Logging out. Connection closed by foreign host.
4. Installing Squirrelmail , Httpd
yum install squirrelmail httpd mysql mysql-server -y
Cấu hình Squirrelamail và Apache
cd /usr/share/squirrelmail/config ./conf.pl
Chọn 2 để cài đặt server
Chọn 1 thay đổi Domain
Chọn 3 thay đổi SMTP

Chọn S để Save , Q để Thoát
Cấu hình Httpd
vi /etc/httpd/conf/httpd.conf
Tạo Alias
Alias /webmail "/usr/share/squirrelmail" <Directory "/usr/share/squirrelmail"> Options Indexes MultiViews FollowSymLinks RewriteEngine On DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory>
Khởi động lại dịch vụ
service httpd restart chkconfig httpd on
Mở port trên firewall
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT iptables save iptables restart
Sử dụng trình duyệt trên máy Server để test , vì ở đây mình chưa xây dựng DNS server nên chúng ta sẽ đi bằng IP . ví dụ : 172.16.1.254/webmail

Khắc phục lỗi Login Error khi đăng nhập
# /usr/sbin/setsebool -P httpd_can_network_connect=1
Đăng nhập thành công
Notice : Nếu bạn đã dựng DNS server thì phải thêm records MX vào 2 file foward và reverse zones . Cách cấu hình DNS Server bạn có thế tham khảo tại đây , sau khi đã thêm các bạn có thể truy cập bằng tên miền ,ví dụ : mail.adminvietnam.org/webmail
Chúc các bạn thành công
LuanPM-adminvietnam.org



