一、环境
-
python-2.7.5
-
centos-7.5
项目地址:https://github.com/iqiyi/auklet/blob/master/doc/tiny-swift/README.md
二、部署
1、创建用户
# useradd swift
# setenforce 0
2、依赖安装
# yum group install "Development Tools" -y
# yum install python-virtualenv memcached rsync libffi-devel openssl-devel python-devel libxslt-devel -y
3、虚拟环境
# 创建虚拟环境
# virtualenv /opt/openstack/swift-kilo
# 进入虚拟环境
# source /opt/openstack/swift-kilo/bin/activate
4、安装swift依赖
# yum -y install https://buildlogs.centos.org/centos/7/cloud/x86_64/openstack-rocky/liberasurecode-1.5.0-1.el7.x86_64.rpm
# yum -y install https://buildlogs.centos.org/centos/7/cloud/x86_64/openstack-rocky/liberasurecode-devel-1.5.0-1.el7.x86_64.rpm
5、安装swift
# pip install -i https://mirrors.aliyun.com/pypi/simple swift 内网环境建议
# pip install swift 外网建议
6、初始化存储空间
官方引入了两种类型存储设置
-
使用分区进行存储
-
使用环回设备进行存储
本次单机,顾采用第二种方法。
# mkdir -p /srv/node/{sdb,sdc,sdd,sde}
# mkdir -p /var/cache/swift
# mkdir -p /var/run/swift
# mkdir /srv/vdisks/
# truncate -s 10G /srv/vdisks/{sdb,sdc,sdd,sde}
# 格式化
# mkfs.xfs /srv/vdisks/{sdb,sdc,sdd,sde}
# mount /srv/vdisks/sdb /srv/node/sdb
相继挂载
# chown swift.swift -R /srv/node/sdb 类推
脚本
#!/bin/bash
mkdir -p /srv/vdisks
mkdir -p /var/cache/swift
mkdir -p /var/run/swift
chown swift.swift -R /var/cache/swift
chown swift.swift -R /var/run/swift
for disk in sdb sdc sdd sde
do
# Create disk images
truncate -s 10G /srv/vdisks/$disk
# Create file systems
mkfs.xfs /srv/vdisks/$disk
# Create mount points
mkdir -p /srv/node/$disk
echo "/srv/vdisks/$disk /srv/node/$disk xfs defaults 0 0" >> /etc/fstab
mount /srv/vdisks/$disk /srv/node/$disk
chown swift:swift -R /srv/node/$disk
done
7、配置文件
7.1、新建配置目录
# mkdir /etc/swift
7.2、swift.conf
[swift-hash]
swift_hash_path_prefix = changeme
swift_hash_path_suffix = emegnahc
[storage-policy:0]
default = yes
name = gold
policy_type = replication
[swift-constraints]
# Limit maximum object size to 5G
max_file_size = 5368709120
7.3、proxy-server.conf
[DEFAULT]
bind_port = 8080
bind_ip = 0.0.0.0
workers = 1
user = swift
[pipeline:main]
pipeline = catch_errors gatekeeper healthcheck proxy-logging cache tempurl slo dlo proxy-logging proxy-server
[app:proxy-server]
use = egg:swift#proxy
allow_account_management = no
account_autocreate = yes
object_post_as_copy = no
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:cache]
use = egg:swift#memcache
memcache_servers = 127.0.0.1:11211
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:tempurl]
use = egg:swift#tempurl
[filter:slo]
use = egg:swift#slo
[filter:dlo]
use = egg:swift#dlo
[filter:gatekeeper]
use = egg:swift#gatekeeper
7.4、account-server.conf
[DEFAULT]
bind_ip = 0.0.0.0
bind_port = 6002
workers = 1
user = swift
[pipeline:main]
pipeline = account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
[account-auditor]
[account-reaper]
7.5、container-server.conf
[DEFAULT]
bind_ip = 0.0.0.0
bind_port = 6001
workers = 1
mount_check = false
allow_versions = True
user = swift
[pipeline:main]
pipeline = container-server
[app:container-server]
use = egg:swift#container
[container-replicator]
[container-updater]
interval = 10
[container-auditor]
[container-sync]
[container-sharder]
7.6、container-reconciler.conf
[DEFAULT]
user = swift
[container-reconciler]
[pipeline:main]
pipeline = catch_errors proxy-logging cache proxy-server
[app:proxy-server]
use = egg:swift#proxy
[filter:cache]
use = egg:swift#memcache
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:catch_errors]
use = egg:swift#catch_errors
7.7、object-server.conf
[DEFAULT]
bind_ip = 0.0.0.0
bind_port = 6000
workers = 1
user = swift
[pipeline:main]
pipeline = object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
sync_method = ssync
[object-auditor]
log_level = DEBUG
concurrency = 4
interval = 30
files_per_second = 0
bytes_per_second = 0
[object-updater]
interval = 10
[object-auditor]
[object-reconstructor]
[object-expirer]
7.8、object-expirer.conf
[DEFAULT]
user = swift
[object-expirer]
# auto_create_account_prefix = .
[pipeline:main]
pipeline = catch_errors cache proxy-server
[app:proxy-server]
use = egg:swift#proxy
[filter:cache]
use = egg:swift#memcache
memcache_servers = 127.0.0.1:11211
[filter:catch_errors]
use = egg:swift#catch_errors
7.9、internal-client.conf
[DEFAULT]
[pipeline:main]
pipeline = catch_errors proxy-logging cache symlink proxy-server
[app:proxy-server]
use = egg:swift#proxy
account_autocreate = true
# See proxy-server.conf-sample for options
[filter:symlink]
use = egg:swift#symlink
# See proxy-server.conf-sample for options
[filter:cache]
use = egg:swift#memcache
# See proxy-server.conf-sample for options
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:catch_errors]
use = egg:swift#catch_errors
# See proxy-server.conf-sample for options
8、配置rsync
# egrep -v "^$|*#" /etc/rsyncd.conf
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[account]
max connections = 2
path = /srv/node
read only = false
lock file = /var/lock/account.lock
[container]
max connections = 4
path = /srv/node
read only = false
lock file = /var/lock/container.lock
[object]
max connections = 8
path = /srv/node
read only = false
lock file = /var/lock/object.lock
# 启动
# systemctl restart rsyncd
9、创建rings
#!/bin/bash
cd /etc/swift
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder object.builder create 8 3 1
swift-ring-builder object.builder add r1z1-127.0.0.1:6000/sdb 1
swift-ring-builder object.builder add r1z2-127.0.0.1:6000/sdc 1
swift-ring-builder object.builder add r1z3-127.0.0.1:6000/sdd 1
swift-ring-builder object.builder add r1z4-127.0.0.1:6000/sde 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 8 3 1
swift-ring-builder container.builder add r1z1-127.0.0.1:6001/sdb 1
swift-ring-builder container.builder add r1z2-127.0.0.1:6001/sdc 1
swift-ring-builder container.builder add r1z3-127.0.0.1:6001/sdd 1
swift-ring-builder container.builder add r1z4-127.0.0.1:6001/sde 1
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 8 3 1
swift-ring-builder account.builder add r1z1-127.0.0.1:6002/sdb 1
swift-ring-builder account.builder add r1z2-127.0.0.1:6002/sdc 1
swift-ring-builder account.builder add r1z3-127.0.0.1:6002/sdd 1
swift-ring-builder account.builder add r1z4-127.0.0.1:6002/sde 1
swift-ring-builder account.builder rebalance
10、启动
# swift-init start all
# swift-init status all
# 默认情况下所有日志都写入/var/log/messages
11、测试
# 创建 contaien
curl -v -X PUT http://127.0.0.1:8080/v1/iqiyi/auklet
#上传对象
curl -v -X PUT -H "Content-Type: text/plain" -d "Hello World" http://127.0.0.1:8080/v1/iqiyi/auklet/hi
网友评论