วิธีติดตั้ง Mail Server บน CentOS (Linux) (Postfix, Dovecot, SquirrelMail)


Mail Server คือ การให้บริการด้านการส่ง และรับอีเมล์บนระบบเครือข่ายทั้งแบบอินเทอร์เน็ต และอินทราเน็ต โดยบทความนี้จะสอนวิธีการติดตั้ง Mail Server ด้วยโปรแกรม Postfix, Dovecot และ SquirrelMail บน Linux CentOS 6

องค์ประกอบโปรแกรมของ Mail Server
1. Postfix คือ โปรแกรมในส่วนของการส่งอีเมล์ (Send Email)
2. Dovecot  คือ โปรแกรมในส่วนของการรับอีเมล์ (Receive Email)
3. SquirrelMail คือ โปรแกรมในรูปแบบของ เว็บไซต์ เพื่อจัดการอีเมล์บนโปรแกรมเว็บเบราว์เซอร์ (Web based access)

รายละเอียดของ Server
1. IP Address 192.168.1.39
2. Hostname mail.demo.local
3. Linux CentOS 6 32bit
4. Domain demo.local

วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS
1. กำหนด IP Address แบบ Static IP Address

วิธีตั้งค่า Static IP Address บน CentOS (Linux)


2. ปิดการทำงาน selinux
1
2
3
4
vi /etc/selinux/config
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:

3. ปิด Firewall (ปิดเพื่อการทดสอบเท่านั้น)
1
2
3
4
service iptables stop
service ip6tables stop
chkconfig iptables off
chkconfig ip6tables off

4. ลบโปรแกรม sendmail ออก
1
yum remove sendmail

5. Restart เครื่อง
1
reboot

6. แก้ไข Hostname
1
2
vi /etc/sysconfig/network
hostname=mail.demo.local

7. ติตตั้งโปรแกรม postfix
1
yum install postfix -y

8. Config โปรแกรม postfix
1
2
3
4
5
6
7
8
vi /etc/postfix/main.cf
myhostname = mail.demo.local
mydomain = demo.local
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
home_mailbox = Maildir/

9. Start Service postfix
1
2
service postfix start
chkconfig postfix on

10. ติดตั้งโปรแกรม telnet
1
yum install telnet -y

11. สร้าง User ใหม่ 2 User คือ user1 และ user2
1
2
3
4
5
useradd user1
passwd user1
....................
useradd user2
passwd user2

12. ทดสอบการติดตั้ง postfix (ตัวสีแดงคือให้กรอกลงไป)
1
telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.demo.local ESMTP Postfix
ehlo localhost
250-mail.demo.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1>
250 2.1.0 Ok
rcpt to:<user1>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
message
.
250 2.0.0 Ok: queued as 57DBF7D9A
quit
221 2.0.0 Bye
Connection closed by foreign host.

ทดสอบหลังการส่งอีเมล์จะต้องพบไฟล์การส่งอีเมล์แล้วสามารถเรียกขึ้นมาอ่านได้
(ชื่อของไฟล์ขอให้อ้างอิงในเครื่องของผู้อ่าน เพราะจะไม่มีเหมือนกัน)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd /home/user1/Maildir/new/
ls
1377361942.Vfd00I60158M571583.mail.demo.local
cat 1377361942.Vfd00I60158M571583.mail.demo.local
Return-Path: >user1@demo.local<
X-Original-To: user1
Delivered-To: user1@demo.local
Received: from localhost (localhost.localdomain [127.0.0.1])
        by mail.demo.local (Postfix) with ESMTP id 07862993B
        for >user1<; Sat, 24 Aug 2013 23:32:06 +0700 (ICT)
Message-Id: >20130824163217.07862993B@mail.demo.local<
Date: Sat, 24 Aug 2013 23:32:06 +0700 (ICT)
From: user1@demo.local
To: undisclosed-recipients:

13. ติดตั้งโปรแกรม dovecot
1
yum install dovecot -y

14. Config โปรแกรม dovecot ไฟล์ที่ 1
1
2
vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp

