前言
环境:centos7.9 ceph version 13.2.10
上一篇我们讲了文件类型的分布式存储–glusterfs,这次我们来讲另外一个分布式存储系统,即ceph;
Ceph是一个能提供文件存储、块存储、对象存储的分布式存储文件系统,它提供了一个可无限伸缩的Ceph存储集群。
名词术语
Ceph集群包括两种守护进程:Ceph OSD、Ceph Monitor;
Ceph OSD(object storage device):功能是存储数据,处理数据的复制、恢复、回填、再均衡,并通过检查其他OSD守护进程的心跳来向Ceph Monitor提供一些监控信息,我们可以简单理解OSD为磁盘设备。
Ceph Monitor:是一个监视器,监视Ceph集群状态和维护集群中的各种关系。
Ceph存储集群至少需要1个Ceph Monitor和2个OSD守护进程。
环境要求及搭建
1、准备3个干净的存储服务器+1个干净的客户端服务器,3个存储服务器都挂载1块新磁盘,不用分区;
2、配置4个服务器的主机名为node1、node2、node3、client,绑定本地解析主机名;
vim /etc/hosts192.168.118.128node1192.168.118.129node2192.168.118.130node3192.168.118.131client
3、4个服务器都能上外网,而且两两ping通;
4、4台服务器都配置好公网的centos7源+epel源+Ceph源(如果不想配置外网,也可以自己配置本地ceph源)
yum install epel-release -y#安装配置epel源vim /etc/yum.repos.d/ceph.repo#配置ceph源[ceph]name=cephbaseurl=/ceph/rpm-mimic/el7/x86_64/enabled=1gpgcheck=0priority=1[ceph-noarch]name=cephnoarchbaseurl=/ceph/rpm-mimic/el7/noarch/enabled=1gpgcheck=0priority=1[ceph-source]name=Ceph source packagesbaseurl=/ceph/rpm-mimic/el7/SRPMSenabled=1gpgcheck=0priority=1
集群搭建
以上环境准备完毕,我们来开始搭建集群。
第1步、配置ssh免密登
此步骤不是必须,如果使用ceph-deploy来安装集群,免密会比较方便;
以node1为部署节点,在node1上配置免密登录;
[root@node1 ~]# ssh-keygen -t rsa #在node1上做免密登陆Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): #按回车表示默认Enter passphrase (empty for no passphrase): #按回车Enter same passphrase again: #按回车Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:88Mn62RbS9FFvo7ACScolYVj4gc8qY8QSasUNPFnjLc root@node1The key's randomart image is:+---[RSA 2048]----+|o*o . ..+..|| o= o*.=.o || o.oo*=..o . o||o. .+.o. = .. ..||. . oE. S +. .. || . . + ..o ||B +. . || o O . || .+ . |+----[SHA256]-----+[root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1#分发公钥,自己也要加[root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2#分发公钥[root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3#分发公钥[root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@client#分发公钥[root@node2 ~]# cd /root/.ssh && cat authorized_keys#去到node1、node2、node3、client的这个目录查看公钥是否分发成功[root@node1 ~]# ssh root@node2#验证免密登陆node2[root@node1 ~]# ssh root@node3#验证免密登陆node3[root@node1 ~]# ssh root@client#验证免密登陆client
第2步、以node1为部署节点,在node1配置部署工具
[root@node1 ~]# yum install ceph-deploy -y
第3步、在node1上创建集群
[root@node1 ~]# mkdir /etc/ceph[root@node1 ~]# cd /etc/ceph[root@node1 ceph]# ceph-deploy new node1#创建一个集群,node1是主机名,不是集群名Traceback (most recent call last):File "/usr/bin/ceph-deploy", line 18, in <module>from ceph_deploy.cli import mainFile "/usr/lib/python2.7/site-packages/ceph_deploy/cli.py", line 1, in <module>import pkg_resourcesImportError: No module named pkg_resources#报错了,原因是缺python-setuptools,安装它即可[root@node1 ceph]# yum install -y python-setuptools#安装python-setuptools依赖[root@node1 ceph]# ceph-deploy new node1 #继续创建一个集群,node1是主机名,不是集群名[ceph_deploy.conf][DEBUG ] found configuration file at: /root/.cephdeploy.conf[ceph_deploy.cli][INFO ] Invoked (2.0.1): /usr/bin/ceph-deploy new node1[ceph_deploy.cli][INFO ] ceph-deploy options:[ceph_deploy.cli][INFO ] username : None[ceph_deploy.cli][INFO ] func: <function new at 0x7fc5b6a1a320>[ceph_deploy.cli][INFO ] verbose : False[ceph_deploy.cli][INFO ] overwrite_conf: False[ceph_deploy.cli][INFO ] quiet: False[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7fc5b618b7a0>[ceph_deploy.cli][INFO ] cluster : ceph[ceph_deploy.cli][INFO ] ssh_copykey : True[ceph_deploy.cli][INFO ] mon : ['node1'][ceph_deploy.cli][INFO ] public_network: None[ceph_deploy.cli][INFO ] ceph_conf : None[ceph_deploy.cli][INFO ] cluster_network: None[ceph_deploy.cli][INFO ] default_release: False[ceph_deploy.cli][INFO ] fsid: None[ceph_deploy.new][DEBUG ] Creating new cluster named ceph#ceph是集群名,自动帮我们生成一个名叫ceph的集群[ceph_deploy.new][INFO ] making sure passwordless SSH succeeds[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[node1][DEBUG ] find the location of an executable[node1][INFO ] Running command: /usr/sbin/ip link show[node1][INFO ] Running command: /usr/sbin/ip addr show[node1][DEBUG ] IP addresses found: [u'192.168.118.128'][ceph_deploy.new][DEBUG ] Resolving host node1[ceph_deploy.new][DEBUG ] Monitor node1 at 192.168.118.128[ceph_deploy.new][DEBUG ] Monitor initial members are ['node1'][ceph_deploy.new][DEBUG ] Monitor addrs are ['192.168.118.128'][ceph_deploy.new][DEBUG ] Creating a random mon key...[ceph_deploy.new][DEBUG ] Writing monitor keyring to ceph.mon.keyring...[ceph_deploy.new][DEBUG ] Writing initial config to ceph.conf...[root@node1 ceph]# ll#查看一下生成了哪些文件total 12-rw-r--r--. 1 root root 198 Jan 3 13:52 ceph.conf#集群配置文件-rw-r--r--. 1 root root 2923 Jan 3 13:52 ceph-deploy-ceph.log#使用ceph-deploy部署的日志记录-rw-------. 1 root root 73 Jan 3 13:52 ceph.mon.keyring#mon的验证key文件[root@node1 ceph]#
第4步、ceph集群节点安装ceph
[root@node1 ~]# yum install ceph ceph-radosgw -y#在node1、node2、node3上安装软件[root@node2 ~]# yum install ceph ceph-radosgw -y#如果出现依赖冲突,执行解决[root@node3 ~]# yum install ceph ceph-radosgw -y#安装的软件依赖会比较多[root@node1 ~]# ceph -v#查看版本ceph version 13.2.10 (564bdc4ae87418a232fc901524470e1a0f76d641) mimic (stable)[root@node1 ~]#
第5步、客户端安装ceph-common
[root@client ~]# yum -y install ceph-common
第6步、创建mon(监控)
[root@node1 ~]# cd /etc/ceph/#以下操作的目录均在集群的配置目录下面进行操作[root@node1 ceph]# vim ceph.confpublic network = 10.1.1.0/24#监控网络[root@node1 ~]# cd /etc/ceph/#必须进入集群的配置文件目录[root@node1 ceph]# ceph-deploy mon create-initial#创建初始化monitor监控[ceph_deploy.conf][DEBUG ] found configuration file at: /root/.cephdeploy.conf[ceph_deploy.cli][INFO ] Invoked (2.0.1): /usr/bin/ceph-deploy mon create-initial[ceph_deploy.cli][INFO ] ceph-deploy options:[ceph_deploy.cli][INFO ] username : None[ceph_deploy.cli][INFO ] verbose : False[ceph_deploy.cli][INFO ] overwrite_conf: False[ceph_deploy.cli][INFO ] subcommand: create-initial[ceph_deploy.cli][INFO ] quiet: False[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7f5b7c02d1b8>[ceph_deploy.cli][INFO ] cluster : ceph[ceph_deploy.cli][INFO ] func: <function mon at 0x7f5b7c2898c0>[ceph_deploy.cli][INFO ] ceph_conf : None[ceph_deploy.cli][INFO ] default_release: False[ceph_deploy.cli][INFO ] keyrings : None[ceph_deploy.mon][DEBUG ] Deploying mon, cluster ceph hosts node1[ceph_deploy.mon][DEBUG ] detecting platform for host node1 ...[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[node1][DEBUG ] find the location of an executable[ceph_deploy.mon][INFO ] distro info: CentOS Linux 7.9. Core[node1][DEBUG ] determining if provided host has same hostname in remote[node1][DEBUG ] get remote short hostname[node1][DEBUG ] deploying mon to node1[node1][DEBUG ] get remote short hostname[node1][DEBUG ] remote hostname: node1[node1][DEBUG ] write cluster configuration to /etc/ceph/{cluster}.conf[node1][DEBUG ] create the mon path if it does not exist[node1][DEBUG ] checking for done path: /var/lib/ceph/mon/ceph-node1/done[node1][DEBUG ] done path does not exist: /var/lib/ceph/mon/ceph-node1/done[node1][INFO ] creating keyring file: /var/lib/ceph/tmp/ceph-node1.mon.keyring[node1][DEBUG ] create the monitor keyring file[node1][INFO ] Running command: ceph-mon --cluster ceph --mkfs -i node1 --keyring /var/lib/ceph/tmp/ceph-node1.mon.keyring --setuser 167 --setgroup 167[node1][INFO ] unlinking keyring file /var/lib/ceph/tmp/ceph-node1.mon.keyring[node1][DEBUG ] create a done file to avoid re-doing the mon deployment[node1][DEBUG ] create the init path if it does not exist[node1][INFO ] Running command: systemctl enable ceph.target[node1][INFO ] Running command: systemctl enable ceph-mon@node1[node1][WARNIN] Created symlink from /etc/systemd/system/ceph-mon.target.wants/ceph-mon@node1.service to /usr/lib/systemd/system/ceph-mon@.service.[node1][INFO ] Running command: systemctl start ceph-mon@node1[node1][INFO ] Running command: ceph --cluster=ceph --admin-daemon /var/run/ceph/ceph-mon.node1.asok mon_status[node1][DEBUG ] ********************************************************************************[node1][DEBUG ] status for monitor: mon.node1[node1][DEBUG ] {[node1][DEBUG ] "election_epoch": 3, [node1][DEBUG ] "extra_probe_peers": [], [node1][DEBUG ] "feature_map": {[node1][DEBUG ]"mon": [[node1][DEBUG ] {[node1][DEBUG ] "features": "0x3ffddff8ffacfffb", [node1][DEBUG ] "num": 1, [node1][DEBUG ] "release": "luminous"[node1][DEBUG ] }[node1][DEBUG ]][node1][DEBUG ] }, [node1][DEBUG ] "features": {[node1][DEBUG ]"quorum_con": "4611087854031667195", [node1][DEBUG ]"quorum_mon": [[node1][DEBUG ] "kraken", [node1][DEBUG ] "luminous", [node1][DEBUG ] "mimic", [node1][DEBUG ] "osdmap-prune"[node1][DEBUG ]], [node1][DEBUG ]"required_con": "144115738102218752", [node1][DEBUG ]"required_mon": [[node1][DEBUG ] "kraken", [node1][DEBUG ] "luminous", [node1][DEBUG ] "mimic", [node1][DEBUG ] "osdmap-prune"[node1][DEBUG ]][node1][DEBUG ] }, [node1][DEBUG ] "monmap": {[node1][DEBUG ]"created": "-01-03 15:00:22.569173", [node1][DEBUG ]"epoch": 1, [node1][DEBUG ]"features": {[node1][DEBUG ] "optional": [], [node1][DEBUG ] "persistent": [[node1][DEBUG ] "kraken", [node1][DEBUG ] "luminous", [node1][DEBUG ] "mimic", [node1][DEBUG ] "osdmap-prune"[node1][DEBUG ] ][node1][DEBUG ]}, [node1][DEBUG ]"fsid": "4aaecade-1822-43ba-a7e7-ae20d4241527", [node1][DEBUG ]"modified": "-01-03 15:00:22.569173", [node1][DEBUG ]"mons": [[node1][DEBUG ] {[node1][DEBUG ] "addr": "192.168.118.128:6789/0", [node1][DEBUG ] "name": "node1", [node1][DEBUG ] "public_addr": "192.168.118.128:6789/0", [node1][DEBUG ] "rank": 0[node1][DEBUG ] }[node1][DEBUG ]][node1][DEBUG ] }, [node1][DEBUG ] "name": "node1", [node1][DEBUG ] "outside_quorum": [], [node1][DEBUG ] "quorum": [[node1][DEBUG ]0[node1][DEBUG ] ], [node1][DEBUG ] "rank": 0, [node1][DEBUG ] "state": "leader", [node1][DEBUG ] "sync_provider": [][node1][DEBUG ] }[node1][DEBUG ] ********************************************************************************[node1][INFO ] monitor: mon.node1 is running[node1][INFO ] Running command: ceph --cluster=ceph --admin-daemon /var/run/ceph/ceph-mon.node1.asok mon_status[ceph_deploy.mon][INFO ] processing monitor mon.node1[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[node1][DEBUG ] find the location of an executable[node1][INFO ] Running command: ceph --cluster=ceph --admin-daemon /var/run/ceph/ceph-mon.node1.asok mon_status[ceph_deploy.mon][INFO ] mon.node1 monitor has reached quorum![ceph_deploy.mon][INFO ] all initial monitors are running and have formed quorum[ceph_deploy.mon][INFO ] Running gatherkeys...[ceph_deploy.gatherkeys][INFO ] Storing keys in temp directory /tmp/tmpkP__ti[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[node1][DEBUG ] get remote short hostname[node1][DEBUG ] fetch remote file[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --admin-daemon=/var/run/ceph/ceph-mon.node1.asok mon_status[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --name mon. --keyring=/var/lib/ceph/mon/ceph-node1/keyring auth get client.admin[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --name mon. --keyring=/var/lib/ceph/mon/ceph-node1/keyring auth get client.bootstrap-mds[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --name mon. --keyring=/var/lib/ceph/mon/ceph-node1/keyring auth get client.bootstrap-mgr[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --name mon. --keyring=/var/lib/ceph/mon/ceph-node1/keyring auth get client.bootstrap-osd[node1][INFO ] Running command: /usr/bin/ceph --connect-timeout=25 --cluster=ceph --name mon. --keyring=/var/lib/ceph/mon/ceph-node1/keyring auth get client.bootstrap-rgw[ceph_deploy.gatherkeys][INFO ] Storing ceph.client.admin.keyring[ceph_deploy.gatherkeys][INFO ] Storing ceph.bootstrap-mds.keyring[ceph_deploy.gatherkeys][INFO ] Storing ceph.bootstrap-mgr.keyring[ceph_deploy.gatherkeys][INFO ] keyring 'ceph.mon.keyring' already exists[ceph_deploy.gatherkeys][INFO ] Storing ceph.bootstrap-osd.keyring[ceph_deploy.gatherkeys][INFO ] Storing ceph.bootstrap-rgw.keyring[ceph_deploy.gatherkeys][INFO ] Destroy temp directory /tmp/tmpkP__ti[root@node1 ceph]# ceph-deploy admin node1 node2 node3#将配置文件信息同步到所有节点[root@node1 ceph]# ceph -s#查看集群状态cluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527#集群idhealth: HEALTH_WARN#集群健康状态mon node1 is low on available space#这个警告说存储空间少的,是说node1节点的根目录可用存储空间少于70%,这里我的node1根存储空间已经达到79%,所以我需要删除一些文件来释放跟空间services:mon: 1 daemons, quorum node1#有1个监控,mon可以有多个mgr: no daemons active#这个是mgr管理,等下第7步我们再创建osd: 0 osds: 0 up, 0 indata:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 0 B used, 0 B / 0 B availpgs:#为了防止mon单点故障,可以加多个mon节点(建议奇数个,因为有quorum仲裁投票)[root@node1 ceph]# ceph-deploy mon add node2#加多一个mon[root@node1 ceph]# ceph-deploy mon add node3#再加多一个mon[root@node1 ceph]# ceph -s#再次查看集群状态cluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_WARNclock skew detected on mon.node3#总是报node3节点时间有误差mons node1,node2 are low on available space#需要释放node1和node2根存储空间降到70%以下services:mon: 3 daemons, quorum node1,node2,node3#现在已经有3个mon监控了mgr: no daemons activeosd: 0 osds: 0 up, 0 indata:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 0 B used, 0 B / 0 B availpgs:[root@node1 ceph]# #如何处理集群总是报node3时间有偏差呢?监控到时间不同步的解决方法可以有两种方案:#1、在ceph集群所有节点上(node1、node2、node3)不使用ntpd服务,直接使用ntpdate命令+crontab定时任务同步systemctl stop ntpdsystemctl disable ntpdcrontab -e*/5 * * * * ntpdate #每5或10分钟同步1次公网的任意时间服务器#2、调大时间警告的阈值(这里我采用这种方法处理)[root@node1 ceph]# cd /etc/ceph[root@node1 ceph]# vim ceph.conf[global]#在global参数组里添加以下两行......mon clock drift allowed = 2# monitor间的时钟滴答数(默认0.5秒)mon clock drift warn backoff = 30#调大时钟允许的偏移量(默认为5)[root@node1 ceph]# systemctl restart ceph-mon.target#在所有node节点上重启ceph-mon.target服务[root@node1 ceph]# ceph-deploy --overwrite-conf admin node1 node2 node3#将配置文件信息同步到所有节点,加--overwrite-conf参数表示覆盖#为什么要同步ceph.conf配置文件呢?因为修改了node1的/etc/ceph/ceph.conf配置文件,为了保持各个节点的配置文件一致,不然后面的操作可能会出现报错。#为了不让它再报存储空间low的问题,我需要把node1和node2删除一些文件来达到释放根目录空间[root@node1 /]# ceph -s#再次查看集群监控状态cluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_OK#现在集群健康状态已经是ok了services:mon: 3 daemons, quorum node1,node2,node3mgr: no daemons activeosd: 0 osds: 0 up, 0 indata:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 0 B used, 0 B / 0 B availpgs:[root@node1 /]#
第7步、 创建mgr(管理)
ceph luminous版本中新增加了一个组件:Ceph Manager Daemon,简称ceph-mgr,该组件的主要作用是分担和扩展monitor的部分功能,减轻monitor的负担,让更好地管理ceph存储系统。
[root@node1 /]# cd /etc/ceph/#同样需要切换到集群配置问文件目录[root@node1 ceph]# ceph-deploy mgr create node1#创建一个mgr,node1是主机名[ceph_deploy.conf][DEBUG ] found configuration file at: /root/.cephdeploy.conf[ceph_deploy.cli][INFO ] Invoked (2.0.1): /usr/bin/ceph-deploy mgr create node1[ceph_deploy.cli][INFO ] ceph-deploy options:[ceph_deploy.cli][INFO ] username : None[ceph_deploy.cli][INFO ] verbose : False[ceph_deploy.cli][INFO ] mgr : [('node1', 'node1')][ceph_deploy.cli][INFO ] overwrite_conf: False[ceph_deploy.cli][INFO ] subcommand: create[ceph_deploy.cli][INFO ] quiet: False[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7f2afb48>[ceph_deploy.cli][INFO ] cluster : ceph[ceph_deploy.cli][INFO ] func: <function mgr at 0x7f2a20a0c5f0>[ceph_deploy.cli][INFO ] ceph_conf : None[ceph_deploy.cli][INFO ] default_release: False[ceph_deploy.mgr][DEBUG ] Deploying mgr, cluster ceph hosts node1:node1[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[ceph_deploy.mgr][INFO ] Distro info: CentOS Linux 7.9. Core[ceph_deploy.mgr][DEBUG ] remote host will use systemd[ceph_deploy.mgr][DEBUG ] deploying mgr bootstrap to node1[node1][DEBUG ] write cluster configuration to /etc/ceph/{cluster}.conf[node1][WARNIN] mgr keyring does not exist yet, creating one[node1][DEBUG ] create a keyring file[node1][DEBUG ] create path recursively if it doesn't exist[node1][INFO ] Running command: ceph --cluster ceph --name client.bootstrap-mgr --keyring /var/lib/ceph/bootstrap-mgr/ceph.keyring auth get-or-create mgr.node1 mon allow profile mgr osd allow * mds allow * -o /var/lib/ceph/mgr/ceph-node1/keyring[node1][INFO ] Running command: systemctl enable ceph-mgr@node1[node1][WARNIN] Created symlink from /etc/systemd/system/ceph-mgr.target.wants/ceph-mgr@node1.service to /usr/lib/systemd/system/ceph-mgr@.service.[node1][INFO ] Running command: systemctl start ceph-mgr@node1[node1][INFO ] Running command: systemctl enable ceph.target#添加多个mgr可以实现HA[root@node1 ceph]# ceph-deploy mgr create node2#同理再创建一个node2[root@node1 ceph]# ceph-deploy mgr create node3#再创建一个node3[root@node1 ceph]# ceph -scluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_WARNOSD count 0 < osd_pool_default_size 3services:mon: 3 daemons, quorum node1,node2,node3mgr: node1(active), standbys: node2, node3#已经创建好了3个mgr,node1为主,node2,node3为备osd: 0 osds: 0 up, 0 indata:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 0 B used, 0 B / 0 B availpgs:[root@node1 ceph]#
第8步、创建osd(存储盘)
[root@node1 ~]# cd /etc/ceph#切换到集群的配置文件目录[root@node1 ceph]# ceph-deploy disk --help#可以查看命令帮助#列表所有node节点的磁盘,都有sda和sdb两个盘,sdb为我们要加入分布式存储的盘[root@node1 ceph]# ceph-deploy disk list node1#列出node1节点服务器的磁盘[root@node1 ceph]# ceph-deploy disk list node2#列出node2节点服务器的磁盘[root@node1 ceph]# ceph-deploy disk list node3#列出node3节点服务器的磁盘#zap表示干掉磁盘上的数据,相当于格式化[root@node1 ceph]# ceph-deploy disk zap node1 /dev/sdb#格式化node1上的sdb磁盘[root@node1 ceph]# ceph-deploy disk zap node2 /dev/sdb#格式化node2上的sdb磁盘[root@node1 ceph]# ceph-deploy disk zap node3 /dev/sdb#格式化node3上的sdb磁盘[root@node1 ceph]# ceph-deploy osd --help#查看帮助[root@node1 ceph]# ceph-deploy osd create --data /dev/sdb node1#将node1上的sdb磁盘创建为osd[root@node1 ceph]# ceph -s#查看集群状态cluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_WARNOSD count 1 < osd_pool_default_size 3services:mon: 3 daemons, quorum node1,node2,node3mgr: node1(active), standbys: node2, node3osd: 1 osds: 1 up, 1 in#这是已经有了1个osd了data:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 5.2 MiB used, 1015 MiB / 1020 MiB avail#可用空间时1G,因为我的node1的sdb空间就是1Gpgs:[root@node1 ceph]# ceph-deploy osd create --data /dev/sdb node2#继续将node3上的sdb磁盘创建为osd[root@node1 ceph]# ceph-deploy osd create --data /dev/sdb node3#继续将node3上的sdb磁盘创建为osd[root@node1 ceph]# ceph -s#再来看一下集群状态cluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_OK#健康状态是okservices:mon: 3 daemons, quorum node1,node2,node3#3个monmgr: node1(active), standbys: node2, node3#3个mgr,1主2备osd: 3 osds: 3 up, 3 in#3个osddata:pools: 0 pools, 0 pgsobjects: 0 objects, 0 Busage: 19 MiB used, 3.0 GiB / 3.0 GiB avail#可用存储空间时3G,因为我的3个node节点的sdb磁盘空间都是1Gpgs:[root@node1 ceph]#
以上8大步骤我们已经搭建完了ceph存储了。
小结-- 集群节点的扩容方法
假设需要扩容,那么再加一个新的集群节点node4,做以下几步即可:
1、主机名配置和绑定,配置ceph源,设置时间同步;
2、在node4上yum install ceph ceph-radosgw -y
安装软件;
3、在部署节点node1上同步配置文件给node4节点:ceph-deploy admin node4
;
4、按需求选择在node4上添加mon或mgr;
5、格式化node4磁盘,如:ceph-deploy disk zap node4 /dev/sdb
6、 在node1上将将node4上的磁盘创建为osd,如:ceph-deploy osd create --data /dev/sdb node4
存储原理
要实现数据存取需要创建一个pool,创建pool要先分配PG。pool里要分配PG,PG里可以存放多个对象, 对象就是由客户端写入的数据分离的单位。
创建pool
[root@node1 ~]# ceph osd pool create test_pool 16#创建一个test_pool的池,并分配16个pg[root@node1 ~]# ceph osd pool get test_pool pg_num#查看指定池的pg数量pg_num: 16[root@node1 ~]# ceph osd pool set test_pool pg_num 18#调整pg的数量set pool 1 pg_num to 18[root@node1 ~]# ceph osd pool get test_pool pg_num#再次查看指定池的pg数量pg_num: 18[root@node1 ~]# ceph -scluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_OK services:mon: 3 daemons, quorum node1,node2,node3mgr: node1(active), standbys: node2, node3osd: 3 osds: 3 up, 3 indata:pools: 1 pools, 18 pgs#有1个池,18个pgobjects: 0 objects, 0 Busage: 1.2 GiB used, 1.8 GiB / 3.0 GiB availpgs:50.000% pgs unknown8 unknown8 active+clean
删除pool
#删除pool之前需在ceph.conf配置文件添加mon_allow_pool_delete=true参数,并重启ceph-mon.target服务[root@node1 ~]# cd /etc/ceph[root@node1 ceph]# vim ceph.conf#打开配置文件添加下面这行参数mon_allow_pool_delete=true[root@node1 ceph]# ceph-deploy --overwrite-conf admin node1 node2 node3#同步文件[root@node1 ceph]# systemctl restart ceph-mon.target#重启ceph-mon.target服务[root@node1 ~]# ceph osd pool delete test_pool test_pool --yes-i-really-really-mean-it[root@node1 ceph]# ceph -scluster:id:4aaecade-1822-43ba-a7e7-ae20d4241527health: HEALTH_WARNmon node1 is low on available spaceservices:mon: 3 daemons, quorum node1,node2,node3mgr: node1(active), standbys: node2, node3osd: 3 osds: 3 up, 3 indata:pools: 0 pools, 0 pgs#test_pool已经删除objects: 0 objects, 0 Busage: 1.2 GiB used, 1.8 GiB / 3.0 GiB availpgs:
创建Ceph文件存储
要运行Ceph文件系统, 你必须先创建至少带一个mds的Ceph存储集群(Ceph块设备和Ceph对象存储不使用MDS)。
Ceph MDS: Ceph文件存储类型存放与管理元数据metadata的服务。
#第1步、 在node1节点创建mds服务(最少创建一个mds,也可以做多个mds实现HA)[root@node1 ceph]# cd /etc/ceph[root@node1 ceph]# ceph-deploy mds create node1 node2 node3#创建3个mds[root@node1 ceph]# ceph mds stat#查看mds状态cephfs-1/1/1 up {0=node3=up:active}, 2 up:standby[root@node1 ceph]##第2步、 一个Ceph文件系统需要至少两个RADOS存储池,一个用于存放数据,一个用于存放元数据,下面我们就来创建这两个池[root@node1 ceph]# ceph osd pool create ceph_data 16#创建ceph_data池,用于存数据[root@node1 ceph]# ceph osd pool create ceph_metadata 8#创建ceph_metadata池,用于存元数据#第3步、创建ceph文件系统,并确认客户端访问的节点[root@node1 ceph]# ceph fs new cephfs ceph_metadata ceph_data #cephfs就是ceph文件系统名,即客户端挂载点,ceph_metadata是上一步创建的元数据池,ceph_data是上一步创建的数据此,这两个池的顺序不能乱new fs with metadata pool 3 and data pool 4[root@node1 ceph]# ceph fs ls#查看我们创建的ceph文件系统name: cephfs, metadata pool: ceph_metadata, data pools: [ceph_data ][root@node1 ceph]#
客户端挂载Ceph文件存储
上一步我们已经创建好了一个叫cephfs的文件存储系统,下面我们就来进行客户端挂载;
一个客户端想要挂载远程上的ceph文件存储系统,它需要连接谁呢?答案是连接monitor监控,所以客户端只需要连接mon监控的节点和端口,而mon监控端口为6789;
在ceph的配置文件ceph.conf中,有auth_client_required = cephx的几行,这几行表示cepg启用了cephx认证, 所以客户端的挂载必须要验证秘钥,而ceph在创建集群的时候就生成一个客户端秘钥;
[root@node1 ~]#cd /etc/ceph[root@node1 ceph]# cat ceph.client.admin.keyring#在node1上查看客户端的秘钥文件内容,这个文件叫ceph.client.admin.keyring,其中admin是用户名[client.admin]#admin是用户名key = AQAGn9JhQ3AUOxAAHz+xz6M8B86uoj+gV/ElIw==#这个就是客户端的秘钥caps mds = "allow *"caps mgr = "allow *"caps mon = "allow *"caps osd = "allow *"[root@node1 ceph]#[root@client ~]# mkdir /etc/ceph#在cline客户端创建一个/etc/ceph目录[root@client ceph]# echo 'AQAGn9JhQ3AUOxAAHz+xz6M8B86uoj+gV/ElIw==' >>admin.key#新建一个秘钥文件,并把从node1上看到的客户端秘钥复制到这个文件里来[root@client ceph]# cat admin.key AQAGn9JhQ3AUOxAAHz+xz6M8B86uoj+gV/ElIw==[root@client ceph]# mkdir /cephfs_data#先创建一个目录作为挂载点[root@client ceph]# mount.ceph node1:6789:/ /cephfs_data/ -o name=admin,secretfile=/etc/ceph/admin.key#解读:node1:6789:/ /cephfs_data/,其中6789是mon的端口,客户端挂载连接找mon的,因为我们node1上创建了3个mon,所以这里写node2,node3都可以,斜杠表示找根,找node1的根就是找我们在node1上创建的cephfs文件系统,/cephfs_data/表示挂载到本地的ceph_data目录,-o表示指定参数选项,name=admin,secretfile=/etc/ceph/admin.key 表示使用用户名为admin,秘钥使用/etc/ceph/admin.key秘钥文件进行连接[root@client ceph]# df -h#查看是否挂载了df: 鈥data/gv8鈥 Transport endpoint is not connectedFilesystemSize Used Avail Use% Mounted ondevtmpfs 475M0 475M 0% /devtmpfs487M0 487M 0% /dev/shmtmpfs487M 14M 473M 3% /runtmpfs487M0 487M 0% /sys/fs/cgroup/dev/mapper/centos-root 6.2G 1.6G 4.7G 26% //dev/sda11014M 138M 877M 14% /boottmpfs 98M0 98M 0% /run/user/0192.168.118.128:6789:/ 532M0 532M 0% /cephfs_data#已成功挂载#可以使用多个客户端, 同时挂载此文件存储,可实现同读同写
删除Ceph文件存储
上一步我们创建一个ceph文件存储,下载我们测试删除ceph文件存储。
#第1步: 在客户端上删除数据,并umount所有挂载[root@client /]# cd /cephfs_data/ [root@client cephfs_data]# rm -rf *#删除全部文件[root@client /]# umount /cephfs_data/#在客户端先卸载[root@client /]# df -h#查看一下,发现已经卸载了df: 鈥data/gv8鈥 Transport endpoint is not connectedFilesystemSize Used Avail Use% Mounted ondevtmpfs 475M0 475M 0% /devtmpfs487M0 487M 0% /dev/shmtmpfs487M 14M 473M 3% /runtmpfs487M0 487M 0% /sys/fs/cgroup/dev/mapper/centos-root 6.2G 1.6G 4.7G 26% //dev/sda11014M 138M 877M 14% /boottmpfs 98M0 98M 0% /run/user/0[root@client /]##第2步: 停掉所有节点的mds(只有停掉mds才能删除文件存储),因为我们刚开始的创建了3个mds,所以需要都停掉[root@node1 ~]# systemctl stop ceph-mds.target#停掉node1上的mds服务[root@node2 ~]# systemctl stop ceph-mds.target#停掉node2上的mds服务[root@node3 ~]# systemctl stop ceph-mds.target#停掉node3上的mds服务#第3步: 回到集群任意一个节点上(node1,node2,node3其中之一)删除Ceph文件存储[root@node1 ceph]# ceph fs rm cephfs --yes-i-really-mean-it#删除文件存储,文件存储名就是cephfs [root@node1 ceph]# ceph fs ls#查看文件存储,已经没有了No filesystems enabled[root@node1 ceph]##第4步: 删除文件存储的那两个池[root@node1 ceph]# ceph osd pool ls#查看池ceph_metadataceph_data[root@node1 ceph]# ceph osd pool delete ceph_metadata ceph_metadata --yes-i-really-really-mean-it#删除ceph_metadata池pool 'ceph_metadata' removed[root@node1 ceph]# [root@node1 ceph]# ceph osd pool delete ceph_data ceph_data --yes-i-really-really-mean-it#删除ceph_data池pool 'ceph_data' removed[root@node2 ceph]# ceph osd pool ls#查看池已经被删除了#第4步: 如果你下次还要创建ceph文件存储,可以把mds服务启动[root@node1 ~]# systemctl start ceph-mds.target[root@node2 ~]# systemctl start ceph-mds.target[root@node3 ~]# systemctl start ceph-mds.target
创建Ceph块存储
注意:块存储要在客户端上面做的,这一点与gluster不同。
#第1步: 在node1上同步配置文件到client客户端,因为要在客户端上做块储存[root@node1 ~]# cd /etc/ceph#切换目录[root@node1 ceph]# ceph-deploy admin client#将node1上的配置文件同步给client客户端#第2步: 客户端建立存储池,并初始化[root@client ~]# cd /etc/ceph#切换目录[root@client ceph]# ceph osd pool create rbd_pool 64#创建pool,pg为64个pool 'rbd_pool' created[root@client ceph]# rbd pool init rbd_pool#使用rdb命令初始化存储池#第3步: 创建一个image(我这里image名为volume1,大小为1024M)[root@client ceph]# rbd create volume1 --pool rbd_pool --size 1024#创建一个1G的image,名为volume1 [root@client ceph]# rbd ls rbd_pool#查看imagevolume1[root@client ceph]# rbd info volume1 -p rbd_pool#查看刚才创建image rbd image 'volume1':size 1 GiB in 256 objectsorder 22 (4 MiB objects)id: 86256b8b4567block_name_prefix: rbd_data.86256b8b4567format: 2features: layering, exclusive-lock, object-map, fast-diff, deep-flattenop_features: flags: create_timestamp: Wed Jan 5 21:19:19 [root@client ceph]# #第4步: 将创建的image 映射成块设备[root@client ceph]# rbd map rbd_pool/volume1#将创建的volume1映射成块设备rbd: sysfs write failed#因为rbd镜像的一些特性,OS kernel并不支持,所以映射报错RBD image feature set mismatch. You can disable features unsupported by the kernel with "rbd feature disable rbd_pool/volume1 object-map fast-diff deep-flatten".In some cases useful info is found in syslog - try "dmesg | tail".rbd: map failed: (6) No such device or address[root@client ceph]# rbd feature disable rbd_pool/volume1 object-map fast-diff deep-flatten#根据上面的报错提示执行这一条命令[root@client ceph]# rbd map rbd_pool/volume1#继续将创建的volume1映射成块设备,映射成功/dev/rbd0#这个就是映射成功的块设备,可以自由分区格式化了#第5步: 查看映射[root@client ceph]# rbd showmapped#显示已经映射的块设备id poolimage snap device 0 rbd_pool volume1 - /dev/rbd0 [root@client ceph]# rbd unmap /dev/rbd0#使用这条命令可以取消映射#第6步: 分区,格式化,挂载[root@client ceph]# fdisk /dev/rbd0#分区[root@client ceph]# lsblk#查看磁盘设备NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda8:0 0 8G 0 disk sda1 8:1 0 1G 0 part /bootsda2 8:2 0 7G 0 part centos-root 253:0 0 6.2G 0 lvm /centos-swap 253:1 0 820M 0 lvm [SWAP]sr0 11:0 1 4.4G 0 rom rbd0 252:0 0 1G 0 disk rbd0p1 252:1 0 1020M 0 part #已经分好区了[root@client ceph]# mkfs.xfs /dev/rbd0p1 #格式化分区,创建文件系统Discarding blocks...Done.meta-data=/dev/rbd0p1 isize=512 agcount=8, agsize=32768 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data= bsize=4096 blocks=261120, imaxpct=25= sunit=1024 swidth=1024 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log=internal log bsize=4096 blocks=624, version=2= sectsz=512 sunit=8 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@client ceph]# [root@client ceph]# mount /dev/rbd0p1 /mnt/#挂载[root@client ceph]# df -Th#查看已挂载设备df: 鈥data/gv8鈥 Transport endpoint is not connectedFilesystem TypeSize Used Avail Use% Mounted ondevtmpfsdevtmpfs 475M0 475M 0% /devtmpfs tmpfs487M0 487M 0% /dev/shmtmpfs tmpfs487M 14M 473M 3% /runtmpfs tmpfs487M0 487M 0% /sys/fs/cgroup/dev/mapper/centos-root xfs 6.2G 1.6G 4.7G 26% //dev/sda1xfs1014M 138M 877M 14% /boottmpfs tmpfs98M0 98M 0% /run/user/0/dev/rbd0p1 xfs1018M 33M 986M 4% /mnt#已成功挂载[root@client ceph]# cat /etc/passwd >>/mnt/file.txt#读写文件测试,正常#注意:块存储是不能实现同读同写的,请不要两个客户端同时挂载进行读写
块存储在线扩容
经测试,分区后/dev/rbd0p1
不能在线扩容,直接使用/dev/rbd0
才可以。为了更好的演示扩容,这里把上一步的分区删掉。
#先把上一步创建的分区删除,直接使用整块磁盘不分区[root@client ~]# cd /etc/ceph[root@client ceph]# umount /mnt#先卸载[root@client ceph]# fdisk /dev/rbd0#输入d删除分区[root@client ceph]# mkfs.xfs /dev/rbd0 -f#将整个设备格式化,不分区了[root@client ceph]# mount /dev/rbd0 /mnt#重新挂载[root@client ceph]# df -h |tail -1#查看是否挂载成功,已经挂载成功了/dev/rbd01014M 33M 982M 4% /mnt#开始在线扩容[root@client ceph]# rbd resize --size 1500 rbd_pool/volume1#扩容成1500M,原来是1024MResizing image: 100% complete...done.[root@client ceph]# rbd info rbd_pool/volume1 |grep size#现在变成1.5G了size 1.5 GiB in 375 objects[root@client ceph]# xfs_growfs -d /mnt/#扩展文件系统,虽然上一步扩容了磁盘,但还需要使用xfs_growfs命令来扩容xfs文件系统[root@client ceph]# df -h |tail -1#查看是否扩容成功,已经显示为1.5G了/dev/rbd01.5G 33M 1.5G 3% /mnt[root@client ceph]#
块存储离线缩容
缩容必须要数据备份,卸载,缩容后重新格式化再挂载,所以这里只做了解,因为企业线上环境一般不会做缩容。
[root@client ceph]# rbd resize --size 500 rbd_pool/volume1 --allow-shrink#容量缩小为500MResizing image: 100% complete...done.[root@client ceph]# rbd info rbd_pool/volume1 |grep size#查看容量,已经是500M了size 500 MiB in 125 objects[root@client ceph]# umount /mnt/#客户端卸载[root@client ceph]# mkfs.xfs -f /dev/rbd0#重新格式化设备Discarding blocks...Done.meta-data=/dev/rbd0 isize=512 agcount=8, agsize=16384 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data= bsize=4096 blocks=128000, imaxpct=25= sunit=1024 swidth=1024 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log=internal log bsize=4096 blocks=624, version=2= sectsz=512 sunit=8 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@client ceph]# mount /dev/rbd0 /mnt/#重新挂载[root@client ceph]# df -h |tail -1#查看已挂载设备,已经是500M了,缩容成功/dev/rbd0498M 26M 473M 6% /mnt[root@client ceph]#
删除块存储
当一个块存储不需要的时候,我们可以删除块存储。
[root@client ceph]# umount /mnt/#客户端先卸载[root@client ceph]# rbd unmap /dev/rbd0#取消映射[root@client ceph]# ceph osd pool delete rbd_pool rbd_pool --yes-i-really-really-mean-it#删除poolpool 'rbd_pool' removed
对象存储
上面我们学过了ceph的文件存储,块存储,下面我们接下来继续学习对象存储。
#第1步: 在node1上创建rgw对象网关[root@node1 ~]# cd /etc/ceph/#必须先切换到ceph的配置文件目录[root@node1 ceph]# ceph-deploy rgw create node1#创建一个对象存储,关键字就是rgw[ceph_deploy.conf][DEBUG ] found configuration file at: /root/.cephdeploy.conf[ceph_deploy.cli][INFO ] Invoked (2.0.1): /usr/bin/ceph-deploy rgw create node1[ceph_deploy.cli][INFO ] ceph-deploy options:[ceph_deploy.cli][INFO ] username : None[ceph_deploy.cli][INFO ] verbose : False[ceph_deploy.cli][INFO ] rgw : [('node1', 'rgw.node1')][ceph_deploy.cli][INFO ] overwrite_conf: False[ceph_deploy.cli][INFO ] subcommand: create[ceph_deploy.cli][INFO ] quiet: False[ceph_deploy.cli][INFO ] cd_conf : <ceph_deploy.conf.cephdeploy.Conf instance at 0x7f7b32ef6f38>[ceph_deploy.cli][INFO ] cluster : ceph[ceph_deploy.cli][INFO ] func: <function rgw at 0x7f7b3353f500>[ceph_deploy.cli][INFO ] ceph_conf : None[ceph_deploy.cli][INFO ] default_release: False[ceph_deploy.rgw][DEBUG ] Deploying rgw, cluster ceph hosts node1:rgw.node1[node1][DEBUG ] connected to host: node1 [node1][DEBUG ] detect platform information from remote host[node1][DEBUG ] detect machine type[ceph_deploy.rgw][INFO ] Distro info: CentOS Linux 7.9. Core[ceph_deploy.rgw][DEBUG ] remote host will use systemd[ceph_deploy.rgw][DEBUG ] deploying rgw bootstrap to node1[node1][DEBUG ] write cluster configuration to /etc/ceph/{cluster}.conf[node1][WARNIN] rgw keyring does not exist yet, creating one[node1][DEBUG ] create a keyring file[node1][DEBUG ] create path recursively if it doesn't exist[node1][INFO ] Running command: ceph --cluster ceph --name client.bootstrap-rgw --keyring /var/lib/ceph/bootstrap-rgw/ceph.keyring auth get-or-create client.rgw.node1 osd allow rwx mon allow rw -o /var/lib/ceph/radosgw/ceph-rgw.node1/keyring[node1][INFO ] Running command: systemctl enable ceph-radosgw@rgw.node1[node1][WARNIN] Created symlink from /etc/systemd/system/ceph-radosgw.target.wants/ceph-radosgw@rgw.node1.service to /usr/lib/systemd/system/ceph-radosgw@.service.[node1][INFO ] Running command: systemctl start ceph-radosgw@rgw.node1[node1][INFO ] Running command: systemctl enable ceph.target[ceph_deploy.rgw][INFO ] The Ceph Object Gateway (RGW) is now running on host node1 and default port 7480#7480就是对象存储的对外端口[root@node1 ceph]# lsof -i:7480#7480就是对象存储的对外端口COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEradosgw 94111 ceph 40u IPv4 7209300t0 TCP *:7480 (LISTEN)[root@node1 ceph]# #第2步: 在客户端测试连接对象网关。连接对象存储需要用户账号秘钥连接,所以需要再客户端创建用户秘钥#创建账号秘钥,如下所示(radosgw-admin命令其实是yum -y install ceph-common安装的)[root@client ceph]# radosgw-admin user create --uid="iflytek" --display-name="iflytek"{"user_id": "iflytek","display_name": "iflytek","email": "","suspended": 0,"max_buckets": 1000,"auid": 0,"subusers": [],"keys": [{"user": "iflytek",#用户名"access_key": "KPCUG4915AJIEWIYRPP5",#访问秘钥"secret_key": "bobYij5DMcMM7qnXyQrr8jtcuoPjhFH2nsB7Psim"#安全密码}],"swift_keys": [],"caps": [],"op_mask": "read, write, delete","default_placement": "","placement_tags": [],"bucket_quota": {"enabled": false,"check_on_raw": false,"max_size": -1,"max_size_kb": 0,"max_objects": -1},"user_quota": {"enabled": false,"check_on_raw": false,"max_size": -1,"max_size_kb": 0,"max_objects": -1},"temp_url_keys": [],"type": "rgw","mfa_ids": []}#第3步:使用S3连接ceph对象网关#AmazonS3是一种面向Internet的对象存储服务.我们这里可以使用s3工具连接ceph的对象存储进行操作。[root@client ceph]# yum install s3cmd -y#安装s3模块,用于连接对象存储#安装好s3包后就会有s3cmd命令用于连接对象存储,为了方便,我们可以把一些连接参数写成一个.s3cfg文件,s3cmd命令默认会去读这个文件[root@client ~]# vim /root/.s3cfg#创建文件,并写入一下内容[default]access_key = KPCUG4915AJIEWIYRPP5#这个访问秘钥就是我们创建iflytek用户时的访问秘钥secret_key = bobYij5DMcMM7qnXyQrr8jtcuoPjhFH2nsB7Psim#这个安全秘钥就是我们创建iflytek用户时的安全秘钥host_base = 192.168.118.128:7480#对象存储的IP和端口host_bucket = 192.168.118.128:7480/%(bucket)#桶,对象存储的IP和端口cloudfront_host = 192.168.118.128:7480use_https = False#第4步:s3cmd命令测试连接对象存储[root@client ceph]# s3cmd mb s3://iflytek#创建一个名为iflytek的桶,桶的概念可理解为目录Bucket s3://iflytek/ created[root@client ceph]# s3cmd ls#查看桶-01-05 16:19 s3://iflytek[root@client ~]# s3cmd put /var/log/yum.log s3://iflytek#put文件到桶,即上传文件upload: /var/log/yum.log -> s3://iflytek/yum.log [1 of 1]5014 of 5014 100% in 1s3.72 KB/s done[root@client ~]# s3cmd get s3://iflytek/yum.log#get文件到本地,即下载文件到本地download: s3://iflytek/yum.log -> ./yum.log [1 of 1]5014 of 5014 100% in 0s 1106.05 KB/s done[root@client ~]# ll#查看文件total 12-rw-------. 1 root root 1203 Jan 1 15:45 anaconda-ks.cfg-rw-r--r--. 1 root root 5014 Jan 5 16:22 yum.log#文件已经下载到本地了