利用虚拟机安装swift

来源:互联网 发布:清空文件夹内容 linux 编辑:程序博客网 时间:2024/06/11 14:35

看了openstack的部署后开始就专注它的对象存储这一块了,也就是上面我介绍的swift-,http://blog.csdn.net/u010263670/article/details/9195831

里面详细讲解了swift的工作原理和实施环境,今天也给大家一个巨大的消息了,那就是swiftstack介绍的Erasure code算法,给swift的优化更近一步,在我看来,swiftstack是个商业化的对象存储公司,他利用开源的swift tool,进行很好的改进,变成人们需要的商业化的存储,可以让swift稳点安全,持久。

不对废话了,下面就开始对swift安装在虚拟机进行部署吧,下面应对的虚拟机是ubuntu12.04 lts版本,如果要安装在其他的linux下,请参考以下地址:https://wiki.openstack.org/wiki/SAIOInstructions

部署前期要求:

  • 虚拟机控制平台:vmware Fusion(因为本人是利用MAC)
  • 虚拟机系统:Ubuntu server 12.04 lts(据说这个版本是ubuntu长期维护,加上是server版本,对什么cup优化的不错)下载地址:http://www.ubuntu.com/download/server

安装核心代码和依赖包:

  • 一开始最好进入ROOT用户,开始ubuntu是默认没开启root用户的
    • #sudo passwd root            设置root密码
    • #su root                             进入root权限
  • 安装依赖包:
    • #apt-get update
    • #apt-get install curl gcc memcached rsync sqlite3 xfsprogs git-core python-setuptools
    • #apt-get install python-coverage python-dev python-nose python-simplejsonpython-xattr python-eventlet python-greenlet python-pastedeploypython-netifaces python-pip python-dnspython python-mock
  • 安装其他需要的安装包:
    • 例如:SSH,vim,screen,etc等,看个人需求
  • 接下来是分区的问题,这里建议你利用vmware软件对虚拟机分配一个新的虚拟硬盘。

利用一个partition(逻辑卷)作为一个新的分区:

  • #fdisk /dev/sdb (set up a single partition)            建立一个饿逻辑卷

  • #mkfs.xfs /dev/sdb1                                             对逻辑卷进行格式化

  • Edit /etc/fstab and add                                         在文件里加入以下这一行,指定你mount的磁盘

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

  • #mkdir /mnt/sdb1

  • #mount /mnt/sdb1

  • #mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4

  • #chown <your-user-name>:<your-group-name> /mnt/sdb1/*

  • #mkdir /srv

  • #for x in {1..4}; do ln -s /mnt/sdb1/$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 <your-user-name>:<your-group-name> /etc/swift /srv/[1-4]/ /var/run/swiftMake sure to include the trailing slash after /srv/[1-4]/

  • 加入以下配置到/etc/rc.local(注意:exit 0后加入):
  • mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4chown <your-user-name>:<your-group-name> /var/cache/swift*mkdir -p /var/run/swiftchown <your-user-name>:<your-group-name> /var/run/swift
  • 最后同步下,同步过程在下面。
