2014年7月8日火曜日

CentOS5.x にpostfix2.12をソースからインストール

CentOS5.xでpostfixをyumでインストールするとバージョンが2.3.3と非常に古い。
epel-postfixリポジトリを利用して、バージョン2.9や2.10をRPMで導入するのもいいのですが、どうせなら一番新しいpostfixをソースからインストールしてみよう!というのが今回の内容です。
※なお、作業はCentOS5.10(x86_64)で実施しています。


今回インストールする条件

※あくまでも1例です。
  必ずこの通りビルドしなくてはいけないという事ではないので、ドキュメントで良く確認して必要な機能を増減させてください。


・以下の2つを実現するためにstableな2.11ではなく、experimentalな2.12を利用します
 - 共有ライブラリをサポートするpostfixをビルドする
 - 様々なルックアップテーブルをプラグインとして利用する

・SMTP認証を利用します(タイプはdovecot)
・ルックアップテーブルとしてPCREを利用します
・TLSを利用します



Postfix2.12のインストール手順


1. パッケージ postfixのアンインストール

もし、インストールされていない場合は、一度インストールを実施してください。
インストール実施後、起動ファイルの/etc/rc.d/init.d/postfixを任意の場所に退避(コピー)してから改めてアンインストールを実施してください。
これで、以下の2つの作業が省略できます。

 - postfixの動作に必要なユーザやグループの作成
 - 起動ファイルの作成


2. パッケージ sendmailのアンインストール

もし、インストールされているようであればアンインストールしてください。
※Postfixをソースからインストールする事で、パッケージのsendmailに含まれるsendmailコマンドやmailqコマンドを上書いてしまう為、管理を煩雑にしないためアンインストールをお勧めします
※依存関係でエラーになる場合は下記のように"--nodeps"オプションを付与して実施してください
 →他のパッケージが依存しているsendmailコマンド等は、postfixをインストールする事で用意されます

# rpm -e --nodeps sendmail


3.openssl1.x、その他のビルドに必要なパッケージのインストール

CentOS5.xのopensslのバージョンはこちらも0.9.8と古く、そのままだとpostfix2.12ではTLS関連のビルドが行えませんので、ここではソースから最新のopensslを/usr/local配下にインストールします。
$ wget -O - http://www.openssl.org/source/openssl-1.0.1h.tar.gz | tar zxf -
$ cd openssl-1.0.1h/
$ ./config  --prefix=/usr/local
$ make
$ su
# make install

また、Postfixのビルドに必要なその他のパッケージを以下のようにインストールしておきます。
# yum -y install pcre-devel db4-devel


4.ソースの展開

$ wget http://mirror.postfix.jp/postfix-release/experimental/postfix-2.12-20140703.tar.gz  ←★改行されてますがここまでが1行
$ tar zxf postfix-2.12-20140703.tar.gz
$ cd postfix-2.12-20140703


 5.makefilesの作成

インストールする条件に合わせて、以下のように実施します。

$ make makefiles shared=yes \
shlib_directory=/usr/lib64/postfix/2.12-20140703/ dynamicmaps=yes \
CCARGS="-DUSE_TLS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\" \
-I/usr/local/include/openssl" \
AUXLIBS="-lssl -lcrypto -L/usr/local/lib64" \
AUXLIBS_PCRE=`pcre-config --libs`


6. ビルドとインストール

