热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

OpenStackswiftSAIO安装指南

参考官方文档,及一些国内同行的博客我的装系统是分了个lvm,/dev/sda7注意:2.1~2.5必须以root身份进行操作2.1、安装依赖包apt-getinstallpython-software-propertiesadd-apt-repositoryppa:swift-core/ppaapt-getupdate
参考官方文档,及一些国内同行的博客
我的装系统是分了个lvm,/dev/sda7

注意:2.1~2.5必须以root身份进行操作
2.1、安装依赖包

apt-get install python-software-properties

add-apt-repository ppa:swift-core/ppa

apt-get update

apt-get install curl gcc bzr memcached python-configobj python-coverage python-dev python-nose python-setuptools python-simplejson python-xattr sqlite3 xfsprogs pythonwebob python-eventlet python-greenlet python-pastedeploy python-netifaces

2.2、创建swift用户

创建swift用户

sudo useradd -mk /home/swift -s /bin/bash swift

sudo password swift

编辑/etc/sudoers,添加以下一行

# User alias specification

swift   ALL=(ALL) NOPASSWD:ALL

Using a partition for storage

If you are going to use a separate partition for Swift data, be sure to add another device when creating the VM, and follow these instructions.

        mkfs.xfs -i size=1024 /dev/sda7

        Edit /etc/fstab and add

