2012年12月24日月曜日

DRBD 8.4.x  設定(初回フル同期スキップ)

前回作成したRPMをインストールし、設定を行っていきます。


(注意)OSインストール時にパーティションを切る場合、DRBDで利用する領域は”未割り当て”
    な状態としておく必要があります     
    →マウントポイントを作成しない or フォーマットもしない”空き領域”としておきます
    

今回の検証環境は、VMware上に稼動系と待機系の2台を用意して行っています。

■稼動系
ホスト名: node01
OS: CentOS6.3(x86_64)
DRBD: Ver8.4.2
OS領域: /dev/sda
DRBD領域: /dev/sdb
ネットワークインターフェース: 3つ

■待機系
ホスト名: node01
OS: CentOS6.3(x86_64)
DRBD: Ver8.4.2
OS領域: /dev/sda
DRBD領域: /dev/sdb
ネットワークインターフェース: 3つ



<構成概要図>


インストール

●node01とnode02で実施

# rpm -ivh *.rpm
Preparing...                ########################################### [100%]
   1:drbd-utils             ########################################### [ 17%]
   2:drbd-bash-completion   ########################################### [ 33%]
   3:drbd-pacemaker         ########################################### [ 50%]
   4:drbd-udev              ########################################### [ 67%]
   5:drbd                   ########################################### [ 83%]
   6:drbd-km-2.6.32_279.19.1########################################### [100%]
#


※ここでインストールしたdrbd-bash-completionパッケージにより、drbdadmコマンドのサブコマンドにTAB補完が効くようになるので以下のようにすると楽ができます。

# echo "source /etc/bash_completion.d/drbdadm" >> ~/.bash_profile
# source ~/.bash_profile




DRBD領域の用意

●node01とnode02で実施
※以下では、/dev/sdbを全てDRBDの領域に割り当てています

# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa235ee65.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n    ←★新しいパーティションを作成
Command action
   e   extended
   p   primary partition (1-4)
p                 ←★プライマリパーティションとして指定
Partition number (1-4): 1       ←★パーティションの1番目を指定
First cylinder (1-652, default 1):  ←★そのままEnterを押す
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): ←★そのままEnter
Using default value 652

Command (m for help): p    ←★作成したパーティションを確認表示

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa235ee65

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  83  Linux

Command (m for help): w    ←★問題なければディスクに書き込み
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
#



設定ファイルの作成

●node01とnode02で実施
※以下は、最低限必要となるパラメータで作成しています
※パラメータの説明はここではしませんので、man 5 drbd.confやドキュメントで確認してください

/etc/drbd.d/global_common.conf:


global {
        usage-count no;
}
common {
        net {
                protocol C;
        }
        syncer {
                rate 100M;
        }
}




/etc/drbd.d/r0.res:


resource r0 {
  volume 0 {
     device    minor 0;
disk      /dev/sdb1;
  meta-disk internal;
   }
on node01 {             ←★"uname -n"の値をon以下に指定
address   10.0.0.91:7789;
}
on node02 {
address   10.0.0.92:7789;
}
}





metaデータの領域を作成

●node01とnode02で実施
もし、「'r0' not defined in your config (for this host).」のようなエラーが表示されたら、
 設定ファイルに”uname -n”で出力されたホスト名を指定しているか再確認を


# drbdadm create-md r0 (もしくは drbdadm create-md r0/0)
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
#



DRBDの起動

●node01とnode02で実施

# /etc/rc.d/init.d/drbd start
Starting DRBD resources: [
     create res: r0
   prepare disk: r0
    adjust disk: r0
     adjust net: r0
]
.....
#

この作業後、DRBDの状態を確認すると

[root@node01 ~]# cat /proc/drbd
version: 8.4.2 (api:1/proto:86-101)
GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by user01@node01.example.com, 2012-12-22 01:11:07
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:5236960
[root@node01 ~]#

もしくは、

[root@node01 ~]# drbd-overview
  0:r0/0  Connected Secondary/Secondary Inconsistent/Inconsistent C r-----
[root@node01 ~]#



となる。



初回フル同期スキップを実施

●どちらかのノードで実施(以下では、node01で実施)
※DRBDは、初回利用時に各ノードのDRBD領域をフル同期する必要があるが、同期する容量
 によっては同期が完了するまでに非常に時間がかかってしまうので、、ここではフル同期を
 スキップさせる方法をとってみる。
