分享

Ubuntu 12.04 OpenStack Swift单节点部署指导

pig2 发表于 2014-3-10 17:16:06 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 17535
本帖最后由 pig2 于 2014-3-10 17:46 编辑
Swift能单独使用吗?如何单独部署?

如何从git上获取python-swiftclient代码,下载到本地?
文件/etc/swift/swift.conf是如何配置的?

扩充:
Rsync的作用是什么?


已有(2)人评论

跳转到指定楼层
pig2 发表于 2014-3-10 17:45:54

部署环境
  • VMware Workstation 9 (推荐版本,低版本亦可,只要能安装Ubuntu 12.04)
  • Ubuntu 12.04 Server 32 bit
  • OpenStack Swift v1.8 (Grizzly)
说明
  • 此文档为基于官方修改的只针对Ubuntu 12.04,完整的参阅官方文档
  • 本部署为开发环境,Swift配置为以root权限运行,生产环境推荐新建用户swift
  • 选择Ubuntu 12.04因其默认内核为3.5,减少部署时的麻烦
  • Ubuntu Server安装时不选其它组件,最小化安装
  • 以下安装命令全部以root身份运行


Ubuntu 更改为国内源(非必需)
  1. sudo vi /etc/apt/sources.list
  2. %s/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g #修改前面一部分
  3. %s/security.ubuntu.com/mirrors.ustc.edu.cn/g #修改security的源地址
  4. sudo apt-get update
  5. sudo apt-get upgrade
复制代码
安装依赖
  1. apt-get update
  2. apt-get install curl gcc memcached rsync sqlite3 xfsprogs git python-setuptools
  3. apt-get install python-coverage python-dev python-nose python-simplejson python-xattr python-eventlet
  4. python-greenlet python-pastedeploy python-netifaces python-pip python-dnspython python-mock
复制代码
使用回环设备作为存储,若需要使用一个分区作为存储,参见官方文档
  1. mkdir /srv
  2. truncate -s 1GB /srv/swift-disk
  3. mkfs.xfs /srv/swift-disk
复制代码
修改/etc/fstab 添加如下行
  1. /srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0
