ceph部署实践(mimic版本)

作者:【吴业亮】

博客:https://wuyeliang.blog.csdn.net/

关于luminous版本的请参照这篇文章

一、准备环境

4台adminos7.4 环境,存储节点上两块磁盘(sda操作系统,sdb数据盘)

client
admin 
storage1
storage2
storage3

二、配置环境

1、修改主机名(对应节点上执行)

# hostnamectl  set-hostname client
# hostnamectl  set-hostname admin
# hostnamectl  set-hostname storage1
# hostnamectl  set-hostname storage2
# hostnamectl  set-hostname storage3

2、配置hosts文件(每个节点上均执行)

# cat <<"EOF">/etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.8.91 client 
172.16.8.92 admin
172.16.8.93 storage1
172.16.8.94 storage2
172.16.8.95 storage3
EOF

3、修改sudo配置文件,注释下面行(每个节点上均执行)
执行visudo命令注释下面一行

#Defaults    requiretty

4、ceph的官方源在国外,网速比较慢,此处添加ceph源为清华源(每个节点上均执行)

# cat <<END >/etc/yum.repos.d/ceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/x86_64/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc

[Ceph-noarch]
name=Ceph noarch packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/noarch/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc

[ceph-source]
name=Ceph source packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/SRPMS/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
END

5、关闭selinux和firewall(各个节点)

# setenforce 0
# sed -i  "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
# systemctl disable firewalld.service
# systemctl stop firewalld.service

6、各个节点更新系统(各个节点)

# yum update -y

注意:如果最新操作系统:此步骤可以省略

7、创建用户并设置密码为Changeme_123(各个节点)

# useradd admin
# echo Changeme_123 | passwd --stdin admin

8、配置sudo权限(各个节点)

# echo -e 'Defaults:admin !requiretty\nadmin ALL = (root) NOPASSWD:ALL' | tee /etc/sudoers.d/ceph 
# chmod 440 /etc/sudoers.d/ceph

9、安装NTP(各个节点)

#  yum -y install ntp

修改配置文件/etc/ntp.conf

server NTP-server
注意:

NTP-server修改为自己的NTP服务器,如果局域网内无NTP服务器,此处可以用默认配置,采用centos官方ntp服务器

启动服务并设置开机启动

# systemctl start ntpd
# systemctl enable ntpd

查看ntp状态

# ntpq -p

注意:

如果ntp时钟不同步,后面ceph服务起不来!

9、重启(各个节点)

# reboot

三、安装和配置ceph(以下操作均在admin节点上执行)

1、配置互信

# su - admin 
$ ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""
$ ssh-copy-id 172.16.8.91
$ ssh-copy-id 172.16.8.92
$ ssh-copy-id 172.16.8.93
$ ssh-copy-id 172.16.8.94
$ ssh-copy-id 172.16.8.95
exit

2、安装ceph-deploy包

$ sudo yum -y install ceph-deploy

注意:最新版的ceph-deploy是2.0,安装操作系统用mimal的ISo会报如下错误,需要安装python-setuptools

[root@storage1 ceph]# ceph-deploy  --help
Traceback (most recent call last):
  File "/bin/ceph-deploy", line 18, in <module>
    from ceph_deploy.cli import main
  File "/usr/lib/python2.7/site-packages/ceph_deploy/cli.py", line 1, in <module>
    import pkg_resources
ImportError: No module named pkg_resources
# yum install python-setuptools 

3、创建配置文件目录

$ mkdir /etc/ceph

4、创建集群

$ cd /etc/ceph 
$ ceph-deploy new storage1 storage2 storage3

注意:如果需要指定网络,创建命令跟以下参数

--cluster-network  
--public-network

5、在各个节点上安装ceph包

# yum -y install ceph ceph-radosgw

6、、设置monitor和key

$ ceph-deploy mon create-initial

注意:执行完成后会在/etc/ceph目录多以下内容:

