OpenStack之Swift操作指南

swift-ring-builder account.builder create 18 3 1
swift-ring-builder container.builder create 18 3 1
swift-ring-builder object.builder create 18 3 1

swift-ring-builder account.builder add z1-127.0.0.1:6002/sda1 100
swift-ring-builder container.builder add z1-127.0.0.1:6001/sda1 100
swift-ring-builder object.builder add z1-127.0.0.1:6000/sda1 100

swift-ring-builder account.builder
swift-ring-builder container.builder
swift-ring-builder object.builder

swift-ring-builder account.builder rebalance
swift-ring-builder container.builder rebalance
swift-ring-builder object.builder rebalance

swift-ring-builder account.builder search z1
swift-ring-builder account.builder set_min_part_hours 2
swift-ring-builder account.builder remove :6012
swift-ring-builder account.builder set_info :6022 10.28.1.216:6022/sdb2_account2
验证配置
swauth-prep -K swauthkey -A https://localhost:8089/auth/
添加用户
swauth-add-user -K swauthkey -A https://localhost:8089/auth/ -a system root testpass
swauth-list -K swauthkey -A https://localhost:8089/auth/
查询某个账户下的信息:
swauth-list -K swauthkey -A https://localhost:8089/auth/ system
查看某个账户下的某个用户的信息
swauth-list -K swauthkey -A https://10.28.1.97:8089/auth/ system root
swauth-delete-user -K swauthkey -A https://localhost:8089/auth/ system root

swauth-delete-account -K swauthkey -A https://localhost:8089/auth/ sys
curl -k -v -H 'X-Storage-User: buy360:root' -H 'X-Storage-Pass: testpass' https://localhost:8089/auth/v1.0
swauth-add-account -K swauthkey -A https://localhost:8089/auth/ system
/var/log/messages
/etc/init.d/memcached
dd if=/dev/zero  of=/srv/swift-disk bs=1G count=20
mkfs.xfs /srv/swift-disk(文件系统必须是xfs)
echo "mount /srv/swift-disk /mnt/sdb1 -o loop" >> /etc/rc.local
挂载 mount /srv/swift-disk /mnt/sdb1 -o loop 
启动同步服务 /usr/bin/rsync –daemon –config=/etc/rsyncd.conf
将同步命令加入开机启动 echo "/usr/bin/rsync –daemon  –config=/etc/rsyncd.conf" >> /etc/rc.local

获取X-Storage-Url和X-Auth-Token
curl -k -v -H 'X-Storage-User: system:root' -H 'X-Storage-Pass: testpass' https://localhost:443/auth/v1.0
验证X-Auth-Token
curl -k -v -H 'X-Auth-Token: AUTH_tk8f5cbb6c6f3d41d98172c10fc59ad1d3'  https://10.28.1.216:8089/v1/AUTH_aa002b51-24e5-4385-806f-1087ec9c2fa8

. 检测 swift 命令是否工作正常 (输出应为 zero containers, zero objects, 和 zero bytes):
swift  -A https://localhost:8089/auth/v1.0  -U system:root -K testpass stat
 Account: AUTH_cfc10b95-6033-4fd2-b4c5-c6a7c73a4478
Containers: 0
   Objects: 0
     Bytes: 0
Accept-Ranges: bytes
查看账户相关信息
swift  -A https://localhost:8089/auth/v1.0  -U system:root -K testpass stat -v
StorageURL: https://localhost:8089/v1/AUTH_cfc10b95-6033-4fd2-b4c5-c6a7c73a4478
Auth Token: AUTH_tk70a2e31982bb4a68881d563a19da6883
   Account: AUTH_cfc10b95-6033-4fd2-b4c5-c6a7c73a4478
Containers: 2
   Objects: 38
     Bytes: 12562615
Accept-Ranges: bytes

上传文件到myfiles容器中:
swift  -A https://localhost:8089/auth/v1.0  -U buy360:root -K testpass upload myfiles 123.txt
创建容器:
swift  -A https://localhost:8089/auth/v1.0  -U buy360:root -K testpass post myfiles
 下载myfiles容器中的所有文件
swift  -A https://10.28.1.97:8089/auth/v1.0  -U buy360:root -K testpass download myfiles *
下载某个账户下面的所有内容
swift  -A https://localhost:8089/auth/v1.0  -U system:root -K testpass  download –all
将对象下载到指定文件
 swift  -A https://localhost:8089/auth/v1.0  -U system:root -K testpass  download myfiles swift.conf -o liu.test
列出所有容器
swift  -A https://localhost:8089/auth/v1.0  -U buy360:root -K testpass list
列出前缀为my的容器
swift  -A https://localhost:8089/auth/v1.0   -U buy360:root -K testpass list -p my
查看容器myfiles中的对象
swift  -A https://localhost:8089/auth/v1.0  -U buy360:root -K testpass list myfiles
将对象分段上传
swift  -A https://localhost:443/auth/v1.0  -U system:root -K testpass upload largeobject -S 1024000 account.builder 

定位账户,容器,对象存储的位置:swift-get-nodes

必须将文件夹组跟用户设置为swift,不然报错
chown swift:swift /mnt/sdb1/*
当试着上传一个大于5G的对象,就会报错
-bash-4.1# swift  -A https://localhost:8089/auth/v1.0  -U system:root -K testpass upload largeobject /tmp/swiftdev1
Object PUT failed: https://10.28.1.216:8089/v1/AUTH_72d3e323-b8e3-47ce-af21-95e96690436b/largeobject//tmp/swiftdev1 413 Request Entity Too Large
swauth-prep -K swauthkey -A https://localhost:8089/auth/

swift Could not create the main auth account:将代码重新安装一次

sqlite数据库
.h on 查询的时候显示表字段

查询当前数据库的表结构
 select * from sqlite_master WHERE type = "table"; 

glance add name="test-1" is_public=true < /home/images/euca-centos-5.3-x86_64.tar.gz 
/usr/bin/glance-control api restart

swift设计上的缺点:
1)上传的时候,不应该多分上传,而是应该上传一份,然后让它自己复制多分
2)每次加入一个节点,进行rebalance的操作的时候,会重新进行分区号的分配,可能会涉及到大量对象的移动
/usr/bin/glance-control registry restart

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!

发表评论