なお、このスキップの方法はver8.4系のものなので、それ以外のバージョンを利用する場合は、
 そのバージョンのドキュメントを確認してください

[root@node01 ~]# drbdadm new-current-uuid --clear-bitmap r0/0



この作業後、DRBDの状態を確認すると

[root@node01 ~]# cat /proc/drbd
version: 8.4.2 (api:1/proto:86-101)
GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by toshiaki@node01.do-style.com, 2012-12-22 01:11:07
 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@node01 ~]#

もしくは、

[root@node01 ~]# drbd-overview
  0:r0/0  Connected Secondary/Secondary UpToDate/UpToDate C r-----
[root@node01 ~]#


となる。
 →DiskのStatusが、InconsistentからUpToDateな状態へ遷移する


(余談)初回フル同期スキップをver8.3の時のようにをvolume idを指定しないで実施した
    ところ以下のようなエラーが表示された。

[root@node01 ~]# drbdadm new-current-uuid --clear-bitmap r0
new-current-uuid requires a specific volume id, but none is specified.
Try 'new-current-uuid minor-<minor_number>' or 'new-current-uuid r0/<vnr>'
[root@node01 ~]#

ドキュメントには<resouce>としか書いてないので、不親切ですね。



DRBD領域のマウントまで

●稼動系にしたいノードで実施(以下では、node01で実施)
※DRBD領域を/dataにマウントする


