Multiple Domain with Postfix, Dovecot, Squirrelmail, Postfixadmin di Centos VPS

Supaya g lupa, setelah sebelumnya membuat mail server dengan OpenDKIM. Pada tutorial saat ini, kita akan membuat Mail Server dengan multiple domain. Sebenarnya tutorial ini berdasarkan dari link ini, tetapi saat dibuat login ke webmail client dan kirim pesan kok tidak bisa. Setelah dilakukan utak atik, alhamdulillah bisa.  Seperti biasa kita akan membuat 2 email address yaitu virtual.uk.to dan virtual.jumpingcrab.com dengan menggunakan subdomain dari freedns.afraid.org. Untuk pembuatan subdomain dapat dilihat pada link ini

Langkah yang akan kita lakukan adalah:

  1. Membuat direktory user
  2. Konfigurai Postfix
  3. Konfigurasi Dovecot
  4. Konfigurasi Mysql
  5. Membuat Postfixadmin
  6. Membuat Webmail

1. Membuat Directory user

Instalasi paket :

yum install httpd-* mysql-* php php-devel php-mbstring php-mysql php-imap php-gd postfix-* dovecot-* telnet-* wget man vim-*

Membuat direktori user

groupadd -g 501 vmail
useradd -g 501 -d /var/vmail -s /sbin/nologin -c "Virtual Mail" vmail
chmod 770 /var/vmail/
chown vmail.vmail /var/vmail/

Membuat Postfix agar SSL dan TLS

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

2. Konfigurasi Postfix

Kita backup konfigurasi postfixnya

cp /etc/postfix/main.cf /etc/postfix/main.cf.ori

Lakukan edit pada file /etc/postfix/main.cf

myhostname = virtual.uk.to
mydomain = uk.to
myorigin = $myhostname
inet_interfaces = all
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = localhost
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, permit
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf
virtual_mailbox_base = /var/vmail
virtual_uid_maps = static:501
virtual_gid_maps = static:501
alias_maps = hash:/etc/aliases
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

 3. Konfigurasi Dovecot

Kita backup file asli dari dovecot

cp/etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.ori

 Lakukan edit pada file /etc/dovecot/dovecot.conf

