ceph2--块存储RBD/对象存储RGW/文件存储cephfs/

一、(RBD)块存储

1、创建rbd存储池

rbd存储池不能直接用于块设备,需要创建映像并把映像文件作为块设备使用

#1、创建存储池并初始化rbd
[ceph@ceph-deploy ceph-cluster]$ ceph osd pool create rbd-data1 32 32 #创建存储池
[ceph@ceph-deploy ceph-cluster]$ ceph osd pool ls #验证存储池
[ceph@ceph-deploy ceph-cluster]$ ceph osd pool application enable rbd-data1 rbd #在存储池启用 rbd
[ceph@ceph-deploy ceph-cluster]$ rbd pool init -p rbd-data1 #初始化 rbd

#2、创建 img 镜像:
$ rbd create data-img1 --size 3G --pool rbd-data1 --image-format 2 --image-feature layering 
$ rbd create data-img2 --size 5G --pool rbd-data1 --image-format 2 --image-feature layering 
#验证镜像: 
$ rbd ls --pool rbd-data1
$ rbd ls --pool rbd-data1 -l
#查看镜像详细信息: 
$ rbd --image data-img1 --pool rbd-data1 info
$ rbd --image data-img2 --pool rbd-data1 info
#以 json 格式显示镜像信息: 
$ rbd ls --pool rbd-data1 -l --format json --pretty-format
#启用指定存储池中指定镜像的特性: 
$ rbd feature enable exclusive-lock --pool rbd-data1 --image data-img1 
$ rbd feature enable object-map --pool rbd-data1 --image data-img1 
$ rbd feature enable fast-diff --pool rbd-data1 --image data-img1 
#验证镜像特性: 
$ rbd --image data-img1 --pool rbd-data1 info
	features: layering, exclusive-lock, object-map, fast-diff
#禁用指定存储池中指定镜像的特性: 
$ rbd feature disable fast-diff --pool rbd-data1 --image data-img1 
#验证镜像特性: 
$ rbd --image data-img1 --pool rbd-data1 info
	features: layering, exclusive-lock

#3、配置客户端使用 RBD:
#安装 ceph 客户端:
#Ubuntu: 
# wget -q -O- 'https://mirrors.tuna.tsinghua.edu.cn/ceph/keys/release.asc' | sudo apt-key add - 
# vim /etc/apt/sources.list 
# apt install ceph-common -y
#Centos: 
# yum install epel-release 
# yum install https://mirrors.aliyun.com/ceph/rpm-octopus/el7/noarch/ceph-release-1-1.el7.noarch.rpm 
# yum install ceph-common -y

#(1)客户端使用 admin 账户挂载并使用 RBD
#同步 admin 账户认证文件: 
[ceph@ceph-deploy ceph-cluster]$ scp ceph.conf ceph.client.admin.keyring root@192.168.150.129:/etc/ceph/
#管理端关闭 img data-img1 特性 object-map 
[ceph@ceph-deploy ceph-cluster]$ rbd feature disable rbd-data1/data-img1 object-map 
#客户端映射镜像: 
[root@ceph-client ~]# rbd -p rbd-data1 map data-img1
[root@ceph-client ~]# rbd -p rbd-data1 map data-img2
#客户端验证镜像: 
[root@ceph-client ~]# lsblk
#在客户端格式化 rbd 并挂载 
[root@ceph-client ~]# mkfs.xfs /dev/rbd1
[root@ceph-client ~]# mkfs.xfs /dev/rbd2
[root@ceph-client ~]# mkdir /data1 /data2 -p 
[root@ceph-client ~]# mount /dev/rbd1 /data1
[root@ceph-client ~]# mount /dev/rbd2 /data2
[root@ceph-client ~]# df -TH
/dev/rbd1               xfs       3.3G   34M  3.2G   2% /data1
/dev/rbd2               xfs       5.4G   34M  5.4G   1% /data2