[root@node01 ~]# drbdadm primary r0
[root@node01 ~]# mkfs.ext4 /dev/drbd0  ←★ext4でフォーマット
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309240 blocks
65462 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@node01 ~]#
[root@node01 ~]# tune2fs -c 0 -i 0 /dev/drbd0
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
[root@node01 ~]#
[root@node01 ~]# mkdir /data
[root@node01 ~]# mount /dev/drbd0 /data
[root@node01 ~]#
[root@node01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.3G   16G   8% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             194M   63M  122M  34% /boot
/dev/drbd0            5.0G  138M  4.6G   3% /data
[root@node01 ~]#
[root@node01 ~]# drbd-overview
  0:r0/0  Connected Primary/Secondary UpToDate/UpToDate C r----- /data ext4 5.0G 138M 4.6G 3%
[root@node01 ~]#








2012年12月16日日曜日

DRBD 8.4.x RPM作成

2014/08/04追記: 「DRBD 8.4.x コミュニティバイナリでセットアップ」も参照ください



今回の環境は、CentOSの6.3です。
CentOS5.xではextrasに存在していたはずのdrbd8xパッケージが(探し方が悪いのか)見つからないので、自分で作る事にしました。

以下、その手順(ドキュメントはここ)。


事前準備


今回、RPMを作成するにあたり、以下のパッケージが必要だったので、事前にインストールした。

・flex
・kernel-devel
・libxslt



SPECファイルの作成


RPMを作成するにあたり、極力必要のないパッケージは作りたくないし、インストールもしたくないので先にSPECファイルを作成する。
※自分には、drbd-xenパッケージが必要ない


[user01@node01 ~]$ wget http://oss.linbit.com/drbd/8.4/drbd-8.4.2.tar.gz
[user01@node01 ~]$ tar zxf drbd-8.4.2.tar.gz
[user01@node01 ~]$ cd drbd-8.4.2
[user01@node01 drbd-8.4.2]$ ./configure --enable-spec --with-km

(snip)

config.status: creating drbd.spec
config.status: creating drbd-km.spec
config.status: creating drbd-kernel.spec
[user01@node01 drbd-8.4.2]$


これで、3つのspecファイルが生成される。



カーネルモジュール以外のRPMの作成



[user01@node01 drbd-8.4.2]$ cd ..
[user01@node01 ~]$ cp drbd-8.4.2.tar.gz rpmbuild/SOURCES/
[user01@node01 ~]$ rpmbuild --define="dist .el6" --without xen \
> -bb drbd-8.4.2/drbd.spec

(snip)

Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-8.4.2-2.el6.x86_64.rpm
Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-utils-8.4.2-2.el6.x86_64.rpm
Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-udev-8.4.2-2.el6.x86_64.rpm
Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-pacemaker-8.4.2-2.el6.x86_64.rpm
Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-heartbeat-8.4.2-2.el6.x86_64.rpm
Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-bash-completion-8.4.2-2.el6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.mLoAdQ
+ umask 022
+ cd /home/toshiaki/rpmbuild/BUILD
+ cd drbd-8.4.2
+ rm -rf /home/toshiaki/rpmbuild/BUILDROOT/drbd-8.4.2-2.el6.x86_64
+ exit 0
[user01@node01 ~]$




カーネルモジュールを含むRPMの作成



[user01@node01 ~]$ rpmbuild --define="dist .el6" -bb drbd-8.4.2/drbd-km.spec

(snip)

Wrote: /home/toshiaki/rpmbuild/RPMS/x86_64/drbd-km-2.6.32_279.14.1.el6.x86_64-8.4.2-2.el6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.hGEqVw
+ umask 022
+ cd /home/toshiaki/rpmbuild/BUILD
+ cd drbd-8.4.2
+ rm -rf /home/toshiaki/rpmbuild/BUILDROOT/drbd-km-8.4.2-2.el6.x86_64
+ exit 0
[user01@node01 ~]$




以上で、今後の作業に必要なRPMが作成できた。


[user01@node01 ~]$ ls -l rpmbuild/RPMS/x86_64/
total 2368
-rw-rw-r-- 1 user01 user01   25670 Dec 15 17:47 drbd-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01    5917 Dec 15 17:47 drbd-bash-completion-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01    7822 Dec 15 17:47 drbd-heartbeat-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01 1973374 Dec 15 17:49 drbd-km-2.6.32_279.14.1.el6.x86_64-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01   22448 Dec 15 17:47 drbd-pacemaker-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01    4626 Dec 15 17:47 drbd-udev-8.4.2-2.el6.x86_64.rpm
-rw-rw-r-- 1 user01 user01  371090 Dec 15 17:47 drbd-utils-8.4.2-2.el6.x86_64.rpm
[user01@node01 ~]$

2012年12月10日月曜日

CentOS5でrsyslog ver7.xを使う

rsyslog ver7.2.3のリリースノートを覗いたらRPMのリポジトリが用意されたようなので、利用してみる。
なお、今回の環境はCentOS5.8で、普通のsyslogが稼動している状態から検証している。

以下、その手順。


リポジトリの作成


ここの記述どおりに、/etc/yum.repos.d/rsyslog.repo として 作成した。



インストール


[root@cent5 ~]# yum install rsyslog
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package rsyslog.i386 0:7.2.3-1.el5.centos set to be updated
--> Processing Dependency: libjson.so.0 for package: rsyslog
--> Processing Dependency: libestr.so.0 for package: rsyslog
--> Processing Dependency: libee.so.0 for package: rsyslog
--> Running transaction check
---> Package json-c.noarch 0:0.9-4.el5.centos set to be updated
---> Package libee.i386 0:0.4.1-1.el5.centos set to be updated
---> Package libestr.i386 0:0.1.3-1.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================
 Package           Arch             Version                         Repository            Size
========================================================================
Installing:
 rsyslog           i386             7.2.3-1.el5.centos              rsyslog_v7           885 k
     replacing  sysklogd.i386 1.4.1-46.el5

Installing for dependencies:
 json-c            noarch           0.9-4.el5.centos                rsyslog_v7            37 k
 libee             i386             0.4.1-1.el5.centos              rsyslog_v7            22 k
 libestr           i386             0.1.3-1.el5.centos              rsyslog_v7           7.9 k

Transaction Summary
========================================================================
Install       4 Package(s)
Upgrade       0 Package(s)

Total size: 952 k
Total download size: 922 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): json-c-0.9-4.el5.centos.noarch.rpm                               |  37 kB     00:00
(2/2): rsyslog-7.2.3-1.el5.centos.i386.rpm                              | 885 kB     00:02
-------------------------------------------------------------------------
Total                                                          181 kB/s | 922 kB     00:05
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : libestr                                                                 1/5
  Installing     : libee                                                                   2/5
  Installing     : json-c                                                                  3/5
  Installing     : rsyslog                                                                 4/5
  Erasing        : sysklogd                                                                5/5

Installed:
  rsyslog.i386 0:7.2.3-1.el5.centos

Dependency Installed:
  json-c.noarch 0:0.9-4.el5.centos                libee.i386 0:0.4.1-1.el5.centos
  libestr.i386 0:0.1.3-1.el5.centos

Replaced:
  sysklogd.i386 0:1.4.1-46.el5

Complete!
[root@cent5 ~]#



起動