## Dovecot configuration file
# Protocols we want to be serving.
protocols = imap pop3 lmtp
# A comma separated list of IPs or hosts where to listen in for connections.
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
# If you want to specify non-default ports or anything more complex,
# edit conf.d/master.conf.
listen = *
# Base directory where to store runtime data.
#base_dir = /var/run/dovecot/
# Greeting message for clients.
login_greeting = Dovecot ready.
dict {
}
# Most of the actual configuration gets included below. The filenames are
# first sorted by their ASCII value and parsed in that order. The 00-prefixes
# in filenames are intended to make it easier to understand the ordering.
!include conf.d/*.conf
service auth {
unix_listener /var/spool/postfix/dovecot-auth {
user = postfix
group = postfix
mode = 0666
}
unix_listener auth-master {
user = vmail
group = vmail
mode = 0666
}
unix_listener auth-userdb {
user = vmail
group = vmail
mode = 0660
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
# Mail location and mailbox format.
mail_location = maildir:/var/vmail/%d/%n/Maildir
#
# # Authentication related settings.
# # Append this domain name if client gives empty realm.
auth_default_realm =
#
# # Authentication mechanisms.
auth_mechanisms = PLAIN LOGIN
# User/group who owns the message files:
mail_uid = 501
mail_gid = 501
# # Assign uid to virtual users.
first_valid_uid = 501
last_valid_uid = 501
# Virtual mail accounts.
userdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
passdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
# Virtual mail accounts.
userdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
passdb {
args = /etc/dovecot/dovecot-mysql.conf
driver = sql
}
protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

4. Konfigurasi Mysql

Setelah service mysql di start, maka buat user postfix dengan database postfix.

 service mysqld start
mysql -u root -p
mysql> CREATE DATABASE postfix;
mysql> grant all on postfix.* to postfix@localhost identified by '123456';
mysql> flush privileges;
mysql> \q;

Lakukan konfigurasi penghubung antars postfix dengan Mysql

vi /etc/postfix/mysql-domains.cf
host = localhost
user = postfix
password = 123456
dbname   postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
vi /etc/postfix/mysql-users.cf 
host = localhost
user = postfix
password = 123456
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = '1'
result_format = %sMaildir/
vi /etc/postfix/mysql-aliases.cf 
host = localhost
user = postfix
password = 123456
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'

Konfigurasi penghubung dovecot dan Mysql

vi /etc/dovecot/dovecot-mysql.conf
driver = mysqlconnect = host=localhost dbname=postfix user=postfix password=123456
default_pass_scheme = MD5 #MD5-CRYPT
user_query = SELECT maildir, 501 AS uid, 501 AS gid FROM mailbox WHERE username = '%u'
password_query = SELECT username as user, password FROM mailbox WHERE username = '%u' AND active='1'

5. Konfigurasi Postfixadmin

Postfixadmin merupakan aplikasi webbase yang mengatur domain dan user di postfix. Postfix admin yang dipakai merupakan versi 2.9.1

cd /var/www/html
wget http://jaist.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.91/postfixadmin-2.91.tar.gz
tar xzf postfixadmin-2.91.tar.gz mv postfixadmin-2.91 postfixadmin

Langkah selanjutnya edit file config.inc.php pada folder postfixadmin

cd /var/www/html/postfixadmin
cp config.inc.php config.inc.php.bak
vi config.inc.php
$CONF['configured'] = true; 
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = '123456';
$CONF['database_name'] = 'postfix';
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt';
$CONF['authlib_default_flavor'] = 'md5raw';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['emailcheck_resolve_domain']='NO';

Testing Postfixadmin

Buka browser  http://ip_address/postfixadmin/setup.php. Maka akan muncul seperti ini

Postfix1

Masukkan password yang berguna untuk men setup postfixadmin. Lalu tekan Generate hash. 

Postfix2

Masukkan password generate hash ke file config.inc.php di /var/www/html/postfixadmin. Pada baris bagian $CONF[‘setup_password’] =’password_generate_hash’. Setelah itu, buka kembali ke browser, tuliskan kolom- kolom dibawahnya sebagai admin (thyspir@virtual.uk.to) dari postfixadmin dan klik tombol Add Admin

Jika sudah selesai maka buka http://ip_address/postfixadmin maka akan tampil seperti ini :

Postfix3

Tuliskan login email dan password yang telah dibuat, maka akan muncul

Postfix4

Untuk membuat mail server agar dapat berjalan maka kita buat dua domain (virtual.uk.to dan virtualjumpingcrab.com) dengan memilih menu Domain List, lalu New Domain.  

Postfix5

Setelah domain dibuat maka kita membuat usernya yaitu dengan memilih menu  Virtual List -> Add Mailbox. Kita tambahkan user yang ingin kita gunakan pada masing-masing domain.

Postfix6

6. Konfigurasi Webmail dengan Squirrelmail

Pada langkah ini kita menggunakan webmail client dari squirrelmail

wget http://nchc.dl.sourceforge.net/project/squirrelmail/stable/1.4.22/squirrelmail-webmail-1.4.22.tar.gz
tar -xzf squirrelmail-webmail-1.4.22.tar.gz
mv squirrelmail-webmail-1.4.22 webmail
mkdir -p /var/local/squirrelmail/data/
mkdir -p /var/local/squirrelmail/attach/
chown apache:apache /var/local/squirrelmail/data/
chown apache:apache /var/local/squirrelmail/attach/
cd /var/www/html/webmail/

Konfigurasi webmail

cd /var/www/html/webmail
./configure
Pilih Nomor 2
Pilih Nomor 1 (masukkan domain yang dipakai yaitu virtual.uk.to)
Pilih Huruf B Pilih Nomor 8 (ketik dovecot)
Pilih huruf B Pilih Nomor 7 (Jawab dengan n, login, n)
Pilih huruf S Pilih huruf Q

Menyalakan semua service

service postfix start 
service dovecot start
service httpd start

Testing webmail dengan squirrelmail

Buka alamat http://ip_address/webmail dan masukkan login yang telah dibuat lengkap dengan domainnya (tes@virtual.uk.to)

Postfix7

Untuk mengecek log dapat menggunakan syntakas tail-f /var/log/maillog

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s