ceph.client.admin.keyring
ceph.bootstrap-mgr.keyring
ceph.bootstrap-osd.keyring
ceph.bootstrap-mds.keyring
ceph.bootstrap-rgw.keyring
ceph.bootstrap-rbd.keyring
ceph.bootstrap-rbd-mirror.keyring

7、将ceph.client.admin.keyring拷贝到各个节点上

# ceph-deploy admin  storage1 storage2 storage3  

8、安装MGR

# ceph-deploy mgr create  storage1 storage2 storage3

9、启动osd,如果磁盘比较多,安装规划磁盘名称,重复执行即可

# ceph-deploy osd create --data  /dev/sdb storage1
# ceph-deploy osd create --data  /dev/sdb storage2
# ceph-deploy osd create --data  /dev/sdb storage3

拓展:
默认采用的是bluestore,如果需要指定更详细的参数请参照下面步骤:

使用filestore

9.1.1、使用filestore采用journal模式(每个节点数据盘需要两块盘或两个分区)
创建逻辑卷

vgcreate data /dev/sdb 
lvcreate --size 100G --name log data

9.1.2、创建OSD

# ceph-deploy osd create  --filestore   --fs-type xfs --data /dev/sdc  --journal data/log   storage1
# ceph-deploy osd create  --filestore   --fs-type xfs --data /dev/sdc  --journal data/log   storage2
# ceph-deploy osd create  --filestore   --fs-type xfs --data /dev/sdc  --journal data/log   storage3

使用bluestore

9.2.1、创建逻辑卷

vgcreate cache /dev/sdb 
lvcreate --size 100G --name db-lv-0 cache

vgcreate cache /dev/sdb 
lvcreate --size 100G --name wal-lv-0 cache

9.2.2、创建OSD

# ceph-deploy osd create   --bluestore storage1 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0
# ceph-deploy osd create   --bluestore storage2 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0
# ceph-deploy osd create   --bluestore storage3 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0

关于filestore和bluestore的区别这篇文章做了详细的说明,在有ssd的情况下bluestore优势比较明显。

http://www.yuncunchu.org/portal.php?mod=view&aid=74

wal & db 的大小问题

使用混合机械和固态硬盘设置时,block.db为Bluestore创建足够大的逻辑卷非常重要 。通常,block.db应该具有 尽可能大的逻辑卷。
建议block.db尺寸不小于4% block。例如,如果block大小为1TB,则block.db 不应小于40GB。
如果不使用快速和慢速设备的混合,则不需要为block.db(或block.wal)创建单独的逻辑卷。Bluestore将在空间内自动管理这些内容block。

10、验证

$ ceph health 
HEALTH_OK

四、ceph集群对外提供块存储服务(均在client上执行)

1、通过admin用户登录client节点

[admin@client ~]$ sudo chmod 644 /etc/ceph/ceph.client.admin.keyring

2、创建一个存储池

[admin@client ~]$ ceph osd pool create test 128

注意:

创建pool 通常在创建pool之前,需要覆盖默认的pg_num,官方推荐:
若少于5个OSD, 设置pg_num为128。
5~10个OSD,设置pg_num为512。
10~50个OSD,设置pg_num为4096。
超过50个OSD,可以参考pgcalc计算

3、创建一个10G的块

[admin@client ~]$ rbd create disk01 --size 10G --image-feature layering
# rbd create --size 10G disk01 --pool test

4、查看rbd

[admin@client ~]$ rbd ls -l 
NAME     SIZE PARENT FMT PROT LOCK
disk01 10240M          2

5、将10G的块映射到本地

[admin@client ~]$ sudo rbd map disk01 
/dev/rbd0

注意:
因为adminos7默认内核版本比较低,ceph的一些特性无法使用,需要手动禁用才能map成功。命令如下

$ rbd feature disable test/disk01 exclusive-lock object-map fast-diff deep-flatten

6、查看映射

[admin@client ~]$ rbd showmapped 
id pool image  snap device
0  rbd  disk01 -    /dev/rbd0

7、格式化为xfs格式

[admin@client ~]$ sudo mkfs.xfs /dev/rbd0

