githubにリポジトリを登録する

 よく忘れてしまうので、メモ。

  1. SSH鍵を作成する(初回のみ)
    ssh-keygen -t rsa -C "mail address"
  2. githubで作成した公開鍵を登録する
     Keyの欄に、~/.ssh/id_rsa.pub の中身を貼り付けます。
    f:id:wankomagic:20131020113536p:plain
  3. githubでリポジトリを作成する

    f:id:wankomagic:20131020113820p:plain

  4. 自分の環境をリポジトリに登録する
     githubでリポジトリを作成すると、登録するためのコマンドが表示されるので、この通り実行する。

    f:id:wankomagic:20131020120513p:plain

DevOpsDays TOkyo 2013に行きました

プログラム: http://devopsdays.org/events/2013-tokyo/ja/program/

USTREAM: http://ustre.am/14dK3

Togetter: http://togetter.com/li/570042

 

 今年はヤフーさんで行われました。ちゃんと机があるっていいですね。参加登録は満席だったのに、結構席が空いてるのが気になりますが。

 感覚的なのですが、昨年はDevOpsって何か、インフラ構築をプログラミングしましょう(chef/puppet)、うまく回すためにこんなツールがあります(CIとか)、といった話だったのが、今年はモニタリングでDevとOpsとBizでコミュニケーションできるようにしましょう、といった話が増えてきた気がします。オープンスペースは相変わらずChefの話のようでしたが(参加してなくて、議題を見ただけなので、具体的にはわかりませんが)。Zabbix, muninは使っていますが、他のものはあまり使っていないので、今後試してみるつもりです。

 あとはジョブスケジューリングをコード化したいけれど、みんなはどうしているのでしょうか。

 

muninのズーム機能をSELinuxを有効にした状態で利用する

 muninの各グラフはCGIによりズーム表示することができます。2.0.16ではデフォルトで設定されているのですが、2.0.6では少し手を加える必要があります。

 

環境

手順

ズーム機能の設定

 http://d.hatena.ne.jp/pospome/20130221/1361447896 を参考にさせて頂きました。

  1. munin-cgi がインストールされていない場合はインストールする
  2. muninの設定ファイル /etc/munin/munin.conf に次の記述がなければ追記する
    cgiurl_graph /munin-cgi/munin-cgi-graph
  3. httpdの設定ファイル /etc/httpd/conf.d/munin.conf に次の記述がない場合は追記する
    ScriptAlias /munin-cgi/munin-cgi-graph /var/www/cgi-bin/munin-cgi-graph
  4. httpdのCGI設定ファイル /etc/httpd/conf.d/munin-cgi.conf がある場合は削除する
  5. munin-node と httpd を再起動する

 

SELinuxのポリシーファイルの作成

 SELinuxを無効にしておくとグラフが個別に表示され、ズームすることができるのですが、有効にしておくと、グラフが表示されません。setroubleshootパッケージをインストールしておけば、/var/log/audit/audit.logにdeniedが出力されるので、これをもとに、ポリシーファイルを作成します。エラーは次のようなものが出力されます(何度かアクセスエラー+設定を繰り返します)。

type=AVC msg=audit(1374249069.044:764787): avc:  denied  { search } for  pid=31282 comm="munin-cgi-graph" name="munin" dev=sda2 ino=281106 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=dir

type=AVC msg=audit(1374249989.708:764820): avc:  denied  { getattr } for  pid=32987 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304179 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250204.627:764848): avc:  denied  { unix_read unix_write } for  pid=33159 comm="mysql_network_t" key=1667461225  
scontext=unconfined_u:system_r:munin_services_plugin_t:s0 
tcontext=system_u:system_r:munin_services_plugin_t:s0 
tclass=shm

type=AVC msg=audit(1374250438.152:764892): avc:  denied  { read } for  pid=33653 comm="munin-cgi-graph" name="datafile.storable" dev=sda2 ino=304184 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250438.158:764893): avc:  denied  { search } for  pid=33653 comm="munin-cgi-graph" name="munin" dev=sda2 ino=281767 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_log_t:s0 
tclass=dir

type=AVC msg=audit(1374250893.404:765016): avc:  denied  { open } for  pid=34755 comm="munin-cgi-graph" name="datafile.storable" dev=sda2 ino=304185 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250893.413:765017): avc:  denied  { open } for  pid=34755 comm="munin-cgi-graph" name="munin-cgi-graph.log" dev=sda2 ino=281111 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=unconfined_u:object_r:munin_log_t:s0 
tclass=file

