ceph-ansible-自动化-安装-luminous

之前一直使用ceph-deploy部署ceph,后来学习了ansible,感觉挺好用的,正好ceph官方有一套ceph-ansible 对ceph 进行 自动化 的安装,所以直接拿来用了:

环境准备

IP 主机名 节点 系统
172.28.7.238 cephrepo-001 ceph-ansible Centos7.2.1511
172.28.7.244 cephansible-001 mon、mgr、osd Centos7.2.1511
172.28.7.245 cephansible-002 mon、mgr、osd Centos7.2.1511
172.28.7.246 cephansible-003 mon、mgr、osd Centos7.2.1511

每个虚拟机分别再挂载两块磁盘:/dev/vdb(500G)、/dev/vdc(8G), 分别用于data和db

说明

  1. 这里直接使用root用户部署
  2. 若无特别提醒,都在 172.28.7.238 机器上操作

免密登陆

我们需要ceph-ansible节点对所有的mon、osd、mgr节点进行免密登陆

1
2
3
[172.28.7.238:root@cephrepo-001:/root]# ssh-copy-id root@172.28.7.245
[172.28.7.238:root@cephrepo-001:/root]# ssh-copy-id root@172.28.7.245
[172.28.7.238:root@cephrepo-001:/root]# ssh-copy-id root@172.28.7.245

/etc/hosts 配置

1
2
3
4
5
[172.28.7.238:root@cephrepo-001:/root]# cat /etc/hosts
...
172.28.7.244 cephansible-001
172.28.7.245 cephansible-002
172.28.7.246 cephansible-003

配置源

所有ceph节点删除默认的源文件,然后配置本地源(172.28.7.238)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# cat /etc/yum.repos.d/base.repo
[base]
name=Base repo
baseurl=http://172.28.7.238/mirrors/CentOS/7/os/x86_64
enabled=1
gpgcheck=0
[updates]
name=updates repo
baseurl=http://172.28.7.238/mirrors/CentOS/7/updates/x86_64
enabled=1
gpgcheck=0
[extras]
name=extras repo
baseurl=http://172.28.7.238/mirrors/CentOS/7/extras/x86_64
enabled=1
gpgcheck=0
[centosplus]
name=centosplus repo
baseurl=http://172.28.7.238/mirrors/CentOS/7/centosplus/x86_64
enabled=1
gpgcheck=0
[epel]
name=epel repo
baseurl=http://172.28.7.238/mirrors/CentOS/7/epel
enabled=1
gpgcheck=0
[ceph]
name=Ceph packages for $basearch
baseurl=http://172.28.7.238/mirrors/CentOS/7/ceph/rpm-luminous/el7/$basearch
enabled=1
gpgcheck=0
priority=1
type=rpm-md
gpgkey=http://172.28.7.238/mirrors/CentOS/7/ceph/keys/release.asc
[ceph-noarch]
name=Ceph noarch packages
baseurl=http://172.28.7.238/mirrors/CentOS/7/ceph/rpm-luminous/el7/noarch
enabled=1
gpgcheck=0
priority=1
type=rpm-md
gpgkey=http://172.28.7.238/mirrors/CentOS/7/ceph/keys/release.asc

yum update
rm -rf /etc/yum.repos.d/CentOS-*
yum clean all
yum makecache

时间同步

把 172.28.7.244作为时钟服务器
所有ceph节点执行:

1
# yum install ntp

172.28.7.244执行:

1
2
3
4
5
6
7
8
9
# vim /etc/ntp.conf
注释如下四项:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
# systemctl start ntpd.service
# systemctl enable ntpd.service

172.28.7.245、172.28.7.246执行:

1
2
3
4
5
6
7
8
9
10
11
# vim /etc/ntp.conf
注释如下四项:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
添加如下项:
server 172.28.7.244
# systemctl start ntpd.service
# systemctl enable ntpd.service

依赖安装

我们通过lvm来管理, 所以需要在所有osd节点安装lvm

1
# yum install lvm2

磁盘准备(pv/vg/lv)

mon 节点

