openstack安装笔记 swift(四)

所有的安装都是yum
改配置
在keystone库中写service表
写endpoint表,作为api调用
有的建立个库

安装swift
yum install xfsprogs openstack-swift-proxy openstack-swift-object openstack-swift-container openstack-swift-account openstack-utils memcached

注释:实际生产环境的话,此处的VG最好和上面的cinder使用的VG不同。自己另外创建一个VG
准备一个单独的逻辑卷或者磁盘,假设逻辑卷是/dev/vgstorage/lvswift
[root@controller rhel65(keystone_admin)]# cd /dev/vgstorage/
[root@controller vgstorage(keystone_admin)]# ls
volume-d6e1529f-633c-4e86-ad45-fc61734b950e
[root@controller vgstorage(keystone_admin)]# lvcreate --size 5G --name lvswift vgstorage
  Logical volume "lvswift" created
[root@controller vgstorage(keystone_admin)]# ls
lvswift  volume-d6e1529f-633c-4e86-ad45-fc61734b950e

[root@controller vgstorage(keystone_admin)]# mkfs.xfs -f -i size=1024 /dev/vgstorage/lvswift
meta-data=/dev/vgstorage/lvswift isize=1024   agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@controller vgstorage(keystone_admin)]#


mkdir /mnt/sdb1
mount /dev/vgstorage/lvswift   /mnt/sdb1
vi /etc/fstab
加入 /dev/vgstorage/lvswift   /mnt/sdb1            xfs     defaults        0 0

mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
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 swift:swift /etc/swift/ /srv/ /var/run/swift/ /mnt/sdb1


keystone service-create --name swift --type object-store --description "Swift Storage Service hao"
WARNING: Bypassing authentication using a token & endpoint (authentication credentials are being ignored).
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |    Swift Storage Service hao     |
|      id     | dac813a9993c4743977a057c2f4b199e |
|     name    |              swift               |
|     type    |           object-store           |
+-------------+----------------------------------+
[root@controller srv(keystone_admin)]# 

# keystone endpoint-create --service swift  --publicurl "http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s" --adminurl "http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s"  --internalurl "http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s" --region beijing  
WARNING: Bypassing authentication using a token & endpoint (authentication credentials are being ignored).
+-------------+-------------------------------------------------+
|   Property  |                      Value                      |
+-------------+-------------------------------------------------+
|   adminurl  | http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s |
|      id     |         50cd09254c324fcc9ce04a4c16836007        |
| internalurl | http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s |
|  publicurl  | http://172.16.21.233:8080/v1/AUTH_%(tenant_id)s |
|    region   |                     beijing                     |
|  service_id |         dac813a9993c4743977a057c2f4b199e        |
+-------------+-------------------------------------------------+
[root@controller srv(keystone_admin)]# 


在keystone库的service表中加了一条数据
在endpoint表加了3条数据
---------------
设置rsync:
修改/etc/xinetd.d/rsync文件
disable = no
新建文件/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/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
重新启动rsyslog服务
mkdir -p /var/log/swift/hourly
chmod -R g+w /var/log/swift
service rsyslog restart
	•	备份一些配置文件
mkdir  /etc/swift/bak
mv  /etc/swift/account-server.conf   /etc/swift/bak
mv  /etc/swift/container-server.conf  /etc/swift/bak
mv  /etc/swift/object-expirer.conf  /etc/swift/bak
mv  /etc/swift/object-server.conf  /etc/swift/bak



开始修改swift配置文件:
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken admin_tenant_name admin
 openstack-config --set /etc/swift/proxy-server.conf   filter:authtoken admin_user admin
 openstack-config --set /etc/swift/proxy-server.conf   filter:authtoken admin_password openstack
openstack-config --set /etc/swift/proxy-server.conf  filter:authtoken auth_host 172.16.21.233
openstack-config --set /etc/swift/proxy-server.conf  filter:keystone operator_roles admin,SwiftOperator,Member

设置一个随机值
openstack-config --set /etc/swift/swift.conf swift-hash  swift_hash_path_suffix $(openssl rand -hex 10)