後は起動するだけだが、”-c”オプションがobsoleteになっている(man rsyslogdで確認を)ようで、単純に起動すると以下のようにerrorがでる。

[root@cent5 ~]# /etc/rc.d/init.d/rsyslog start
Starting system logger: rsyslogd: error: option -c is no longer supported - ignored
                                                           [  OK  ]
[root@cent5 ~]#


なので、/etc/sysconfig/rsyslogの記述を以下のように修正し、rsyslogを再起動する。

SYSLOGD_OPTIONS=""


(備考)


なお、/etc/rsyslog.confは特にいじらなくても普通に起動できるが、v6 formatというのもあるらしい。
こちらはおいおい・・・


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

2012年10月15日月曜日

SMTP認証専用のdovecot

最近は、PostfixでSMTP認証をする際にdovecotを利用するケースが増えてきたのだが、SMTP認証のためだけにPOP/IMAPサーバを起動するのが嫌な場合(というよりPOP/IMAPのサービスが不要であればこちらを推奨する)は、dovecotを認証専用のサービスとして起動すればいい。

具体的には、まず /etc/dovecot/dovecot.conf でprotocolsを以下のように設定する。
 
        protocols = none

その上で、dovecotのドキュメントにあるように、/etc/dovecot/conf.d/10-master.confに
以下のように設定する。


   service auth {
      unix_listener /var/spool/postfix/private/auth {
        group = postfix
        mode = 0666
       user = postfix
      }
    }

あとは、dovecotが認証に利用する情報に合わせて/etc/dovecot/conf.d/10-auth.confあたりを編集してdovecotを起動すればいい。


起動後、netstatで確認すると以下のようになる。

[root@fc17 ~]# netstat -ant | egrep '110|143|993|995'
[root@fc17 ~]#
※POP/IMAP関連のポートはオープンしていない


なお、Postifx側の設定は(詳細はドキュメントで要確認)、main.cfに以下の記述をすれば良い。

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

2012年10月8日月曜日

yum パッケージのダウングレード

パッケージを最新にアップデートしたものの何かしら不具合が見つかり、古いバージョンに戻したいといった場合は以下のようにする。

 例えば、Fedora17でdovecotをダウングレードする場合
※Ver2.1.10からVer2.1.5へダウングレード

 [root@fc17 ~]# rpm -q dovecot 
dovecot-2.1.10-1.fc17.x86_64
[root@fc17 ~]#
[root@fc17 ~]# yum downgrade dovecot

読み込んだプラグイン:langpacks, presto, refresh-packagekit
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ dovecot.x86_64 1:2.1.5-1.fc17 は ダウングレード です
---> パッケージ dovecot.x86_64 1:2.1.10-1.fc17 は 削除 です
--> 依存性解決を終了しました。

依存性を解決しました

========================================================================
 Package        アーキテクチャ               バージョン                          リポジトリー                  容量
========================================================================
ダウングレード中:
 dovecot           x86_64                       1:2.1.5-1.fc17                      fedora                       2.3 M

トランザクションの要約
========================================================================
ダウングレード  1 パッケージ

総ダウンロード容量: 2.3 M
これでいいですか? [y/N]


これと同じ事をyumではなくrpmコマンドで実施する場合は、ローカルに古いバージョンのパッケージを用意して、以下のようにする。

# rpm -Uvh --oldpackage [pakage名]



なお、yumでバージョンまで調べようとした場合、最新のパッケージしか調べられない(表示されない)と思うが、/etc/yum.confの[main]セクションに以下の記述を追記することにより、全てのバージョンが調べられるようになる。

showdupesfromrepos=1

例えばdovecotを調べると、以下のようになる。

[root@fc17 ~]# yum list | grep dovecot
dovecot.x86_64                         1:2.1.10-1.fc17               @updates
dovecot.i686                           1:2.1.5-1.fc17                fedora
dovecot.x86_64                         1:2.1.5-1.fc17                fedora
dovecot.i686                           1:2.1.10-1.fc17               updates
dovecot.x86_64                         1:2.1.10-1.fc17               updates
dovecot-devel.i686                     1:2.1.5-1.fc17                fedora
dovecot-devel.x86_64                   1:2.1.5-1.fc17                fedora
dovecot-devel.i686                     1:2.1.10-1.fc17               updates
dovecot-devel.x86_64                   1:2.1.10-1.fc17               updates
dovecot-mysql.x86_64                   1:2.1.5-1.fc17                fedora
dovecot-mysql.x86_64                   1:2.1.10-1.fc17               updates
dovecot-pgsql.x86_64                   1:2.1.5-1.fc17                fedora
dovecot-pgsql.x86_64                   1:2.1.10-1.fc17               updates
dovecot-pigeonhole.x86_64              1:2.1.5-1.fc17                fedora
dovecot-pigeonhole.x86_64              1:2.1.10-1.fc17               updates
[root@fc17 ~]#

