Langkah-langkah Instalasi Postfix Menggunakan Courier IMAP di Centos 5.4

Posted: November 29, 2010 in Email, Ilmu Dunia, Mail Server

Berikut adalah hasil dari oprekan saya sendiri yang bersumber dari http://www.catatanlepas.com. Tujuan dari tulisan ini dibuat tidak lain hanyalah untuk dokumentasi saya pribadi, dan syukur-syukur bisa bermanfaat bagi yang membacanya dan mengiktuti langkah-langkah instalasi mail server ini. Selamat mencoba

17 Mei 2010

Instalasi paket-paket
=====================
[root@server1 src]# yum -y install openldap-devel openldap-servers expect-devel gamin-devel httpd* php* mysql* rpm-build* libtool gdbm-devel pam-devel gcc-c++ redhat-rpm-config libtool-ltdl-devel libtool-ltdl postgresql-devel pam-devel

Download paket-paket
====================
[root@server1 src]# wget ftp://ftp.reverse.net/pub/postfix/official/postfix-2.6.5.tar.gz
[root@server1 src]# wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.22.tar.gz
[root@server1 src]# wget http://sourceforge.net/projects/courier/files/authlib/0.62.4/courier-authlib-0.62.4.tar.bz2/download
[root@server1 src]# wget http://sourceforge.net/projects/courier/files/imap/4.5.1/courier-imap-4.5.1.tar.bz2/download
[root@server1 src]# wget squirrelmail
[root@server1 src]# wget postfixadmin

Cek paket-paket
===============
[root@server1 src]# rpm -qa | grep sendmail;rpm -qa | grep postfix;rpm -qa | grep cyrus;rpm -qa | grep dovecot
sendmail-8.13.8-2.el5
sendmail-cf-8.13.8-2.el5
cyrus-sasl-plain-2.1.22-5.el5_4.3
cyrus-sasl-lib-2.1.22-5.el5_4.3
cyrus-sasl-2.1.22-5.el5_4.3
cyrus-sasl-devel-2.1.22-5.el5_4.3
dovecot-1.0.7-7.el5

Uninstall paket-paket
=====================
[root@server1 src]# rpm -e sendmail-8.13.8-2.el5 cyrus-sasl-lib-2.1.22-5.el5_4.3 cyrus-sasl-2.1.22-5.el5_4.3 cyrus-sasl-devel-2.1.22-5.el5_4.3 dovecot-1.0.7-7.el5 –nodeps
warning: /var/log/mail/statistics saved as /var/log/mail/statistics.rpmsave

B. Konfigurasi Hostname
1. Merubah Hostname
Penulis mengisi file network sebagai berikut:

[root@server1 src]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=mail

2. Merubah Hosts
Penulis merubah file hosts sehingga menjadi seperti berikut:
[root@server1 src]# vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
10.10.2.210 mail.example.com mail

3. Restart hostname
Restart hostname dengan cara:

/bin/hostname -f /etc/hosts

C. Instalasi Cyrus-SASL
=======================
Cyrus-SASL merupakan software yang menyediakan metode dan mekanisme yang berbeda untuk autentifikasi.

1. Ekstrak Paket

[root@mail src]# cd /usr/local/src/
[root@mail src]# tar -xvf cyrus-sasl-2.1.22.tar.gz
[root@mail src]# cd cyrus-sasl-2.1.22

2. Instalasi Paket

[root@mail cyrus-sasl-2.1.22]# export CPPFLAGS=”-I/usr/include/mysql”
[root@mail cyrus-sasl-2.1.22]# export LDFLAGS=”-L/usr/lib/mysql -lmysqlclient -lz -lm”
./configure –enable-anon –enable-plain –enable-login –enable-sql –disable-krb4 –disable-otp –disable-cram –disable-digest –with-mysql=/usr/lib/mysql –without-pam –without-saslauthd –without-pwcheck –prefix=/usr –with-plugindir=/usr/lib/sasl2; make -j2; make install

Selasa,11 mei 2010
===================

D. Instalasi Postfix
1. Menghapus user dan grup

2. Membuat user dan grup

[root@mail src]# groupadd -g 500 postfix
[root@mail src]# groupadd -g 501 postdrop
[root@mail src]# useradd -g 500 -G postdrop postfix
[root@mail src]# id postfix
uid=500(postfix) gid=500(postfix) groups=500(postfix),501(postdrop) context=root:system_r:unconfined_t:SystemLow-SystemHigh