在/etc/swift/account-server目录下,新建四个配置文件1.conf,2.conf,3.conf,4.conf,这四个文件的内容如下:

[======account-server目录下的1.conf的内容==========
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6012
user = swift
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_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]

======account-server目录下的2.conf的内容=========
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6022
user = swift
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
eventlet_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]

======account-server目录下的3.conf的内容===========
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6032
user = swift
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_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]

======account-server目录下的4.conf的内容===========
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6042
user = swift
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_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]


-----------
在container-server目录下,新建四个文件1.conf,2.conf,3.conf,4.conf,四个文件的内容如下.
cd /etc/swift/container-server
======container-server目录下的1.conf的内容===========
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6011
user = swift
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_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]
======container-server目录下的2.conf的内容===========
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6021
user = swift
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
eventlet_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]

======container-server目录下的3.conf的内容===========
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6031
user = swift
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_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]

======container-server目录下的4.conf的内容===========
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6041
user = swift
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_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]

-----------------
在object-server目录下,新建四个文件1.conf,2.conf,3.conf,4.conf,
cd /etc/swift/object-server
======object-server目录下的1.conf的内容===========
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6010
user = swift
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_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]

======object-server目录下的2.conf的内容===========
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6020
user = swift
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
eventlet_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]

======object-server目录下的3.conf的内容===========
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6030
user = swift
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_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]

======object-server目录下的4.conf的内容===========
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6040
user = swift
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_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]

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

#!/bin/bash

cd /etc/swift

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

swift-ring-builder object.builder create 10 3 1                            haohao:????
swift-ring-builder object.builder add r1z1-172.16.21.233:6010/sdb1 1
swift-ring-builder object.builder add r1z2-172.16.21.233:6020/sdb2 1
swift-ring-builder object.builder add r1z3-172.16.21.233:6030/sdb3 1
swift-ring-builder object.builder add r1z4-172.16.21.233:6040/sdb4 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 10 3 1
swift-ring-builder container.builder add r1z1-172.16.21.233:6011/sdb1 1
swift-ring-builder container.builder add r1z2-172.16.21.233:6021/sdb2 1
swift-ring-builder container.builder add r1z3-172.16.21.233:6031/sdb3 1
swift-ring-builder container.builder add r1z4-172.16.21.233:6041/sdb4 1
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 10 3 1
swift-ring-builder account.builder add r1z1-172.16.21.233:6012/sdb1 1
swift-ring-builder account.builder add r1z2-172.16.21.233:6022/sdb2 1
swift-ring-builder account.builder add r1z3-172.16.21.233:6032/sdb3 1
swift-ring-builder account.builder add r1z4-172.16.21.233:6042/sdb4 1
swift-ring-builder account.builder rebalance


chmod 755 /root/remakering.sh
/root/remakering.sh
执行
[root@controller ~(keystone_admin)]# ./remakering.sh 
Device d0r1z1-172.16.21.233:6010R172.16.21.233:6010/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-172.16.21.233:6020R172.16.21.233:6020/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-172.16.21.233:6030R172.16.21.233:6030/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-172.16.21.233:6040R172.16.21.233:6040/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.
Device d0r1z1-172.16.21.233:6011R172.16.21.233:6011/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-172.16.21.233:6021R172.16.21.233:6021/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-172.16.21.233:6031R172.16.21.233:6031/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-172.16.21.233:6041R172.16.21.233:6041/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.
Device d0r1z1-172.16.21.233:6012R172.16.21.233:6012/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-172.16.21.233:6022R172.16.21.233:6022/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-172.16.21.233:6032R172.16.21.233:6032/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-172.16.21.233:6042R172.16.21.233:6042/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.
[root@controller ~(keystone_admin)]# 

----------------
权限
chown -R swift:swift /srv/
chown -R swift:swift /etc/swift
chown -R swift:swift /mnt/sdb1

启动
启动memcached
/etc/init.d/memcached start
chkconfig memcached on
• 启动swift (swift没有配置开机启动)
swift-init all start
开启swift的debug模式 (可选)
在proxy-server.conf 里的 [default]配置里面加上下面2行
log_facility = LOG_LOCAL1
log_level = DEBUG