/dev/sda7 /mnt/sda7 xfs noatime,nodiratime,nobarrier,logbufs=8 0 0

        mkdir /mnt/sda7

        mount /mnt/sda7

        mkdir /mnt/sda7/1 /mnt/sda7/2 /mnt/sda7/3 /mnt/sda7/4

        chown swift:swift /mnt/sda7/*

        mkdir /srv

        for x in {1..4}; do ln -s /mnt/sda7/$x /srv/$x; done

        mkdir -p /etc/swift/object-server /etc/swift/container-server /etc/swift/account-server /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4 /var/run/swift

        chown -R swift:swift /etc/swift /srv/[1-4]/ /var/run/swift
    ? Make sure to include the trailing slash after /srv/[1-4]/

        Add to /etc/rc.local (before the exit 0):

        mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4
        chown swift:swift /var/cache/swift*
        mkdir -p /var/run/swift
        chown swift:swift /var/run/swift

设置rsync

创建文件:/etc/rsyncd.conf:

uid = swift

gid = swift

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

address = 127.0.0.1

[account6012]

max cOnnections= 25

path = /srv/1/node/

read Only= false

lock file = /var/lock/account6012.lock

[account6022]

max cOnnections= 25

path = /srv/2/node/

read Only= false

lock file = /var/lock/account6022.lock

[account6032]

max cOnnections= 25

path = /srv/3/node/

read Only= false

lock file = /var/lock/account6032.lock

[account6042]

max cOnnections= 25

path = /srv/4/node/

read Only= false

lock file = /var/lock/account6042.lock

[container6011]

max cOnnections= 25

path = /srv/1/node/

read Only= false

lock file = /var/lock/container6011.lock

[container6021]

max cOnnections= 25

path = /srv/2/node/

read Only= false

lock file = /var/lock/container6021.lock

[container6031]

max cOnnections= 25

path = /srv/3/node/

read Only= false

lock file = /var/lock/container6031.lock

[container6041]

max cOnnections= 25

path = /srv/4/node/

read Only= false

lock file = /var/lock/container6041.lock

[object6010]

max cOnnections= 25

path = /srv/1/node/

read Only= false

lock file = /var/lock/object6010.lock

[object6020]

max cOnnections= 25

path = /srv/2/node/

read Only= false

lock file = /var/lock/object6020.lock

[object6030]

max cOnnections= 25

path = /srv/3/node/

read Only= false

lock file = /var/lock/object6030.lock

[object6040]

max cOnnections= 25

path = /srv/4/node/

read Only= false

lock file = /var/lock/object6040.lock

编辑/etc/default/rsync:

RSYNC_ENABLE设置为true

重启服务:

service rsync restart

2.5、日志设置(可选)

编辑/etc/rsyslog.d/10-swift.conf:

# Uncomment the following to have a log containing all logs together

#local1,local2,local3,local4,local5.* /var/log/swift/all.log

# Uncomment the following to have hourly proxy logs for stats processing

#$template HourlyProxyLog,"/var/log/swift/hourly/%$YEAR%%$MONTH%%$DAY%%

$HOUR%"

#local1.*;local1.!notice ?HourlyProxyLog

local1.*;local1.!notice /var/log/swift/proxy.log

local1.notice /var/log/swift/proxy.error

local1.* ~

local2.*;local2.!notice /var/log/swift/storage1.log

local2.notice /var/log/swift/storage1.error

local2.* ~

local3.*;local3.!notice /var/log/swift/storage2.log

local3.notice /var/log/swift/storage2.error

local3.* ~

local4.*;local4.!notice /var/log/swift/storage3.log

local4.notice /var/log/swift/storage3.error

local4.* ~

local5.*;local5.!notice /var/log/swift/storage4.log

local5.notice /var/log/swift/storage4.error

local5.* ~

修改/etc/rsyslog.conf:

$PrivDropToGroup adm

mkdir -p /var/log/swift/hourly

chown -R syslog.adm /var/log/swift

service rsyslog restart

注意:2.6~2.9必须以swift身份进行操作

2.6、获取代码和设置测试环境

su - swift

mkdir ~/bin

        Check out the swift repo with
git clone https://github.com/openstack/swift.git

        Build a development installation of swift, for example:
 cd ~/swift; sudo python setup.py develop

        Check out the python-swiftclient repo with
 cd ~
 git clone https://github.com/openstack/python-swiftclient.git

        Build a development installation of python-swiftclient, for example:
cd ~/python-swiftclient; sudo python setup.py develop

        Edit ~/.bashrc and add to the end:

        export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf
        export PATH=${PATH}:~/bin

        . ~/.bashrc

编辑~/.bashrc,在最后加入:

export SWIFT_TEST_CONFIG_FILE=/etc/swift/func_test.conf

export PATH=${PATH}:~/bin

 
chmod a+x .bashrc
. ~/.bashrc

2.7、配置各个节点(以下这些文件不存在的话,就需要自己创建)

1)/etc/swift/proxy-server.conf

[DEFAULT]

bind_port = 8080

user = swift

log_facility = LOG_LOCAL1

[pipeline:main]

pipeline = healthcheck cache swauth proxy-server

[app:proxy-server]

use = egg:swift#proxy

allow_account_management = true

[filter:swauth]

use = egg:swift#swauth

# Highly recommended to change this.

super_admin_key = swauthkey

[filter:healthcheck]

use = egg:swift#healthcheck

[filter:cache]

use = egg:swift#memcache

2)/etc/swift/swift.conf

[swift-hash]

# random unique string that can never change (DO NOT LOSE)

swift_hash_path_suffix = 91d23be389715dab   //可以是任意的单字符串

3)/etc/swift/account-server/1.conf

[DEFAULT]

devices = /srv/1/node

mount_check = false

bind_port = 6012

user = swift

log_facility = LOG_LOCAL2

[pipeline:main]

pipeline = account-server

[app:account-server]

use = egg:swift#account

[account-replicator]

vm_test_mode = yes

[account-auditor]

[account-reaper]

4)/etc/swift/account-server/2.conf

[DEFAULT]

devices = /srv/2/node

mount_check = false

bind_port = 6022

user = swift

log_facility = LOG_LOCAL3

[pipeline:main]

pipeline = account-server

[app:account-server]

use = egg:swift#account

[account-replicator]

vm_test_mode = yes

[account-auditor]

[account-reaper]

5)/etc/swift/account-server/3.conf

[DEFAULT]

devices = /srv/3/node

mount_check = false

bind_port = 6032

user = swift

log_facility = LOG_LOCAL4

[pipeline:main]

pipeline = account-server

[app:account-server]

use = egg:swift#account

[account-replicator]

vm_test_mode = yes

[account-auditor]

[account-reaper]

6)/etc/swift/account-server/4.conf

[DEFAULT]

devices = /srv/4/node

mount_check = false

bind_port = 6042

user = swift

log_facility = LOG_LOCAL5

[pipeline:main]

pipeline = account-server

[app:account-server]

use = egg:swift#account

[account-replicator]

vm_test_mode = yes

[account-auditor]

[account-reaper]

 7)/etc/swift/container-server/1.conf

[DEFAULT]

devices = /srv/1/node

mount_check = false

bind_port = 6011

user = swift

log_facility = LOG_LOCAL2

[pipeline:main]

pipeline = container-server

[app:container-server]

use = egg:swift#container

[container-replicator]

vm_test_mode = yes

[container-updater]

[container-auditor]

[container-sync]

8)/etc/swift/container-server/2.conf

[DEFAULT]

devices = /srv/2/node

mount_check = false

bind_port = 6021

user = swift

log_facility = LOG_LOCAL3

[pipeline:main]

pipeline = container-server

[app:container-server]

use = egg:swift#container

[container-replicator]

vm_test_mode = yes

[container-updater]

[container-auditor]

[container-sync]

 9)/etc/swift/container-server/3.conf

[DEFAULT]

devices = /srv/3/node

mount_check = false

bind_port = 6031

user = swift

log_facility = LOG_LOCAL4

[pipeline:main]

pipeline = container-server

[app:container-server]

use = egg:swift#container

[container-replicator]

vm_test_mode = yes

[container-updater]

[container-auditor]

[container-sync]

10)/etc/swift/container-server/4.conf

[DEFAULT]

devices = /srv/4/node

mount_check = false

bind_port = 6041

user = swift

log_facility = LOG_LOCAL5

[pipeline:main]

pipeline = container-server

[app:container-server]

use = egg:swift#container

[container-replicator]

vm_test_mode = yes

[container-updater]

[container-auditor]

[container-sync]

11)/etc/swift/object-server/1.conf

[DEFAULT]

devices = /srv/1/node

mount_check = false

bind_port = 6010

user = swift

log_facility = LOG_LOCAL2

[pipeline:main]

pipeline = object-server

[app:object-server]

use = egg:swift#object

[object-replicator]

vm_test_mode = yes

[object-updater]

[object-auditor]

12)/etc/swift/object-server/2.conf

[DEFAULT]

devices = /srv/2/node

mount_check = false

bind_port = 6020

user = swift

log_facility = LOG_LOCAL3

[pipeline:main]

pipeline = object-server

[app:object-server]

use = egg:swift#object

[object-replicator]

vm_test_mode = yes

[object-updater]

[object-auditor]

 13)/etc/swift/object-server/3.conf

[DEFAULT]

devices = /srv/3/node

mount_check = false

bind_port = 6030

user = swift

log_facility = LOG_LOCAL4

[pipeline:main]

pipeline = object-server

[app:object-server]

use = egg:swift#object

[object-replicator]

vm_test_mode = yes

[object-updater]

[object-auditor]

14)/etc/swift/object-server/4.conf

[DEFAULT]

devices = /srv/4/node

mount_check = false

bind_port = 6040

user = swift

log_facility = LOG_LOCAL5

[pipeline:main]

pipeline = object-server

[app:object-server]

use = egg:swift#object

[object-replicator]

vm_test_mode = yes

[object-updater]

[object-auditor]

2.8、创建运行swift运行的脚本

1) ~/bin/resetswift

#!/bin/bash

swift-init all stop

sudo umount /mnt/sdb1

sudo mkfs.xfs -f -i size=1024 /srv/swift-disk

sudo mount /mnt/sdb1

sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4

sudo chown swift:swift /mnt/sdb1/*

mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4

sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog

sudo service rsyslog restart

sudo service memcached restart

2) ~/bin/remakerings

#!/bin/bash

cd /etc/swift

rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz

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

swift-ring-builder object.builder add z1-127.0.0.1:6010/sdb1 1

swift-ring-builder object.builder add z2-127.0.0.1:6020/sdb2 1

swift-ring-builder object.builder add z3-127.0.0.1:6030/sdb3 1

swift-ring-builder object.builder add z4-127.0.0.1:6040/sdb4 1

swift-ring-builder object.builder rebalance

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

swift-ring-builder container.builder add z1-127.0.0.1:6011/sdb1 1

swift-ring-builder container.builder add z2-127.0.0.1:6021/sdb2 1

swift-ring-builder container.builder add z3-127.0.0.1:6031/sdb3 1

swift-ring-builder container.builder add z4-127.0.0.1:6041/sdb4 1

swift-ring-builder container.builder rebalance

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

swift-ring-builder account.builder add z1-127.0.0.1:6012/sdb1 1

swift-ring-builder account.builder add z2-127.0.0.1:6022/sdb2 1

swift-ring-builder account.builder add z3-127.0.0.1:6032/sdb3 1

swift-ring-builder account.builder add z4-127.0.0.1:6042/sdb4 1

swift-ring-builder account.builder rebalance

 3) ~/bin/startmain

#!/bin/bash

swift-init main start

4) ~/bin/startrest
        #!/bin/bash

swift-init rest start

2.9、脚本测试

1)添加~/bin/*的执行权限

# chmod +x ~/bin/*

2)重新产生rings

# remakerings

输出以下信息:

Device z1-127.0.0.1:6010/sdb1_"" with 1.0 weight got id 0

Device z2-127.0.0.1:6020/sdb2_"" with 1.0 weight got id 1

Device z3-127.0.0.1:6030/sdb3_"" with 1.0 weight got id 2

Device z4-127.0.0.1:6040/sdb4_"" with 1.0 weight got id 3

Reassigned 262144 (100.00%) partitions. Balance is now 0.00.

……

3)单元测试

# cd ~/swift; ./.unittests

输出以下信息说明单元测试通过:

……

TOTAL                                   7622   5983    78%  

----------------------------------------------------------------------

Ran 632 tests in 40.013s

 OK (SKIP=8)

4)启动startmain
cd ~/bin
#startmain

#####################################################################
       运行startmain可能会报错,此网页可以解决 : https://answers.launchpad.net/swift/+question/162957
#####################################################################

 5)获取一个 X-Storage-Url 和 X-Auth-Token:

# curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0

 6)检查账户:

# curl -v -H 'X-Auth-Token:

 7)检查swift工作:

# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat

正确情况下,应该输出以下信息:

 Account: AUTH_test

 Containers: 0

 Objects: 0

 Bytes: 0

 Accept-Ranges: bytes

 8)# cp ~/swift/test/functional/sample.conf /etc/swift/func_test.conf

 9)功能测试

# cd ~/swift; ./.functests

正确情况下,输出类似于3)单元测试的结果。

 10)probe测试

# cd ~/swift; ./.probetests

该测试脚本会在每次测试前,调用resetswift脚本

三、上传/下载文件测试

3.1、获得test用户的Storage_Auth_Token和URL
       # curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0

得到以下回复信息:

* About to connect() to 127.0.0.1 port 8080 (#0)

*   Trying 127.0.0.1... connected

* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)

> GET /auth/v1.0 HTTP/1.1

> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15

> Host: 127.0.0.1:8080

> Accept: */*