3. Ekstrak Postfix

[root@mail src]# cd /usr/local/src
[root@mail src]# tar -zxvf postfix-2.6.5.tar.gz
[root@mail src]# cd postfix-2.6.5
[root@mail postfix-2.6.5]# make makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_TLS -DUSE_CYRUS_SASL -I/usr/include/sasl’ ‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto -lsasl2′
[root@mail postfix-2.6.5]# make install

=============================================================================================================================================================
Setelah itu, kita akan diberikan banyak pertanyaan tentang folder-folder yang akan dijadikan sebagai folder postfix. Daripada bingung, sebaiknya tekan enter saja semua pertanyaan tersebut karena linux telah menyediakan folder-folder default untuk postfix jika kita menekan enter.

install_root: [/]
tempdir: [/usr/local/src/postfix-2.6.5]
config_directory: [/etc/postfix]
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no]
mail_owner: [postfix]
mailq_path: [/usr/bin/mailq]
manpage_directory: [/usr/local/man]
newaliases_path: [/usr/bin/newaliases]
queue_directory: [/var/spool/postfix]
readme_directory: [no]
sendmail_path: [/usr/sbin/sendmail]
setgid_group: [postdrop]
=============================================================================================================================================================

4. Konfigurasi Postfix

a. Konfigurasi main.cf
=======================
[root@mail postfix-2.6.5]# cd /etc/postfix/
[root@mail postfix]# cp main.cf main.cf.ori

Tambahkan file main.cf dengan skrip sebagai berikut:

# vi main.cf
alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = no
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
mydomain = tuelegi.web.id
myhostname = mail.tuelegi.web.id
myorigin = #myhostname
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
smtp_tls_note_starttls_offer = yes
smtp_use_tls = yes
smtpd_banner = #myhostname ESMTP “mail.tuelegi.web.id”
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_pipelining,reject_unauth_destination,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = #myhostname
smtpd_sasl_security_options = noanonymous
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:500
virtual_mailbox_base = /var/vmail/
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 500
virtual_transport = virtual
virtual_uid_maps = static:500

Perlu diingat bahwa di dalam penulisan di file main.cf diusahakan bagaimana caranya agar satu skrip dalam satu baris khususnya pada bagian smtpd_recipient_restrictions.

b. Membuat file-file
====================
Buat file tersebut di foler /etc/postfix dan tambahkan skrip sebagai berikut:
[root@censmtp html]# cd /etc/postfix/
[root@censmtp postfix]# vi mysql_virtual_alias_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address=’%s’ AND active = ‘1’

[root@censmtp postfix]# vi mysql_virtual_domains_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain=’%s’ AND active = ‘1’

[root@censmtp postfix]# vi mysql_virtual_mailbox_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username=’%s’ AND active = ‘1’

E. Membuat Sertifikat SSL
=========================
SSL (Secure Sockets Layer) adalah teknologi standar keamanan yang diperlukan untuk komunikasi melalui jaringan seperti internet dan sekarang berubah menjadi TLS (Transport Layer Security). Berikut adalah langkah-langkahnya:
[root@mail postfix]# mkdir /etc/postfix/ssl
[root@mail postfix]# cd /etc/postfix/ssl/
[root@mail ssl]# openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
223 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
…………………………………..++++++
.++++++
e is 65537 (0x10001)
Enter pass phrase for smtpd.key:panji45
[root@mail ssl]# chmod 600 smtpd.key
[root@mail ssl]# openssl req -new -key smtpd.key -out smtpd.csr
[root@mail ssl]# openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
[root@mail ssl]# openssl rsa -in smtpd.key -out smtpd.key.unencrypted
[root@mail ssl]# mv -f smtpd.key.unencrypted smtpd.key
[root@mail ssl]# openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
[root@mail ssl]# chmod o= /etc/postfix/ssl/smtpd.key

F. Instalasi Courier Authlib
============================
Courier Authlib merupakan sebuah set dari program-program yang dibuat untuk menangani autentifikasi request login ke service-service paket courier IMAP.

***12 Mei 2010***
*****************

[root@mail ~]# cd /usr/local/src/
[root@mail src]# rpmbuild -ta courier-authlib-0.62.4.tar.bz2
[root@mail src]# cd /usr/src/redhat/RPMS/i386/
[root@mail i386]# rpm -ivh courier-authlib*