如果是生产环境,则会单独准备一块ssd,然后分区挂载到/var/lib/ceph/osd给mon使用,

1
# mount /dev/vdd1 /var/lib/ceph/osd

这里是测试环境,就使用默认的系统文件系统

osd节点

如果是生产环境,综合成本性能考虑,我们会把用作db的ssd磁盘,根据osd个数N,平均分成N个分区。
因为是测试环境,每个节点只有一个osd进程,我们把整块的磁盘给db使用

创建pv

1
2
# pvcreate /dev/vdb
# pvcreate /dev/vdc

创建vg

1
2
# vgcreate data_vg1 /dev/vdb ## data_vg1: vg名称,/dev/vdb: 上面创建的pv 该vg用于data
# vgcreate block_db_vg1 /dev/vdc ## block_db_vg1: vg名称,/dev/vdc: 上面创建的pv 该vg用于db

创建lv

1
2
3
# vgs #查看vgs,需要根据vg的大小来确定lv的大小,lv必须小于或者等于vg
# lvcreate -n data_lv1 -L 499.99g data_vg1 ## data_lv1: lv名称,499.99g:lv大小, data_vg1: 上面创建的vg
# lvcreate -n block_db_lv1 -L 7.99g block_db_vg1 ## block_db_lv1: lv名称, 7.99g: lv大小, block_db_vg1:上面创建的vg

ansible/ceph-ansible安装

在 172.28.7.238 上安装:

1
2
3
4
# pip install ansible==2.3.2
# git clone https://github.com/ceph/ceph-ansible.git
# git checkout remotes/origin/stable-3.1 –b statble-3.1

配置ansible

1
2
3
4
5
6
7
8
9
10
11
12
13
# vim /etc/ansible/hosts
...
[mons]
cephansible-00[1:3]
[osds]
cephansible-00[1:3]
[mgrs]
cephansible-00[1:3]
[mgrs]
cephansible-00[1:3]

配置ceph-ansible

我们需要哪一些,就执行:

1
# cp **.yml.sample **.yml

修改成.yml的格式

site.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# cd ceph-ansible
# cp site.yml.sample site.yml
# vim site.yml
...
## 根据实际选择只保留mons、osds、mgrs
- hosts:
- mons
#- agents
- osds
#- mdss
#- rgws
#- nfss
#- restapis
#- rbdmirrors
- clients
- mgrs
#- iscsi-gws
...

group_vars/all.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# cp group_vars/all.yml.sample group_vars/all.yml
# vim group_vars/all.yml
...
ceph_custom: true
ceph_origin: repository
#ceph_repository: community
ceph_repository: custom
ceph_stable: true
ceph_mirror: http://172.28.7.238/mirrors/CentOS/7/ceph
ceph_stable_key: http://172.28.7.238/mirrors/CentOS/7/ceph/keys/release.asc
ceph_stable_release: luminous
ceph_stable_redhat_distro: el7
cpu_arch: x86_64
ceph_custom_repo: "{{ ceph_mirror }}/rpm-{{ ceph_stable_release }}/{{ ceph_stable_redhat_distro }}/{{ cpu_arch }}"
monitor_address: 172.28.7.239
ip_version: ipv4
public_network: 172.28.4.0/22
#cluster_network: 172.28.7.0/22 #生产环境会分离public和cluster网络,这里测试就没分离
...
generate_fsid: false
fsid: efeda920-833a-492d-85d7-9b409b86a079 ##通过uuidgen生成
...
osd_objectstore: bluestore
...
ceph_conf_overrides:
global:
osd_pool_default_size: 3
osd_pool_default_min_size: 2
mon_osd_backfillfull_ratio: 0.75
mon_osd_full_ratio: .85
mon_osd_nearfull_ratio: .70
osd_failsafe_full_ratio: 0.90
osd_deep_scrub_randomize_ratio: 0.01
osd:
osd_max_write_size: 1024
osd_recovery_op_priority: 1
osd_recovery_max_active: 1
osd_recovery_max_single_start: 1
osd_recovery_max_chunk: 1048576
osd_recovery_threads: 1
osd_max_backfills: 1
osd_scrub_begin_hour: 22
osd_scrub_end_hour: 7
osd_recovery_sleep: 0
osd_crush_update_on_start: false
...