type=AVC msg=audit(1374251968.585:765185): avc:  denied  { ioctl } for  pid=36533 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304179 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374251102.485:765022): avc:  denied  { associate } for  pid=34814 comm="mysql_innodb_bp" key=1667461225  
scontext=unconfined_u:system_r:munin_services_plugin_t:s0 
tcontext=system_u:system_r:munin_services_plugin_t:s0 
tclass=shm

type=AVC msg=audit(1374252419.524:765299): avc:  denied  { ioctl } for  pid=37619 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304185 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374252419.540:765300): avc:  denied  { open } for  pid=37619 comm="munin-cgi-graph" name="munin-cgi-graph.log" dev=sda2 ino=281111 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=unconfined_u:object_r:munin_log_t:s0 
tclass=file

 これをもとに、次のTEファイルを作成します(仮に、munin-cgi-graph-policy.te とします)。

module munin-cgi-graph-policy 1.0;

require {
  type httpd_sys_script_t;
  type munin_var_lib_t;
  type munin_services_plugin_t;
  type munin_log_t;
  class dir { search };
  class file { getattr read open ioctl };
  class shm { unix_read unix_write associate };
}

allow httpd_sys_script_t munin_var_lib_t:dir { search };
allow httpd_sys_script_t munin_var_lib_t:file { getattr read open ioctl };
allow httpd_sys_script_t munin_log_t:dir { search };
allow httpd_sys_script_t munin_log_t:file { open };
allow munin_services_plugin_t self:shm { unix_read unix_write associate };

 作成したらコンパイルして、適用します。

make -f /usr/share/selinux/devel/Makefile
semodule -i munin-cgi-graph-policy.pp

  セキュリティコンテキストの設定でもっとうまくできないかが今後の課題。

Subversion1.8をRPMでインストールする

 今更Subversionかとも思うし、だからバージョンアップしてもパッケージングされなくてソースコードビルドすることになるんだけど、そのためにまず古いSubversionをインストールしないといけないというRubyみたいなこともしたくないので、パッケージングしてるリポジトリを探したら、WANdiscoという所を見つけました。

 

環境

手順

  1. /etc/yum.repos.d/wandisco.repo というファイルを作成する
    [wandisco]
    name=WANDisco Repository - svn-1.8 centos6
    baseurl=http://opensource.wandisco.com/centos/6/svn-1.8/RPMS/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-WANdisco
  2. GPGキーを取り込む
    rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
  3. インストールを実行する
     yum install --enablerepo=wandisco --disablerepo=base,updates subversion

  Subversionのためだけなので、普段は無効に。デフォルトだとCentOSのBaseやupdatesの方が優先されるので、対象外にする。

MySQL5.6からMariaDB10.0に移行する(のに失敗した話)

 今までMySQLを使っていたのだけれど、SkySQLとMonty Programの合併でMariaDBに注力されるみたいだし、wikipediaとかいろんなところがMariaDBに乗り換えてるとか聞くし、ZabbixもMariaDBサポート!?みたいな話を人づて(ソース不明)に聞いたので、ちょっと試してみました。

 

環境

 

準備

 https://kb.askmonty.org/en/installing-mariadb-with-yum/

上記サイトを参考に、リポジトリファイルを作成します。

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1

 mysqlは停止させておきます。

 

 updateしてみる

yum update mysql

 を実行してみたところ、こうなりました。

=============================================================
Package Arch Version Repository Size
=============================================================
Installing:
MariaDB-client x86_64 10.0.2-1 mariadb 10 M
replacing MySQL-client.x86_64 5.6.11-2.el6
MariaDB-server x86_64 10.0.2-1 mariadb 33 M
replacing MySQL-server.x86_64 5.6.11-2.el6
Installing for dependencies:
MariaDB-common x86_64 10.0.2-1 mariadb 23 k
MariaDB-compat x86_64 10.0.2-1 mariadb 2.7 M

Transaction Summary
============================================================

 MariaDBのサイトを見ると、 yum install MariaDB-server・・・と書いてますが、mysql と書くと同様の動きをします。MySQLMariaDBはアップグレードらしい。

しかし、これではdevelやsharedが変わらないので、これらを個別に指定する必要があるのですが、shared-compatが競合するため、予め削除する必要があります。つまり、実際には次のコマンドを実行します。

rpm -e MySQL-shared-compat --nodeps
yum update MySQL-server MySQL-client MySQL-devel MySQL-shared

 devel, sharedを追加すると、mysqlでserverとclientがインストール対象にならないので、わざわざ指定しています。

このまま起動すると、バイナリログの差異エラーが出るので、予め削除しておきます。

rm -f /var/lib/mysql/ib_logfile*

起動ファイルが同じ名前で作成されているので、同じように起動します。

service mysql start

