ceph-1.ceph安装

431 阅读4分钟

手动安装

1. 准备

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装ceph repo
yum install centos-release-ceph-luminous -y 
yum update -y
#安装ceph-deploy
yum installl ceph-deploy -y
yum install yum-plugin-priorities -y
#yum install ntp ntpdate ntp-doc -y
#配置管理节点到其他server免密登录
useradd ceph
passwd ceph
su - ceph
ssh-keygen
ssh-copy-id NODE_IP

2. 部署

#在管理节点使用ceph-deploy部署ceph cluster
#创建部署目录
mkdir ~/my-cluster
cd ~/my-cluster
#从头开始(非第一次部署ceph,清理环境)
ceph-deploy purge {ceph-node}[{ceph-node}]
ceph-deploy purgedata {ceph-node}[{ceph-node}]
ceph-deploy forgetkeys
rm ceph.*
##创建集群
#创建monitor节点
#例如:ceph-deploy new {initial-monitor-node(s)}
ceph-deploy new node1 node2 node3
#安装ceph包到各个节点
ceph-deploy install node1 node2 node3
#初始化monitor节点,获取keys
ceph-deploy mon create-initial
#上述命令执行成功后,你会在当前目录下得到keyring文件
#将keyring文件分发到各个节点
ceph-deploy admin node1 node2 node3
#部署manager
ceph-deploy mgr create node1
ceph mgr module enable dashboard 
ceph mgr service #查看dashboard地址
#部署osd节点(这里使用虚拟机,挂载了/dev/vdb卷)
ceph-deploy osd create node1:/dev/vdb node2:/dev/vdb node3:/dev/vdb
#添加metadate server
ceph-deploy mds create node1
#添加rgw实例
#为了使用ceph object gateway,需要部署rgw实例
ceph-deploy rgw create node1
#rgw默认监听端口是7480,可以通过编辑ceph.conf修改端口
[client]
rgw frontends = civetweb port=80

#查看quorum状态
ceph quorum_status --format json-pretty
ceph osd pool create cephfs_metadata 128

#检查集群,在管理节点执行
ceph health
ceph -s

3. 创建虚拟磁盘(如果虚拟机没有硬盘)

dd if=/dev/zero of=/export/ceph/data4.img bs=1M seek=100000 count=0
losetup /dev/loop4 /export/ceph/data4.img   
pvcreate /dev/loop4 -y
vgcreate sdavg4 /dev/loop4 -y
lvcreate -L 97G -n sdalv4 sdavg4 -y
ceph-deploy osd create node1 sdavg4/sdalv4        #ceph-deploy osd create --data sdavg2/sdalv2 YZ-25-58-1

4. 挂载cephfs

ceph osd pool create cephfs_data 128
ceph osd pool create cephfs_metadata 128
ceph fs new cephfs cephfs_metadata cephfs_data

使用mount.ceph挂载

echo `ceph auth get-key client.admin|base64` > /etc/ceph/admin_secret.key
mount.ceph 192.168.60.111:6789,192.168.60.112:6789,192.168.60.113:6789:/ /mnt/mycephfs -o name=admin,secretfile=/etc/ceph/admin_secret.key
# 开机自动挂载
cat >> /etc/fstab << EOF
192.168.60.111:6789,192.168.60.112:6789,192.168.60.113:6789:/     /mnt/mycephfs    ceph    name=admin,secretfile=/etc/ceph/secret.key,noatime,_netdev    0       2
EOF
df -h #查看

使用ceph-fuse挂载

yum install ceph-fuse -y
mkdir -p /etc/ceph
mkdir -p /mnt/mycephfs
# 获取storage-ha-x任意一个节点上的ceph配置文件
scp storage@storage-ha-1:/etc/ceph/ceph.conf /etc/ceph/ceph.conf
# 以下写入的secret请根据'获取用户授权信息'章节中获取到的'key'进行修改
cat > /etc/ceph/ceph.keyring << EOF
[client.admin]
        key = AQAm4L5b60alLhAARxAgr9jQDLopr9fbXfm87w==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[client.fs-test-1]
        key = AQA0Cr9b9afRDBAACJ0M8HxsP41XmLhbSxWkqA==
        caps mds = "allow r, allow rw path=/test-1"
        caps mon = "allow r"
        caps osd = "allow rw tag cephfs data=cephfs"
EOF
# 1. 使用'admin'用户挂载cephfs的根目录
# ip或主机名请根据实际情况修改
ceph-fuse -m 192.168.60.111:6789,192.168.60.112:6789,192.168.60.113:6789 /mnt/mycephfs
# 开机自动挂载
cat >> /etc/fstab << EOF
none    /mnt/ceph  fuse.ceph ceph.id=admin,ceph.conf=/etc/ceph/ceph.conf,_netdev,defaults  0 0
EOF
# 2. 使用只读的用户挂载
mkdir -p /mnt/mycephfs/test_1
mkdir -p /mnt/test_cephfs_1
# 使用'fs-test-1'用户挂载cephfs的根目录
# ip或主机名请根据实际情况修改
# 这里填写的'-n client.fs-test-1'是完整的'client.fs-test-1'.
ceph-fuse -m 192.168.60.111:6789,192.168.60.112:6789,192.168.60.113:6789 -n client.fs-test-1 /mnt/test_cephfs_1