G. Instalasi Courier-IMAP
Courier-IMAP merupakan software dari courier yang digunakan untuk metode pengiriman email. Program ini mendukung format penyimpanan email dengan menggunakan format Maildir. Dalam hal ini kita menggunakan Courier-Imap untuk backend dari webmail squirrelmail. Untuk menginstalasinya, tidak bisa langsung melalui root, tetapi harus non root.

[root@mail i386]# useradd courier
[root@mail i386]# su courier
[courier@mail i386]$ mkdir $HOME/rpm
[courier@mail i386]$ mkdir $HOME/rpm/SOURCES
[courier@mail i386]$ mkdir $HOME/rpm/SPECS
[courier@mail i386]$ mkdir $HOME/rpm/BUILD
[courier@mail i386]$ mkdir $HOME/rpm/SRPMS
[courier@mail i386]$ mkdir $HOME/rpm/RPMS
[courier@mail i386]$ mkdir $HOME/rpm/RPMS/i386
[courier@mail i386]$ echo “%_topdir $HOME/rpm” >> $HOME/.rpmmacros
[courier@mail i386]$ mkdir $HOME/downloads
[courier@mail i386]$ cd $HOME/downloads
[courier@mail downloads]$ cd /usr/local/src
[courier@mail src]$ sudo mv courier-imap* $HOME/downloads

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Password:

Tekan saja enter kalau diminta untuk memasukkan password

[courier@mail src]$ rpmbuild -ta courier-imap*

Balik lagi menjadi root
[courier@mail src]$ su
[root@mail src]# cd /home/courier/rpm/RPMS/i386
[root@mail i386]# rpm -ivh courier-imap*

H. Edit File-File
*****************

1. Edit file authmysqlrc
Tambahkan di file authmysqlrc dengan skrip sebagai berikut:

[root@mail i386]# cd /etc/authlib/
[root@mail authlib]# mv authmysqlrc authmysqlrc.ori
[root@mail authlib]# vi /etc/authlib/authmysqlrc

MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD password123
MYSQL_PORT 0
MYSQL_OPT 0
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD ‘500’
MYSQL_GID_FIELD ‘500’
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD ‘/var/vmail/’
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir

2. File authdaemonrc
Rubah file authdaemonrc dengan cara merubah authmodulelist dan DEBUG_LOGIN:

[root@mail authlib]# cp authdaemonrc authdaemonrc.ori
[root@mail authlib]# vi authdaemonrc
authmodulelist=”authmysql authpam”
DEBUG_LOGIN=1

3. Membuat file SMTP-AUTH
Buat file smtpd.conf dan tambahkan skrip di bawah:
[root@mail authlib]# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/spool/authdaemon/socket
[root@mail authlib]# chmod o+x /var/spool/authdaemon

4. Membuat file direktori vmail
File vmail digunakan untuk menyimpan data user postfix.

[root@mail authlib]# mkdir /var/vmail
[root@mail authlib]# chown -R postfix:postfix /var/vmail/

I. MENYALAKAN SERVICE
1. Nyalakan courier-authlib

[root@mail authlib]# chkconfig –levels 235 courier-authlib on
[root@mail authlib]# /etc/init.d/courier-authlib start

2. Nyalakan authdaemon

[root@mail authlib]# chkconfig –levels 235 courier-imap on
[root@mail authlib]# /etc/init.d/courier-imap start
Starting Courier-IMAP server: imap generating-SSL-certificate… imap-ssl pop3 generating-SSL-certificate… pop3-ssl

3. Nyalakan Postfix

[root@mail authlib]# postfix start
postfix/postfix-script: starting the Postfix mail system

J. Menginstal Postfixadmin
1. Ekstrak Paket

[root@mail authlib]# cd /usr/local/src
[root@mail src]# tar -zxvf postfixadmin_2.3.tar.gz

2. Konfigurasi Postfixadmin

[root@mail src]# mv postfixadmin-2.3 postfixadmin
[root@mail src]# cp -r postfixadmin /var/www/html/
[root@mail src]# cd /var/www/html/postfixadmin

Merubah file config.inc.php menjadi seperti berikut:

[root@mail postfixadmin]# vi config.inc.php
$CONF[‘configured’] = true;
$CONF[‘database_type’] = ‘mysql’;
$CONF[‘database_host’] = ‘localhost’;
$CONF[‘database_user’] = ‘postfix’;
$CONF[‘database_password’] = ‘password123’;
$CONF[‘database_name’] = ‘postfix’;
$CONF[‘database_prefix’] = ”;