8、挂载rbd0到本地的目录中

[admin@client ~]$ sudo mount /dev/rbd0 /mnt
[admin@client ~]$ df -hT 
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        26G  1.8G   25G   7% /
devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs               tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run
tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda1           xfs      1014M  231M  784M  23% /boot
tmpfs               tmpfs     396M     0  396M   0% /run/user/0
/dev/rbd0           xfs        10G   33M   10G   1% /mnt

五、使用ceph集群提供cephfs文件系统

1、在admin节点上执行如下命令,启用storage1上的mds服务

[admin@admin ceph]$ ceph-deploy mds create storage1

2、在storage1节点上进行如下操作

[admin@storage1 ~]$ sudo chmod 644 /etc/ceph/ceph.client.admin.keyring

3、创建名为cephfs_data的pool

[admin@storage1 ~]$ ceph osd pool create cephfs_data 128 
pool 'cephfs_data' created

4、创建名为cephfs_metadata的pool

[admin@storage1 ~]$ ceph osd pool create cephfs_metadata 128 
pool 'cephfs_metadata' created

5、启用pool

[admin@storage1 ~]$ ceph fs new cephfs cephfs_metadata cephfs_data 
new fs with metadata pool 2 and data pool 1

6、查看

[admin@storage1 ~]$ ceph fs ls 
name: cephfs, metadata pool: cephfs_metadata, data pools: [cephfs_data ]

7、查看mds状态

[admin@storage1 ~]$ ceph mds stat 
e4: 1/1/1 up {0=storage1=up:creating}

以下操作在client节点上

8、安装rpm包

[root@client ~]# yum -y install ceph-fuse

9、获取admin的key

[root@client ~]# ssh admin@storage1 "sudo ceph-authtool -p /etc/ceph/ceph.client.admin.keyring" > admin.key 
[root@client ~]# chmod 600 admin.key

10、挂载

[root@client ~]# mount -t ceph storage1:6789:/ /mnt -o name=admin,secretfile=admin.key 
[root@client ~]# df -hT 
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        26G  1.9G   25G   7% /
devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs               tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run
tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda1           xfs      1014M  231M  784M  23% /boot
tmpfs               tmpfs     396M     0  396M   0% /run/user/0
172.16.8.94:6789:/    ceph       78G   21G   58G  27% /mnt

六、安装RGW

radosgw的FastCGI可以支持多种类型的WebServer,如Apache2、Nginx等。Ceph从Hammer版本开始,在使用Ceph-deploy的情况下默认使用内置的civetweb替代旧版本的Apache2部署方式。

6.1、安装rgw服务

# ceph-deploy rgw create  storage1 storage2 storage3

6.2、查看状态

[root@storage1 ceph]# ceph -s
  cluster:
    id:     9eb106eb-2af4-4aaf-bcdb-58e95bce828c
    health: HEALTH_OK
 
  services:
    mon: 3 daemons, quorum storage1,storage2,storage3
    mgr: storage3(active), standbys: storage1, storage2
    osd: 3 osds: 3 up, 3 in
    rgw: 3 daemons active
 
  data:
    pools:   4 pools, 32 pgs
    objects: 189  objects, 2.2 KiB
    usage:   3.0 GiB used, 237 GiB / 240 GiB avail
    pgs:     32 active+clean
 
  io:
    client:   48 KiB/s rd, 0 B/s wr, 57 op/s rd, 38 op/s wr

七、安装dashboard
mimic 版 dashboard 安装
1、添加mgr 功能

# ceph-deploy mgr create node1 node2 node3

2、开启dashboard 功能

# ceph mgr module enable dashboard

3、创建证书

# ceph dashboard create-self-signed-cert

4、创建 web 登录用户密码

# ceph dashboard set-login-credentials user-name password

5、查看服务访问方式

# ceph mgr services

6、在/etc/ceph/ceph.conf中添加

[mgr]
mgr modules = dashboard

7、设置dashboard的ip和端口