2012年9月16日日曜日

知らなかったコマンド

何かの拍子に知らないコマンドの存在に気づくことがある。

最近知ったのは、usleepコマンドとsetquotaコマンド。

usleepコマンド

sleepコマンドより単位を細かくしたもの。
例えば、10秒カウントするなら以下のように使う。
#例がよくない(普通にsleep 10で事足りる)

[root@fc17 ~]# time usleep 10000000

real    0m10.001s
user    0m0.000s
sys     0m0.000s
[root@fc17 ~]#




 setquotaコマンド

普段は、edquotaコマンドを利用していたが、こちらの方がわかりやすいかも。
使い方はこんな感じ。
#ハードリミットとして2GBを割り当て

[root@fc17 ~]# setquota -u $USER 0 2048000 0 0 $QUOTA_PARTITION

2012年9月9日日曜日

クラウドメッセージングサミット

9/6に開催されたそれに参加してきた。

期待していたVMwareのセッションは、単にZimbra(ジンブラ)の紹介で終わってナンだよー感たっぷりだったが、それでも(自分にとって)有益な情報を得られたので、メモレベルだが以下に記す。

Sentrion
Sendmail社の製品で、ハードウェア形仮想アプライアンスの2種類がある。
基本となるプラットフォームに、必要な機能(例えばアンチスパム+アンチウィルスなどなど)だけを取り入れてシステムを構築できる。以前からMailstream Managerという製品がありそれに似ているが、送信者認証など実現可能な事が増えている。

RING Organic Storage
安価な普通のLinuxサーバを使って、分散型かつスケールアウトできるストレージを実現する技術だそうです。この技術を上手く使えれば以下のようなケースはあまり考えなくて済みそうです。
  • SANやNASを使ってシステムを構築し、そのシステムの更新時期にデータの移行やマイグレーションが発生し、システムを停止する必要に迫られるケース
  • メールデータが肥大化し、そのデータのレプリケーションにも時間がかかり、レプリケーション自体が破綻するようなケース



2012年8月27日月曜日

Fedora17でyumが使えなくなった

何か変更したつもりは全くないが、最近になってyumを使うと以下のようなエラーが出るようになった。

 [root@fc17 ~]# yum update
読み込んだプラグイン:langpacks, presto, refresh-packagekit
 http://ftp.riken.jp/Linux/fedora/releases/17/Everything/x86_64/os/repodata/repomd.xml: [Errno 14] curl#7 - "Couldn't connect" 他のミラーを試します。
 エラー: failure: repodata/repomd.xml from fedora: [Errno 256] No more mirrors to try.
 [root@fc17 ~]#

何でだろう?と思いつつ、/etc/yum.repos.d配下のファイルを編集してみても状況はかわらず。。
ネットワーク周りをひとつずつ見直していたらデフォルトゲートウェイがなくなっている事に気づいた。


