VagrantでのDisk追加(VirtaulBox)


VagrantでのDisk追加の方法として

Vagrant.configure("2") do |config|
    file_to_disk = './box-disk3.vmdk'
    unless File.exist?(file_to_disk)
      vb.customize [ "createhd", "--filename", file_to_disk, "--size", 80*1024 ] 
    end
    vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 4, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
end

でうまくいきました。

内容としては。

file_to_disk に作成したいDisk名を代入してunlessでファイルの有無を確認します。
unless File.exist?(file_to_disk)
ファイルが存在しなかった場合、ファイルを作成します。今回は80GBのディスクの容量を作成します。
vb.customize [ "createhd", "--filename", file_to_disk, "--size", 80*1024 ]

その後、virtualboxに認識させます。
vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 4, '--device', 0, '--type', 'hdd', '--medium', file_to_disk] 

--storagectl  VirtualBoxのストレージの設定でのコントローラー名(ストレージツリーの最上層の部分)です。
--port     該当するコントローラーでのポートの番号を指定します。

すいません。それ以降の内容はまだ分かりません。頑張って調べます。

VBoxManage storageattach --storagectl LsiLogic --port 0 --device 0 --type hdd --medium "DiskPATH"




windowsでvagrantのネットの接続が遅い件

windowsvagrantを使って、開発をしています。
そこでVagrantfileでprivate_networkを利用してIPアドレスを設定しているのですが
ネットの接続が異常に遅くなってしましました。

以下は、その時に使用していたVagrantfileです。
Vagrant.configure("2") do |config|
    config.vm.hostname = "my-server"
    config.vm.box = "CentOS-6.4-x86_64-v20130731"
    config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box"
    config.vm.network :private_network, ip: "192.168.56.2"

    config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2048"]
    end

end


解決策としては、以下の設定を追加するだけでよかったです。
しかし、この設定はVirtualBoxのみになりそうです。

    config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2048"]
       # 以下を追加
        vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    end

上記の設定はサーバ上で以下のコマンドを打つのを同じみたいです。たぶん。

VBoxManage modifyvm "VM name" --natdnshostresolver1 on

参考URL

vagrant-virtualbox-dns-10-0-2-3-not-working
vagrant-slow-internet-connection-in-guest


Gitをソースコードからインストールした時のエラー

Gitがyumでインストールしたら、1.7だったので1.8にバージョンアップしました。 
yum remove git-core

$ sudo yum install openssl097a.x86_64 openssl-perl.x86_64 curl-devel
$ wget https://git-core.googlecode.com/files/git-1.8.5.3.tar.gz
$ tar zxf git-1.8.5.3.tar.gz
$ cd git-1.8.5.3 && ./configure && make && sudo make install

openssl1097a.x86_64とopenssl-perl.x86_64は以下のエラーが出たためインストールを行った 
$ git clone https://github.com/oomatomo/perl-test.git
Cloning into 'perl-test'
fatal: Unable to find remote helper for 'https'





以上でうまくいきました。

 

chefでカスタムリソースを作る


自分独自のResourceを作成します。
作成したファイルは以下の通り


├── providers
│   └── test.rb
├── recipes
│   └── default.rb
├── resources
│   └── test.rb


* resources  
カスタムResourceのAttributeの設定。
* providers  
定義したResourceの実際の処理の部分。

resources

# resources/test.rb
# ここで利用出来るアクションの設定
# actions :action_name1, :action_name2, :action_name...
actions :foo, :bar

# actionが何も指定されなかったとき、実行するアクション
# default_action :action_name1
default_action :foo

# Attributeの設定
# attribute :attribute_name, :kind_of => value, :validation_parameter => value
attribute :name, :kind_of => String, :name_attribute => true
attribute :type, :kind_of => String, :default => "bar"
:name_attribute => trueとは、リソースの後に追加される文字列のこと
以下では”test foo”が該当する。

custom_resource_test "test foo" do
end

providers


new_resource.attribute_nameでresources/test.rbに
設定している

 
# providers/test.rb
# resources/test.rbで定義したアクションの処理を記述
# new_resource.nameは以下の “test foo”の部分と一致する
# custom_resource_test "test foo" do
# end

action :foo do
  p "#{new_resource.name}"
  p "#{new_resource.type}"
end

action :bar do
  p "#{new_resource.name}"
  p "#{new_resource.type}"
  bash "test" do
    user "root"
    code <<-EOH
      echo #{new_resource.type}
    EOH
  end
end


recipes


COOKBOOKNAME_FILENAMEがリソース名となる。  
FILENAMEがdefault.rbの場合、COOKBOOKNAMEがリソース名。  
今回は、custom_resourceがCOOKBOOKNAMEで  
providers/test.rbとresources/test.rbがあるため  
リソース名は`custom_resource_test`となる  

