设为首页 收藏本站
查看: 1624|回复: 0

[经验分享] OpenStack Object Storage swif操作和实践

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-7-1 10:41:45 | 显示全部楼层 |阅读模式
  之前已经介绍了OpenStack Object Storage (swift)的相关概念,接下来介绍一些swift的操作。【环境搭建】
为了方便在初期学习swift功能的时候我们可以不考虑身份验证的部分,所以我们要做一点处理:
在安装之前我们可以修改源码中一个配置文件proxy-server.conf,如图:
将tempauth去掉
wKioL1OxG2iyI-A1AAHDrkspWWM914.jpg
同时屏蔽掉下面两行
wKioL1OxG5mRXskJAAFx6_6C4mI137.jpg
因为在swift中功能都是模块化的,你可以根据需求来开启或者关闭。
修改之后我们可以安照上篇博客中介绍的快速部署Swift的SAIO环境 一文中的方法执行脚本setup_saio.sh安装了。

这里我们简单注释一下setup_saio.sh脚本(是根据swift官网文档编写的)

1
2
<span style="font-size:16px;">#!/bin/sh<br>#install indepency<br>sudo apt-get install -y python-software-properties<br># If you want install swift use deb package,enable it<br>#sudo add-apt-repository ppa:swift-core/release<br>sudo apt-get update<br>sudo apt-get install -y curl<br>sudo apt-get install -y gcc<br>sudo apt-get install -y git-core<br>sudo apt-get install -y memcached<br>sudo apt-get install -y python-configobj<br>sudo apt-get install -y python-coverage<br>sudo apt-get install -y python-dev<br>sudo apt-get install -y python-nose<br>sudo apt-get install -y python-setuptools<br>sudo apt-get install -y python-simplejson<br>sudo apt-get install -y python-xattr<br>sudo apt-get install -y sqlite3<br>sudo apt-get install -y xfsprogs<br>sudo apt-get install -y python-webob<br>sudo apt-get install -y python-eventlet<br>sudo apt-get install -y python-greenlet<br>sudo apt-get install -y python-pastedeploy<br>sudo apt-get install -y python-netifaces<br>sudo apt-get install -y memcached<br>#Add swift user<br>sudo useradd -d /home/swift -s /bin/bash -U swift<br>sudo password swift<br>#setup xfs for disk<br>sudo apt-get -y install vsftpd<br>#创建一个回环设备来做存储点<br>sudo dd if=/dev/zero of=:w<br>sudo dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=1000000<br>sudo mkfs.xfs -i size=1024 /srv/swift-disk<br>sudo echo "/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab<br>sudo mkdir /mnt/sdb1<br>sudo mount /mnt/sdb1<br>sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4 /mnt/sdb1/test<br>sudo chown -R swift:swift /mnt/sdb1/*<br>if ! [ -e /srv ]<br>then<br>    sudo mkdir /srv<br>fi<br>for x in 1 2 3 4<br>do<br>  sudo ln -s /mnt/sdb1/$x /srv/$X<br>done<br>sudo mkdir -p /etc/swift/object-server /etc/swift/container-server /etc/swift/account-server<br>for x in 1 2 3 4<br>do<br>  sudo mkdir -p /srv/$x/node/sdb$x<br>done<br>sudo mkdir -p /var/run/swift<br>sudo chown -R swift:swift /etc/swift /srv/1/ /srv/2/ /srv/3/ /srv/4/ /var/run/swift<br>sudo echo -e "mkdir /var/run/swift \\n chown swift:swift /var/run/swift" >> /etc/rc.local<br>if [ -e /home/swift/.bashrc ]<br>then<br>   sudo echo -e "export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf \\n export PATH=${PATH}:~/bin" >> /home/swift/.bashrc<br>   sudo source ~/.bashrc<br>fi<br>#configure swift and related conf<br>if ! [ -e /etc/swift ]<br>then<br>    sudo mkdir /etc/swift<br>fi<br>chown swift:swift /etc/swift<br># copy conf files
<br>cp --recursive conf/* /etc/swift/<br>cp rsyncd.conf /etc<br>sudo service rsync restart<br>#some system need easy_install and pip<br>apt-get -y install python-setuptools<br>easy_install pip<br>#Install swift<br>git clone git://github.com/openstack/swift.git<br>cd swift ; pip install -r tools/pip-requires<br>sudo python setup.py install; cd ..<br>#Install swiftclient<br>git clone https://github.com/openstack/python-swiftclient.git<br>cd python-swiftclient; pip install -r tools/pip-requires<br> sudo python setup.py install;cd ..<br>#make ring and start server<br>cd bin;<br>#创建ring<br>sh remakerings<br>#启动服务<br>swift-init main start</span>



此时我们搭建的环境是一个默认的三副本配置。

【基本操作】
1.生成builder文件和builder相关配置
   你可以在终端中直接输入swift-ring-builder,查看swift-ring-builder命令相关的解释:
swift-ring-builder <builder_file>    Shows information about the ring and the devices within.
   显示ring以及ring中设备的信息,swift-1.8.0中对device新增了一个region属性swift-ring-builder <builder_file> add    z<zone>-<ip>:<port>/<device_name>_<meta> <weight>    [z<zone>-<ip>:<port>/<device_name>_<meta> <weight>] ...    Adds devices to the ring with the given information. No partitions will be    assigned to the new device until after running 'rebalance'. This is so you    can make multiple device changes and rebalance them all just once.
   使用给出的信息添加新的设备到ring上。add操作不会分配partitions到新的设备上,只有运行了'rebalance'命令后才会进行分区的分配。
   因此,这种机制可以允许你一次添加多个设备,并只执行一次rebalance实现对这些设备的分区分配。

swift-ring-builder <builder_file> create <part_power> <replicas> <min_part_hours>    Creates <builder_file> with 2^<part_power> partitions and <replicas>.    <min_part_hours> is number of hours to restrict moving a partition more    than once.
   使用2的<part_power>次方个分区和<replicas>副本数创建<builder_file>.<min_part_hour>是一个分区被连续移动两次之间的最小时间间隔swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..    Returns a 2 column list of all the partitions that are assigned to any of    the devices matching the search values given. The first column is the    assigned partition number and the second column is the number of device    matches for that partition. The list is ordered from most number of matches    to least. If there are a lot of devices to match against, this command    could take a while to run.
   返回一个两列的列表,包含与搜索值相匹配的所有设备的所有分区。
   第一列是关联的分区编号
   第二列是与分区匹配的设备编号
   列表按匹配的编号大小从大到小排序,如果有很多设备与搜索符合,则这个命令需要多运行一会儿

swift-ring-builder <builder_file> rebalance    Attempts to rebalance the ring by reassigning partitions that haven't been    recently reassigned.
   rebalance命令尝试重新平衡环,通过重新分配分区最近没有被重新分配的分区。swift-ring-builder <builder_file> remove <search-value> [search-value ...]    Removes the device(s) from the ring. This should normally just be used for    a device that has failed. For a device you wish to decommission, it's best    to set its weight to 0, wait for it to drain all its data, then use this    remove command. This will not take effect until after running 'rebalance'.    This is so you can make multiple device changes and rebalance them all just    once.
   remove命令将设备从ring中移除。一般情况下,这个命令应该仅用在那些失败的设备上。
   如果你想将一个设备退役掉,那么最好的方式是将它的weight设置为0,待它将其上所有的数据都移走之后,再使用这个命令移除设备。
   remove操作不会重新分配partitions,只有运行了'rebalance'命令后才会进行分区的分配。因此,这种机制可以允许你一次添加删除个设备,并只执行一次rebalance实现对这些设备的分区分配。swift-ring-builder <builder_file> search <search-value>    Shows information about matching devices.
   显示匹配的设备的信息swift-ring-builder <builder_file> set_info    <search-value> <ip>:<port>/<device_name>_<meta>    [<search-value> <ip>:<port>/<device_name>_<meta>] ...    For each search-value, resets the matched device's information.    This information isn't used to assign partitions, so you can use    'write_ring' afterward to rewrite the current ring with the newer    device information. Any of the parts are optional in the final    <ip>:<port>/<device_name>_<meta> parameter; just give what you    want to change. For instance set_info d74 _"snet: 5.6.7.8" would    just update the meta data for device id 74.
   set_info命令会重新设置每一个与<search-value>相匹配的设备信息。这个信息不会用来重新分配分区,因此你可以使用'write_ring'来直接重写当前的ring。
   <ip>:<port>/<device_name>_<meta>参数的任意一个部分都是可选的,你只需要给出你需要更改的部分。
   比如,set_info d74 _"snet: 5.6.7.8"就仅仅会把id为74的设备的元数据更新为"snet: 5.6.7.8"swift-ring-builder <builder_file> set_min_part_hours <hours>    Changes the <min_part_hours> to the given <hours>. This should be set to    however long a full replication/update cycle takes. We're working on a way    to determine this more easily than scanning logs.
   set_min_part_hours命令将<min_part_hours>设置为参数给定的<hours>.
   这个时间应该被设置的至少满足一个完整的replication/update周期。我们正在努力找到一个方法可以比看日志更简单的决定这个时间swift-ring-builder <builder_file> set_weight <search-value> <weight>    [<search-value> <weight] ...    Resets the devices' weights. No partitions will be reassigned to or from    the device until after running 'rebalance'. This is so you can make    multiple device changes and rebalance them all just once.
   重新设置设备的weight。set_weight操作后,设备上的partition不会重新分配,只有运行了'rebalance'命令后才会进行分区的分配。
   因此,这种机制可以允许你一次添加多个设备,并只执行一次rebalance实现对这些设备的分区分配。 swift-ring-builder <builder_file> set_replicas <replicas>
    Changes the replica count to the given <replicas>. <replicas> may
    be a floating-point value, in which case some partitions will have
    floor(<replicas>) replicas and some will have ceiling(<replicas>)
    in the correct proportions.A rebalance is needed to make the change take effect.
    set_replicas命令用于使用参数中的<replicas>来设置副本数。
    <replicas>可以是一个浮点数,因此在一些场景中一些分区的副本数可能是floor(<replicas>),也可能是(<replicas>),这取决于正确的比例。
    需要执行一个rebalance命令来使副本设置生效。该命令是swift-1.8.0新增的。
swift-ring-builder <builder_file> validate    Just runs the validation routines on the ring.    仅运行builder的validate方法,使ring生效

swift-ring-builder <builder_file> write_ring    Just rewrites the distributable ring file. This is done automatically after    a successful rebalance, so really this is only useful after one or more    'set_info' calls when no rebalance is needed but you want to send out the    new device information.
   write_ring命令仅是用来重写分部环境下的ring文件。这个命令会在成功执行一个rebalance操作后呗自动执行。
   因此,它仅在你执行了一次或多次'set_info'命令,不想rebalance却想保留新信息时使用。2.使用curl工具访问swift
创建账户:
#curl -X PUT -I http://localhost:8080/v1.0/myaccount01
返回201 Created,表示正常。

创建容器
#curl -X PUT -I http://localhost:8080/v1.0/myaccount01/mycontainer01/
返回 201 Created,表示正常。

上传文件
#curl -X PUT -I -T yourfile http://localhost:8080/v1.0/myaccount01/mycontainer01/
返回 201 Created,表示正常。

查看容器中的文件:
#curl -D- http://localhost:8080/v1.0/myaccount01/mycontainer01

#curl -s http://localhost:8080/v1.0/myaccount01/mycontainer01/ -X GET

删除容器中的对象:
curl -s http://localhost:8080/v1.0/myaccount01/mycontainer01 -X DELETE

查看自己的文件存放的物理位置:
#swift-get-nodes /etc/swift/object.ring.gz myaccount01 mycontainer01 yourfile
根据返回结果,可以自己去验证文件的最终物理存储位置。

获取帐户的所有容器
curl -D- http://localhost:8080/v1.0/myaccount01  


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-21366-1-1.html 上篇帖子: OpenStack在登录时报“module' object has no attirbute 'Login'的解决 下篇帖子: Openstack Havana 单机安装 Object
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表