> X-Storage-User: test:tester

> X-Storage-Pass: testing

* Connection #0 to host 127.0.0.1 left intact

Closing connection #0

3.2、创建container

创建一个名称为container_test的container(目录)

 # curl -X PUT -D -  -H "X-Auth_Token:AUTH_tk6474e5ee0cb04832b9d2a168e1a164d8" http://127.0.0.1:8080/v1/AUTH_test/container_test

//正确情况下,应该得到以下信息:

HTTP/1.1 201 Created

Content-Length: 18

Content-Type: text/html; charset=UTF-8

Date: Mon, 04 Jul 2011 01:39:38 GMT

查看test用户的container列表,发现只有一个目录:container_test:

# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list

container_test

3.3、上传Object(文件)

# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload container_test ./cvs/CVSROOT/config            //上传config文件到ljl1目录中

cvs/CVSROOT/config

# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list container_test   //查看container_tese目录内的信息

bin/startmain    

cvs/CVSROOT/config

3.4、下载Object(文件)

swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download  container_test

//将ljl1目录内的所有内容下载到目前所在目录

 
注意:如果上传文件的时候,有嵌套目录,则上传到swift上后,也是以嵌套目录的形式存在,下载后,会在当前目录创建一样的嵌套目录。

四、遇到的问题