# recipes/default.rb
custom_resource_test "test foo" do
end

custom_resource_test "test bar" do
  action :bar
  type "bar type"
end


Chefのバージョンによってdefault_actionの書き方が異なるので 注意 。
ただ現状はif defined?(default_action)がなくても動く。

actions :create, :destroy
default_action :create if defined?(default_action) # Chef > 10.8
 
# Default action for Chef <= 10.8
def initialize(*args)
  super
  @action = :create
end
   

zshのシェルオプションについて


zshのシェルオプションについて

・setopt       オプションの有効
・unsetopt   オプションの無効

setopt auto_menu            # タブで補完候補を表示する
setopt auto_cd              # ディレクトリ名のみ入力時、cdを適応させる
setopt auto_list            # 補完候補が複数ある時に、一覧表示
setopt auto_pushd           # cd実行時、ディレクトリスタックにpushされる
setopt auto_param_keys      # カッコの対応などを自動的に補完
setopt auto_param_slash     # ディレクトリ名の補完で末尾に/を自動的に付加
setopt correct              # コマンドのスペルを訂正する
setopt equals               # =commandを`which command`と同じ処理
setopt globdots             # ドットの指定なしでドットファイルも候補に入る
setopt interactive_comments # コマンドラインでの#以降をコメントと見なす
setopt list_types           # 候補にファイルの種別を表示(ls -F)
setopt list_packed          # 補完結果をできるだけ詰める
setopt no_beep              # ビープ音を鳴らさない
setopt nolistbeep           # 補完候補表示時にビープ音を鳴らさない
setopt no_tify              # バックグランドジョブが終了時知らせてくれる
setopt magic_equal_subst    # 引数での=以降も補完(--prefix=/usrなど)
setopt mark_dirs            # ファイル名の展開でディレクトリにマッチした場合末尾に / を付加する
setopt prompt_subst         # プロンプト定義内で変数置換やコマンド置換を扱う
setopt print_exit_value     # 戻り値が 0 以外の場合終了コードを表示
setopt pushd_ignore_dups    # ディレクトリスタックに重複する物は古い方を削除
# 履歴のシェルオプション
setopt bang_hist            # !を使った履歴展開を行う(d)
setopt extended_history     # 履歴に実行時間も保存する
setopt hist_ignore_dups     # 直前と同じコマンドは履歴に追加しない
setopt hist_reduce_blanks   # 余分なスペースを削除して履歴に保存する
setopt hist_no_store        # historyコマンドは履歴に登録しない
setopt hist_expand          # 補完時に履歴を自動的に展開
setopt hist_ignore_dups     # 入力したコマンドが直前のものと同一なら履歴に登録しない
setopt hist_save_no_dups    # 入力したコマンドが直前のものと同一なら古いコマンドのほうを削除する
setopt hist_find_no_dups    # ラインエディタでヒストリ検索し、ヒットした場合でも重複したものとみなさない
setopt hist_ignore_all_dups # 入力したコマンドを履歴に登録する時、同一がすでに存在した場合登録しない
setopt hist_no_functions    # 関数定義のためのコマンドは履歴から削除する
setopt hist_no_store        # 履歴参照のコマンドは履歴に登録しない
setopt hist_reduce_blanks   # コマンド中の余分な空白を削除する
setopt inc_append_history   # 履歴をインクリメンタルに追加
setopt share_history        # 他のシェルのヒストリをリアルタイムで共有する

メモ
githubのwiki

頑張ろう自分用のwikiの更新
 

Cassandraでのエラー 「The stack size specified is too small」


Cassandra起動時のエラーが出たので解決方法のメモを残します。
 OSはcentosです。

The stack size specified is too small, Specify at least 160k
Could not create the Java virtual machine.

環境変数を変更しました。
JVM_OPTS="$JVM_OPTS -Xss160k" #変更前
JVM_OPTS="$JVM_OPTS -Xss128k" #変更後

上記の内容でうまくいきました。

 ちなみに該当する設定ファイルは「cassandra/conf/cassandra-env.sh 」です。

tmuxのcolor一覧について

tmuxのcolor一覧について

tmuxで利用できる色の一覧のシェルスクリプトです。

tmux-powerlineから拝借


for i in $(seq 0 8 255); do
  for j in $(seq $i $(expr $i + 7)); do
    for k in $(seq 1 $(expr 7 - ${#j})); do
            printf " "
    done
    printf "\x1b[38;5;${j}mcolour${j}"
     $(expr $j % 8) != 7  && printf "    "
  done
  printf "\n"
done


sepについてはこちら

tmux-color

こんな感じで見れます