复制代码
  1. mkdir /mnt/sdb1
  2. mount /mnt/sdb1
  3. mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
  4. chown root:root /mnt/sdb1/*
  5. for x in {1..4}; do ln -s /mnt/sdb1/$x /srv/$x; done
  6. mkdir -p /etc/swift/object-server /etc/swift/container-server /etc/swift/account-server
  7. mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4 /var/run/swift
  8. chown -R root:root /etc/swift /srv/[1-4]/ /var/run/swift
复制代码
编辑文件/etc/rc.local,在exit 0 之前添加如下4行:
  1. mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4
  2. chown <your-user-name>:<your-group-name> /var/cache/swift*
  3. mkdir -p /var/run/swift
  4. chown <your-user-name>:<your-group-name> /var/run/swift
复制代码
设置Rsync

创建文件/etc/rsyncd.conf:
  1. uid = root
  2. gid = root
  3. log file = /var/log/rsyncd.log
  4. pid file = /var/run/rsyncd.pid
  5. address = 127.0.0.1
  6. [account6012]
  7. max connections = 25
  8. path = /srv/1/node/
  9. read only = false
  10. lock file = /var/lock/account6012.lock
  11. [account6022]
  12. max connections = 25
  13. path = /srv/2/node/
  14. read only = false
  15. lock file = /var/lock/account6022.lock
  16. [account6032]
  17. max connections = 25
  18. path = /srv/3/node/
  19. read only = false
  20. lock file = /var/lock/account6032.lock
  21. [account6042]
  22. max connections = 25
  23. path = /srv/4/node/
  24. read only = false
  25. lock file = /var/lock/account6042.lock
  26. [container6011]
  27. max connections = 25
  28. path = /srv/1/node/
  29. read only = false
  30. lock file = /var/lock/container6011.lock
  31. [container6021]
  32. max connections = 25
  33. path = /srv/2/node/
  34. read only = false
  35. lock file = /var/lock/container6021.lock
  36. [container6031]
  37. max connections = 25
  38. path = /srv/3/node/
  39. read only = false
  40. lock file = /var/lock/container6031.lock
  41. [container6041]
  42. max connections = 25
  43. path = /srv/4/node/
  44. read only = false
  45. lock file = /var/lock/container6041.lock
  46. [object6010]
  47. max connections = 25
  48. path = /srv/1/node/
  49. read only = false
  50. lock file = /var/lock/object6010.lock
  51. [object6020]
  52. max connections = 25
  53. path = /srv/2/node/
  54. read only = false
  55. lock file = /var/lock/object6020.lock
  56. [object6030]
  57. max connections = 25
  58. path = /srv/3/node/
  59. read only = false
  60. lock file = /var/lock/object6030.lock
  61. [object6040]
  62. max connections = 25
  63. path = /srv/4/node/
  64. read only = false
  65. lock file = /var/lock/object6040.lock
复制代码
编辑文件/etc/default/rsync,设置参数RSYNC_ENABLE为true:
  1. RSYNC_ENABLE=true
复制代码
启动rsync服务
  1. service rsync restart
复制代码
确认rsync启动成功
  1. rsync rsync://pub@localhost/
复制代码
设置独立日志(非必需,略,见官方文档)

获取代码并设置测试环境

从git上获取swift代码,下载到本地
  1. git clone https://github.com/openstack/swift.git
复制代码
安装Swift的开发版本
  1. cd ~/swift
  2. git checkout -t origin/stable/grizzly # checkout稳定分支1.8
  3. python setup.py develop
  4. cd ..
复制代码
从git上获取python-swiftclient代码,下载到本地
  1. git clone https://github.com/openstack/python-swiftclient.git
复制代码
安装python-swiftclient的开发版本
  1. cd ~/python-swiftclient
  2. python setup.py develop
  3. cd ..
复制代码
配置各结点

创建文件/etc/swift/proxy-server.conf,
  1. [DEFAULT]
  2. bind_port = 8080
  3. user = root
  4. log_facility = LOG_LOCAL1
  5. eventlet_debug = true
  6. [pipeline:main]
  7. pipeline = healthcheck cache tempauth proxy-logging proxy-server
  8. [app:proxy-server]
  9. use = egg:swift#proxy
  10. allow_account_management = true
  11. account_autocreate = true
  12. [filter:tempauth]
  13. use = egg:swift#tempauth
  14. user_admin_admin = admin .admin .reseller_admin
  15. user_test_tester = testing .admin
  16. user_test2_tester2 = testing2 .admin
  17. user_test_tester3 = testing3
  18. [filter:healthcheck]
  19. use = egg:swift#healthcheck
  20. [filter:cache]
  21. use = egg:swift#memcache
  22. [filter:proxy-logging]
  23. use = egg:swift#proxy_logging
复制代码
创建文件/etc/swift/swift.conf,
  1. [swift-hash]
  2. # random unique strings that can never change (DO NOT LOSE)
  3. swift_hash_path_prefix = rui
  4. swift_hash_path_suffix = jie
复制代码
Create /etc/swift/account-server/1.conf:
  1. [DEFAULT]
  2. devices = /srv/1/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6012
  6. user = root
  7. log_facility = LOG_LOCAL2
  8. recon_cache_path = /var/cache/swift
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon account-server
  12. [app:account-server]
  13. use = egg:swift#account
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [account-replicator]
  17. vm_test_mode = yes
  18. [account-auditor]
  19. [account-reaper]
复制代码
Create /etc/swift/account-server/2.conf:
  1. [DEFAULT]
  2. devices = /srv/2/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6022
  6. user = root
  7. log_facility = LOG_LOCAL3
  8. recon_cache_path = /var/cache/swift2
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon account-server
  12. [app:account-server]
  13. use = egg:swift#account
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [account-replicator]
  17. vm_test_mode = yes
  18. [account-auditor]
  19. [account-reaper]
复制代码
Create /etc/swift/account-server/3.conf:
  1. [DEFAULT]
  2. devices = /srv/3/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6032
  6. user = root
  7. log_facility = LOG_LOCAL4
  8. recon_cache_path = /var/cache/swift3
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon account-server
  12. [app:account-server]
  13. use = egg:swift#account
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [account-replicator]
  17. vm_test_mode = yes
  18. [account-auditor]
  19. [account-reaper]
复制代码
Create /etc/swift/account-server/4.conf:
  1. [DEFAULT]
  2. devices = /srv/4/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6042
  6. user = root
  7. log_facility = LOG_LOCAL5
  8. recon_cache_path = /var/cache/swift4
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon account-server
  12. [app:account-server]
  13. use = egg:swift#account
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [account-replicator]
  17. vm_test_mode = yes
  18. [account-auditor]
  19. [account-reaper]
复制代码
Create /etc/swift/container-server/1.conf:
  1. [DEFAULT]
  2. devices = /srv/1/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6011
  6. user = root
  7. log_facility = LOG_LOCAL2
  8. recon_cache_path = /var/cache/swift
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon container-server
  12. [app:container-server]
  13. use = egg:swift#container
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [container-replicator]
  17. vm_test_mode = yes
  18. [container-updater]
  19. [container-auditor]
  20. [container-sync]
复制代码
Create /etc/swift/container-server/2.conf:
  1. [DEFAULT]
  2. devices = /srv/2/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6021
  6. user = root
  7. log_facility = LOG_LOCAL3
  8. recon_cache_path = /var/cache/swift2
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon container-server
  12. [app:container-server]
  13. use = egg:swift#container
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [container-replicator]
  17. vm_test_mode = yes
  18. [container-updater]
  19. [container-auditor]
  20. [container-sync]
复制代码
Create /etc/swift/container-server/3.conf:
  1. [DEFAULT]
  2. devices = /srv/3/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6031
  6. user = root
  7. log_facility = LOG_LOCAL4
  8. recon_cache_path = /var/cache/swift3
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon container-server
  12. [app:container-server]
  13. use = egg:swift#container
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [container-replicator]
  17. vm_test_mode = yes
  18. [container-updater]
  19. [container-auditor]
  20. [container-sync]
复制代码
Create /etc/swift/container-server/4.conf:
  1. [DEFAULT]
  2. devices = /srv/4/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6041
  6. user = root
  7. log_facility = LOG_LOCAL5
  8. recon_cache_path = /var/cache/swift4
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon container-server
  12. [app:container-server]
  13. use = egg:swift#container
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [container-replicator]
  17. vm_test_mode = yes
  18. [container-updater]
  19. [container-auditor]
  20. [container-sync]
复制代码
Create /etc/swift/object-server/1.conf:
  1. [DEFAULT]
  2. devices = /srv/1/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6010
  6. user = root
  7. log_facility = LOG_LOCAL2
  8. recon_cache_path = /var/cache/swift
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon object-server
  12. [app:object-server]
  13. use = egg:swift#object
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [object-replicator]
  17. vm_test_mode = yes
  18. [object-updater]
  19. [object-auditor]
复制代码
Create /etc/swift/object-server/2.conf:
  1. [DEFAULT]
  2. devices = /srv/2/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6020
  6. user = root
  7. log_facility = LOG_LOCAL3
  8. recon_cache_path = /var/cache/swift2
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon object-server
  12. [app:object-server]
  13. use = egg:swift#object
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [object-replicator]
  17. vm_test_mode = yes
  18. [object-updater]
  19. [object-auditor]
复制代码
Create /etc/swift/object-server/3.conf:
  1. [DEFAULT]
  2. devices = /srv/3/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6030
  6. user = root
  7. log_facility = LOG_LOCAL4
  8. recon_cache_path = /var/cache/swift3
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon object-server
  12. [app:object-server]
  13. use = egg:swift#object
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [object-replicator]
  17. vm_test_mode = yes
  18. [object-updater]
  19. [object-auditor]
复制代码
Create /etc/swift/object-server/4.conf:
  1. [DEFAULT]
  2. devices = /srv/4/node
  3. mount_check = false
  4. disable_fallocate = true
  5. bind_port = 6040
  6. user = root
  7. log_facility = LOG_LOCAL5
  8. recon_cache_path = /var/cache/swift4
  9. eventlet_debug = true
  10. [pipeline:main]
  11. pipeline = recon object-server
  12. [app:object-server]
  13. use = egg:swift#object
  14. [filter:recon]
  15. use = egg:swift#recon
  16. [object-replicator]
  17. vm_test_mode = yes
  18. [object-updater]
  19. [object-auditor]
复制代码
创建Swift运行脚本
  1. mkdir ~/bin
复制代码
创建脚本~/bin/resetswift

因未创建rsyslog作为独立日志,已移除find /var/log/swift…这一行
如果使用的是单独分区存储需要将/srv/swift-disk替换为/dev/sdb1
  1. #!/bin/bash
  2. swift-init all stop
  3. sudo umount /mnt/sdb1
  4. sudo mkfs.xfs -f /srv/swift-disk
  5. sudo mount /mnt/sdb1
  6. sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
  7. sudo chown root:root /mnt/sdb1/*
  8. mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4
  9. sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog
  10. find /var/cache/swift* -type f -name *.recon -exec rm -f {} \;
  11. sudo service rsyslog restart
  12. sudo service memcached restart
复制代码
创建脚本~/bin/remakerings
  1. #!/bin/bash
  2. cd /etc/swift
  3. rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
  4. swift-ring-builder object.builder create 10 3 1
  5. swift-ring-builder object.builder add r1z1-127.0.0.1:6010/sdb1 1
  6. swift-ring-builder object.builder add r1z2-127.0.0.1:6020/sdb2 1
  7. swift-ring-builder object.builder add r1z3-127.0.0.1:6030/sdb3 1
  8. swift-ring-builder object.builder add r1z4-127.0.0.1:6040/sdb4 1
  9. swift-ring-builder object.builder rebalance
  10. swift-ring-builder container.builder create 10 3 1
  11. swift-ring-builder container.builder add r1z1-127.0.0.1:6011/sdb1 1
  12. swift-ring-builder container.builder add r1z2-127.0.0.1:6021/sdb2 1
  13. swift-ring-builder container.builder add r1z3-127.0.0.1:6031/sdb3 1
  14. swift-ring-builder container.builder add r1z4-127.0.0.1:6041/sdb4 1
  15. swift-ring-builder container.builder rebalance
  16. swift-ring-builder account.builder create 10 3 1
  17. swift-ring-builder account.builder add r1z1-127.0.0.1:6012/sdb1 1
  18. swift-ring-builder account.builder add r1z2-127.0.0.1:6022/sdb2 1
  19. swift-ring-builder account.builder add r1z3-127.0.0.1:6032/sdb3 1
  20. swift-ring-builder account.builder add r1z4-127.0.0.1:6042/sdb4 1
  21. swift-ring-builder account.builder rebalance
复制代码
创建~/bin/startmain
  1. #!/bin/bash
  2. swift-init main start
复制代码
创建~/bin/startrest
  1. #!/bin/bash
  2. swift-init rest start
复制代码
  1. chmod +x ~/bin/*
复制代码
编辑~/.bashrc,在最后添加如下两行
  1. export PATH=${PATH}:~/bin
  2. <!-- lang: shell -->
  3. . ~/.bashrc
  4. remakerings
  5. cp ~/swift/test/sample.conf /etc/swift/test.conf
复制代码
开启Swift
  1. startmain
复制代码
检查Swift工作
  1. swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat
复制代码
正确情况下,应该输出以下信息
  1. Account: AUTH_test
  2. Containers: 0
  3. Objects: 0
  4. Bytes: 0
  5. Accept-Ranges: bytes
复制代码
重启main服务
  1. swift-init main restart
复制代码
swift-init

swift-init命令有许多参数,具体查看帮助



回复

使用道具 举报

CoderDream 发表于 2015-1-25 22:59:54
感谢分享!

请问“<your-user-name>:<your-group-name>”这两个属性值如何设置?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条