5. 测试

存储、检索对象数据 为了存储对象数据,ceph client需要具备:

  1. 设置一个对象名
  2. 指定一个pool ceph client 检索最近的集群map和CRUSH算法去计算怎样映射对象到PG,然后计算如何动态映射PG到OSD, 只需要对象name和pool name即可找到对象的位置。 ceph osd map {poolname}{object-name}
  3. 练习:定位对象
#创建一个对象,测试文件
echo {Test-data}> testfiles.txt
ceph osd pool create mytest 8
#使用rados put 命令指定对象名,含有对象数据的测试文件,pool name
#rados put {object-name} {file-path} --pool=mytest
rados put test-object-1 testfile.txt --pool=mytest
#验证ceph集群已经存储了此object
rados -p mytest ls
#找到对象位置
#ceph osd map {pool-name} {object-name}
ceph osd map mytest test-oobject-1
#ceph会输出对象位置
osdmap e537 pool 'mytest'(1) object 'test-object-1'-> pg 1.d1743484(1.4)-> up [1,0] acting [1,0]
#删除测试对象object
rados rm test-object-1--pool-mytest
#删除mytest pool
ceph osd pool rm mytest

随着集群的发展,对象位置可能会动态变化。 Ceph的动态重新平衡的一个好处是,Ceph可以让您不必手动执行数据迁移或平衡。

6. 客户端认证使用

#创建一个k8s存储池,用于存放数据卷
ceph osd pool create k8s 64 64
#创建cephx用户,用于挂载由admin创建好的rbd
ceph auth get-or-create client.k8s mon 'allow r' osd 'allow * pool=k8s'
#获取k8s用户的key,以base64编码
ceph auth get-key client.k8s|base64

7. 状态查看

# 查看集群整体状态
ceph -s
# 查看集群健康状态
ceph health
# 查看集群健康状态详情
ceph health detail
# 查看cephfs列表
ceph fs ls
# 查看mds状态
ceph mds stat
# 查看 osd节点状态
ceph osd tree
# 查看监视器情况
ceph quorum_status --format json-pretty
# 查看pool状态信息
rados df
# 查看集群配置
ceph --show-config
ceph-conf -D  |grep mon_allow_pool_delete   

8. 问题记录

问题:ceph_disk.main.Error: Error: Device /dev/sdavg4/sdalv4 is in use by a device-mapper mapping (dm-crypt?): dm-1 解决:升级ceph-deploy版本 #ceph-deploy --version 2.0.1

自动安装

制作离线yum源

方法一

#yum   --downloadonly --downloaddir=./rpms install snappy leveldb gdisk python-argparse gperftools-libs
#yum --downloadonly --downloaddir=./rpms install ceph ceph-radosgw
yum install -c /etc/yum.conf --releasever=7 --installroot=/export/ns/rpm2/root  --downloadonly --downloaddir rpms/ ansible

cd rpms/
createrepo ./
python -m SimpleHTTPServer 8888
# 添加yum源配置:
cat /etc/yum.repos.d/ceph-local.repo 
[local]
name=Ceph packages for $basearch
baseurl=http://192.168.0.180:8888/
enabled=1
gpgcheck=0
type=rpm-md
priority=1

方法二

reposync –r ceph –p /var/www/html/cephyumsource
reposync –r ceph-noarch –p /var/www/html/cephyumsource
reposync –r epel –p /var/www/html/epel
reposync –r centos-updates –p /var/www/html/others
createrepo /var/www/html/cephyumsource/ceph
createrepo /var/www/html/cephyumsource/ceph-noarch
createrepo /var/www/html/epel/epel

ansible安装

  1. ansible安装配置,下载ceph-ansible-3.2.40.tar.gz 解压 yum install ansible

  2. 修改配置

  • 修改hosts文件
[mons]
192.168.0.180
192.168.0.47
192.168.0.65
[osds]
192.168.0.180
192.168.0.47
192.168.0.65
[mdss]
192.168.0.180
[mgrs]
192.168.0.180
  • 修改site.yml文件
---
# Defines deployment design and assigns role to server groups

- hosts:
  - mons
  - osds
  - mdss
  - mgrs
#parted /dev/vdb mklabel gpt 
#parted /dev/vdb print
修改group_vars/all.yml
cluster: ceph                                #集群名
ceph_origin: distro                          #使用distro,则不会使用公网源
ceph_repository: local                       #被操作节点使用本地的repo文件
ceph_stable_release: luminous                #安装版本
ceph_stable: true
ceph_mirror: http://192.168.0.180:8888/
ceph_stable_repo: "{{ ceph_mirror }}"
ceph_stable_redhat_distro: el7
monitor_interface: eth0
public_network: 192.168.0.0/24
修改group_vars/osds.yml
devices:
  - '/dev/vdb'
osd_scenario: collocated
  1. 安装
ansible-playbook -i hosts site.yml

ceph osd pool set cephfs_data pg_num 32
ceph osd pool set cephfs_metadata pg_num 32
ceph osd pool set cephfs_data pgp_num 32
ceph osd pool set cephfs_metadata pgp_num 32