[root@fc17 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 p1p1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 p1p1
[root@fc17 ~]#

ということで修正を施し(/etc/sysconfig/networkにGATEWAYを追加)、

[root@fc17 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 p1p1
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 p1p1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 p1p1
[root@fc17 ~]#

これで、問題なくyumが使えるようになりました。

2012年8月19日日曜日

systemdになって変わったもの

最近のFedoraではchkconfigコマンドやserviceコマンドの役割がsystemctlコマンドに引き継がれていて、使い方に慣れるのまでが結構面倒でした(何故にSolarisっぽくなった?)。

さらに(普段はSSHでしかログインしないので)ふとランレベルを変更しようと/etc/inittabを開いたところ、コメントが書かれている以外何もない状態になっていました。(Fedora17で確認、それより前のVersionではランレベルの記述だけはあったと記憶しているのですが)。
で、そのコメントに、Ctrl-Alt-Deleteを押した時の動作やランレベルの変更についてきちんと書かれており、そのコメントに従えば(具体的には以下のように実行すれば)ランレベルが変更されました。

# cd /etc/systemd/system/
# ls -l default.target
lrwxrwxrwx. 1 root root 36  6月  2 08:47 default.target -> /lib/systemd/system/runlevel5.target
# ln -f -s /lib/systemd/system/runlevel3.target  /etc/systemd/system/default.target
   ※ここで"-f"オプションを付与する事で、runlevel5.targetへ張られていたシンボリックリンクを
    強制的に上書きを行います

2012年8月12日日曜日

yumでセキュリティパッチだけを適用する

Red Hatが提供するアップデートには以下のものがある。

 ・セキュリティに関する修正      RHSA(Red Hat Security Advisory)
 ・バグに関する修正           RHBA(Red Hat Bug Fix Advisory)
 ・機能強化や追加に関する修正 RHEA(Red Hat Enhancement Advisory)

通常yum update をするとこれら全ての修正がアップデート対象になりますが、"--security"という
オプションを付与するとRHSAに関する修正だけをアップデート対象にする事ができます。

このオプションを使うと、例えばハードウェアベンダーのサポートがRHEL5.7でないと
受けれない場合、(表現の仕方が正しいかは微妙ですが)RHEL5.7をHOLDしたまま
アップデート・パッケージを適用するといった運用ができるようになっています。
#RHELでは5.1以降で利用可能
#CentOS5 or 6でも、yum-securityパッケージを導入することにより利用可能

[root@cent5 ~]# yum info yum-security
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: rsync.atworks.co.jp
 * extras: rsync.atworks.co.jp
 * updates: ftp.iij.ad.jp
Available Packages
Name       : yum-security
Arch       : noarch
Version    : 1.1.16
Release    : 21.el5.centos
Size       : 27 k
Repo       : base
Summary    : Yum plugin to enable security filters
URL        : http://linux.duke.edu/yum/download/yum-utils/
License    : GPLv2+
Description: This plugin adds the options --security, --cve, --bz and --advisory flags
           : to yum and the list-security and info-security commands.
           : The options make it possible to limit list/upgrade of packages to specific
           : security relevant ones. The commands give you the security information.
[root@cent5 ~]#

CentOSの場合、man 8 yum-securityで詳細を確認してください。

2012年8月5日日曜日

任意のタイミングでのログをローテーションする

例えば、メールログを日付が変わる0:00のタイミングでローテートし、日付をつけて保存したい場合などはないでしょうか?自分の場合、そんな時は以下のようにしています。

1.OS標準のログローテートからはずす

  メールログの場合は、/etc/logrotate.d/syslogを修正する
      →/var/log/maillogの記述を削除する

 (修正前)
 /var/log/messages /var/log/maillog /var/log/secure /var/log/spooler /var/log/boot.log /var/log/cron {


 (修正後)
 /var/log/messages /var/log/secure /var/log/spooler /var/log/boot.log /var/log/cron {

2.ログをローテートさせるスクリプトを作成する

 例)maillog-rotate.sh  (コテコテですが)
 <ここから>------------------------------------------------------------------
 #!/bin/bash
 

 PID=`cat /var/run/rsyslogd.pid`
 SRCDIR=/var/log
 DSTDIR=/var/log/postfix
 YESTERDAY=`env TZ=JST+15 date +%Y%m%d`

 # PRE ROTATE
 #
 if [ -r ${SRCDIR}/maillog ]; then
         cp -p ${SRCDIR}/maillog ${SRCDIR}/maillog.1
         cp /dev/null ${SRCDIR}/maillog
 fi

 kill -HUP ${PID}        #RECONFIG SYSLOG PROCCESS
 # POST ROTATE
 #
 mv ${SRCDIR}/maillog.1 ${DSTDIR}/maillog-${YESTERDAY}
 find /var/log/postfix -type f ! -name "*.gz" -and -mtime +7 -exec gzip {} \;

 exit 0

   <ここまで>------------------------------------------------------------------

3.cronを設定する

 0 0 * * * /usr/local/sbin/maillog-rotate.sh



以上を設定すると、こんな感じにログが保存されるようになります。

-rw-r----- 1 root logadmin   8342 Jul 24 23:55 maillog-20120724.gz
-rw-r----- 1 root logadmin   9636 Jul 25 23:59 maillog-20120725.gz
-rw-r----- 1 root logadmin   8049 Jul 26 23:59 maillog-20120726.gz
-rw-r----- 1 root logadmin   8204 Jul 27 23:58 maillog-20120727.gz
-rw-r----- 1 root logadmin  50061 Jul 28 23:54 maillog-20120728
-rw-r----- 1 root logadmin  52978 Jul 29 23:52 maillog-20120729
-rw-r----- 1 root logadmin 105343 Jul 30 23:55 maillog-20120730
-rw-r----- 1 root logadmin  51856 Jul 31 23:52 maillog-20120731
-rw-r----- 1 root logadmin  67329 Aug  1 23:56 maillog-20120801
-rw-r----- 1 root logadmin  73968 Aug  2 23:58 maillog-20120802
-rw-r----- 1 root logadmin  53923 Aug  3 23:53 maillog-20120803
-rw-r----- 1 root logadmin  33898 Aug  4 23:56 maillog-20120804

2012年7月29日日曜日

一般ユーザでログを参照する

rootじゃなくても(sudoを実行しなくても)ログを参照したいが、
特定のユーザに限定したい時は以下のようにする。

1.まず、ログを参照するユーザだけが所属するグループを作成
 
 [root@cent6 ~]# groupadd logadmin

2.そのグループにユーザを追加

 [root@cent6  ~]# usermod -a -G logadmin user1

3.ログのアクセス権を修正

  [root@cent6 ~]# chmod g+r /var/log/maillog
  [root@cent6 ~]# chgrp logadmin /var/log/maillog


これでlogadminグループに所属するuser1ユーザは、rootにならずとも/var/log/maillogが参照できるようになる。

なお、ログローテーションが実施された時に都度アクセス権を修正するのではなく、自動的に修正された状態にするには、/etc/logrotate.confの記述を以下のように修正する。

(修正前)
create

(修正後)
create 640 root logadmin

2012年7月22日日曜日

logrotate (ログのローテーション)

CentOS6(RHEL6)になって、ログローテーションまわりも変わっている事に気づいた。
今までローテーションされたファイルはsecure.1やsecure2のようになり、タイムスタンプを見ないと、いつローテーションされたのかすぐにわからなかったが、今度は日付がつくようになっている。


[root@cent6 ~]# ll /var/log/secure* /var/log/messages*
-rw-r----- 1 root logadmin     0 Jul 22 04:02 /var/log/messages
-rw-r----- 1 root logadmin  3246 Jul  8 04:02 /var/log/messages-20120708
-rw-r----- 1 root logadmin 38684 Jul 15 04:02 /var/log/messages-20120715
-rw-r----- 1 root logadmin  7275 Jul 22 04:02 /var/log/messages-20120722
-rw-r----- 1 root logadmin   687 Jul 22 16:15 /var/log/secure
-rw-r----- 1 root logadmin 10624 Jul  7 17:07 /var/log/secure-20120708
-rw-r----- 1 root logadmin  8140 Jul 15 00:47 /var/log/secure-20120715
-rw-r----- 1 root logadmin  6437 Jul 20 10:08 /var/log/secure-20120722
[root@cent6 ~]#

で、/etc/logrotate.confを確認したところ”dateext”というパラメータが指定されているせいですね。
※CentOS5でも”man 8 logrotate”で確認しましたが、知らなかっただけで、ちゃんと存在していました・・・

2012年7月15日日曜日

CentOS6系で変更されたnss_ldapまわり

CentOS6(RHEL6)になって、libnss_ldap.soを含むnss_ldapパッケージがnss-pam-ldapdというパッケージに変更された。そのnss-pam-ldapdパッケージには、nslcdというデーモンが含まれるようになった。
→ 「# Description: Provides naming services using a directory server. 」とある
→ 設定ファイルは、/etc/nslcd.conf

変更されて良くなった点は、(個人的には)以下の通り。
・LDAPでユーザ管理をしている状態で、LDAPサーバが停止してしまった場合にローカルアカウントでもログインできなくなる症状が改善されている
→ 以前は、/etc/pam.d/system-authに"authinfo_unavail=ignore"を追加したり、
/etc/ldap.confに"bind_policy soft"を指定していた

→ 今度はLDAPサーバが停止していても、デフォルト設定で約10秒ほど待つと普通にログインできるようになった
(さらに、一度、LDAPサーバにはつなげないと判断すると、次回からは待ち時間なしで接続可)
→"bind_policy soft"のように動作させるには、"reconnect_retrytime 0"とすれば良い