tmux + wemux のテスト環境をwindows + vagrantで構築してみる
後輩に「wemuxとか知ってますか?」と聞かれたので、試してみた。
ちなみにうちはscreen派でtmuxは一度挫折なんかしてたりするのです。
つまみ食いして放置したパターン!
VirtualBoxをインストール
←こちらから [Downloads]→[for Windows hosts x86/amd64]をクリック
インストーラーに従ってインストールするだけ。
ちなみに起動しなくてもいい。
vagrantをインストール
Vagrant ←こちらから [DOWNLOAD]をクリック
インストーラーに従ってインストールするだけ。
boxを追加する
A list of base boxes for Vagrant - Vagrantbox.es ←こちらから 用意したいboxを探し出します。
今回は「CentOS 6.3 x86_64 minimal」を選びました(なぜCentOS 6.4系を選んでなかったのか不明)
URLの横に「COPY」ってあるのでそこでURLをコピーしてきます。
> vagrant add centos6.3 https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box
と入力。しばらく待ちます。
VM作成
処理が終わりましたらVagrantの設定ファイル置いておく場所を決めます。
ここでは「C:\vm\test」のディレクトリを作り、そこに移動します。
> cd C:\ > mkdir vm > cd vm > mkdir test > cd test
vagrantの初期化を行います。
さっき追加したboxを指定して初期化します。
> vagrant init centos6.3
初期化後、Vagrantfileというのが作られるのでそれをテキストエディタで開きます。
とりあえず、SSHでアクセスできるようにネットワークに関数部分を編集します。
< # config.vm.network :private_network, ip: "192.168.33.10" > config.vm.network :private_network, ip: "192.168.33.10"
VMを起動します
> vagrant up
インスコ作業もやるので、初回は時間かかります。
SSHで入る
コマンドプロンプトで入れればいんですが、残念ながら入れません!
> vagrant ssh `ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use the PuTTY SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: vagrant Private key: C:/Users/[user名]/.vagrant.d/insecure_private_key
コマンドプロンプトから入ろうとすると次のように怒られます。(コマンドプロンプトにSSH機能なんてないので)
仕方ないのでSSHクライアントで上記に出てるようなパラメータでログインしてください。
うちは、minttyで次のように入りました
$ ssh vagrant@127.0.0.1 -p 2222 -i C:/Users/[user名]/.vagrant.d/insecure_private_key もしくは $ cd /c/vm/test/; vagrant ssh
パッケージインストール
パッケージをアップデート後、必要になるパッケージをインストール
$ sudo yum -y update $ sudo yum -y install git automake libtool
前準備:libeventのインストール
$ mkdir ~/src $ cd ~/src $ git clone https://github.com/libevent/libevent.git libevent $ cd libevent $ git checkout release-2.1.3-alpha Note: checking out 'release-2.1.3-alpha'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 85a4004... Add regress_finalize to makefile.nmake $ sh autogen.sh $ ./configure && make $ sudo make install
gitのほうで何か警告出てますがするーしてます。
参照できるように、ld.so.confに追加し、反映させておく
$ sudo cp /etc/ld.so.conf{,.bak} $ sudo vi /etc/ld.so.conf $ diff -u /etc/ld.so.conf{.bak,} --- /etc/ld.so.conf.bak 2013-10-09 04:16:23.508305514 +0200 +++ /etc/ld.so.conf 2013-10-09 04:17:32.928074934 +0200 @@ -1 +1,3 @@ include ld.so.conf.d/*.conf + +/usr/local/lib $ sudo ldconfig -v
tmuxのインストール
$ cd ~/src $ git clone https://github.com/ThomasAdam/tmux.git tmux $ cd tmux $ sh autogen.sh $ ./configure && make $ sudo make install
tmuxの起動確認
$ tmux
$ exit
起動時になんやかんや出たら、ld.so.conf周りがうまくいっていない可能性があるので、見直してみよう。
何も出なければインスコ成功なのでそのまま一度終わります。
wemuxのインストール
$ sudo git clone git://github.com/zolrath/wemux.git /usr/local/share/wemux $ sudo ln -s /usr/local/share/wemux/wemux /usr/local/bin/wemux $ sudo cp /usr/local/share/wemux/wemux.conf.example /usr/local/etc/wemux.conf
The・定型文。
次に設定。
$ sudo vi /usr/local/etc/wemux.conf $ diff /usr/local/share/wemux/wemux.conf.example /usr/local/etc/wemux.conf --- /usr/local/share/wemux/wemux.conf.example 2013-10-09 04:29:00.555060853 +0200 +++ /usr/local/etc/wemux.conf 2013-10-09 04:34:39.178041390 +0200 @@ -10,7 +10,7 @@ ## them to create wemux servers for other users to attach to. ## Add the usernames of users who should use wemux in host mode: ## example: host_list=(zolrath csagan brocksamson) -host_list=(change_this) +host_list=(vagrant)
host_listにいるユーザのみhostになることができます。
今回の場合、vagrantというユーザのみ、ホストになれます。
違いはhelpをみると一目瞭然
$ wemux help wemux version 3.1.0 Usage: wemux [command] To host a wemux server please use one of the following: [s] start: Start the wemux server/attach to an existing wemux server. [a] attach: Attach to an existing wemux server. [k] stop: Kill the wemux server 'wemux', delete its socket. [u] users: List all users currently attached to 'wemux' kick: Disconnect an SSH user, remove their wemux server. [c] config: Open the wemux configuration file in vi. [h] help: Display this screen. no args: Start the wemux server/attach to an existing wemux server. $ sudo -s # wemux help wemux version 3.1.0 Usage: wemux [command] To connect to wemux please use one of the following: [m] mirror: Attach to 'wemux' in read-only mode. [p] pair: Attach to 'wemux' in pair mode, which allows editing. [r] rogue: Attach to 'wemux' in rogue mode, allowing you to pair and also work in other windows independent of the host. [o] logout: Log out of the current wemux rogue session. [u] users: List all users currently attached to 'wemux' [h] help: Display this screen. no args: Attach to rogue session on 'wemux' if it already exists, otherwise, attach in pair mode.
HostのときはServerやらKickやらの説明が出てきて、
Clientのときはどんなモードでattachするか書いてあります。
- mirror → ClientはHostのターミナルを見てるだけ
- pair → 両者の操作が反映される
- rogue → 同じセッションでそれぞれ別の行動ができる
というモードの特徴があります。
詳しくは各々入れて確認してみてください!
使用例
mintty A(host)
$ wemux
mintty B(client)
この場合、rootでやっているが、host_listにないユーザであればなんでも良い
$ sudo -s # wemux mirror or # wemux pair or # wemux rogue