kibana3でelasticsearchの9200番ポートを公にしない方法

Kibana3というのもありまして - @johtaniの日記 2nd
にあるようにブラウザが動作するマシンからelasticsearchに接続しないといけないが
大人の事情で9200番ポートが使えなかったり
elasticsearchに直結はなーと悩んだときは

httpd.confにこんな感じにして

ProxyPass /es/ http://127.0.0.1:9200/
ProxyPassReverse /es/ http://127.0.0.1:9200/

/var/www/html/kibana/config.jsは

  return new Settings({
    elasticsearch: "https://www.example.net/es",
    ...
  });

とすると9200番への直結も避けられる

あとはApacheHTTPDにBASIC認証など仕込めばよさげ

続Shibboleth-IdPのログをfluentdのin_tailで拾うための正規表現

Shibboleth-IdPのログをfluentdのin_tailで拾うための正規表現 - kame-tの日記
の続きでidp-process.logを取り込む
Shibboleth-IdPのデフォルトの設定では

<Pattern>%date{HH:mm:ss.SSS} - %level [%logger:%line] - %msg%n</Pattern>

となっている
(1) ミリ秒の表記は
instance method Time#strftime
から"%L"でOK
(2) Javaのエラーが複数行に渡る問題は
tomohisaota/fluent-plugin-tail-multiline · GitHub
のpluginで対応できる

fluent.confには

<source>
  type tail_multiline
  path /opt/shibboleth-idp-2.4.0/logs/idp-process.log
  format /^(?<time>[^ ]+) - (?<level>[^ ]+)  \[(?<logger>[^\:]*)\:(?<line>[^\]]*)\] - (?<message>.*)/
  time_format %H:%M:%S.%L
  tag shibboleth-idp.process
</source>

と書くとよさそう

Shibboleth-IdPのログをfluentdのin_tailで拾うための正規表現

Shibboleth-IdPも複数台で運用して
ログも分散するようになって集計も面倒になってきたので
fluentdで集約してみようと一念発起

Shibboleth-IdPのログはマニュアル
IdPLogging - Shibboleth 2.x - Confluence
に書かれているが要はパイプ'|'で区切ってログ情報が出力されている
ただしidp-audit.logのserverHostとserverPortの区切りがコロン':'なので注意

fluent.confには

<source>
  type tail
  path /opt/shibboleth-idp-2.4.0/logs/idp-access.log
  format /^(?<time>[^\|]+)\|(?<remoteHost>[^\|]*)\|(?<serverHost>[^\:]*)\:(?<serverPort>[^\|]*)\|(?<requestPath>[^\|]*)\|$/
  time_format %Y%m%dT%H%M%S%Z
  tag shibboleth-idp.access
</source>
<source>
  type tail
  path /opt/shibboleth-idp-2.4.0/logs/idp-audit.log
  format /^(?<time>[^\|]+)\|(?<requestBinding>[^\|]*)\|(?<requestId>[^\|]*)\|(?<releyingPartyId>[^\|]*)\|(?<messageProfileId>[^\|]*)\|(?<assertingPartyId>[^\|]+)\|(?<responseBinding>[^\|]*)\|(?<responseId>[^\|]*)\|(?<principalName>[^\|]*)\|(?<authNMethod>[^\|]*)\|(?<releasedAttributeId>[^\|]*)\|(?<nameIdentifier>[^\|]*)\|(?<assertionID>[^\|]*)\|$/
  time_format %Y%m%dT%H%M%S%Z
  tag shibboleth-idp.audit
</source>

と書くとよさそう

下記でテストできた
fluentdのformat(正規表現)の作り方について試行錯誤中 #fluentd - Glide Note - グライドノート
Fluentdでparser用の正規表現を書く・試す - tagomorisのメモ置き場
Fluentular: a Fluentd regular expression editor

RHEL6のlogrotateのcompress(gzip)でNFSv4のACLが上書きされる

RHEL6のApache-HTTPDのログファイルにNFSv4のACLを付与している
logrotateで
普通の新ログファイル生成はnocreateでWebサーバまかせにしていて
この場合はちゃんと上位ディレクトリのデフォルトACLを引き継いでいる
しかしcompress(gzip)したログファイルに関しては
デフォルトACLを引き継がず新しいACLが上書きされていた

logrotate-3.7.8-16.el6のSRPMを拾ってきて調べると
logrotate.cにおいて

