iSCSI TargetをUbuntu 12.04にセットアップ

[bash]
$ sudo apt-get update
$ sudo apt-get install iscsitarget
$ dpkg -l iscsitarget
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii iscsitarget 1.4.20.2-10u amd64 iSCSI Enterprise Target userland
$ sudo vi /etc/default/iscsitarget 
ISCSITARGET_ENABLE=true
$ dd if=/dev/zero of=iscsi.img count=0 bs=1 seek=1G
$ sudo vi /etc/iet/ietd.conf
(末尾に追記)
Target iqn.2013-08.me.hrendoh:test.disk
Lun 0 Path=/home/cloudn/iscsi.img,Type=fileio
$ sudo service iscsitarget restart
* Removing iSCSI enterprise target devices: [ OK ]
* Starting iSCSI enterprise target service FATAL: Module iscsi_trgt not found.
[fail]</pre>
起動しようとするとエラー「FATAL: Module iscsi_trgt not found.」
iscsitarget-dkmsをインストールすると解消する(参考:<a href="http://www.heath-bar.com/blog/?p=203">Setup an Ubuntu iSCSI target (server)</a>)
<pre>$ sudo apt-get install iscsitarget-dkms
$ sudo service iscsitarget restart
* Removing iSCSI enterprise target devices: [ OK ]
* Starting iSCSI enterprise target service [ OK ]
[ OK ]
[/bash]
Firewallを設定

1.2.3.xのアクセスをCIDRで指定(Cloudnを利用)

iSCSIターゲット用Firewall設定 Cloudn
iSCSIターゲット用Firewall設定 Cloudn

Ufwなら
[bash]
$ ufw allow from 111.222.333.0/24 to any port 3260
[/bash]

追加ディスクを利用する場合

[bash]
$ sudo fdisk -l

Disk /dev/vda: 16.1 GB, 16106127360 bytes
16 heads, 63 sectors/track, 31207 cylinders, total 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e1e29

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 499711 248832 83 Linux
/dev/vda2 501758 31455231 15476737 5 Extended
/dev/vda5 501760 31455231 15476736 8e Linux LVM

Disk /dev/vdb: 107.4 GB, 107374182400 bytes
16 heads, 63 sectors/track, 208050 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdb doesn’t contain a valid partition table

Disk /dev/mapper/localhost-root: 13.7 GB, 13652459520 bytes
255 heads, 63 sectors/track, 1659 cylinders, total 26664960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/localhost-root doesn’t contain a valid partition table

Disk /dev/mapper/localhost-swap_1: 2143 MB, 2143289344 bytes
255 heads, 63 sectors/track, 260 cylinders, total 4186112 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/localhost-swap_1 doesn’t contain a valid partition table
$ sudo vi /etc/iet/ietd.conf
Target iqn.2013-08.me.hrendoh:test.disk
Lun 0 Path=/dev/vdb,Type=blockio
$ sudo service iscsitarget restart
[/bash]

Bulk update

Rails ActiveRecord – Batch Updates
http://apidock.com/rails/ActiveRecord/Base/update_all/class

Tag.where(:is_featured => true).each do |tag|
  tag.update_attribute(:is_featured, false)
end

これだとTagオブジェクトがロードされるのでメモリーを食ってしまうので直接Update文を実行したい

Rails RDocのActiveRecord::Relation#update_allに記述されている書き方

Tag.where({:is_featured => true }).update_all({ :is_featured => false })

第二引数に条件を付けられるのでこちらの方が簡潔

Tag.update_all({ :is_featured => false }, {:is_featured => true })

どちらも実行されるSQLは同じ

UPDATE `tags` SET `is_featured` = 0 WHERE `tags`.`is_featured` = 1

Railsのgeneratorの使い方がわからない

公式ドキュメント
A Guide to The Rails Command Line 1.3 rails generate
Getting Up and Running Quickly with Scaffolding

Scafold

$ rails g  scaffold Post title:string text:text
      invoke  active_record
      create    db/migrate/20130814020256_create_posts.rb
      create    app/models/post.rb
      invoke    test_unit
      create      test/unit/post_test.rb
      create      test/fixtures/posts.yml
      invoke  resource_route
       route    resources :posts
      invoke  scaffold_controller
      create    app/controllers/posts_controller.rb
      invoke    erb
      create      app/views/posts
      create      app/views/posts/index.html.erb
      create      app/views/posts/edit.html.erb
      create      app/views/posts/show.html.erb
      create      app/views/posts/new.html.erb
      create      app/views/posts/_form.html.erb
      invoke    test_unit
      create      test/functional/posts_controller_test.rb
      invoke    helper
      create      app/helpers/posts_helper.rb
      invoke      test_unit
      create        test/unit/helpers/posts_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/posts.js.coffee
      invoke    scss
      create      app/assets/stylesheets/posts.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

Controller

$ rails generate controller admin/Users

Model

Rspec