group_vars/mon.yml

mon没有手动修改项,只需要存在mon.yml文件就可以

1
## cp group_vars/mon.yml.sample group_vars/mon.yml

group_vars/osd.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cp group_vars/osd.yml.sample group_vars/osd.yml
# vim group_vars/osd.yml
...
osd_scenario: lvm
...
## 使用前面创建的pv、vg、lv,如果每个主机有多个osd,则由多个 – 组成
lvm_volumes:
- data: data_lv1
data_vg: data_vg1
#wal: block_db_lv1
#wal_vg: block_db_vg1
db: block_db_lv1
db_vg: block_db_vg1
...

group_vars/mgrs.yml

没有改变mgr配置,只需要存在mgrs.yml文件即可

1
# cp group_vars/mgrs.yml.sample group_vars/mgrs.yml

roles/ceph-config/templates/ceph.conf

没有改变ceph.conf,只需要存在ceph.conf文件即可

1
cp roles/ceph-config/templates/ceph.conf.j2 roles/ceph-config/templates/ceph.conf

roles/ceph-defaults/defaults/main.yml

1
2
3
4
5
6
7
8
9
vim roles/ceph-defaults/defaults/main.yml
...
centos_package_dependencies:
- python-pycurl
- hdparm
#- epel-release #注释该项,以免安装默认的epel源
- python-setuptools
- libselinux-python
...

roles/ceph-common/tasks/main.yml

1
2
3
4
5
6
#- name: include checks/check_firewall.yml
# include: checks/check_firewall.yml
# when:
# - check_firewall
# Hard code this so we will skip the entire file instead of individual tasks (Default isn't Consistent)
# static: False

安装

在 172.28.7.238 上执行:

1
2
# cd ceph-ansible
# ansible-playbook site.yml

问题

安装过程mon如果有问题,需要所有 mon 执行如下:

1
systemctl reset-failed ceph-mon@cephansible-00X.service

然后再次执行:

1
# ansible-playbook site.yml

当执行完成后,通过:

1
# ceph -s

可以看到集群已经ok,所有osd也已经up/in
由于我们配置里设置了:osd_crush_update_on_start = False
所以当我们创建pool的时候集群状态会提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
cluster:
id: efeda920-833a-492d-85d7-9b409b86a079
health: HEALTH_WARN
Reduced data availability: 128 pgs inactive
too few PGs per OSD (21 < min 30)
...
data:
pools: 1 pools, 128 pgs
objects: 0 objects, 0 bytes
usage: 6170 MB used, 2993 GB / 2999 GB avail
pgs: 100.000% pgs unknown
128 unknown

解决方式:拷贝osd节点的/etc/ceph/ceph.conf 到172.28.7.238上,然后设置该ceph.conf:
osd_crush_update_on_start = True,然后再把该ceph.conf 拷贝到所有osd节点覆盖, 最后重启所有osd.
通过ansible执行:

1
2
3
4
5
6
7
## 拷贝ceph.conf到所有osd节点
# ansible osds -m copy -a "src=/root/ceph.conf dest=/etc/ceph/ceph.conf owner=ceph group=ceph mode=644 backup=yes"
## 远程重启所有osd节点的 所有ceph-osd服务
# ansible osds -m service -a "name=ceph-osd@* state=restarted"
## 或者限定某台节点:
# ansible osds -m service -a "name=ceph-osd@* state=restarted" --limit "cephansible-001"

注意:因为是测试环境,而且是第一次部署,所以可以这么操作。如果是生产环境的情况下,需要考虑集群的稳定性

最后设置ceph.conf 的osd_crush_update_on_start = False , 然后再次覆盖所有osd的ceph.conf,这次不用重启osd服务

最后附动态调参格式:

1
ceph tell osd.* injectargs "--osd_crush_update_on_start False"