AWS
EC2
インスタンスCentOS 6.5
Chef
はOmnibus Installer
にてインストール済みChef Handlers
→chef-handler-graphite
→Graphite
とかで結果を可視化している(Sensu Server
とはあまり関係無いw)
localhost
にSensu server
とSensu client
をセットアップする
knife solo init chef-repo-sensu
cd chef-repo-sens
cat << EOT >> solo.rb
file_cache_path "/path/to/chef-solo"
cookbook_path ["/path/to/chef-repo-sensu/cookbooks", "/path/to/chef-repo-sensu/site-cookbooks"]
role_path "/path/to/chef-repo-sensu/roles"
log_level :info
data_bag_path "/path/to/chef-repo-sensu/data_bags"
# 以下、chef-handler-graphite で実行結果を Graphite に飛ばすオプション
require 'chef-handler-graphite'
graphite_handler = GraphiteReporting.new
graphite_handler.metric_key = "kappatest.chef.#{Chef::Config.node_name}"
graphite_handler.graphite_host = "localhost"
graphite_handler.graphite_port = "2003"
report_handlers << graphite_handler
exception_handlers << graphite_handler
EOT
cd chef-repo-sensu
rm -rf Berksfile
rm -rf cookbooks
cat << EOT >> Berksfile
source "https://api.berkshelf.com/"
cookbook 'sensu'
EOT
/opt/chef/embedded/bin/berks vendor cookbooks
但し、librarian-chef
は使わない。
cd cookbooks/sensu/example
gem install bundler
bundle install
cd ssl
./ssl_certs.sh generate
knife data bag
を実行すると鍵が無いよって怒られるので諦めて...
knife data bag create sensu
knife data bag --secret-file /path/to/your/secret from file sensu ssl.json
Chef Server
だったら大丈夫。
mkdir ~/chef-repo-sensu/data_bags/sensu
cp ssl.json ~/chef-repo-sensu/data_bags/sensu/
cd ~/chef-repo-sensu
cat << EOT >> nodes/localhost.json
{
"default_attributes": {
},
"override_attributes": {
},
"run_list": [
"sensu",
"sensu::redis",
"sensu::rabbitmq",
"sensu::client_service"
]
}
EOT
vim chef-repo-sensu/cookbooks/sensu/recipes/client_service.rb
以下を追加する。
sensu_client node.name do
address node.ipaddress
subscriptions node.roles + ["all"]
end
上記を定義した後で収束させると /etc/sensu/conf.d/client.json
が以下の通りに生成される。
{
"client": {
"name": "ip-xxx-xxx-x-xx.ec2.internal",
"address": "xxx.xxx.x.xx",
"subscriptions": [
"all"
]
}
}
/opt/chef/bin/chef-solo -c solo.rb -j nodes/localhost.json -W
/opt/chef/bin/chef-solo -c solo.rb -j nodes/localhost.json
クライアントの追加も出来ている。