K. Konfigurasi mysql
1. Masuk ke mysql

[root@mail postfixadmin]# mysql -u root -p

2. Membuat database postfix

mysql> create database postfix;

3. Membuat Grant untuk database postfix

mysql> grant all on postfix.* to postfix@localhost identified by ‘password123’;
mysql > \q

L. Melihat Postfixadmin
1. Restart webserver

[root@mail postfixadmin]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

2. Lihat ke browser lalu ketikkan:

http://alamat_ip/postfixadmin/setup.php

Jum’at 14-Mei-2010
******************

M. Instalasi Webmail
Webmail yang akan kita gunakan adalah squirrelmail. Berikut adalah langkah-langkahnya:

[root@mail data]# cd /usr/local/src/
[root@mail src]# tar -xvf squirrelmail-1.4.20.tar.gz
[root@mail src]# mv squirrelmail-1.4.20 webmail
[root@mail src]# mv webmail /var/www/html/
[root@mail src]# mkdir -p /var/local/squirrelmail/data/
[root@mail src]# mkdir -p /var/local/squirrelmail/attach/
[root@mail src]# chown apache:apache /var/local/squirrelmail/data/
[root@mail src]# chown apache:apache /var/local/squirrelmail/attach/

Kemudian kita konfigurasi webmail dengan cara:

# cd /var/www/html/webmail
# ./configure
– Pilih Nomor 2 (Server Settings)
– Pilih Huruf A (Update IMAP Settings)

– Pilih Nomor 6 (Authentification type)

Jawab Pertanyaan dengan menjawab N dan login

– Pilih Nomor 8 (Server Software)

Tulis courier

– Pilih Huruf B (Update SMTP Settings)

– Pilih Nomor 7 (SMTP Authentification)

Jawab Pertanyaan dengan N, login, dan N

– Pilih Huruf S

– Pilih Huruf Q

III. Testing Postfix
Jika kita sudah selesai menginstal postfix dan membuat postfixadmin, kini saatnya kita menguji postfix.
1. Pengujian Courier Authdaemon
Untuk menguji Authdaemon, ketikkan format sebagai berikut:

# authtest -s smtp alamat_email password_email

[root@mail postfixadmin]# authtest -s smtp aji@tuelegi.web.id aji
Authentication succeeded.

Authenticated: aji@tuelegi.web.id (uid 500, gid 500)
Home Directory: /var/vmail/
Maildir: aji@tuelegi.web.id/
Quota: (none)
Encrypted Password: $1$97bd3d58$X3YBPPtOClGrhO.hLMv5F.
Cleartext Password: aji
Options: (none)

2. Pengujian POP3
Untuk menguji POP3 dalam sistem kita, ketikkan format sebagai berikut:

# telnet localhost 110

[root@mail postfixadmin]# telnet localhost 110
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
+OK Hello there.
user aji@tuelegi.web.id
+OK Password required.
pass aji
+OK logged in.
quit
+OK Bye-bye.
Connection closed by foreign host.

3. Pengujian IMAP
Untuk menguji IMAP, kita menggunakan format:

# telnet localhost 143

[root@mail postfixadmin]# telnet localhost 143
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2008 Double Precision, Inc. See COPYING for distribution information.
a login aji@tuelegi.web.id aji
a OK LOGIN Ok.
a logout
* BYE Courier-IMAP server shutting down
a OK LOGOUT completed
Connection closed by foreign host.

4. Pengujian smtp
Untuk menguji smtp, tuliskan perintah berikut:

# telnet localhost 25

[root@mail postfixadmin]# telnet localhost 25
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
220 #myhostname ESMTP “mail.tuelegi.web.id”
ehlo localhost
250-mail.tuelegi.web.id
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

6. Menguji email
Untuk menguji email, buatlah 2 user dengan menggunakan postfixadmin dan cobalah saling kirim dengan menggunakan webmail (squirrelmail) dan seharusnya email sudah dapat saling terkirim dengan baik. Jika email tidak terkirim, cobalah cek error lognya di /var/log/maillog.

Sumber : http://www.catatanlepas.com/komputer/37-aplikasi-linux/132-instalasi-postfix-di-centos-54.html
http://squirrelmail.org/

Advertisements
Comments
  1. ukis says:

    Sekalian dong untuk DNS nya mas, jadi bisa coba-coba lebih jauh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s