设为首页 收藏本站
云服务器等爆品抢先购,低至4.2元/月
查看: 924|回复: 0

[经验分享] 云主机Swif

[复制链接]

尚未签到

发表于 2015-7-14 15:50:30 | 显示全部楼层 |阅读模式
“云主机Swift”是5月12日在线测试题中 任务三、IaaS 运维中,在云主机中安装配置swift的过程,以及题目中要求的查询云存储swift 的状态、创建swift 用户、swift 文件管理的操作方法。

需要新建云主机,先完成“云主机基本环境&Keystone”,再按照这个文档安装配置Swift。

单独一台云主机做

5、对象存储服务Swift
在本文档中,将swift安装在云主机中,必须先完成“云主机基本环境&Keystone”,才可以开始安装swift。

(1)基础配置
source admin-openrc.sh

keystone user-create --name=swift --pass=SWIFT_PASS --email=swift@localhost
keystone user-role-add --user=swift --tenant=service --role=admin
keystone role-create --name=SwiftOperator
keystone user-role-add --user=swift --tenant=service --role=SwiftOperator

keystone service-create --name=swift --type=object-store --description="OpenStack Object Storage"
keystone endpoint-create --service-id=$(keystone service-list | awk '/ object-store/ {print $2}') \
--publicurl="http://controller:8080/v2/AUTH_%(tenant_id)s" \
--internalurl="http:/controller:8080/v2/AUTH_%(tenant_id)s" \
--adminurl="http://controller:8080/v2/AUTH_%(tenant_id)s"

mkdir -p /etc/swift
echo "[swift-hash]" >> /etc/swift/swift.conf
echo "swift_hash_path_suffix = fLIbertYgibbitZ" >> /etc/swift/swift.conf

(2)存储服务配置-1
yum install openstack-swift openstack-swift-account openstack-swift-container openstack-swift-object xfsprogs xinetd rsync

fdisk /dev/sda

partx -a /dev/sda

(这里以sda3为例)
mkfs.xfs -i size=1024 -f /dev/sda3

echo "/dev/sda3 /srv/node xfs noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab

mkdir -p /srv/node
mount /dev/sda3 /srv/node
chown -R swift:swift /srv/node

vi /etc/rsyncd.conf
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = 127.0.0.1
[account]
max connections = 2
path = /srv/node
read only = false
lock file = /var/lock/account.lock
[container]
max connections = 2
path = /srv/node
read only = false
lock file = /var/lock/container.lock
[object]
max connections = 2
path = /srv/node
read only = false
lock file = /var/lock/object.lock

vi /etc/xinetd.d/rsync
disable = no
flags = IPv4

service xinetd start
chkconfig xinetd on

mkdir -p /var/swift/recon
chown -R swift:swift /var/swift/recon

(3)代理服务配置
yum install openstack-swift-proxy memcached python-swiftclient

openstack-config --set /etc/swift/proxy-server.conf DEFAULT bind_port 8080
openstack-config --set /etc/swift/proxy-server.conf DEFAULT workers 8
openstack-config --set /etc/swift/proxy-server.conf DEFAULT user swift
openstack-config --set /etc/swift/proxy-server.conf DEFAULT log_name proxy
openstack-config --set /etc/swift/proxy-server.conf DEFAULT log_level DEBUG
openstack-config --set /etc/swift/proxy-server.conf DEFAULT log_facility LOG_LOCAL0
openstack-config --set /etc/swift/proxy-server.conf pipeline:main pipeline healthcheck\ cache\ authtoken\ keystone\ proxy-server
openstack-config --set /etc/swift/proxy-server.conf app:proxy-server use egg:swift#proxy
openstack-config --set /etc/swift/proxy-server.conf app:proxy-server allow_account_management true
openstack-config --set /etc/swift/proxy-server.conf app:proxy-server account_autocreate true
openstack-config --set /etc/swift/proxy-server.conf filter:cache use egg:swift#memcache
openstack-config --set /etc/swift/proxy-server.conf filter:cache memcache_servers 127.0.0.1:11211
openstack-config --set /etc/swift/proxy-server.conf filter:catch_errors use egg:swift#catch_errors
openstack-config --set /etc/swift/proxy-server.conf filter:healthcheck use egg:swift#healthcheck
openstack-config --set /etc/swift/proxy-server.conf filter:keystone use egg:swift#keystoneauth
openstack-config --set /etc/swift/proxy-server.conf filter:keystone operator_roles admin,\ SwiftOperator,\ _member_
openstack-config --set /etc/swift/proxy-server.conf filter:keystone is_admin true
openstack-config --set /etc/swift/proxy-server.conf filter:keystone cache swift.cache
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken paste.filter_factory keystoneclient.middleware.auth_token:filter_factory
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken signing_dir /tmp/keystone-signing-swift
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_protocol http
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_host controller
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_port 35357
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken admin_tenant_name service
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken admin_user swift
openstack-config --set /etc/swift/proxy-server.conf filter:authtoken admin_password SWIFT_PASS

