ぬけラボ

φ(..)メモメモ

CentOS6.3にGrowthForecastを導入メモ

基本的にはこちらの記事を参考にさせて頂きました。
[Scientific Linux6.2 に GrowthForecast を導入したメモ]
http://d.hatena.ne.jp/do_aki/20120522/1337665000

依存パッケージインストール

# yum groupinstall "Development Tools"
・RRDToolの依存パッケージ
# yum install pkgconfig glib2-devel gettext libxml2-devel pango-devel cairo-devel
・growthforecastのグラフが文字化け対応
# yum install ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts ipa-pmincho-fonts

インストールユーザ作成

# useradd growthforecast
# su - growthforecast

perlbrewインストール

$ curl -kL http://install.perlbrew.pl | bash
$ echo '[[ -s "$HOME/perl5/perlbrew/etc/bashrc" ]] && source "$HOME/perl5/perlbrew/etc/bashrc"' >> .bash_profile
$ source $HOME/perl5/perlbrew/etc/bashrc

perl and cpanmインストール

$ perlbrew install perl-5.16.2
$ perlbrew switch perl-5.16.2
$ perlbrew install-cpanm

RRDTool install

$ wget http://search.cpan.org/CPAN/authors/id/G/GF/GFUJI/Alien-RRDtool-0.03.tar.gz
$ cpanm Alien-RRDtool-0.03.tar.gz

GrowthForecast install

$ git clone https://github.com/kazeburo/GrowthForecast.git GrowthForecast
$ cd GrowthForecast
$ cpanm --installdeps .
$ exit

起動スクリプト作成

サンプル作成
https://github.com/hiro-su/gf-sample/blob/master/growthforecast

# cd ~
# wget -nd -O - https://github.com/hiro-su/gf-sample/archive/master.tar.gz|tar zxvf -
# cd gf-sample-master
# cp -rp growthforecast /etc/init.d
# chmod +x /etc/init.d/growthforecast
# mkdir /var/run/growthforecast
# mkdir /var/log/growthforecast

起動

# /etc/init.d/growthforecast start

ブラウザで http://localhost:5125 にアクセスして動作確認

動作テスト

vmstatの値をグラフ化してみた
https://github.com/hiro-su/gf-sample/blob/master/post-sample.sh

# cd ~
# cd gf-sample-master
# sh post-sample.sh >/dev/null

GrowthForecastは小数を扱えないらしい
マイナス値は使うことが出来た

メイン画面

複合グラフ

Ruby json/messagepack

Ruby193 json/messagepackメモ
一度シリアライズするとkeyがStringになる

  • json
require 'json'

def hashtojson
  {"hoge" => 1, :fuga => 2}.to_json
end

def jsontohash(arg)
  JSON.parse(arg)
end

puts jsontohash(hashtojson)
#=> {"hoge" => 1, "fuga" => 2}
  • messagepack
require 'msgpack'

def hashtomsgpack
  {"hoge" => 1, :fuga => 2}.to_msgpack
end

def msgpacktohash(arg)
  MessagePack.unpack(arg)
end

puts msgpacktohash(hashtomsgpack)
#=> {"hoge" => 1, "fuga" => 2}

gerpとかsortの実行速度が遅い

これを

$ time grep -o -e '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+' *.txt|sort |uniq -c|sort -nr |head -1

こんなのにしたら

$ time LC_ALL=C grep -o -e '[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+' *.txt|sort |uniq -c|sort -nr |head -1

8倍はやくなったっ!


原因は環境変数だった

What's "LANG=C" ?
http://mstssk.blogspot.jp/2009/04/whats-langc.html

$ env
...
LANG=C
...
LC_CTYPE=en_US.UTF-8
...

LANG=Cと指定してあるが、
LC_CTYPEにより上書きされていたらしい。

GlusterFS volume作成時に {path} or a prefix of it is already part of a volume と出た場合の対処法

一度volumeを消して、再び同じ名前でvolumeを作成しようとすると以下のエラーが出る場合がある
GlusterFS: {path} or a prefix of it is already part of a volume