启动后输出:
[root@controller ~(keystone_admin)]# swift-init all start
Starting container-updater...(/etc/swift/container-server/1.conf)
Starting container-updater...(/etc/swift/container-server/2.conf)
Starting container-updater...(/etc/swift/container-server/3.conf)
Starting container-updater...(/etc/swift/container-server/4.conf)
Starting account-auditor...(/etc/swift/account-server/1.conf)
Starting account-auditor...(/etc/swift/account-server/2.conf)
Starting account-auditor...(/etc/swift/account-server/3.conf)
Starting account-auditor...(/etc/swift/account-server/4.conf)
Starting object-replicator...(/etc/swift/object-server/1.conf)
Starting object-replicator...(/etc/swift/object-server/2.conf)
Starting object-replicator...(/etc/swift/object-server/3.conf)
Starting object-replicator...(/etc/swift/object-server/4.conf)
Starting proxy-server...(/etc/swift/proxy-server.conf)
Starting container-replicator...(/etc/swift/container-server/1.conf)
Starting container-replicator...(/etc/swift/container-server/2.conf)
Starting container-replicator...(/etc/swift/container-server/3.conf)
Starting container-replicator...(/etc/swift/container-server/4.conf)
Starting object-auditor...(/etc/swift/object-server/1.conf)
Starting object-auditor...(/etc/swift/object-server/2.conf)
Starting object-auditor...(/etc/swift/object-server/3.conf)
Starting object-auditor...(/etc/swift/object-server/4.conf)
Unable to locate config for object-expirer
Starting container-auditor...(/etc/swift/container-server/1.conf)
Starting container-auditor...(/etc/swift/container-server/2.conf)
Starting container-auditor...(/etc/swift/container-server/3.conf)
Starting container-auditor...(/etc/swift/container-server/4.conf)
Starting container-server...(/etc/swift/container-server/1.conf)
Starting container-server...(/etc/swift/container-server/2.conf)
Starting container-server...(/etc/swift/container-server/3.conf)
Starting container-server...(/etc/swift/container-server/4.conf)
Starting account-server...(/etc/swift/account-server/1.conf)
Starting account-server...(/etc/swift/account-server/2.conf)
Starting account-server...(/etc/swift/account-server/3.conf)
Starting account-server...(/etc/swift/account-server/4.conf)
Starting account-reaper...(/etc/swift/account-server/1.conf)
Starting account-reaper...(/etc/swift/account-server/2.conf)
Starting account-reaper...(/etc/swift/account-server/3.conf)
Starting account-reaper...(/etc/swift/account-server/4.conf)
Starting container-sync...(/etc/swift/container-server/1.conf)
Starting container-sync...(/etc/swift/container-server/2.conf)
Starting container-sync...(/etc/swift/container-server/3.conf)
Starting container-sync...(/etc/swift/container-server/4.conf)
Starting account-replicator...(/etc/swift/account-server/1.conf)
Starting account-replicator...(/etc/swift/account-server/2.conf)
Starting account-replicator...(/etc/swift/account-server/3.conf)
Starting account-replicator...(/etc/swift/account-server/4.conf)
Starting object-updater...(/etc/swift/object-server/1.conf)
Starting object-updater...(/etc/swift/object-server/2.conf)
Starting object-updater...(/etc/swift/object-server/3.conf)
Starting object-updater...(/etc/swift/object-server/4.conf)
Starting object-server...(/etc/swift/object-server/1.conf)
Starting object-server...(/etc/swift/object-server/2.conf)
Starting object-server...(/etc/swift/object-server/3.conf)
Starting object-server...(/etc/swift/object-server/4.conf)



测试
新建container
swift post haocontainer
上传文件
swift upload haocontainer a.txt
查询一级目录
swift list
查询haocontainer目录下面的文件
swift list haocontainer

[root@controller ~(keystone_admin)]# swift list haocontainer
a.txt
[root@controller ~(keystone_admin)]# swift list
haocontainer

你可能感兴趣的:(openstack)