15. Config โปรแกรม dovecot ไฟล์ที่ 2
1
2
vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir

16. Config โปรแกรม dovecot ไฟล์ที่ 3
1
2
3
vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login

17. Config โปรแกรม dovecot ไฟล์ที่ 4
1
2
3
4
5
vi /etc/dovecot/conf.d/10-master.conf
unix_listener auth-userdb {
    #mode = 0600
    user = postfix
    group = postfix

18. Start service dovecot 
1
2
service dovecot start
chkconfig dovecot on

19. ทดสอบการติดตั้งโปรแกรม dovecot (ให้พิมพ์แล้วกด Enter ตัวสีแดง) โดยจะต้องสามารถอ่านอีเมล์ที่พึ่งส่งไปได้
1
# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 420
.
retr 1
+OK 420 octets
Return-Path: <user1@demo.local>
X-Original-To: user1
Delivered-To: user1@demo.local
Received: from localhost (localhost.localdomain [127.0.0.1])
        by mail.demo.local (Postfix) with ESMTP id 07862993B
        for <user1>; Sat, 24 Aug 2013 23:32:06 +0700 (ICT)
Message-Id: <20130824163217.07862993B@mail.demo.local>
Date: Sat, 24 Aug 2013 23:32:06 +0700 (ICT)
From: user1@demo.local
To: undisclosed-recipients:;
test
.
quit
+OK Logging out.
Connection closed by foreign host.
20. ติดตั้งโปรแกรม httpd, php, mysql และอื่น ๆ (ติดตั้ง php, mysql เอาไว้ก่อนเพื่อนำไปใช้ในส่วนของการติดตั้ง roundcubemail)
1
yum install httpd php php-common php-json php-xml php-mbstring php-imap php-pear-DB php-mysql mysql mysql-server

21. ติดตั้งโปรแกรม squirrelmail
1
2
3
4
5
wget -4 http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install squirrelmail
service httpd start
chkconfig httpd on

22. Config โปรแกรม squirrelmail
1
2
cd /usr/share/squirrelmail/config/
./conf.pl

23. พิมพ์หมายเลข 2 แล้วกด Enter
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

24. แก้ไขค่าต่าง ๆ (เฉพาะในจุดที่เป็นสีแดง) แก้่ไขโดยการพิมพ์หมายเลขหน้าข้อมูลที่ต้องการแก้ไข
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                          : demo.local
2.  Invert Time                    : false
3.  Sendmail or SMTP          : SMTP
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 >>

25. แก้ไขครบหมดแล้วให้พิมพ์ S แล้วกด Enter 2 ครั้ง จากนั้นพิมพ์ Q แล้วกด Enter เพื่อออกจากการ Config

26. เพิ่มข้อมูลเข้าไปในไฟล์ โดยให้ใส่เข้าไปที่บรรทัดสุดท้ายของไฟล์
1
2
3
4
5
6
7
8
9
10
vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

27. Restart httpd 
1
service httpd restart

28. ทดสอบการติดตั้งโปรแกรม squirrelmail โดยการเปิดโปรแกรมเว็บเบราว์เซอร์แล้วพิมพ์ http://192.168.1.39/webmail หรือ http://localhost/webmail
วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS - รับทำเว็บไซต์ รับเขียนเว็บไซต์

29. ทดสอบการส่งอีเมล์โดยการ login ด้วย user1
วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS - รับทำเว็บไซต์ รับเขียนเว็บไซต์

30. ทดสอบการส่งอีเมล์ไปหา user2
วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS - รับทำเว็บไซต์ รับเขียนเว็บไซต์

31. ทดสอบการรับอีเมล์โดยการ login ด้วย user2
วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS - รับทำเว็บไซต์ รับเขียนเว็บไซต์

32. ใน Inbox ของ user2 จะปรากฏอีเมล์ของ user1 ที่ส่งไป
วิธีการติดตั้ง Mail Server (Postfix, Dovecot, SquirrelMail) บน Linux CentOS - รับทำเว็บไซต์ รับเขียนเว็บไซต์

ไม่มีความคิดเห็น:

แสดงความคิดเห็น