static int compressLogFile(char *name, struct logInfo *log, struct stat *sb)
{
    char *compressedName;
    const char **fullCommand;
    int inFile;
    int outFile;
    int i;
    int status;
     :
    outFile =
        createOutputFile(compressedName, O_RDWR | O_CREAT | O_TRUNC, sb, prev_acl, 0);
#ifdef WITH_ACL
        if (prev_acl) {
                acl_free(prev_acl);
                prev_acl = NULL;
        }
#endif

とcompressLogFileでcreateOutputFileしている
ここでWITH_ACLと書いているのはPOSIX ACLのこと
createOutputFileでなにをしているかというと
同じくlogrotate.cにおいて

int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, int force_mode)
{
    int fd;
        char template[PATH_MAX + 1];
        mode_t umask_value;
    struct stat sb_create;
        int acl_set = 0;
        snprintf(template, PATH_MAX, "%s/logrotate_temp.XXXXXX", ourDirName(fileName));
     :
       if (!acl_set || force_mode) {
                if (fchmod(fd, sb->st_mode)) {
                        message(MESS_ERROR, "error setting mode of %s:
                %s\n",
                                        fileName, strerror(errno));
                        close(fd);
                        unlink(template);
                        return -1;
                }
        }

のようにchmodしてたのでここで上書きされていたのが原因

まあPOSIX ACLみたいなパッチを書けばいいと思うけど
そんな頑なにgzipしなければいけないわけでもないので
とりあえずnocompress(gzipなし)で運用

CentOS6ではlogrotateの標準(エラー)?出力は/dev/nullに落ちる

CentOS5では標準(エラー)?出力をメールでくれるのに
CentOS6ではlogrotateの設定のpostrotateなどで出力してもメールがこない
これはRHEL6やSL6も同様

とりあえず下記のようにコメントアウトした
/etc/cron.daily/logrotate

/usr/sbin/logrotate /etc/logrotate.conf #>/dev/null 2>&1

ちなみにFedora20では再び出力するように変更されている
Fedora17でも出力されるみたいなのでCentOS7は大丈夫でしょ

389-dsでマルチマスタ

CentOS5に389-dsをインストール - kame-tの日記
389-dsで2000件以上検索できないとき - kame-tの日記
389-dsで外部で取得したサーバ証明書を設定 - kame-tの日記
の続き

マルチマスタ構成にする場合
11.5. Configuring Multi-Master Replication
Stray Penguin - Linux Memo (389 DS-5)
でOKですが
server1->server2のレプリカID(nsDS5ReplicaId)と
server1<-server2のレプリカIDは別の番号にしておく必要があるので要注意
一旦IDを付与すると
レプリカの設定自体を削除して再設定しないといけない
dse.ldifを編集しただけではNGだった

389-dsで外部で取得したサーバ証明書を設定

以前書いた
CentOS5に389-dsをインストール - kame-tの日記の続き

すでに取得したサーバ証明書を使って
ldapsを動作させる
答えはここ
http://www.redhat.com/archives/fedora-directory-users/2009-December/msg00162.html
にあるけど要はp12ファイルにして取り込むとよい

% sudo openssl pkcs12 -export -in /etc/pki/tls/certs/cert.pem -inkey /etc/pki/tls/private/key.pem -out /etc/pki/tls/certs/cert.p12 -nodes -name 'servername'
% cd /etc/dirsrv/slapd-[INSTANCE_NAME]/
% sudo pk12util -d . -i /etc/pki/tls/certs/cert.p12

あと関連のCA証明書を中間証明書も一緒に登録する

% cd /etc/dirsrv/slapd-[INSTANCE_NAME]/
% sudo certutil -d . -A -n 'middle' -t CT,, -a -i /etc/pki/tls/certs/middle.crt
% sudo certutil -d . -A -n 'root' -t CT,, -a -i /etc/pki/tls/certs/root.crt

こっから先はGUI

% 389-console &
  1. 「[INSTANCE_NAME]」openして
  2. 「Tasks」タブの「Manage Certificates」で
  3. 「Server Certs」と「CA Certs」を確認
  4. 「[INSTANCE_NAME]」の「Configuration」タブを開き「Enable SSL for this server」をチェック
  5. 「Use this cipher family RSA」をチェックして「Certificate」をインストール済みの証明書を選択
  6. 「Chipher」で弱い暗号化方法はチェックを外す
  7. 「Save」したあとconsoleを閉じる

636番ポートはGUIではでなくroot権限でないと開けないので
再びコマンドで

% sudo service dirsrv restart

をする

% openssl s_client -connect 127.0.0.1:636

サーバ証明書を確認して

% ldapsearch -x -H ldaps://[HOSTNAME] -D [ADMIN_DN] -W -b [BASE_DN]

で動作を確認する(上記はOpenLDAPのldapsearch)