在已有的分区建立对象分区区域:

  • mkdir /srv

  • truncate -s 1GB /srv/swift-disk

    (modify size to make a larger or smaller partition)

  • mkfs.xfs /srv/swift-disk

  • Edit /etc/fstab and add

    /srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0

  • mkdir /mnt/sdb1

  • mount /mnt/sdb1

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

  • chown <your-user-name>:<your-group-name> /mnt/sdb1/*

  • for x in {1..4}; do ln -s /mnt/sdb1/$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 <your-user-name>:<your-group-name> /etc/swift /srv/[1-4]/ /var/run/swiftMake sure to include the trailing slash after /srv/[1-4]/

  • 加入以下配置到/etc/rc.local(注意:exit 0后加入):
  • mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4chown <your-user-name>:<your-group-name> /var/cache/swift*mkdir -p /var/run/swiftchown <your-user-name>:<your-group-name> /var/run/swift

其实步骤和上面的差不多,只是一个是在已经有的分区上建立分区,上面的是后来建立一个分区做的事。

配置同步数据:

  • 创建一个配置文件/etc/rsyncd.conf:
  • uid = <your-user-name>gid = <your-group-name>log file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidaddress = 127.0.0.1[account6012]max connections = 25path = /srv/1/node/read only = falselock file = /var/lock/account6012.lock[account6022]max connections = 25path = /srv/2/node/read only = falselock file = /var/lock/account6022.lock[account6032]max connections = 25path = /srv/3/node/read only = falselock file = /var/lock/account6032.lock[account6042]max connections = 25path = /srv/4/node/read only = falselock file = /var/lock/account6042.lock[container6011]max connections = 25path = /srv/1/node/read only = falselock file = /var/lock/container6011.lock[container6021]max connections = 25path = /srv/2/node/read only = falselock file = /var/lock/container6021.lock[container6031]max connections = 25path = /srv/3/node/read only = falselock file = /var/lock/container6031.lock[container6041]max connections = 25path = /srv/4/node/read only = falselock file = /var/lock/container6041.lock[object6010]max connections = 25path = /srv/1/node/read only = falselock file = /var/lock/object6010.lock[object6020]max connections = 25path = /srv/2/node/read only = falselock file = /var/lock/object6020.lock[object6030]max connections = 25path = /srv/3/node/read only = falselock file = /var/lock/object6030.lock[object6040]max connections = 25path = /srv/4/node/read only = falselock file = /var/lock/object6040.lock
  • 更改同步属性 /etc/default/rsync: 
    RSYNC_ENABLE=true
  • 下面就开启rsync服务:

            service rsync restart

配置memcached和启动memcached:

  • service memcached start
  • chkconfig memcached on

以下是个可选项用于同步信息到日志文件上:

  • 创建:/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 ?HourlyProxyLoglocal1.*;local1.!notice /var/log/swift/proxy.loglocal1.notice           /var/log/swift/proxy.errorlocal1.*                ~local2.*;local2.!notice /var/log/swift/storage1.loglocal2.notice           /var/log/swift/storage1.errorlocal2.*                ~local3.*;local3.!notice /var/log/swift/storage2.loglocal3.notice           /var/log/swift/storage2.errorlocal3.*                ~local4.*;local4.!notice /var/log/swift/storage3.loglocal4.notice           /var/log/swift/storage3.errorlocal4.*                ~local5.*;local5.!notice /var/log/swift/storage4.loglocal5.notice           /var/log/swift/storage4.errorlocal5.*                ~
  • 配置文件 /etc/rsyslog.conf和更改属性:
    $PrivDropToGroup adm
  • mkdir -p /var/log/swift/hourly
  • chown -R syslog.adm /var/log/swift
  • chmod -R g+w /var/log/swift
  • service rsyslog restart

下面获取swift的代码和测试环境:

配置文件的示例如下,并含有注释

以下配置不需要root权限,通常使用的用户权限即可。bzr的配置不是必须的,无论你是否有launchpad的账号,都可以使用bzr branch 命令:

  • mkdir ~/bin

  • (可选) mkdir ~/.bazaar

  • (可选) 创建 ~/.bazaar/bazaar.conf 并在尾行插入

  • [DEFAULT] email = Your Name <your-email-address>

  • (可选) 如果你需要使用lauchpad账户,获得源代码并做修改,则使用如下命令:bzr launchpad-login <launchpad_id>

  • 创建swift代码仓库 bzr init-repo swift

  • bzr同步出最新的代码,例如:cd ~/swift; bzr branch lp:swift trunk

  • 以开发的方式安装swift,例如 :cd ~/swift/trunk; sudo python setup.py develop

  • 编辑 ~/.bashrc 并在尾行插入:

  • export SWIFT_TEST_CONFIG_FILE=/etc/swift/func_test.confexport PATH=${PATH}:~/bin

  • . ~/.bashrc

接下来就是配置各个节点了(node):
  • 创建 /etc/swift/proxy-server.conf
  • [DEFAULT]bind_port = 8080user = <your-user-name>log_facility = LOG_LOCAL1eventlet_debug = true[pipeline:main]pipeline = healthcheck cache tempauth proxy-logging proxy-server[app:proxy-server]use = egg:swift#proxyallow_account_management = trueaccount_autocreate = true[filter:tempauth]use = egg:swift#tempauthuser_admin_admin = admin .admin .reseller_adminuser_test_tester = testing .adminuser_test2_tester2 = testing2 .adminuser_test_tester3 = testing3[filter:healthcheck]use = egg:swift#healthcheck[filter:cache]use = egg:swift#memcache[filter:proxy-logging]use = egg:swift#proxy_logging
  • 创建 /etc/swift/swift.conf:
  • [swift-hash]# random unique strings that can never change (DO NOT LOSE)swift_hash_path_prefix = changemeswift_hash_path_suffix = changeme
  • 创建 /etc/swift/account-server/1.conf:
  • [DEFAULT]devices = /srv/1/nodemount_check = falsedisable_fallocate = truebind_port = 6012user = <your-user-name>log_facility = LOG_LOCAL2recon_cache_path = /var/cache/swifteventlet_debug = true[pipeline:main]pipeline = recon account-server[app:account-server]use = egg:swift#account[filter:recon]use = egg:swift#recon[account-replicator]vm_test_mode = yes[account-auditor][account-reaper]
  • 创建 /etc/swift/account-server/2.conf:
  • [DEFAULT]devices = /srv/2/nodemount_check = falsedisable_fallocate = truebind_port = 6022user = <your-user-name>log_facility = LOG_LOCAL3recon_cache_path = /var/cache/swift2eventlet_debug = true[pipeline:main]pipeline = recon account-server[app:account-server]use = egg:swift#account[filter:recon]use = egg:swift#recon[account-replicator]vm_test_mode = yes[account-auditor][account-reaper]
  • 创建 /etc/swift/account-server/3.conf:
  • [DEFAULT]devices = /srv/3/nodemount_check = falsedisable_fallocate = truebind_port = 6032user = <your-user-name>log_facility = LOG_LOCAL4recon_cache_path = /var/cache/swift3eventlet_debug = true[pipeline:main]pipeline = recon account-server[app:account-server]use = egg:swift#account[filter:recon]use = egg:swift#recon[account-replicator]vm_test_mode = yes[account-auditor][account-reaper]
  • 创建 /etc/swift/account-server/4.conf:
  • [DEFAULT]devices = /srv/4/nodemount_check = falsedisable_fallocate = truebind_port = 6042user = <your-user-name>log_facility = LOG_LOCAL5recon_cache_path = /var/cache/swift4eventlet_debug = true[pipeline:main]pipeline = recon account-server[app:account-server]use = egg:swift#account[filter:recon]use = egg:swift#recon[account-replicator]vm_test_mode = yes[account-auditor][account-reaper]
  • 创建 /etc/swift/container-server/1.conf:
  • [DEFAULT]devices = /srv/1/nodemount_check = falsedisable_fallocate = truebind_port = 6011user = <your-user-name>log_facility = LOG_LOCAL2recon_cache_path = /var/cache/swifteventlet_debug = true[pipeline:main]pipeline = recon container-server[app:container-server]use = egg:swift#container[filter:recon]use = egg:swift#recon[container-replicator]vm_test_mode = yes[container-updater][container-auditor][container-sync]
  • 创建 /etc/swift/container-server/2.conf::
  • [DEFAULT]devices = /srv/2/nodemount_check = falsedisable_fallocate = truebind_port = 6021user = <your-user-name>log_facility = LOG_LOCAL3recon_cache_path = /var/cache/swift2eventlet_debug = true[pipeline:main]pipeline = recon container-server[app:container-server]use = egg:swift#container[filter:recon]use = egg:swift#recon[container-replicator]vm_test_mode = yes[container-updater][container-auditor][container-sync]
  • 创建 /etc/swift/container-server/3.conf:
  • [DEFAULT]devices = /srv/3/nodemount_check = falsedisable_fallocate = truebind_port = 6031user = <your-user-name>log_facility = LOG_LOCAL4recon_cache_path = /var/cache/swift3eventlet_debug = true[pipeline:main]pipeline = recon container-server[app:container-server]use = egg:swift#container[filter:recon]use = egg:swift#recon[container-replicator]vm_test_mode = yes[container-updater][container-auditor][container-sync]
  • 创建 /etc/swift/container-server/4.conf:
  • [DEFAULT]devices = /srv/4/nodemount_check = falsedisable_fallocate = truebind_port = 6041user = <your-user-name>log_facility = LOG_LOCAL5recon_cache_path = /var/cache/swift4eventlet_debug = true[pipeline:main]pipeline = recon container-server[app:container-server]use = egg:swift#container[filter:recon]use = egg:swift#recon[container-replicator]vm_test_mode = yes[container-updater][container-auditor][container-sync]
  • 创建/etc/swift/object-server/1.conf:
  • [DEFAULT]devices = /srv/1/nodemount_check = falsedisable_fallocate = truebind_port = 6010user = <your-user-name>log_facility = LOG_LOCAL2recon_cache_path = /var/cache/swifteventlet_debug = true[pipeline:main]pipeline = recon object-server[app:object-server]use = egg:swift#object[filter:recon]use = egg:swift#recon[object-replicator]vm_test_mode = yes[object-updater][object-auditor]
  • 创建 /etc/swift/object-server/2.conf:
  • [DEFAULT]devices = /srv/2/nodemount_check = falsedisable_fallocate = truebind_port = 6020user = <your-user-name>log_facility = LOG_LOCAL3recon_cache_path = /var/cache/swift2eventlet_debug = true[pipeline:main]pipeline = recon object-server[app:object-server]use = egg:swift#object[filter:recon]use = egg:swift#recon[object-replicator]vm_test_mode = yes[object-updater][object-auditor]
  • 创建 /etc/swift/object-server/3.conf:
  • [DEFAULT]devices = /srv/3/nodemount_check = falsedisable_fallocate = truebind_port = 6030user = <your-user-name>log_facility = LOG_LOCAL4recon_cache_path = /var/cache/swift3eventlet_debug = true[pipeline:main]pipeline = recon object-server[app:object-server]use = egg:swift#object[filter:recon]use = egg:swift#recon[object-replicator]vm_test_mode = yes[object-updater][object-auditor]
  • 创建 /etc/swift/object-server/4.conf:
  • [DEFAULT]devices = /srv/4/nodemount_check = falsedisable_fallocate = truebind_port = 6040user = <your-user-name>log_facility = LOG_LOCAL5recon_cache_path = /var/cache/swift4eventlet_debug = true[pipeline:main]pipeline = recon object-server[app:object-server]use = egg:swift#object[filter:recon]use = egg:swift#recon[object-replicator]vm_test_mode = yes[object-updater][object-auditor]
  • 更新你的用户:<youre - user - name>
  • find /etc/swift/ -name \*.conf | xargs sed -i "s/<your-user-name>/${USER}/"

写一个脚本运行swift:

  • mkdir ~/bin
  • 创建 ~/bin/resetswift
  • 如果选择了“在已有的分区上建立存储分区”,那么如下脚本中,`/dev/sdb1` 需替换成 /srv/swift-disk.

    如果没有选择“按照个人需要设置 rsyslog ,生成特有的日志文件”, 请注释掉 find /var/log/swift... 这一行:

  • #!/bin/bashswift-init all stopfind /var/log/swift -type f -exec rm -f {} \;sudo umount /mnt/sdb1sudo mkfs.xfs -f /dev/sdb1sudo mount /mnt/sdb1sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4sudo chown <your-user-name>:<your-group-name> /mnt/sdb1/*mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslogfind /var/cache/swift* -type f -name *.recon -exec rm -f {} \;sudo service rsyslog restartsudo service memcached restart
  • 创建 ~/bin/remakerings
  • #!/bin/bashcd /etc/swiftrm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gzswift-ring-builder object.builder create 10 3 1swift-ring-builder object.builder add r1z1-127.0.0.1:6010/sdb1 1swift-ring-builder object.builder add r1z2-127.0.0.1:6020/sdb2 1swift-ring-builder object.builder add r1z3-127.0.0.1:6030/sdb3 1swift-ring-builder object.builder add r1z4-127.0.0.1:6040/sdb4 1swift-ring-builder object.builder rebalanceswift-ring-builder container.builder create 10 3 1swift-ring-builder container.builder add r1z1-127.0.0.1:6011/sdb1 1swift-ring-builder container.builder add r1z2-127.0.0.1:6021/sdb2 1swift-ring-builder container.builder add r1z3-127.0.0.1:6031/sdb3 1swift-ring-builder container.builder add r1z4-127.0.0.1:6041/sdb4 1swift-ring-builder container.builder rebalanceswift-ring-builder account.builder create 10 3 1swift-ring-builder account.builder add r1z1-127.0.0.1:6012/sdb1 1swift-ring-builder account.builder add r1z2-127.0.0.1:6022/sdb2 1swift-ring-builder account.builder add r1z3-127.0.0.1:6032/sdb3 1swift-ring-builder account.builder add r1z4-127.0.0.1:6042/sdb4 1swift-ring-builder account.builder rebalance
  • 创建 ~/bin/startmain:
  • #!/bin/bashswift-init main start
  • 创建 ~/bin/startrest:
  • #!/bin/bashswift-init rest start
  • chmod +x ~/bin/*
  • 编辑 ~/.bashrc和加入带最后一行:
  • export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.confexport PATH=${PATH}:~/bin
  • . ~/.bashrc
  • remakerings
  • cp ~/swift/test/sample.conf /etc/swift/test.conf
  • ~/swift/.unittests
  • startmain (警告 Unable to increase file descriptor limit.  Running as non-root? 是正常的)
  • recreateaccounts
  • 使用curl获得 X-Storage-UrlX-Auth-Token: curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0
  • 检测一下是否可以 GET 到 account: curl -v -H 'X-Auth-Token: <上条命令的X-Auth-Token返回结果>' <上条命令的X-Storage-Url返回结果>
  • 检测一下 swift 命令是否工作正常: swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat
  • cp ~/swift/trunk/test/functional/sample.conf /etc/swift/func_test.conf
  • cd ~/swift/trunk; ./.functests (注意: 功能测试会删除先前配置的任何account信息!)
  • cd ~/swift/trunk; ./.probetests (注意: probe 测试会重设你的swift环境,因为调用了 resetswift 。)

现在在虚拟机搭建的化境就算完成了,之后如果在启动或者别的服务没有启动,都可以去看/var/log/syslog,这里会记录你启动服务时的日志信息,如果有问题,其实就可以手动启动服务,一般也就是上面说的service XXX restart。

谢谢大家认真看完我的博客,希望以后有什么不懂的,或者配置上不对的问题,都可以发邮箱或者留言给我,大家互相帮忙,互相进步。(最后声明下,本人也是个屌丝,也是希望走上自己的未来轨道的一个小孩。嘻嘻)



小白邮箱:baijunhong888@foxmail.com

原创粉丝点击