1、上传文件失败,查看log文件,

 File "/usr/lib/pymodules/python2.6/xattr/__init__.py", line 81, in set#012    self._set(name, value, 0, options | self.options)#012  File "/usr/lib/pymodules/python2.6/xattr/__init__.py", line 16, in _func#012    return func(first, *args)#012IOError: [Errno 95] Operation not supported

出错原因:查看/srv/下面的文件,正确的显示信息应该如下所示:可是我的四个目录显示是没有链接信息的,删除这四个目录,1,2,3,4,重新进行软连接,并修改目录的属主即可

swift@alen:/srv$ ls -l

lrwxrwxrwx 1 swift swift         11 2011-07-04 15:13 1 -> /mnt/sdb1/1

lrwxrwxrwx 1 swift swift         11 2011-07-04 15:13 2 -> /mnt/sdb1/2

lrwxrwxrwx 1 swift swift         11 2011-07-04 15:13 3 -> /mnt/sdb1/3

lrwxrwxrwx 1 swift swift         11 2011-07-04 15:13 4 -> /mnt/sdb1/4

-rw-r--r-- 1 swift swift 1024000000 2011-07-04 15:50 swift-disk


推荐阅读
  • 当前,众多初创企业对全栈工程师的需求日益增长,但市场中却存在大量所谓的“伪全栈工程师”,尤其是那些仅掌握了Node.js技能的前端开发人员。本文旨在深入探讨全栈工程师在现代技术生态中的真实角色与价值,澄清对这一角色的误解,并强调真正的全栈工程师应具备全面的技术栈和综合解决问题的能力。 ... [详细]
  • 作为140字符的开创者,Twitter看似简单却异常复杂。其简洁之处在于仅用140个字符就能实现信息的高效传播,甚至在多次全球性事件中超越传统媒体的速度。然而,为了支持2亿用户的高效使用,其背后的技术架构和系统设计则极为复杂,涉及高并发处理、数据存储和实时传输等多个技术挑战。 ... [详细]
  • Jupyter Notebook多语言环境搭建指南
    本文详细介绍了如何在Linux环境下为Jupyter Notebook配置Python、Python3、R及Go四种编程语言的环境,包括必要的软件安装和配置步骤。 ... [详细]
  • HTML:  将文件拖拽到此区域 ... [详细]
  • 流处理中的计数挑战与解决方案
    本文探讨了在流处理中进行计数的各种技术和挑战,并基于作者在2016年圣何塞举行的Hadoop World大会上的演讲进行了深入分析。文章不仅介绍了传统批处理和Lambda架构的局限性,还详细探讨了流处理架构的优势及其在现代大数据应用中的重要作用。 ... [详细]
  • Bootstrap Paginator 分页插件详解与应用
    本文深入探讨了Bootstrap Paginator这款流行的JavaScript分页插件,提供了详细的使用指南和示例代码,旨在帮助开发者更好地理解和利用该工具进行高效的数据展示。 ... [详细]
  • 在现代前端开发中,组件化已成为不可或缺的技术,尤其在 React 和 Vue 生态中。然而,组件的管理和测试一直是开发者面临的挑战。本文将介绍如何使用 Storybook 来简化这一过程,提高开发效率。 ... [详细]
  • 实践指南:使用Express、Create React App与MongoDB搭建React开发环境
    本文详细介绍了如何利用Express、Create React App和MongoDB构建一个高效的React应用开发环境,旨在为开发者提供一套完整的解决方案,包括环境搭建、数据模拟及前后端交互。 ... [详细]
  • Spring Boot使用AJAX从数据库读取数据异步刷新前端表格
      近期项目需要是实现一个通过筛选选取所需数据刷新表格的功能,因为表格只占页面的一小部分,不希望整个也页面都随之刷新,所以首先想到了使用AJAX来实现。  以下介绍解决方法(请忽视 ... [详细]
  • 使用Echarts for Weixin 小程序实现中国地图及区域点击事件
    本文介绍了如何使用Echarts for Weixin在微信小程序中构建中国地图,并实现区域点击事件。包括效果展示、条件准备和逻辑实现的具体步骤。 ... [详细]
  • 本文介绍了GitHub上的一些Python开源项目,特别是IM(即时通讯)技术的应用。通过Sealtalk项目,探讨了如何利用开源SDK提升开发效率。 ... [详细]
  • 本文深入探讨了NoSQL数据库的四大主要类型:键值对存储、文档存储、列式存储和图数据库。NoSQL(Not Only SQL)是指一系列非关系型数据库系统,它们不依赖于固定模式的数据存储方式,能够灵活处理大规模、高并发的数据需求。键值对存储适用于简单的数据结构;文档存储支持复杂的数据对象;列式存储优化了大数据量的读写性能;而图数据库则擅长处理复杂的关系网络。每种类型的NoSQL数据库都有其独特的优势和应用场景,本文将详细分析它们的特点及应用实例。 ... [详细]
  • 本文详细介绍了如何利用 Bootstrap Table 实现数据展示与操作,包括数据加载、表格配置及前后端交互等关键步骤。 ... [详细]
  • 本文将详细介绍Mybatis Plus框架中@TableField注解的具体使用方法及其应用场景,帮助开发者更好地理解和利用这一强大工具进行高效的数据操作。 ... [详细]
  • JavaScript 实现图片文件转Base64编码的方法
    本文详细介绍了如何使用JavaScript将用户通过文件输入控件选择的图片文件转换为Base64编码字符串,适用于Web前端开发中图片上传前的预处理。 ... [详细]
author-avatar
shouhou1213_491
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有