携帯・ビジネスブログ・CGIスクリプト-qmailとtcpwrapperをインストース、設定、起動します。

トップオープンソース> qmailでバーチャルドメインを構築しよう(その2)

qmailでバーチャルドメインを構築しよう(その2)

qmailとtcpwrapperをインストース、設定、起動します。

はじめに

まずは、既存のsendmailやimap、popdを削除します。
rpm -e imap
rpm -e sendmail
chmod 0 /bin/mail
chmod 0 /usr/bin/mail.local

1.ダウンロードしましょ

qmail とtcpseverは以下より。
http://www.qmail.jp/qmail.html

2.前段階

mkdir /var/qmail
/usr/sbin/groupadd nofiles
/usr/sbin/useradd -g nofiles -d /var/qmail/alias -s /bin/true alias
/usr/sbin/useradd -g nofiles -d /var/qmail -s /bin/true qmaild
/usr/sbin/useradd -g nofiles -d /var/qmail -s /bin/true qmaill
/usr/sbin/useradd -g nofiles -d /var/qmail -s /bin/true qmailp
/usr/sbin/groupadd qmail
/usr/sbin/useradd -g qmail -d /var/qmail -s /bin/true qmailq
/usr/sbin/useradd -g qmail -d /var/qmail -s /bin/true qmailr
/usr/sbin/useradd -g qmail -d /var/qmail -s /bin/true qmails

3.TCPserver編

(1)解凍

gunzip -c ucspi-tcp-0.88.tar.gz | tar xvfp -

(2)ヘッダーファイルを書き換える

cd ucspi-tcp-0.88
vi error.h
extern int errno;

#include <errno.h> に書き換えます。

(3)makeします

make setup check

(4)qmail(SMTP)用のルールを作成します

vi /etc/tcp.smtp
127.:allow,RELAYCLIENT=""
ネットワークアドレス.:allow,RELAYCLIENT=""
:allow
/usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp

4.qmail編

※qmailは/var/qmail 配下にインストールされます。

(1)解凍

gunzip -c qmail-1.03.tar.gz | tar xvfp -

(2)ヘッダーファイルを書き換える

cd qmail-1.03
vi error.h
extern int errno;

#include <errno.h>
に書き換えます。

(3)makeします

make setup check
./config-fast po.hoge.co.jp

(4)設定

cd /var/qmail/alias
touch .qmail-postmaster
touch .qmail-mailer-demon
touch .qmail-root
chown alias:nofiles .qmail-*
chmod 644 .qmail-*

(5)内容確認

cd /var/qmail/control
more defaultdomain
hoge.co.jp
more locals
localhost
po.hoge.co.jp
more me
po.hoge.co.jp
more plusdomain
co.jp
more rcpthosts
localhost
po.hoge.co.jp

(6)起動スクリプト編集

cp /var/qmail/boot/home /var/qmail/rc
vi /var/qmail/rc
qmail-start ./Maildir/ splogger qmail
  ※MailboxをMaildirに変えます。

(7)とりあえずUnixユーザ向けに

/var/qmail/bin/maildirmake /etc/skel/Maildir
とすればユーザが追加されたらqmailがメール配送できるようになります。

(8)起動スクリプト

qmail付属のPOP3Dは使わないという前提で
id qmaild
uid=502(qmaild) gid=501(nofiles) 所属グループ=501(nofiles)

touch /etc/rc.d/init.d/qmail
chmod 755 /etc/rc.d/init.d/qmail
cd /etc/rc.d/rc3.d ; ln -s ../init.d/qmail ./S99qmail ; ln -s ../init.d/qmail ./K99qmail
cd /etc/rc.d/rc4.d ; ln -s ../init.d/qmail ./S99qmail ; ln -s ../init.d/qmail ./K99qmail
cd /etc/rc.d/rc5.d ; ln -s ../init.d/qmail ./S99qmail ; ln -s ../init.d/qmail ./K99qmail

(9)起動スクリプトを編集

オプションのUID/GIDをあわせます。
vi /etc/rc.d/init.d/qmail
#!/bin/sh
#
# qmail: /var/qmail
PATH=/var/qmail/bin:/usr/local/bin:/bin:/usr/bin

[ -f /var/qmail/rc ] || exit 0

case "$1" in
start)
# Start daemons.
echo "Starting qmail."
csh -cf '/var/qmail/rc &'
tcpserver -v -u 502 -g 501 -x /etc/tcp.smtp.cdb \
0 smtp /var/qmail/bin/qmail-smtpd 2>& | /var/qmail/bin/splogger smtpd 3 &
echo
touch /var/lock/qmail
;;
stop)
# Stop daemons.
echo "Shutting down qmail."
PID=`/bin/ps -aefw | grep qmail | awk '{print $2}'`
if [ ! -z "$PID" ] ; then
/bin/kill ${PID} 1> /dev/null 2>&
fi
echo
rm -f /var/lock/qmail
;;
*)
echo "Usage: S99qmail {start|stop}"
exit 1
esac

exit 0

(10)起動してみましょ

/etc/rc.d/init.d/qmail start
ps -ax|grep qmail
1929 pts/0 S 0:00 [qmail-send]
1931 pts/0 S 0:00 /var/qmail/bin/splogger smtpd 3
1934 pts/0 S 0:00 qmail-lspawn ./Maildir/
1935 pts/0 S 0:00 [qmail-rspawn]
1936 pts/0 S 0:00 [qmail-clean]

 qmail-send:SMTP接続を受け付けるデーモン
 qmail-lspawn:ローカル配送用
 qmail-rspawn:SMTP配送用

(11)接続試験

% telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 domain ESMTP
helo dude
250 domain
mail <info@hoge.co.jp>
250 ok
rcpt <info@hoge.co.jp>
250 ok
data
354 go ahead
Subject: testing

This is a test.
.
250 ok 812345679 qp 12345
quit
221 domain
Connection closed by foreign host.


related articles