自前でufwのレシピとserverspecのテストを書いた

ufw = Uncomplicated FireWall です。 レシピはこんなのを作りました。opscode のレシピとか使うと、何設定し ているか分からず結局全部読むことになるので自前で書いてます。 execute 'ufw reload' do action :nothing end execute 'ufw default deny' do not_if 'ufw status verbose | fgrep "Default: deny (incoming)"' notifies :run, 'execute[ufw reload]' end execute 'ufw allow http' do not_if 'ufw status | egrep "^80 +ALLOW"' notifies :run, 'execute[ufw reload]' end execute 'ufw allow ssh' do not_if 'ufw status | egrep "^22 +ALLOW"' notifies :run, 'execute[ufw reload]' end execute 'ufw enable' do command 'yes | ufw enable' not_if 'ufw status | fgrep "Status: active"' end serverspec はだいたいこんな感じです。...

2015-06-29 (Mon) · masutaka

さくらのVPSでCookがダンマリになる件を回避した

[2013-05-19-1] にインストールしたUbuntu 12.04はうっかり32bit版でした。。仕方がないのでUbuntu 14.04へのアップグレードがてら、クリーンインストールすることにしました。 管理画面からポチポチしてOSのインストールは完了。CookはあらかじめVirtualBoxとEC2で確認していたので万全です(キリッ と思いきや、いつまでたってもRecipeが処理されません…。 $ knife solo cook masutaka.net Running Chef on masutaka.net... Checking Chef version... Uploading the kitchen... Generating solo config... Running Chef... Starting Chef Client, version 11.16.2 (ここでダンマリ) これまた仕方がないので、サーバ側の/opt/chef/embedded/lib/ruby/gems/1.9.1/gems以下をprintfデバッグ(というかpデバッグか)で調べたところ、Chefがサーバ情報を取得するときに使うOhaiのGCEプラグインから返ってこないことがわかりました。GCEとはGoogle Compute Engineです。なんでChefが? で、結論から言うと、GCEプラグインをOFFにしたら解決しました。 knife solo prepareのあとに/opt/chefが作られるので、/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.4.0/lib/ohai/config.rbを以下のように修正。あとはknife solo cookするだけです。knife solo bootstrapは出来ないことになります。 default :disabled_plugins, [] ↓ default :disabled_plugins, [:GCE] knife soloはchef-soloをリモートから実行するコマンドで、 /opt/chef/embedded/bin/ruby /usr/bin/chef-solo -c /home/masutaka/chef-solo/solo.rb -j /home/masutaka/chef-solo/dna.json のようなchef-soloコマンドを実行します。root権限だったかな? この/home/masutaka/chef-solo/solo.rbに Ohai::Config[:disabled_plugins] = [:GCE] を書き、前述のchef-soloコマンドを実行すれば/opt/chef以下を修正する必要はありませんが、残念ながらこのファイルはknife solo cook時に自動生成されます。 ローカルの.chef/knife.rbに書いても無視されました。残念。そういうわけで、今はprepareをした後はサーバにログインしてファイルを書き換え、そのあとにcookというイマイチなことをしています。 ではなぜ、さくらのVPSだけダンマリになるのか? /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.4.0/lib/ohai/mixin/gce_metadata.rbのここに違いがありました。 def can_metadata_connect?...

2014-09-23 (Tue) · masutaka

Ubuntu13.10のVagrantで/vagrantが見れなくてハマった

ls /vagrantから返ってこなくて、今日はずっと調べてました。。。 BoxはUbuntu Officialのやつ http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box 結論から言うと、vagrant-vbguest pluginをインストールし、vagrantを起 動、vagrantの中で/usr/lib/VBoxGuestAdditionsを見えるようにしてあげ ればOK。道は長かった。 $ vagrant plugin install vagrant-vbguest $ vagrant up Vagrant起動の途中でvbguest pluginによって /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso がvagrantにインストールされます。 この時点ではマウントに失敗します。 default: /vagrant => /Users/masutaka/projects/example.com Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant sshログインして、/usr/lib/VBoxGuestAdditionsを見えるようにしてあげます。...

2014-04-12 (Sat) · masutaka

GrowthForecastをインストールする

前回[2013-07-17-1] から間が空いてしまいましたが、GrowthForecast をイ ンストールしました。 インストールするだけなら、これだけでOKです。 % mkdir ~/growthforecast % cd ~/growthforecast % echo "requires 'GrowthForecast';" > cpanfile % sudo apt-get build-dep rrdtool % plenv exec carton install 起動方法はこんな感じ。http://example.com:5125とかにアクセスすると確 認出来ると思います。 % cd ~/growthforecast % carton exec -- perl growthforecast.pl --data-dir . & –data-dirオプションを指定しないと ~/growthforecast/local/lib/perl5/auto/share/dist/GrowthForecast/data/ 以下にsqlite関連のファイルが作られます。~/growthforecast/localは 削除することもあるでしょうから、指定した方が良いと思います。 Chefのレシピはこれ。‘Install packages depending RRDTool’のあたりが 汚いですが、仕方がないですかね。 今回初めて知りました。。 loading... 次回はGrowthForecastとfluentdの連携を試してみます。 参考にしたサイト GrowthForecastをインストールする|Act as Professional - hiroki.jp

2013-08-14 (Wed) · masutaka

plenv + cpanm + cartonでPerlの環境を構築した(Ubuntu版)

plenv + cpanm + carton でPerlの開発環境を構築する|Act as Professional - hiroki.jp 私もGrowthForecast をインストールするために、Ubuntu 12.04.2 LTS上に Perlの環境を構築しました。@hirocaster さんと若干違いがあった(下記★ の箇所)ので、私の手順も書き留めておきます。 Perl力はゼロな私ですが、以下の認識でだいたい合っていると思います。 plenv Rubyのrbenvに相当。複数バージョンのperlをHOMEにインストールし、切り 替えて使うツール。というよりシステムを汚さないために使う感じ。 cpanm Rubyのgemに相当。Perlのライブラリをインストールするために必要なツー ル。今はcpanじゃなくてこれを使うみたい。 carton Rubyのbundlerに相当。アプリごとにライブラリを切り替えることが出来る。 plenv+perl-build これは同じ。 % git clone git://github.com/tokuhirom/plenv.git ~/.plenv 以下を~/.zshenv等に設定して、shellを再起動とかして完了。 export PATH=$HOME/.plenv/bin:$PATH eval "$(plenv init -)" Perlをビルドするためにはperl-buildが必要(★)。 % git clone git://github.com/tokuhirom/Perl-Build.git ~/.plenv/plugins/perl-build/ インストール可能なPerlがずらずらと表示されるようになった(★)。 % plenv install -l Available versions: (省略) 5.18.0 5.19.0 5.19.1 Perl 現時点での最新リリース版5.18.0をインストールする。Perlはx.y.zのy番 号が奇数が開発版で偶数が安定版とのこと。’-Dusethreads’がなぜ必要な のかは知らない。 % plenv install 5.18.0 -Dusethreads デフォルトで5.18.0を使うように設定&もろもろ更新 % plenv global 5....

2013-07-17 (Wed) · masutaka