ハマった時は # init 0

試したことを書き綴ってます

openstack havana on ubuntu 13.10 (cinder)

openstackとりまとめページ http://init0.hatenablog.com/entry/2013/10/05/232939

LVMの設定

まずは、cinder用に VGを作成します。

nova 用に、ディスクパーティションを用意できる人用

ディスクに空きパーティションがある人は、一般的な方法で、VGを作成する。

  • vgの名称は、cinder-volumes とする。
    • cinderのデフォルト設定では、「cinder-volumes」を使うため。
# pvcreate /dev/sdb1
# vgcreate  cinder-volumes /dev/sdb1
# vgdisplay 
  --- Volume group ---
  VG Name               cinder-volumes
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               50.00 GiB
  PE Size               4.00 MiB
  Total PE              12799
  Alloc PE / Size       0 / 0   
  Free  PE / Size       12799 / 50.00 GiB
  VG UUID               H14HUP-XwkY-EeQt-tqpT-iNGG-abOt-gmBo2x
   

空きパーティションがない人向け

cinder用に使える空きパーティションがない場合は、ddでファイルを作成し、ループバックマウントして無理やりVGを作成する。

  • 再起動するたびに、losetupしないといけないので、/etc/rc.localに、losetupを記載すると便利。
# dd if=/dev/zero of=/home/cinder01.img bs=1024 count=10000000
# losetup -f /home/cinder01.img
# pvcreate /dev/loop0
  Physical volume "/dev/loop0" successfully created
# vgcreate cinder-volumes /dev/loop0
  Volume group "cinder-volumes" successfully created

DB作成

cinder用にDBを作成します。

  • 事前に、stack@localhost、stack@% というユーザは作成済みです。
  • cinderという名称で、DBを作成
  • stackユーザに、cinder DBを操作する全権限を付与する。
# mysql -u root -p
mysql> CREATE DATABASE cinder;
mysql> GRANT ALL PRIVILEGES ON cinder.* TO 'stack'@'localhost';
mysql> GRANT ALL PRIVILEGES ON cinder.* TO 'stack'@'%';

cinderインストール・設定

インストール

# aptitude install cinder-volume cinder-api cinder-scheduler

設定ファイル変更

  • /etc/cinder/cinder.conf
    • DBへの接続設定を追加する。

以下を追加

[database]
sql_connection = mysql://stack:stack@localhost/cinder
  • /etc/cinder/api-paste.ini
    • keystoneへの接続設定を記載する
# 省略
[filter:authtoken]
paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
auth_host = 127.0.0.1
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = cinder
admin_password = cinder
# 省略

DBにスキーマ登録

# cinder-manage  db sync

keystoneの設定

  • cinderユーザ作成
keystone user-create \
        --name=cinder \
        --pass=cinder \
        --email=cinder@example.com
  • cinderユーザにroleを付与
    • serviceテナントのadminとしてロールを作成。
    • tenant-id, user-id, role-idを事前に調べ、user-role-addの引数で渡す。
# keystone tenant-list | grep service
| 63db5b3fccf04d66b87091d5fbe771b7 | service |   True  |

# keystone user-list | grep cinder
| 300f04f6e9ac442d81ef3ea87fa969c1 |  cinder |   True  |  cinder@example.com |

 # keystone role-list | grep admin
| 58489d413e69439699875718d1407307 |        admin         |

keystone user-role-add \
        --tenant-id 63db5b3fccf04d66b87091d5fbe771b7 \
        --user-id 300f04f6e9ac442d81ef3ea87fa969c1 \
        --role-id 58489d413e69439699875718d1407307
  • REST API バージョン1用のendpointを作成
keystone service-create --name=cinder --type=volume \
  --description="Cinder Volume Service"

# keystone service-list | grep cinder
| 29c2d484d0f64a768423d90c5515b787 |  cinder  |    volume    |      Volume Service      |

keystone endpoint-create \
  --service-id= 29c2d484d0f64a768423d90c5515b787 \
  --publicurl=http://192.168.0.110:8776/v1/%\(tenant_id\)s \
  --internalurl=http://192.168.0.110:8776/v1/%\(tenant_id\)s \
  --adminurl=http://192.168.0.110:8776/v1/%\(tenant_id\)s
  • REST API バージョン2用のendpointを作成
keystone service-create --name=cinderv2 --type=volumev2 \
  --description="Cinder Volume Service V2"

# keystone service-list | grep cinderv2
| a9bbd40f7f9a46debd1f53511fc15d6c | cinderv2 |   volumev2   | Cinder Volume Service V2 |

keystone endpoint-create \
  --service-id=a9bbd40f7f9a46debd1f53511fc15d6c \
  --publicurl=http://192.168.0.110:8776/v2/%\(tenant_id\)s \
  --internalurl=http://192.168.0.110:8776/v2/%\(tenant_id\)s \
  --adminurl=http://192.168.0.110:8776/v2/%\(tenant_id\)s

cinderの再起動

service cinder-api restart
service cinder-volume restart
service cinder-scheduler restart

動作確認

cinderコマンドを使い、volumeを作成・削除する。

# cinder create --display-name vol01 1
# cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 521c6a82-0aac-4418-a6b4-b458353c6039 | available |    vol01     |  1   |     None    |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

# cinder delete vol01

novaのVMインスタンスにvolumeをアタッチする。

VM起動
nova boot --image ubuntu13.04-qcow2  --flavor 2 --key-name default vm01
volume作成 + アタッチ
nova volume-create --display-name vol01 1

# nova volume-list | grep vol01 | awk '{ print $2 }'
1e3534f0-e3c4-4147-82ec-c2cd9a86bd8f

nova volume-attach vm01 1e3534f0-e3c4-4147-82ec-c2cd9a86bd8f  /dev/vdb
VM上でアタッチされたボリュームを使用する
root@vm01:~# fdisk -l /dev/vdb

Disk /dev/vdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders, total 2097152 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




root@vm01:~# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xcc49baf5.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-2097151, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): 
Using default value 2097151

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@vm01:~# mkfs.ext4 /dev/vdb1 
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 261888 blocks
13094 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@vm01:~# mount /dev/vdb1 /mnt/
  • ファイルを作成する。
root@vm01:~# ls /mnt/
lost+found
root@vm01:~# echo "HELLO" > /mnt/hello.txt
  • アンマウントする。
root@vm01:~# umount /mnt 
root@vm01:~# 
volumeデタッチ
nova volume-detach  vm01 1e3534f0-e3c4-4147-82ec-c2cd9a86bd8f
別のVMに作成済みvolumeをアタッチする
# nova boot --image ubuntu13.04-qcow2  --flavor 2 --key-name default vm02
# nova volume-attach vm02 `nova volume-list | grep vol01 | awk '{ print $2 }'` /dev/vdb
VM上でファイルシステムをマウント
  • マウントし、別VMで作成したファイルが存在するか確認
ubuntu@vm02:~$ mount /dev/vdb
vdb   vdb1  
ubuntu@vm02:~$ mount /dev/vdb1 /mnt/
mount: only root can do that
ubuntu@vm02:~$ sudo su - 
root@vm02:~# mount /dev/vdb1 /mnt/
root@vm02:~# ls /mnt/
hello.txt  lost+found
root@vm02:~# cat /mnt/hello.txt 
HELLO