cd /etc/swift
swift-ring-builder account.builder create 18 3 1
swift-ring-builder container.builder create 18 3 1
swift-ring-builder object.builder create 18 3 1

swift-ring-builder account.builder add z1-192.168.8.133:6002R192.168.8.133:6005/sda3 100
swift-ring-builder container.builder add z1-192.168.8.133:6001R192.168.8.133:6004/sda3 100
swift-ring-builder object.builder add z1-192.168.8.133:6000R192.168.8.133:6003/sda3 100

swift-ring-builder account.builder
swift-ring-builder container.builder
swift-ring-builder object.builder

swift-ring-builder account.builder rebalance
swift-ring-builder container.builder rebalance
swift-ring-builder object.builder rebalance

chown -R swift:swift /etc/swift
service openstack-swift-proxy start
chkconfig openstack-swift-proxy on

(4)存储服务配置-2

sed -i 's/^bind_ip.*/#bind_ip = /g' /etc/swift/account-server.conf
sed -i 's/^bind_ip.*/#bind_ip = /g' /etc/swift/container-server.conf
sed -i 's/^bind_ip.*/#bind_ip = /g' /etc/swift/object-server.conf

mv /etc/swift/account-server.conf /etc/swift/account-server/1.conf
mv /etc/swift/container-server.conf /etc/swift/container-server/1.conf
mv /etc/swift/object-server.conf /etc/swift/object-server/1.conf

openstack-config --set /etc/swift/account-server/1.conf DEFAULT bind_port 6002
openstack-config --set /etc/swift/account-server/1.conf DEFAULT workers 2
openstack-config --set /etc/swift/account-server/1.conf DEFAULT user swift
openstack-config --set /etc/swift/account-server/1.conf DEFAULT devices /srv/node/
openstack-config --set /etc/swift/account-server/1.conf DEFAULT mount_check false
openstack-config --set /etc/swift/account-server/1.conf DEFAULT log_name swift-account
openstack-config --set /etc/swift/account-server/1.conf DEFAULT log_facility LOG_LOCAL1
openstack-config --set /etc/swift/account-server/1.conf DEFAULT log_level DEBUG
openstack-config --set /etc/swift/account-server/1.conf account-replicator vm_test_mode no

openstack-config --set /etc/swift/container-server/1.conf DEFAULT bind_port 6001
openstack-config --set /etc/swift/container-server/1.conf DEFAULT workers 2
openstack-config --set /etc/swift/container-server/1.conf DEFAULT user swift
openstack-config --set /etc/swift/container-server/1.conf DEFAULT devices /srv/node/
openstack-config --set /etc/swift/container-server/1.conf DEFAULT mount_check false
openstack-config --set /etc/swift/container-server/1.conf DEFAULT log_name swift-container
openstack-config --set /etc/swift/container-server/1.conf DEFAULT log_facility LOG_LOCAL1
openstack-config --set /etc/swift/container-server/1.conf DEFAULT log_level DEBUG
openstack-config --set /etc/swift/container-server/1.conf account-replicator vm_test_mode no

openstack-config --set /etc/swift/object-server/1.conf DEFAULT bind_port 6000
openstack-config --set /etc/swift/object-server/1.conf DEFAULT workers 2
openstack-config --set /etc/swift/object-server/1.conf DEFAULT user swift
openstack-config --set /etc/swift/object-server/1.conf DEFAULT devices /srv/node/
openstack-config --set /etc/swift/object-server/1.conf DEFAULT mount_check false
openstack-config --set /etc/swift/object-server/1.conf DEFAULT log_name swift-object
openstack-config --set /etc/swift/object-server/1.conf account-replicator vm_test_mode no