ceph config-key put mgr/dashboard/server_addr 192.168.8.106
ceph config-key put mgr/dashboard/server_port 7000

8、登录:

https://172.16.8.94:7000

在这里插入图片描述
八、通过grafana监控ceph
1、启用Prometheus监控模块:

# ceph mgr module enable prometheus
# ss -tlnp|grep 9283
LISTEN     0      5           :::9283                    :::*                   users:(("ceph-mgr",pid=3715,fd=70))

2、安装Prometheus:
下载软件包

wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz

将prometheus拷贝到/usr/local/bin/下

# tar -zxvf prometheus-*.tar.gz                            
# cd prometheus-*
# cp prometheus promtool /usr/local/bin/
# prometheus --version
prometheus, version 2.3.2 (branch: HEAD, revision: 71af5e29e815795e9dd14742ee7725682fa14b7b)
  build user:       root@5258e0bd9cc1
  build date:       20180712-14:02:52
  go version:       go1.10.3

3、配置prometheus服务

# mkdir /etc/prometheus 
# mkdir /var/lib/prometheus  

4、创建 /usr/lib/systemd/system/prometheus.service

# vim /usr/lib/systemd/system/prometheus.service                         ###配置启动项
[Unit]
Description=Prometheus
Documentation=https://prometheus.io

[Service]
Type=simple
WorkingDirectory=/var/lib/prometheus
EnvironmentFile=-/etc/prometheus/prometheus.yml
ExecStart=/usr/local/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/

[Install]
WantedBy=multi-user.target

5、创建配置文件

# vim /etc/prometheus/prometheus.yml                           ##配置配置文件
global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['172.16.8.94:9090']      #storage1的IP
  - job_name: 'ceph'
    static_configs:
      - targets:
          - 172.16.8.94:9283
          - 172.16.8.95:9283
          - 172.16.8.96:9283

6、启动服务

# systemctl daemon-reload
# systemctl start prometheus
# systemctl status prometheus

7、验证:

http://172.16.8.94:9090/graph

在这里插入图片描述

6、安装grafana:

# yum -y localinstall https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.2-1.x86_64.rpm 
# systemctl start grafana-server
# systemctl status grafana-server

7、登录grafana

http://172.16.8.94:9000/

默认用户名和密码:admin/admin,登录后需要修改密码。

8、添加数据源
参照:

http://blog.51cto.com/wangzhijian/2156186

下载json

https://grafana.com/dashboards/917

附录:

1、卸载
在admin节点上执行卸载rpm包

$ ceph-deploy purge admin storage1 storage2 storage3

在admin节点上执行,删除配置

$ ceph-deploy purgedata admin storage1 storage2 storage3
 
$ ceph-deploy forgetkeys

2、修复一个HEALTH_WARN

[root@storage1 ~]# ceph -s
  cluster:
    id:     9eb106eb-2af4-4aaf-bcdb-58e95bce828c
    health: HEALTH_WARN
            application not enabled on 1 pool(s)
 
  services:
    mon: 3 daemons, quorum storage1,storage2,storage3
    mgr: storage3(active), standbys: storage1, storage2
    osd: 3 osds: 3 up, 3 in
    rgw: 3 daemons active
 
  data:
    pools:   5 pools, 96 pgs
    objects: 2.79 k objects, 9.8 GiB
    usage:   18 GiB used, 222 GiB / 240 GiB avail
    pgs:     96 active+clean

通过ceph health detail查看原因

[root@storage1 ~]# ceph health detail
HEALTH_WARN application not enabled on 1 pool(s)
POOL_APP_NOT_ENABLED application not enabled on 1 pool(s)
   application not enabled on pool 'test'
   use 'ceph osd pool application enable <pool-name> <app-name>', where <app-name> is 'cephfs', 'rbd', 'rgw', or freeform for custom applications.

解决办法

# ceph osd pool application enable test  rbd

3、删除 pool

先在ceph.conf 增加下面:

mon_allow_pool_delete = true

并重启ceph-mon:

systemctl restart ceph-mon@storage1
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值