そんな時は以下のサイトで紹介されているコマンドを実行

http://joejulian.name/blog/glusterfs-path-or-a-prefix-of-it-is-already-part-of-a-volume/

setfattr -x trusted.glusterfs.volume-id $brick_path
setfattr -x trusted.gfid $brick_path
rm -rf $brick_path/.glusterfs

GlusterFS 壊れたノードを変更

GlusterFSノードが壊れた際の作業メモ

壊れたマシンのUuidを確認

生きてるマシンで以下のコマンド実行

# gluster peer status
Hostname: hoge
Uuid: hoge-cf46-4a15-be19-fuga
State: Peer in Cluster (Disconnected)

新しいマシンにGlusterFSインストール

# cd /usr/local/src
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-3.3.1-1.el6.x86_64.rpm
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-fuse-3.3.1-1.el6.x86_64.rpm
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-server-3.3.1-1.el6.x86_64.rpm
# rpm -ivh glusterfs*

Uuid変更

新しいマシンのGlusterFS Uuidを壊れたマシンのUuidに変更する

# vim /var/lib/glusterd/glusterd.info
UUID=poyo-b544-4d16-83dc-piyo
↓
UUID=hoge-cf46-4a15-be19-fuga

再起動

# /etc/init.d/glusterd restart

peer追加

どれでもいいのでクラスタを組んでいたpeerを1台追加

# gluster peer probe fuga

再起動

# /etc/init.d/glusterd restart

確認

# gluster peer status
# gluster volume info

GlusterFS v3.3.0からv3.3.1にバージョンアップ

/var/lib/glusterdをバックアップ

# mv /var/lib/glusterd /tmp/glusterd

v3.3.1パッケージにアップデート

# cd /usr/local/src
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-3.3.1-1.el6.x86_64.rpm
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-fuse-3.3.1-1.el6.x86_64.rpm
# wget http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/CentOS/epel-6/x86_64/glusterfs-server-3.3.1-1.el6.x86_64.rpm
# rpm -Uvh glusterfs*

バックアップをリストア

# rm -rf /var/lib/glsuterd
# mv /tmp/glusterd /var/lib/glusterd

再起動

# /etc/init.d/glsuterd restart

ターミナルでパケットキャプチャ

Linux(CentOS)のターミナルもしくはWindowsのコマンドプロンプトでインターネットのパケットをキャプチャしようと思ったときに、
GUI環境だったらWiresharkが有名ですが、ターミナル(CLI)環境だったらどうするのか調べてみました。

tshark

WiresharkにはCLI版の「tshark」と言う物があって
Wiresharkをインストールすると付属されているみたいです。

Linuxでは下記のコマンドでインストールできます。

#yum -y install wireshark

Windowsでは公式サイトからダウンロードしてください。


Linuxでは下記のコマンドで使用するインタフェースを確認します。

#tshark -D
1. eth0
2. any
3. lo

Windowsでは

>cd C:\Program Files\Wireshark
>tshark -D

下記のコマンドでeth0のキャプチャが実行できます。

#tshark -i 1

192.168.1.1宛てのhttp通信だけをフィルタリング

#tshark -i 1 -l host 192.168.1.1 and port http

または、Wiresharkのfilter構文を使って上記と同様の事をするには

#tshark -i 1 -l host 192.168.1.1 -R "tcp.port == 80"

送信元192.168.0.1から宛先192.168.1.1へのhttp通信をキャプチャ

#tshark -i 1 -l host 192.168.1.1 -R "tcp.port == 80 && ip.src == 192.168.0.1"

sshでサーバーにアクセスしてtsharkを動かすと、ssh通信のキャプチャばかりが表示されるので
ssh通信以外のtcpパケットだけをキャプチャ

#tshark -i 1 -R "tcp.srcport != 22 && tcp.dstport != 22"

Wiresharkのfilter構文については以下のサイトが参考になります。
http://www.infraexpert.com/info/wireshark5.html

詳細なオプションについては

#man tshark

もしくは、こちらの公式ページが参考になります。
http://www.wireshark.org/docs/man-pages/tshark.html