echo "local1.* /var/log/swift/storage1.log" >> /etc/rsyslog.d/10-swift.conf
mkdir -p /var/log/swift
chown -R swift:swift /var/log/swift
service rsyslog restart
chown -R swift:swift /var/swift
chown -R swift:swift /var/cache/swift

swift-init object-server start
swift-init object-replicator start
swift-init object-updater start
swift-init object-auditor start
swift-init container-server start
swift-init container-replicator start
swift-init container-updater start
swift-init container-auditor start
swift-init account-server start
swift-init account-replicator start
swift-init account-auditor start

vi /etc/rc.local
/usr/bin/swift-init object-server start
/usr/bin/swift-init object-replicator start
/usr/bin/swift-init object-updater start
/usr/bin/swift-init object-auditor start
/usr/bin/swift-init container-server start
/usr/bin/swift-init container-replicator start
/usr/bin/swift-init container-updater start
/usr/bin/swift-init container-auditor start
/usr/bin/swift-init account-server start
/usr/bin/swift-init account-replicator start
/usr/bin/swift-init account-auditor start

(5)测试Swift

<1>查询云存储swift的状态信息:
[iyunv@controller ~]# swift stat
       Account: AUTH_38ab7f0938f14147a213e7e0e9c58fbe
    Containers: 0
       Objects: 0
         Bytes: 0
  Content-Type: text/plain; charset=utf-8
   X-Timestamp: 1431516198.94843
    X-Trans-Id: tx48df0de6fb604d3cb366a-0055533426
X-Put-Timestamp: 1431516198.94843

<2>创建swift用户:
创建swift用户test1,密码为123456,并创建租户test1,将用户加入到租户test1
和role角色SwiftOperator。提交查询用户列表信息。
. admin-openrc.sh
keystone user-create --name test1 --pass 123456
keystone tenant-create --name test1
keystone user-role-add --user test1 --tenant test1 --role SwiftOperator

[iyunv@controller ~]# keystone user-list
+----------------------------------+-------+---------+-----------------+
|                id                |  name | enabled |      email      |
+----------------------------------+-------+---------+-----------------+
| b3e1db3727014e018c5b89dcc63c6fa9 | admin |   True  | admin@localhost |
| c601d6b307d7481b898977b865a0be7f | swift |   True  | swift@localhost |
| 8438a1c7373d45be845438088f2be72e | test1 |   True  |                 |
| a08f9e5378fe47c3aacb2134de7cd641 | user1 |   True  | user1@localhost |
+----------------------------------+-------+---------+-----------------+

[iyunv@controller ~]# keystone tenant-list
+----------------------------------+---------+---------+
|                id                |   name  | enabled |
+----------------------------------+---------+---------+
| 38ab7f0938f14147a213e7e0e9c58fbe |  admin  |   True  |
| 4f3315bb8a7f46af9a853d42b9a9fbff | service |   True  |
| 38a8ddd9b90d47428750060a71a23d66 |  test1  |   True  |
| 4d41df5401d242eeac1a21062ad9b705 |  user1  |   True  |
+----------------------------------+---------+---------+

<3>swift 文件管理:
在swift 中使用账号test1上传镜像文件到image容器中,命名为centos。提交查询
该账号下容器列表的信息和该容器下内容列表信息。
vi test1-openrc.sh
export OS_USERNAME=test1
export OS_PASSWORD=123456
export OS_TENANT_NAME=test1
export OS_AUTH_URL=http://controller:35357/v2.0

. test1-openrc.sh

创建容器image:
[iyunv@controller ~]# swift post image
查看容器:
[iyunv@controller ~]# swift list
image

上传镜像文件到image容器中,命名为centos:
[iyunv@controller ~]# cd /media/openstack/images/
(将镜像文件通过SFTP传到云主机中,放到某个目录下,这里是/media/openstack/images/。)
[iyunv@controller images]# swift upload --object-name centos image centos_65_x86_6420140327.qcow2
命令格式:swift upload [--object-name <object-name>] <container> <file_or_directory>

查询该账号下容器列表的信息:
[iyunv@controller images]# swift list
image
查询该容器下内容列表信息:
[iyunv@controller images]# swift list image
centos

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-86695-1-1.html 上篇帖子: 云主机基本环境&Keystone 和 云主机Cinder 下篇帖子: 云主机基本环境&Keystone 和 云主机Cinder 主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表