2012年11月25日日曜日

コミュニティ版PostgreSQL9.2 + postfix2.9.4

前回インストールしたコミュニティ版のPostgreSQLをpostfixから利用できるようにする。
(また、デフォルトで組みまれるMySQLは使わないので、組み込まれないようにする)
今回も環境はCentOS6.3で、SRPMはFedoraのメンテナさんのサイトより入手したものを利用した。

以下、その手順。


SPECファイルの編集



[root@cent6 ~]# wget http://mstevens.fedorapeople.org/el6/postfix/2.9.4/x86_64/postfix-2.9.4-1.el6.src.rpm
[root@cent6 ~]# rpm -ivh postfix-2.9.4-1.el6.src.rpm
[root@cent6 ~]# cd rpmbuild/SPECS/
[root@cent6 SPECS]# cp -p postfix.spec{,.orig}
[root@cent6 SPECS]# vi postfix.spec

※編集後のdiff出力

[root@cent6 SPECS]# diff -u postfix.spec.orig postfix.spec
--- postfix.spec.orig   2012-08-02 22:30:10.000000000 +0900
+++ postfix.spec        2012-11-25 16:41:59.135013035 +0900
@@ -83,7 +83,7 @@
 %{?with_sasl:BuildRequires: cyrus-sasl-devel}
 %{?with_pcre:BuildRequires: pcre-devel}
 %{?with_mysql:BuildRequires: mysql-devel}
-%{?with_pgsql:BuildRequires: postgresql-devel}
+%{?with_pgsql:BuildRequires: postgresql92-devel}
 %{?with_tls:BuildRequires: openssl-devel}

 %description
@@ -153,8 +153,8 @@
   AUXLIBS="${AUXLIBS} -L%{_libdir}/mysql -lmysqlclient -lm"
 %endif
 %if %{with pgsql}
-  CCARGS="${CCARGS} -DHAS_PGSQL -I%{_includedir}/pgsql"
-  AUXLIBS="${AUXLIBS} -lpq"
+  CCARGS="${CCARGS} -DHAS_PGSQL -I/usr/pgsql-9.2/include"
+  AUXLIBS="${AUXLIBS} -L/usr/pgsql-9.2/lib -lpq"
 %endif
 %if %{with sasl}
   CCARGS="${CCARGS} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I%{_includedir}/sasl"
[root@cent6 SPECS]#



ビルドとインストール


[root@cent6 SPECS]# rpmbuild -bb --define="dist .el6" --with pgsql --without mysql postfix.spec

(snip)

Wrote: /root/rpmbuild/RPMS/x86_64/postfix-2.9.4-1.el6.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/postfix-perl-scripts-2.9.4-1.el6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.QQTcLP
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd postfix-2.9.4
+ rm -rf /root/rpmbuild/BUILDROOT/postfix-2.9.4-1.el6.x86_64
+ exit 0
[root@cent6 SPECS]#
[root@cent6 SPECS]# cd ../RPMS/x86_64/
[root@cent6 x86_64]# rpm -Fvh postfix-2.9.4-1.el6.x86_64.rpm postfix-perl-scripts-2.9.4-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:postfix                ########################################### [ 50%]
   2:postfix-perl-scripts   ########################################### [100%]
[root@cent6 x86_64]#



確認作業


[root@cent6 x86_64]# postconf -m
btree
cidr
environ
fail
hash
internal
ldap
memcache
nis
pcre
pgsql  ←★この行が表示されればOK
proxy
regexp
static
tcp
texthash
unix
[root@cent6 x86_64]#
[root@cent6 x86_64]# ldd /usr/sbin/postfix | grep pg
        libpq.so.5 => /usr/pgsql-9.2/lib/libpq.so.5 (0x00007fa9a5f51000)
[root@cent6 x86_64]#

2012年11月18日日曜日

コミュニティ版 PostgreSQL 9.2


2014/02/10 追記: こちらにコミュニティ版PostgreSQL9.3のねたをUPしました。


普段はソースからインストールするのだが、趣向を変えてコミュニティ版RPMでセットアップしてみる。

なお、今回インストールした環境はCentOS6.3なので、ここからCentOS 6 - x86_64用のものを利用した。

以下、その手順。


インストール



[root@cent6 ~]# rpm -ivh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
[root@cent6 ~]# yum -y install postgresql92-server.x86_64 postgresql92-devel.x86_64





環境整備

/usr/local/pgsqlな環境に慣れているとすごい違和感を感じるが、/usr/pgsql-9.2配下に何でもインストールされるので、もろもろの環境を整備する。
#何でそんなパスにインストールされるかというと、このあたりに詳しく書かれている

[root@cent6 ~]# su - postgres
[postgres@cent6 ~]$ vi .bash_profile


※以下、その内容

 PATH=$PATH:$HOME/bin:/usr/pgsql-9.2/bin
 PGDATA=/var/lib/pgsql/9.2/data
 MANPATH="$MANPATH":/usr/pgsql-9.2/share/man

 export PATH PGDATA MANPATH

※即時反映するには、以下を実行

[postgres@cent6 ~]$ source .bash_profile




データベース・クラスタの作成と起動


[postgres@cent6 ~]$ initdb --no-locale --encoding=UTF-8
[postgres@cent6 ~]$ pg_ctl start -D $PGDATA
server starting
[postgres@cent6 ~]$ ps -fC postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  1560     1  0 23:44 pts/1    00:00:00 /usr/pgsql-9.2/bin/postgres -D /var/lib/pgsql/9.2/data
postgres  1561  1560  0 23:44 ?        00:00:00 postgres: logger process
postgres  1563  1560  0 23:44 ?        00:00:00 postgres: checkpointer process
postgres  1564  1560  0 23:44 ?        00:00:00 postgres: writer process
postgres  1565  1560  0 23:44 ?        00:00:00 postgres: wal writer process
postgres  1566  1560  0 23:44 ?        00:00:00 postgres: autovacuum launcher process
postgres  1567  1560  0 23:44 ?        00:00:00 postgres: stats collector process
[postgres@cent6 ~]$
[postgres@cent6 ~]$ psql -l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     |
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(3 rows)

[postgres@cent6 ~]$





2012年11月4日日曜日

リモートのDovecotを利用したSMTP認証

今回は、SMTPサーバ以外のホストで既にPOP3 or IMAPサーバとしてのdovecotが稼動していて、それをSMTP認証で利用する場合の設定です。


まずは、リモートで稼動するdovecot側の設定変更をする。
※SMTPサーバが認証で使う任意のTCPポートをオープンさせる(下記の例では、12345/TCP)



/etc/dovecot/conf.d/10-master.conf:

service auth {
 unix_listener auth-userdb {
 }

 inet_listener {
   port = 12345
 }
}





次に、SMTPサーバ(postfix)側の設定を変更する。
※main.cfに以下の記述をする
 →リモートでdovecotが稼動しているサーバのIPアドレスとポートを指定



smtpd_sasl_type = dovecot
smtpd_sasl_path = inet:192.168.0.117:12345