2014年2月24日月曜日

rsyslog 制御文字の出力を抑制するには

今回は、$EscapeControlCharactersOnReceiveディレクティブについてです。
※評価はCentOS6.5(x86_64) + rsyslog-7.6.0で行っています


各種ログで以下のように"#0111"などの制御文字が出力され、ログが見にくいなと感じたことはありませんか?

Feb 20 23:31:48 host1 dovecot: auth: Debug: client passdb out: OK#0111#011user=user01@example.com
Feb 20 23:31:48 host1 dovecot: auth: Debug: master in: REQUEST#0113825991681#0111858#0111#01139e00ee36ea2ede7441004cca9bf81c7#011session_pid=1861


$EscapeControlCharactersOnReceive off

とrsyslog.confに設定することにより、この制御文字の出力を抑制することができます。
これですっきりと読みやすいログになりました。

Feb 20 23:33:26 host1 dovecot: auth: Debug: client passdb out: OK   1   user=user01@example.com
Feb 20 23:33:26 host1 dovecot: auth: Debug: master in: REQUEST  3685744641      1877    1       93338956ff312fddeea4e71e715cd44a      session_pid=1882

2014年2月13日木曜日

ひとつのホストで異なるバージョンのPostgreSQLを起動する

今回は、ひとつのホスト上で異なるバージョンのPostgreSQLを起動してみたいと思います。
起動するPostgreSQLは過去にねたとしてあげたコミュニティ版の9.2と9.3とし、OSはCentOS6.5(x86_64)とします。

コミュニティ版のPostgreSQL9.xは、データベースクラスタが最初から同じ位置ではないので、利用するポートがかぶらないようにすれば実現は簡単です。


起動スクリプトを使う場合


PostgreSQL9.3は5432ポートで起動させるので(特別なことをせずに) /etc/rc.d/init.d/postgresql-9.3 start で起動します。

PostgreSQL9.2は"/etc/rc.d/init.d/postgresql-9.2"内のPGPORTの記述をPostgreSQL9.3が利用する5432ポートと異なるものに変更します。
ここでは、5433ポートに変更します。
PGPORT=5433
後は、/etc/rc.d/init.d/postgresql-9.2 start で起動します。


pg_ctlを使う場合


面倒でもフルパスで指定するのが間違いがないでしょう。

[postgres@pgsql ~]$ /usr/pgsql-9.3/bin/pg_ctl start -D /var/lib/pgsql/9.3/data
[postgres@pgsql ~]$ /usr/pgsql-9.2/bin/pg_ctl start -o "-p 5433" -D /var/lib/pgsql/9.2/data


動作確認


下記のように9.2と9.3のPostgreSQLが起動しているのが確認できます。
[postgres@pgsql ~]$ ps -fC postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  1364     1  0 18:19 pts/0    00:00:00 /usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/9.3/data
postgres  1365  1364  0 18:19 ?        00:00:00 postgres: logger process
postgres  1367  1364  0 18:19 ?        00:00:00 postgres: checkpointer process
postgres  1368  1364  0 18:19 ?        00:00:00 postgres: writer process
postgres  1369  1364  0 18:19 ?        00:00:00 postgres: wal writer process
postgres  1370  1364  0 18:19 ?        00:00:00 postgres: autovacuum launcher process
postgres  1371  1364  0 18:19 ?        00:00:00 postgres: stats collector process
postgres  1406     1  0 18:21 pts/0    00:00:00 /usr/pgsql-9.2/bin/postgres -D /var/lib/pgsql/9.2/data -p 5433
postgres  1407  1406  0 18:21 ?        00:00:00 postgres: logger process
postgres  1409  1406  0 18:21 ?        00:00:00 postgres: checkpointer process
postgres  1410  1406  0 18:21 ?        00:00:00 postgres: writer process
postgres  1411  1406  0 18:21 ?        00:00:00 postgres: wal writer process
postgres  1412  1406  0 18:21 ?        00:00:00 postgres: autovacuum launcher process
postgres  1413  1406  0 18:21 ?        00:00:00 postgres: stats collector process
[postgres@pgsql ~]$

psqlコマンドはより新しいバージョンのものになりますが、ポートを指定して下位のバージョンに接続する事ができます。
[postgres@pgsql ~]$ psql -V
psql (PostgreSQL) 9.3.2
[postgres@pgsql ~]$
[postgres@pgsql ~]$ psql -p 5433
psql (9.3.2, server 9.2.6)
Type "help" for help.
postgres=#

2014年2月10日月曜日

コミュニティ版PostgreSQL9.3

以前のねたをPostgreSQL9.3でリメイクします。
なお、今回インストールした環境はCentOS6.5なので、ここからCentOS6-x86_64用のものを利用しています。


以下、そのセットアップ手順です。

インストール

[root@pgsql ~]# rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
[root@pgsql ~]# yum -y install postgresql93-server


環境整備

/usr/pgsql-9.3配下にいろいろインストールされるので、それに合わせて環境を整備する。
[root@pgsql ~]# su - postgres
[postgres@pgsql ~]$ vi .bash_profile

以下、その編集内容
PATH=$PATH:$HOME/bin:/usr/pgsql-9.3/bin
PGDATA=/var/lib/pgsql/9.3/data
MANPATH="$MANPATH":/usr/pgsql-9.3/share/man

export PATH PGDATA MANPATH

即時反映するには、以下を実行
[postgres@pgsql ~]$ source .bash_profile


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

※ rootユーザで # service postgresql-9.3 initdb を実行してもデータベース・クラスタの作成はできます。
  しかし、localeは指定できてもEncodingが指定できない(SQL_ASCIIになる)ので、ここでは普通にinitdbを実行して
  データベースクラスタを作成しています。

[postgres@pgsql ~]$ initdb --no-locale -E UTF-8
[postgres@pgsql ~]$ pg_ctl start -D $PGDATA
server starting
[postgres@pgsql ~]$ ps -fC postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  1295     1  0 00:28 pts/0    00:00:00 /usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/9.3/data
postgres  1296  1295  0 00:28 ?        00:00:00 postgres: logger process
postgres  1298  1295  0 00:28 ?        00:00:00 postgres: checkpointer process
postgres  1299  1295  0 00:28 ?        00:00:00 postgres: writer process
postgres  1300  1295  0 00:28 ?        00:00:00 postgres: wal writer process
postgres  1301  1295  0 00:28 ?        00:00:00 postgres: autovacuum launcher process
postgres  1302  1295  0 00:28 ?        00:00:00 postgres: stats collector process
[postgres@pgsql ~]$
[postgres@pgsql ~]$ 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@pgsql ~]$


※あとは、rpmに含まれるinitスクリプトを利用して自動起動するようにしておけば良いと思います。
[root@pgsql ~]# chkconfig postgresql-9.3 on