すると、次のエラーが出ます。

 Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

なので、skipモードで起動してみます。

mysqld --skip-grant &

すると、起動はされるのですが、起動中に次のエラーメッセージが何件か表示されます。

[ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'THREAD_ID' at position 0 to have type int(11), found type bigint(20) unsigned.

performance_schemaのいくつかのテーブルの主キーTHREAD_IDは5.5ではint(11)だったのですが、5.6ではbigint(20)になっています。MariaDBの10.0は5.5に対応しているため、エラーが発生しました。

ちなみに、本環境ではMySQL5.6で書いていますが、別環境のMySQL5.5で同じようにやったところ、正常に起動することができました。

 

インストールしなおす

とすることにしました。古いMySQLをアンインストールして、MariaDBをインストールします。データベースは一旦削除します。これを実行する前にダンプファイルをとっておきます。

rpm -e --nodeps MySQL-server MySQL-client MySQL-shared MySQL-shared-compat MySQL-devel
rm -rf /var/lib/mysql
yum install MariaDB-server MariaDB-client MariaDB-devel MySQL-shared

上記と同じコマンドでサービスを起動して、データをインポートすれば完了です。

 

ZabbixとMariaDBの連携

MySQLMariaDBのコマンド名とかモジュール名がほとんど同じなので、連携できるかなーと思ったのですが、phpmysqlライブラリ側で連携が失敗しました。こちらのサイトの「互換性」の見出しのところに原因と対策が書いています。

http://research.sakura.ad.jp/2013/02/28/mariadb-galera-cluster-3/

 

今回はやってません。

SELinuxのポリシー・モジュールを自作する~FileContexts編

 Muninには最初からTomcatプラグインが含まれているのですが、これよりもMunin.warの方がいろんな情報を取得できるので重宝しています。Munin.warについてはこちらを参考してください。

   http://woontai.dip.jp/muninwar/

 このMunin.warのセキュリティ・コンテキストは次のようになっています。

system_u:object_r:munin_unconfined_plugin_exec_t:s0

  これは /etc/selinux/targeted/contexts/files/file_contexts に次のように定義されているためです。

/usr/share/munin/plugins/.* -- system_u:object_r:munin_unconfined_plugin_exec_t:s0

 このファイルにはプラグイン個別に別のタイプが設定されていて、例えばTomcatプラグインは次のように定義されています。

/usr/share/munin/plugins/tomcat_.* -- system_u:object_r:munin_services_plugin_exec_t:s0

 Munin.warのプラグイン名は cataline_.* なので、これが適用されません。 munin_unconfined_plugin_exec_t のままでも問題なく動くのですが、なんとなく気持ち悪いので、munin_services_plugin_exec_t に合わせてみようかと思います。セキュリティ・コンテキストを変更する方法として、chcon コマンドがあります。

chcon -t munin_services_plugin_exec_t /usr/share/munin/plugins/catalina_* 

 けれど、chcon コマンドは一時的なもので、restorecon コマンドを実行したり、autorelabel を実行した場合、上記の file_contexts ファイルに定義されたものに貼り直されてしまいます。なので、セキュリティ・ポリシー・モジュールを作成した方が良いでしょう。

 以前のブログ記事でもセキュリティ・ポリシー・モジュールを作成する方法を記述しましたが、今回は別コンテキストへの実行許可ではなく、ファイル・コンテキストの設定のみしたいので、前回作成しなかったfcファイルを作成します。

 まず、teファイルを作成します。モジュール名は munin-plugin-catalina にします。requireブロックは不要かと思いましたが、記述しないとコンパイルに失敗するので記述しました。typeとして、今回設定する型を記述します。

module munin-plugin-catalina 1.0;
require {
type munin_services_plugin_t;
}

 次に、fcファイルを作成します。

/usr/share/munin/plugins/catalina_.* -- gen_context(system_u:object_r:munin_services_plugin_exec_t,s0)

 コンパイルして、インストールします。

make -f /usr/share/selinux/devel/Makefile
semodule -i munin-plugin-catalina.pp

 インストールしたポリシーを適用します。

restorecon /usr/share/catalina_*

 ls -Z コマンドで適用前と適用後を見比べてみてください。munin_unconfied_plugin_exec_t になっているはずです。

 

追記

 munin.fc の設定や書式については次を参照してください。

   http://oss.tresys.com/projects/refpolicy/browser/policy/modules/services/munin.fc?rev=2666722f002608e57f4eb984c2decc317fdbf9ce


 

 ちなみに、fc ファイルは次の書式でも有効です。

/usr/share/munin/plugins/catalina_.* -- system_u:object_r:munin_services_plugin_exec_t:s0