OpenStack Grizzly - Swift - How to use2013/08/23 |
This example configures Swift like follows.
This example shows to use Swift Storage from a Client Machine. (it's the one 10.0.0.20 below) | +------------+ | +-----------+ | Auth Node |10.0.0.30 | 10.0.0.31| Proxy | | (Keystone) |------------+------------| Node | +------------+ | +-----------+ +----------+ | 10.0.0.20| Client | +------------------------+-----------------------+--------------| Machine | | | | +----------+ |10.0.0.51 |10.0.0.52 |10.0.0.53 +-----------+ +-----------+ +-----------+ | Storage | | Storage | | Storage | | Node1 |------------| Node2 |-----------| Node3 | +-----------+ +-----------+ +-----------+ |
[1] | Add a user for using Swift in Keystone Authentication Node. By the way, if you'd like to use Swift Quickly, it's unnecessarry to add a new user, it's posibble to use with a admin or swift user in Keystone. |
# add swiftservice tenant [root@dlp ~(keystone)]# keystone tenant-create --name swiftservice --description "Swift Users Tenant" --enabled true +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | Swift Users Tenant | | enabled | True | | id | c2ca7fce1e61436db8c45a863ef996a8 | | name | swiftservice | +-------------+----------------------------------+ # add swiftoperator role [root@dlp ~(keystone)]# keystone role-create --name swiftoperator +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | id | 830dd316ec8843abb8c7b6333e2c85e8 | | name | swiftoperator | +----------+----------------------------------+ # add a user [root@dlp ~(keystone)]# keystone user-create --tenant_id c2ca7fce1e61436db8c45a863ef996a8 --name user01 --pass userpassword --enabled true +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | | | enabled | True | | id | 46fc6e8a25944e169c9af8a5af3a9b48 | | name | user01 | | tenantId | c2ca7fce1e61436db8c45a863ef996a8 | +----------+----------------------------------+ # add the user above in swiftoperator role [root@dlp ~(keystone)]# keystone user-role-add --user-id 46fc6e8a25944e169c9af8a5af3a9b48 --tenant_id c2ca7fce1e61436db8c45a863ef996a8 --role-id 830dd316ec8843abb8c7b6333e2c85e8 |
[2] | This is Client's settings. Install Keystoneclient, Swiftclient first. |
# install from EPEL OpenStack, EPEL [root@client ~]# yum --enablerepo=epel-openstack-grizzly,epel -y install python-keystoneclient python-swiftclient
|
[3] | Load environment variables first. ( it's just the value for a user added in [1] ) |
[root@client ~]#
vi ~/keystonerc_swift
export OS_USERNAME=user01
export OS_PASSWORD=userpassword export OS_TENANT_NAME=swiftservice export OS_AUTH_URL=http://10.0.0.30:35357/v2.0/ export PS1='[\u@\h \W(swift)]\$ '
[root@client ~]#
chmod 600 ~/keystonerc_swift [root@client ~]# source ~/keystonerc_swift [root@client ~(swift)]# echo "source ~/keystonerc_swift " >> ~/.bash_profile
# show status [root@client ~(swift)]# swift stat Account: AUTH_a8940116012e4a76af6ead65c7782917 Containers: 0 Objects: 0 Bytes: 0 Accept-Ranges: bytes X-Timestamp: 1377324651.88598 Content-Type: text/plain; charset=utf-8 |
[4] | Create a Container for files. |
[root@client ~(swift)]# swift post test_container [root@client ~(swift)]# swift list test_container # created |
[5] | Upload a file in local to a Container. |
# upload test.txt [root@client ~(swift)]# swift upload test_container test.txt test.txt [root@client ~(swift)]# swift list test_container test.txt # uploaded |
[6] | Download a file from Swift Storage to local. |
[root@client ~(swift)]# swift download test_container test.txt test.txt [headers 0.173s, total 0.174s, 0.000s MB/s] [root@client ~(swift)]# total 44 -rw-------. 1 root root 1047 May 20 23:21 anaconda-ks.cfg -rw-r--r--. 1 root root 9169 May 20 23:21 install.log -rw-r--r--. 1 root root 3161 May 20 23:20 install.log.syslog -rw------- 1 root root 172 Aug 24 15:16 keystonerc_swift -rw-r--r-- 1 root root 19 Aug 24 15:25 test.txt |
[7] | Delere a file on Storage. |
[root@client ~(swift)]# swift delete test_container test.txt test.txt [root@client ~(swift)]# swift list test_container test2.txt # deleted (test.txt) |
[8] | Delete a Container on Storage. |
[root@client ~(swift)]# swift delete test_container [root@client ~(swift)]# swift list # deleted |
Sponsored Link |