$ make
$ su
# make install
   (snip)
  ※以下、聞かれる質問には、表示されるものをそのまま選択します(Enterを押していきます)。
Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to OTHER
machines. See PACKAGE_README for instructions.
install_root: [/]
Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/home/toshiaki/postfix-2.12-20140703]
Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix]
Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin]
Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search path
of any users.
daemon_directory: [/usr/libexec/postfix]
Please specify the final destination directory for Postfix-writable
data files such as caches or random numbers. This directory should not
be shared with non-Postfix software.
data_directory: [/var/lib/postfix]
Please specify the final destination directory for the Postfix HTML
files. Specify "no" if you do not want to install these files.
html_directory: [no]
Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix]Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing command.
mailq_path: [/usr/bin/mailq]
Please specify the final destination directory for the Postfix on-line
manual pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/man]
Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases]
Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix]
Please specify the final destination directory for the Postfix README
files. Specify "no" if you do not want to install these files.
readme_directory: [no]
Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting interface.
sendmail_path: [/usr/sbin/sendmail]
Please specify the group for mail submission and for queue management
commands. Specify a group name with a numerical group ID that is
not shared with other accounts, not even with the Postfix mail_owner
account. You can no longer specify "no" here.
setgid_group: [postdrop]
Please specify the final destination directory for Postfix shared-library
files.
shlib_directory: [/usr/lib64/postfix/2.12-20140703/]
Please specify the final destination directory for non-executable files
that are shared among multiple Postfix instances, such as postfix-files,
dynamicmaps.cf, as well as the multi-instance template files main.cf.proto
and master.cf.proto.
meta_directory: [/etc/postfix]

 (snip)

    Warning: you still need to edit myorigin/mydestination/mynetworks
    parameter settings in /etc/postfix/main.cf.
    See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
    for information about dialup sites or about sites inside a firewalled
    network.
    BTW: Check your /etc/aliases file and be sure to set up aliases
    that send mail for root and postmaster to a real person, then run
    /usr/bin/newaliases.
#



Postfixの起動など

後は、/etc/aliasesや/etc/postfix/main.cfなどの設定ファイルを編集しすれば、postfixが起動できます。

# postfix start (もしくは # /usr/sbin/postfix start

また、os起動時にpostfixを自動起動させるには、postfixをアンインストールする前に退避させておいた/etc/rc.d/init.d/postfixファイルを元の場所にもどし、以下のように設定します。

# chkconfig --add postfix
# chkconfig postfix on 



(備考)

静的ライブラリと共有ライブラリでのバイナリファイルのサイズの違い


<静的ライブラリ>
# ls -lh /usr/sbin/post*
-rwxr-xr-x 1 root root     193K Jan  9  2013 /usr/sbin/postalias*
-rwxr-xr-x 1 root root     112K Jan  9  2013 /usr/sbin/postcat*
-rwxr-xr-x 1 root root     261K Jan  9  2013 /usr/sbin/postconf*
-rwxr-sr-x 1 root postdrop 168K Jan  9  2013 /usr/sbin/postdrop*
-rwxr-xr-x 1 root root     100K Jan  9  2013 /usr/sbin/postfix*
-rwxr-xr-x 1 root root     112K Jan  9  2013 /usr/sbin/postkick*
-rwxr-xr-x 1 root root     108K Jan  9  2013 /usr/sbin/postlock*
-rwxr-xr-x 1 root root     100K Jan  9  2013 /usr/sbin/postlog*
-rwxr-xr-x 1 root root     185K Jan  9  2013 /usr/sbin/postmap*
-rwxr-sr-x 1 root postdrop 189K Jan  9  2013 /usr/sbin/postqueue*
-rwxr-xr-x 1 root root     116K Jan  9  2013 /usr/sbin/postsuper*

<共有ライブラリ>
 ※サイズが大幅に小さくなっているのが確認できます
# ls -lh /usr/sbin/post*
-rwxr-xr-x 1 root root      34K Jul  7 00:34 /usr/sbin/postalias*
-rwxr-xr-x 1 root root      29K Jul  7 00:34 /usr/sbin/postcat*
-rwxr-xr-x 1 root root     318K Jul  7 00:34 /usr/sbin/postconf*
-rwxr-sr-x 1 root postdrop  27K Jul  7 00:34 /usr/sbin/postdrop*
-rwxr-xr-x 1 root root      22K Jul  7 00:34 /usr/sbin/postfix*
-rwxr-xr-x 1 root root      16K Jul  7 00:34 /usr/sbin/postkick*
-rwxr-xr-x 1 root root      19K Jul  7 00:34 /usr/sbin/postlock*
-rwxr-xr-x 1 root root      18K Jul  7 00:34 /usr/sbin/postlog*
-rwxr-xr-x 1 root root      39K Jul  7 00:34 /usr/sbin/postmap*
-rwxr-xr-x 1 root root      52K Jul  7 00:34 /usr/sbin/postmulti*
-rwxr-sr-x 1 root postdrop  30K Jul  7 00:34 /usr/sbin/postqueue*
-rwxr-xr-x 1 root root      48K Jul  7 00:34 /usr/sbin/postsuper*




0 件のコメント:

コメントを投稿