#客户端验证写入数据:
#安装 docker 并创建 mysql 容器,验证容器数据能否写入 rbd 挂载的路径/data 
#安装 docker 
# step 1: 安装必要的一些系统工具 
[root@ceph-client ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 
# Step 2: 添加软件源信息 
[root@ceph-client ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
# Step 3: 更新并安装 Docker-CE 
[root@ceph-client ~]# yum makecache fast 
[root@ceph-client ~]# yum -y install docker-ce 
# Step 4: 开启 Docker 服务 
[root@ceph-client ~]# systemctl start docker

[root@ceph-client ~]# docker run -it -d -p 3306:3306 -v /data1:/var/lib/mysql mysql:5.6.46 
[root@ceph-client ~]# ll /data1 #验证数据

#验证 mysql 访问:
[root@ceph-deploy ~]# yum install mysql 
[root@ceph-deploy ~]# mysql -uroot -p12345678 -h192.168.150.129
MySQL [(none)]> show databases;
MySQL [(none)]> create database mydatabase;
MySQL [(none)]> show databases;

#验证 rbd 数据:
[root@ceph-client ~]# ll /data1
#查看存储池空间:
[root@ceph-deploy ~]# ceph df

#(2)客户端使用普通账户挂载并使用 RBD:
#创建普通账户 
[ceph@ceph-deploy ceph-cluster]$ ceph auth add client.xiaolu mon 'allow r' osd 'allow rwx pool=rbd-data1'
#验证用户信息 
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.xiaolu
#创建用 keyring 文件 
[ceph@ceph-deploy ceph-cluster]$ ceph-authtool --create-keyring ceph.client.xiaolu.keyring
#导出用户 keyring 
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.xiaolu -o ceph.client.xiaolu.keyring
#验证指定用户的 keyring 文件 
[ceph@ceph-deploy ceph-cluster]$ cat ceph.client.xiaolu.keyring
#同步普通用户认证文件: 
[ceph@ceph-deploy ceph-cluster]$ scp ceph.conf ceph.client.xiaolu.keyring root@192.168.150.129:/etc/ceph/
[root@ceph-client2 ~]# cd /etc/ceph/ 
[root@ceph-client2 ceph]# ls
[root@ceph-client2 ceph]# ceph --user xiaolu -s #默认使用 admin 账户
#映射 rbd 
[root@ceph-client2 ceph]# rbd --user xiaolu -p rbd-data1 map data-img2
#验证 rbd 
[root@ceph-client2 ceph]# fdisk -l /dev/rbd0
#格式化并使用 rbd 镜像: 
[root@ceph-client2 ceph]# mkfs.ext4 /dev/rbd0
[root@ceph-client2 ceph]# mkdir /data1 
[root@ceph-client2 ceph]# mount /dev/rbd0 /data1/
[root@ceph-client2 ceph]# cp /var/log/messages /data1/ 
[root@ceph-client2 ceph]# ll /data1/
[root@ceph-client2 ceph]# df -TH
/dev/rbd0               ext4      8.4G   38M  7.9G   1% /data1
#管理端验证镜像状态 
[ceph@ceph-deploy ceph-cluster]$ rbd ls -p rbd-data1 -l
NAME SIZE PARENT FMT PROT LOCK 
data-img1 3 GiB 2 excl #施加锁文件,已经被客户端映射 
data-img2 5 GiB 2
#验证 ceph 内核模块: 
#挂载 rbd 之后系统内核会自动加载 libceph.ko 模块
[root@ceph-client2 ceph]# lsmod | grep ceph
[root@ceph-client2 ceph]# modinfo libceph
2、rbd 镜像空间拉伸及删除
#rbd 镜像空间拉伸:
#可以扩展空间,不建议缩小空间 
#当前 rbd 镜像空间大小 
[ceph@ceph-deploy ceph-cluster]$ rbd ls -p rbd-data1 -l
#rbd 镜像空间拉伸命令 
[ceph@ceph-deploy ceph-cluster]$ rbd help resize
#拉伸 rbd 镜像空间 
[ceph@ceph-deploy ceph-cluster]$ rbd resize --pool rbd-data1 --image data-img2 --size 8G
[ceph@ceph-deploy ceph-cluster]$ rbd ls -p rbd-data1 -l
#客户端验证镜像空间: 
[root@ceph-client2 ~]# fdisk -l /dev/rbd0
#开机自动挂载: 
[root@ceph-client2 ~]# cat << EOF >>/etc/rc.d/rc.local 
rbd --user xiaolu -p rbd-data1 map data-img2 
mount /dev/rbd0 /data/ 
EOF
[root@ceph-client2 ~]# chmod a+x /etc/rc.d/rc.local 
[root@ceph-client2 ~]# reboot 
#查看映射 
[root@ceph-client2 ~]# rbd showmapped
0  rbd-data1 data-img2 -    /dev/rbd0 

#验证挂载 
[root@ceph-client2 ~]# df -TH

#卸载 rbd 镜像: 
[root@ceph-client2 ceph]# umount /data1
[root@ceph-client2 ceph]# rbd --user xiaolu -p rbd-data1 unmap data-img2

#删除 rbd 镜像(慎重):
[ceph@ceph-deploy ceph-cluster]$ rbd help rm
#删除存储池 rbd -data1 中的 data-img1 镜像: 
[ceph@ceph-deploy ceph-cluster]$ rbd rm --pool rbd-data1 --image data-img1

#rbd 镜像回收站机制:
[ceph@ceph-deploy ceph-cluster]$ rbd help trash
#查看镜像状态: 
[ceph@ceph-deploy ceph-cluster]$ rbd status --pool rbd-data1 --image data-img2
#将进行移动到回收站: 
[ceph@ceph-deploy ceph-cluster]$ rbd trash move --pool rbd-data1 --image data-img2 
#查看回收站的镜像: 
[ceph@ceph-deploy ceph-cluster]$ rbd trash list --pool rbd-data1
#从回收站删除镜像 
#如果镜像不再使用,可以直接使用 trash remove 将其从回收站删除
#还原镜像 
[ceph@ceph-deploy ceph-cluster]$ rbd trash restore --pool rbd-data1 --image data-img2 --image-id d42b6b8b4567
#验证镜像: 
[ceph@ceph-deploy ceph-cluster]$ rbd ls --pool rbd-data1 -l
3、镜像快照:
[ceph@ceph-deploy ceph-cluster]$ rbd help snap
	snap create (snap add) #创建快照 
	snap limit clear #清除镜像的快照数量限制 
	snap limit set #设置一个镜像的快照上限 
	snap list (snap ls) #列出快照 
	snap protect #保护快照被删除 
	snap purge #删除所有未保护的快照 
	snap remove (snap rm) #删除一个快照 
	snap rename #重命名快照 
	snap rollback (snap revert) #还原快照 
	snap unprotect #允许一个快照被删除(取消快照保护)
#客户端当前数据:
# df -TH
# ll /data1
#创建并验证快照: 
[ceph@ceph-deploy ceph-cluster]$ rbd help snap create
#创建快照 
$ rbd snap create --pool rbd-data1 --image data-img2 --snap img2-snap-20201215
#验证快照 
$ rbd snap list --pool rbd-data1 --image data-img2

#删除数据并还原快照: 
#客户端删除数据 
[root@ceph-client2 ~]# rm -rf /data/passwd 
#验证数据 
[root@ceph-client2 ~]# ll /data/
#卸载 rbd 
[root@ceph-client2 ~]# umount /data 
[root@ceph-client2 ~]# rbd unmap /dev/rbd0 
#回滚命令: 
[ceph@ceph-deploy ceph-cluster]$ rbd help snap rollback
#回滚快照 
[ceph@ceph-deploy ceph-cluster]$ rbd snap rollback --pool rbd-data1 --image data-img2 --snap img2-snap-20201215
#客户端验证数据: 
#客户端需要重新映射并挂载 rbd 
#客户端映射 rbd 
[root@ceph-client2 ~]# rbd --user xiaolu -p rbd-data1 map data-img2
#客户端挂载 rbd 
[root@ceph-client2 ~]# mount /dev/rbd0 /data1/ 
#客户端验证数据 
[root@ceph-client2 ~]# ll /data1/
#删除指定快照 
[ceph@ceph-deploy ceph-cluster]$ rbd snap remove --pool rbd-data1 --image data-img2 --snap img2-snap-20201215
#验证快照是否删除 
[ceph@ceph-deploy ceph-cluster]$ rbd snap list --pool rbd-data1 --image data-img2

#设置与修改快照数量限制 
[ceph@ceph-deploy ceph-cluster]$ rbd snap limit set --pool rbd-data1 --image data-img2 --limit 30 
[ceph@ceph-deploy ceph-cluster]$ rbd snap limit set --pool rbd-data1 --image data-img2 --limit 20 
[ceph@ceph-deploy ceph-cluster]$ rbd snap limit set --pool rbd-data1 --image data-img2 --limit 15 
#清除快照数量限制 
[ceph@ceph-deploy ceph-cluster]$ rbd snap limit clear --pool rbd-data1 --image data-img2

二、ceph radosgw(RGW)对象存储

http://docs.ceph.org.cn/radosgw/
要点1:每个对象包含数据和数据的元数据,通过 Object ID 来检索,只能通过 API或者第三方客户端来访问对象。
要点2:ceph 使用 bucket 作为存储桶(存储空间),实现对象数据的存储和多用户隔离。

1、部署 radosgw 服务
[root@ceph-mgr1 ~]# apt install radosgw -y
[root@ceph-mgr2 ~]# apt install radosgw -y
#将 ceph-mgr1、ceph-mgr2 服务器部署为高可用的 radosGW 服务
[ceph@ceph-deploy ceph-cluster]$ ceph-deploy rgw create ceph-mgr2 
[ceph@ceph-deploy ceph-cluster]$ ceph-deploy rgw create ceph-mgr1
#验证 radosgw 服务状态:
[ceph@ceph-deploy ~]$ ceph -s
    rgw: 2 daemons active (2 hosts, 1 zones)
#验证 radosgw 服务进程:
[root@ceph-mgr1 ~]# ps -aux | grep radosgw
#浏览器访问 radosgw 服务:
#http://192.168.150.144:7480
#http://192.168.150.145:7480
2、radosgw 高可用架构:
#1、自定义端口:
#网址:https://docs.ceph.com/en/latest/radosgw/frontends/
[root@ceph-mgr2 ~]# vim /etc/ceph/ceph.conf 
[client.rgw.ceph-mgr2] #在最后面添加针对当前节点的自定义配置如下: 
	rgw_host = ceph-mgr2 
	rgw_frontends = civetweb port=8080 
#重启服务 
[root@ceph-mgr2 ~]# systemctl restart ceph-radosgw@rgw.ceph-mgr2.service
#验证:
#http://192.168.150.145:8080/

#2、生成签名证书并配置 radosgw 启用 SSL:
#自签名证书: 
[root@ceph-mgr2 ~]# cd /etc/ceph/ 
[root@ceph-mgr2 ceph]# mkdir certs 
[root@ceph-mgr2 ceph]# cd certs/ 
[root@ceph-mgr2 certs]# openssl genrsa -out civetweb.key 2048 
[root@ceph-mgr2 certs]# openssl req -new -x509 -key civetweb.key -out civetweb.crt -subj "/CN=rgw.magedu.net" 
Can't load /root/.rnd into RNG
139981481546176:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/root/.rnd
#---报错解决
[root@ceph-mgr2 certs]#cd /root
[root@ceph-mgr2 ~]#openssl rand -writerand .rnd
[root@ceph-mgr2 certs]# cat civetweb.key civetweb.crt > civetweb.pem 
[root@ceph-mgr2 certs]# tree 
.
├── civetweb.crt 
├── civetweb.key 
└── civetweb.pem
0 directories, 3 files

#3、SSL 配置: 
[root@ceph-mgr2 certs]# vim /etc/ceph/ceph.conf 
[client.rgw.ceph-mgr2] 
	rgw_host = eph-mgr2 
	rgw_frontends = "civetweb port=8080+8443s ssl_certificate=/etc/ceph/certs/civetweb.pem" 
[root@ceph-mgr2 certs]# systemctl restart ceph-radosgw@rgw.ceph-mgr2.service
#验证 8443 端口:
[root@ceph-mgr2 certs]# ss -ntl
[root@ceph-mgr2 certs]# lsof -i:8443
#验证:
#(1)在本地host文件添加域名解析,使本地浏览器可访问:C:\Windows\System32\drivers\etc\hosts
#https://rgw.magedu.net:8443
#(2)在本机添加域名解析:
[root@ceph-mgr2 certs]# cat >>/etc/hosts <<EOF
192.168.150.145  rgw.magedu.net
EOF
#验证访问:
[root@ceph-mgr2 certs]# curl http://192.168.150.145:8080
[root@ceph-mgr2 certs]# curl -k https://rgw.magedu.net:8443  

#4、优化配置:
#创建日志目录: 
[root@ceph-mgr2 certs]# mkdir /var/log/radosgw 
[root@ceph-mgr2 certs]# chown ceph.ceph /var/log/radosgw 
#配置:
[root@ceph-mgr2 ceph]# vim ceph.conf 
[client.rgw.ceph-mgr2] 
rgw_host = eph-mgr2 
rgw_frontends = "civetweb port=8080+8443s ssl_certificate=/etc/ceph/certs/civetweb.pem request_timeout_ms=30000 error_log_file=/var/log/radosgw/civetweb.error.log access_log_file=/var/log/radosgw/civetweb.access.log num_threads=100" 
#重启服务 
[root@ceph-mgr2 certs]# systemctl restart ceph-radosgw@rgw.ceph-mgr2.service
#访问测试: 
[root@ceph-mgr2 certs]# curl -k https://192.168.150.145:8443 
[root@ceph-mgr2 certs]# curl -k https://rgw.magedu.net:8443
#验证日志: 
[root@ceph-mgr2 certs]# tail /var/log/radosgw/civetweb.access.log

三、(cephfs)文件存储

http://docs.ceph.org.cn/cephfs
Ceph FS 需要运行 MDS 服务,其守护进程为 ceph-mds。ceph-mds 进程管理与 cephFS 上存储的文件相关的元数据,并协调对 ceph 存储集群的访问。

1、部署Ceph-FS 文件存储:
#1、部署 MDS 服务:
(在指定的 ceph-mds 服务器部署 ceph-mds 服务,可以和其它服务器混用(如 ceph-mon、 ceph-mgr)#Ubuntu:
root@ceph-mgr1:~# apt-cache madison ceph-mds 
root@ceph-mgr1:~# apt install ceph-mds=16.2.5-1bionic
#Centos: 
[root@ceph-mgr1 ~]# yum install ceph-mds -y
#部署
[ceph@ceph-deploy $ ceph-deploy mds create ceph-mgr1
#验证 MDS 服务
[ceph@ceph-deploy $ ceph mds stat
 1 up:standby  #当前为备用状态,需要分配 pool 才可以使用
 
#2、创建 CephFS metadata 和 data 存储池
[ceph@ceph-deploy $ ceph osd pool create cephfs-metadata 32 32  #保存 metadata 的 pool 
[ceph@ceph-deploy $ ceph osd pool create cephfs-data 64 64  #保存数据的 pool
[ceph@ceph-deploy $ ceph -s
#创建 cephFS 并验证:
[ceph@ceph-deploy $ ceph fs new mycephfs cephfs-metadata cephfs-data
[ceph@ceph-deploy $ ceph fs ls
[ceph@ceph-deploy $ ceph fs status mycephfs #查看指定 cephFS 状态
#验证 cepfFS 服务状态:
[ceph@ceph-deploy $ ceph mds stat
 mycephfs-1/1/1 up {0=ceph-mgr1=up:active}  #cephfs 状态现在已经转变为活动状态

#3、配置客户端使用:
#安装 ceph 客户端:
#Ubuntu: 
# wget -q -O- 'https://mirrors.tuna.tsinghua.edu.cn/ceph/keys/release.asc' | sudo apt-key add - 
# vim /etc/apt/sources.list 
# apt install ceph-common -y
#Centos: 
# yum install epel-release 
# yum install https://mirrors.aliyun.com/ceph/rpm-octopus/el7/noarch/ceph-release-1-1.el7.noarch.rpm 
# yum install ceph-common -y

#(1)客户端使用 admin 账户挂载 cephFS:
[ceph@ceph-deploy $ cat ceph.client.admin.keyring
[client.admin]
	key = AQDC0DVhwArCKRAApp4ja28Jmx7NVMFhRWdz3w==
	caps mds = "allow *"
	caps mgr = "allow *"
	caps mon = "allow *"
	caps osd = "allow *"
#(内核版本 2.6.34 在 3.6.34 及以上)(需要指定 mon 节点的 6789 端口)
root@ceph-client3-ubuntu1804:~# mount -t ceph 192.168.150.141:6789:/ /mnt -o name=admin,secret=AQDC0DVhwArCKRAApp4ja28Jmx7NVMFhRWdz3w==
#验证挂载点
root@ceph-client3-ubuntu1804:~# df -TH
root@ceph-client3-ubuntu1804:~# cp /var/log/syslog /mnt/ #验证数据
root@ceph-client3-ubuntu1804:~# ls /mnt/ -l
#测试数据写入:
root@ceph-client3-ubuntu1804:~# dd if=/dev/zero of=/mnt/ceph-fs-testfile bs=4M count=25
#验证 ceph 存储池数据空间:
ceph@ceph-deploy:/home/ceph/ceph-cluster$ ceph df


#(2)客户端使用普通账户挂载 cephFS:
#创建账户 
[ceph@ceph-deploy ceph-cluster]$ ceph auth add client.yanyan mon 'allow r' mds 'allow rw' osd 'allow rwx pool=cephfs-data'
#验证账户 
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.yanyan
#创建用 keyring 文件 
[ceph@ceph-deploy ceph-cluster]$ ceph auth get client.yanyan -o ceph.client.yanyan.keyring
#创建 key 文件: 
[ceph@ceph-deploy ceph-cluster]$ ceph auth print-key client.yanyan > yanyan.key
#验证用户的 keyring 文件 
[ceph@ceph-deploy ceph-cluster]$ cat ceph.client.yanyan.keyring
同步客户端认证文件: 
[ceph@ceph-deploy ceph-cluster]$ scp ceph.conf ceph.client.yanyan.keyring yanyan.key root@192.168.150.129:/etc/ceph/

客户端验证权限: 
[root@ceph-client3 ~]# ceph --user yanyan -s

#4、客户端挂载有两种方式,一是内核空间一是用户空间,内核空间挂载需要内核支持 ceph 模块,用户空间挂载需要安装 ceph-fuse
#(1)内核空间挂载 ceph-fs(推荐使用):
客户端通过 key 文件挂载:
[root@ceph-client3 ~]# mkdir /data2 
[root@ceph-client3 ~]# mount -t ceph 192.168.150.144:6789,192.168.150.145:6789,192.168.150.146:6789:/ /data2 -o name=yanyan,secretfile=/etc/ceph/yanyan.key

#验证写入数据 
[root@ceph-client3 ~]# cp /etc/issue /data2/ 
[root@ceph-client3 ~]# dd if=/dev/zero of=/data/testfile bs=1M count=100
#客户端通过 key 挂载: 
[root@ceph-client3 ~]# tail /etc/ceph/yanyan.key
AQAbgjlh6HmANBAAxUYtsbPE/AJbMf2Zxn84JA==
[root@ceph-client3 ~]# umount /data2/ 
[root@ceph-client3 ~]# mount -t ceph 192.168.150.144:6789,192.168.150.145:6789,192.168.150.146:6789:/ /data2 -o name=yanyan,secret=AQAbgjlh6HmANBAAxUYtsbPE/AJbMf2Zxn84JA==
#测试写入数据 
[root@ceph-client3 ~]# cp /etc/yum.repos.d/epel.repo /data2/ 
#查看挂载点状态 
[root@ceph-client3 ~]# stat -f /data2/
#开机挂载: 
[root@ceph-client3 ~]# cat /etc/fstab 
192.168.150.144:6789,192.168.150.145:6789,192.168.150.146:6789:/ /data2 ceph defaults,name=yanyan,secretfile=/etc/ceph/yanyan.key,_netdev 0 0 
[root@ceph-client3 ~]# mount -a
#客户端模块: 
#客户端内核加载 ceph.ko 模块挂载 cephfs 文件系统
[root@ceph-client3 ~]# lsmod | grep ceph
[root@ceph-client3 ~]# modeinfo ceph

#(2)用户空间挂载 ceph-fs:
#安装 ceph-fuse: 
#网址:http://docs.ceph.org.cn/man/8/ceph-fuse/
#在一台新的客户端或还原快照,然后安装 ceph-fuse 
[root@ceph-client2 ~]# yum install epel-release -y 
[root@ceph-client2 ~]# yum install https://mirrors.aliyun.com/ceph/rpm-octopus/el7/noarch/ceph-release-1-1.el7.noarch.rpm -y 
[ceph@ceph-deploy ceph-cluster]$ scp /etc/yum.repos.d/ceph.repo /etc/yum.repos.d/epel* root@192.168.150.129:/etc/yum.repos.d/
[root@ceph-client2 ~]# yum install ceph-fuse ceph-common -y
#ceph-fuse 挂载: 
#同步认证及配置文件: 
[ceph@ceph-deploy ceph-cluster]$ scp ceph.conf ceph.client.yanyan.keyring root@192.168.150.129:/etc/ceph/
#通过 ceph-fuse 挂载 ceph 
[root@ceph-client2 ~]# mkdir /data3 
#默认的认证文件查找路径:
[root@ceph-client2 ~]# ceph-fuse --name client.yanyan -m 192.168.150.144:6789,192.168.150.145:6789,192.168.150.146:6789 /data3
#验证挂载
[root@ceph-client2 ~]# df -TH
#验证 ceph-fuse 读写数据:
[root@ceph-client2 ~]# ll /data3
#开机挂载,指定用户会自动根据用户名称加载授权文件及配置文件 ceph.conf 
[root@ceph-client2 ~]# vim /etc/fstab
none /data3 fuse.ceph ceph.id=yanyan,ceph.conf=/etc/ceph/ceph.conf,_netdev,defaults 0 0 
[root@ceph-client2 ~]# umount /data3 
[root@ceph-client2 ~]# mount -a
2、ceph mds 高可用(两主两备):

https://docs.ceph.com/en/latest/cephfs/add-remove-mds/
设置备份的方法有很多,常用选项如下:

mds_standby_replay:true 表示开启 replay 模式,这种模式下主从 MDS
内的数量实时同步,主宕机从可以快速的切换。false 则只有宕机的时候才去同步数据,这样会有一段时间的中断。
mds_standby_for_name:设置当前 MDS 进程只用于备份于指定名称的 MDS。
mds_standby_for_rank:设置当前 MDS 进程只用于备份于哪个 Rank,通常为 Rank 编号。另外在存在多个
CephFS 文件系统中,还可以使用 mds_standby_for_fscid 参数来为指定不同的文件系统。
mds_standby_for_fscid:指定 CephFS 文件系统 ID,需要联合 mds_standby_for_rank 生效。

#当前 mds 服务器状态 
$ ceph mds stat 
mycephfs-1/1/1 up {0=ceph-mgr1=up:active}
#添加 MDS 服务器:
将 ceph-mgr2 和 ceph-mon2 和 ceph-mon3 作为 mds 添加至 ceph 集群
#mds 服务器安装 ceph-mds 服务 
[root@ceph-mgr2 ~]# apt install ceph-mds -y 
[root@ceph-mon2 ~]# apt install ceph-mds -y 
[root@ceph-mon3 ~]# apt install ceph-mds -y 
#添加 mds 服务器 
[ceph@ceph-deploy ceph-cluster]$ ceph-deploy mds create ceph-mgr2 
[ceph@ceph-deploy ceph-cluster]$ ceph-deploy mds create ceph-mon2 
[ceph@ceph-deploy ceph-cluster]$ ceph-deploy mds create ceph-mon3 
#验证 mds 服务器当前状态: 
$ ceph mds stat 
	mycephfs-1/1/1 up {0=ceph-mgr1=up:active}, 3 up:standby
#验证 ceph 集群当前状态: 
#当前处于激活状态的 mds 服务器有一台,处于备份状态的 mds 服务器有三台
$ ceph fs status
#当前的文件系统状态: 
$ ceph fs get mycephfs
#设置处于激活状态 mds 的数量: 
#由目前的一主三备优化为两主两备
$ ceph fs set mycephfs max_mds 2 #设置同时活跃的主 mds 最大值为2
$ ceph fs status

#MDS 高可用优化:
#目前是 ceph-mgr1 和 ceph-mon3 分别是 active 状态,ceph-mon2 和 ceph-mgr2 分别处 于 standby 状态;现在可以将 ceph-mgr2 设置为 ceph-mgr1 的 standby,将 ceph-mon3 设置 为 ceph-mon2 的 standby,以实现每个主都有一个固定备份角色的结构
[ceph@ceph-deploy ceph-cluster]$ vim ceph.conf

[mds.ceph-mgr2] 
#mds_standby_for_fscid = mycephfs 
mds_standby_for_name = ceph-mgr1 
mds_standby_replay = true 

[mds.ceph-mon3] 
mds_standby_for_name = ceph-mon2 
mds_standby_replay = true
#分发配置文件保证各 mds 服务重启有效 
$ ceph-deploy --overwrite-conf config push ceph-mon3 
$ ceph-deploy --overwrite-conf config push ceph-mon2 
$ ceph-deploy --overwrite-conf config push ceph-mgr1 
$ ceph-deploy --overwrite-conf config push ceph-mgr2 
[root@ceph-mon2 ~]# systemctl restart ceph-mds@ceph-mon2.service 
[root@ceph-mon3 ~]# systemctl restart ceph-mds@ceph-mon3.service 
[root@ceph-mgr2 ~]# systemctl restart ceph-mds@ceph-mgr2.service 
[root@ceph-mgr1 ~]# systemctl restart ceph-mds@ceph-mgr1.service
#ceph 集群 mds 高可用状态: 
[ceph@ceph-deploy ceph-cluster]$ ceph fs status
#查看 active 和 standby 对应关系(不同版本显示结果不同): 
[ceph@ceph-deploy ceph-cluster]$ ceph fs get mycephfs
3、通过 ganesha 将 cephfs 通过 NFS 协议共享使用

https://www.server-world.info/en/note?os=Ubuntu_20.04&p=ceph15&f=8

#服务端配置: 
root@ceph-mgr1:~# apt install nfs-ganesha-ceph -y
root@ceph-mgr1:~# cd /etc/ganesha/ 
root@ceph-mgr1:/etc/ganesha# cat ganesha.conf 
# create new 
NFS_CORE_PARAM { 
	# disable NLM 
	Enable_NLM = false; 
	# disable RQUOTA (not suported on CephFS) 
	Enable_RQUOTA = false; 
	# NFS protocol 
	Protocols = 4; 
}
EXPORT_DEFAULTS { 
	# default access mode 
	Access_Type = RW; 
}
EXPORT { 
	# uniq ID 
	Export_Id = 1;
	# mount path of 
	CephFS Path = "/"; 
	FSAL {
		name = CEPH; 
		# hostname or IP address of this Node 
		hostname="192.168.150.144"; 
	}
	# setting for root Squash 
	Squash="No_root_squash"; 
	# NFSv4 Pseudo path 
	Pseudo="/magedu"; 
	# allowed security options 
	SecType = "sys"; 
}
LOG {
	# default log level 
	Default_Log_Level = WARN; 
}
root@ceph-mgr1:/etc/ganesha# systemctl restart nfs-ganesha
#客户端挂载测试: 
root@ceph-client3-ubuntu1804:~# mount -t nfs 192.168.150.144:/magedu /data 
#验证挂载:
root@ceph-client3-ubuntu1804:~# df -TH
#客户端测试写入数据: 
root@ceph-client3-ubuntu1804:~# echo "ganesha v11111111" >> /data/magedu/data/magedu.txt 
root@ceph-client3-ubuntu1804:~# mkdir /data/magedu/data/ganesha

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值