tanacasinoのメモ

what are you waiting for ?

Vagrant で VirtualBoxの Guest Additionsをインストールし直す際のメモ その2

先日の日記にて、vagrant-vbguest を使用して明示的にコマンドを叩いて再インストールしてたけど、明示的にコマンドを叩く必要すらないやんという話。

vagrant-vbguestプラグインをインストールしておけば、 vagrant up の際に自動的に Guest Additionsのバージョンをチェックして、ずれてたらその場で入れなおしてくれます。最高です。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
GuestAdditions versions on your host (4.3.12) and guest (4.3.8) do not match.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
Package kernel-devel-2.6.32-431.23.3.el6.x86_64 already installed and latest version
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-136.el6.x86_64 already installed and latest version
Nothing to do
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 4.3.12 - guest version is 4.3.8
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.12 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module[  OK  ]
Building the shared folder support module[  OK  ]
Building the OpenGL support module[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
Starting the VirtualBox Guest Additions [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 4.3.12. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/tanacasino/vagrant/centos65
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

Vagrant で VirtualBoxの Guest Additionsをインストールし直す際のメモ

vagrant を使ってVMを管理する際に、yum updateなどを実行してカーネルのバージョンが変わった場合、 VirtualBoxのGuest Additionsを再インストールしないといけない場合がある。

その場合は、vagrant up すると vboxsf によるホストとゲストのフォルダ共有が動かないため以下のエラーが出る。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/tanacasino/vagrant/centos65
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

手動でGuest Additionsを入れなおす作業はツラいので、vagrantプラグインを使ってこの作業を簡単にする。

# プラグインのインストール
$ vagrant plugin install vagrant-vbguest

# VMのVagrantfileのあるディレクトリに移動して以下を実行
$ vagrant vbguest
GuestAdditions versions on your host (4.3.12) and guest (4.3.8) do not match.
...
... その他色々なメッセージが出る ...
...
Starting the VirtualBox Guest Additions [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 4.3.12. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.

上記のような "Window System drivers" installation failed. が出るが、X使ってない場合は無視してOK。 以下のコマンドで Guest Additionsの状態が確認できる。

$ vagrant vbguest --status
GuestAdditions 4.3.12 running --- OK.

今回使用したvagrantのバージョンはこちら。

$ vagrant version
Installed Version: 1.6.3
Latest Version: 1.6.3

You're running an up-to-date version of Vagrant!

CentOS 6.5 に開発環境を構築するためのメモ

CentOS 6.5 の開発環境にインストールするメモ。日々メンテナンス更新しておきたい。

yumで入るものは書かない。

  1. vim
  2. tmux
  3. zsh
  4. ag
  5. peco
  6. dotfiles (vim,tmux,zsh等の設定)

TODO

  • dotfiles に 以下のことをするスクリプトファイルでも準備しておくと良さげ
  • vimを自分でビルドするのは良いが、python有効になってないことが判明
  • tmuxp
  • nvm
  • rbenv
  • virtualenv
  • autojump
    • z にしようかな

事前準備

sudo yum -y update
sudo yum -y groupinstall 'Development Tools'
sudo yum -y install curl dstat ruby lua mercurial
reboot

git のインストール

CentOSのgitは古くて残念なのでソースからビルドする。

sudo yum -y groupinstall 'Development Tools'
sudo yum -y install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

wget https://www.kernel.org/pub/software/scm/git/git-2.0.4.tar.gz
tar xzf git-2.0.4.tar.gz
cd git-2.0.4

make configure
./configure --prefix=/usr/local
make all doc
sudo make install install-doc install-html

zsh のインストール

/bin/zsh ではなく、/usr/local/bin/zsh になるのに注意せねばならぬ。 また、事故が怖いのでデフォルトシェルの変更はしない。(chshしない) 基本的にtmux使うのでその時に使用する.

wget http://sourceforge.net/projects/zsh/files/zsh/5.0.5/zsh-5.0.5.tar.gz/download -O zsh-5.0.5.tar.gz
tar xzf zsh-5.0.5.tar.gz
cd zsh-5.0.5
./configure
make
sudo make install

vim のインストール

TODO : patchを適用する(面倒くさいので、リポジトリのソースを直接ビルドの方がいいかもしれない。管理方法がわかってないので一緒かもしれんが。)

sudo yum -y groupinstall 'Development Tools'
sudo yum -y install curl git ruby lua
sudo yum -y install bzip2-devel curl-devel expat-devel ncurses-devel zlib-devel python-devel ruby-devel lua-devel

wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
tar xjf vim-7.4.tar.bz2
cd vim74
./configure --disable-selinux --enable-multibyte --with-features=huge --enable-rubyinterp=dynamic --enable-pythoninterp=dynamic --enable-luainterp=dynamic
make
sudo make install

tmuxのインストール

tmux 1.9aには、libevent 2.0系が必要になるのでまずはlibevent入れる必要あり。

sudo yum -y groupinstall 'Development Tools'
sudo yum -y install ncurses-devel

curl -L https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz -o libevent-2.0.21-stable.tar.gz
tar xzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make && sudo make install

cd
wget http://downloads.sourceforge.net/tmux/tmux-1.9a.tar.gz
tar xzf tmux-1.9a.tar.gz
cd tmux-1.9a
export LIBEVENT_CFLAGS="-I/usr/local/include"
export LIBEVENT_LIBS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib -levent"
./configure
make && sudo make install
sudo cp examples/bash_completion_tmux.sh /etc/bash_completion.d/

The Silver Searcher (ag)

find + grepは古すぎますね。時代は ag です。2文字とか最高です。 ちなみに pt 乗り換え予定。

sudo yum -y groupinstall "Development Tools"
sudo yum -y install pcre-devel xz-devel
git clone https://github.com/ggreer/the_silver_searcher
cd the_silver_searcher
./build.sh
mkdir -p ~/bin/
ln -sf `pwd`/ag ~/bin/

pt

UTF-8以外の日本語に対応している agの代替。golangで書かれているのでgolangの勉強にソースを読んでおきたいところ。

mkdir -p ~/bin/
wget https://github.com/monochromegane/the_platinum_searcher/releases/download/v1.7.1/pt_linux_amd64.tar.gz
tar xzf pt_linux_amd64.tar.gz
cd pt_linux_amd64
cp pt ~/bin/

乗り換えようと思って試しているけども、agと動きが微妙に違うのが気になっている。検索結果も違うのがちょっとどうしよっかなという感じ。 真面目にテスト運用が必要そう。

メモ

  • ptは、検索の結果何もない場合に exit codeが 1 で終わる(ag は 0)
  • 隠しファイルの検索を指定するオプションがない
  • ファイル・パスを複数指定した場合の挙動が異なる

peco

mkdir -p ~/bin/
wget https://github.com/peco/peco/releases/download/v0.2.3/peco_linux_amd64.tar.gz
tar xzf peco_linux_amd64.tar.gz
cd peco_linux_amd64
cp peco ~/bin/

dotfiles

自分の設定ファイル

git clone https://github.com/tanacasino/dotfiles.git
cd dotfiles
./setup.sh

まとめ

CentOS 6.x系だとパッケージ古いよねというあるあるネタのせいでソースからビルドする必要があり面倒くさい。 もしかしてだけど、Dropboxとか使ってオレオレyum repo作った方が幸せになれるんじゃないの? とか、CentOS 6.x系は捨てて、CentOS 7系に移行すればええのかもしれんとか思った。

もちろんUbuntuいいと思うけど、本番がCentOSのパターン多いので、できれば統一しておきたいなぁとかは思う。 デプロイ環境がDockerのようなエコシステムに統一されれば、開発環境のホストOSは問わないって感じになるので気にする必要なくなるのかもだけども。

が、そもそもディストリが配布するパッケージは、基本的にリリースされるとメジャーバージョンはフリーズされる(一部のバンバンバージョンあげるWebブラウザみたいなの除く)ので、バージョンが新しくてもシステムに影響を及ぼすわけではないツール類は、homebrew のようなパッケージ管理をディストリのパッケージ管理とは別に個人のホームディレクトリにインストールする形で管理できると素晴らしいのかもしれない。

と思ったら、linuxbrewなるものがあったので期待したい。 残念ながら自分の環境では一部のパッケージがインストールできなかったので、もっと時間のある時に導入しようと思いましたが・・・

あとちょっとしたツール系のコマンド類は、pecoのようにgolangで書かれているとバイナリ1つコピーすればOKなので素晴らしいと思った。 便利なコマンドラインツールは全部golangになればいいですわ!rubyとかpythonで書かれてるとどうしてもインタプリタのバージョン問題があるし、JVM系言語は起動が遅いので一瞬で終了するプログラムに向いてない。 golangだとクロスプラットフォームでバイナリ作れるし、実行速度が早いので素敵やと思う。 (もちろん serf, consulのように libcが古いCentOS 6.x みたいなOSで動かないバイナリもあるけれど・・・)

CentOS 6.x の wgetでSSL handshake error が出る場合の対処方法

いつからか知りませんが、wgetgithub からリリース資材をダウンロードしようとするとエラーになってしまうようです。

$ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
--2014-08-10 14:57:44--  https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
Resolving github.com... 192.30.252.131
Connecting to github.com|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz [following]
--2014-08-10 14:57:45--  https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
Resolving cloud.github.com... 54.230.108.198, 54.230.108.165, 54.230.111.106, ...
Connecting to cloud.github.com|54.230.108.198|:443... connected.
OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Unable to establish SSL connection.

対処方法は、curl を使いましょう!ですw

githubのように302foundとlocationを返してきてたらい回しにされる場合に備えて、-L オプションをつけてたり、outputファイルを指定する -o を指定する必要があるのでちょっと面倒ですね。

# インストールしてない場合はyumで入れてからどうぞ。
$ sudo yum install curl

$ curl -L https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz -o libevent-2.0.21-stable.tar.gz

ちなみにまったく関係ないですが、libeventの2.0系はtmuxの1.9aのインストールに必要です。