# Ansible-ceph集群

### 配置hosts解析

```bash
cat >> /etc/hosts <<EOF
172.19.200.8 ceph-node1
172.19.200.15 ceph-node2
172.19.200.13 ceph-node3
EOF

```

### 关闭防火墙和selinux

```bash
systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
```

### 分别在三个节点设置主机名

```bash
hostnamectl set-hostname ceph-node1
hostnamectl set-hostname ceph-node2
hostnamectl set-hostname ceph-node3

```

### 分别在三个节点配置主机时间同步

```bash
yum install chrony python-netaddr -y-y
timedatectl set-timezone Asia/Shanghai
systemctl restart chronyd.service && systemctl enable chronyd.service

```

### 配置免密登录

```bash
ssh-keygen
ssh-copy-id -i .ssh/id_rsa.pub ceph-node1
ssh-copy-id -i .ssh/id_rsa.pub ceph-node2
ssh-copy-id -i .ssh/id_rsa.pub ceph-node3

```

### 安装pip和ansible、git

```bash
yum install python-pip ansible git -y  
```

### 部署ceph集群

> 这里我选择安装的是ceph nautilus 版本 版本: stable-4.0, 推荐这个版本，其他版本会出现无缘无故的问题 依赖: Ansible version 2.9

```bash
git clone https://github.com/ceph/ceph-ansible.git
cd ceph-ansible
git checkout stable-4.0
```

### 安装ansible依赖包

## 无法安装则使用指定安装路径 -i <https://pypi.tuna.tsinghua.edu.cn/simple>

```bash
pip install --upgrade pip
pip3 install -U pip setuptools
pip3 install -r requirements.txt
```

### 修改hosts文件，添加安装的节点

```bash
cat >> ceph-hosts <<EOF
[mons]
ceph-node1
ceph-node2
ceph-node3

[osds]
ceph-node1
ceph-node2
ceph-node3

[mgrs]
ceph-node1
ceph-node2
ceph-node3

[mdss]
ceph-node1
ceph-node2
ceph-node3

[clients]
ceph-node1
ceph-node2
ceph-node3

[rgws]
ceph-node1
ceph-node2
ceph-node3

[grafana-server]
ceph-node1
ceph-node2
ceph-node3
EOF

```

### 备份group\_vars下的yml文件

```bash
cd group_vars
for file in *;do cp $file ${file%.*};done

```

### 修改group\_vars/all.yml配置

```bash
cat > all.yml <<EOF
---
dummy:
############下载包相关的源配置###############
ceph_origin: repository
ceph_origin: repository
ceph_repository: community
ceph_mirror: http://mirrors.aliyun.com/ceph
ceph_stable_key: "{{ ceph_mirror }}/keys/release.asc"
ceph_stable_release: nautilus
ceph_stable_repo: "{{ ceph_mirror }}/rpm-{{ ceph_stable_release }}"

############非常重要参数###################

public_network: "172.19.200.0/24"
cluster_network: "172.19.200.0/24"
monitor_interface: eth0

############创建osd必要的参数###############
osd_auto_discovery: true
osd_objectstore: filestore
radosgw_interface: eth0
dashboard_enabled: true
dashboard_protocol: http
dashboard_port: 8443
dashboard_admin_user: admin
dashboard_admin_password: admin@123!
grafana_admin_user: admin
grafana_admin_password: admin
grafana_uid: 472
grafana_datasource: Dashboard
grafana_dashboard_version: octopus
grafana_port: 3000
grafana_allow_embedding: True
devices:
  - /dev/vdb
  - /dev/vdc

EOF
```

```bash
cd ..
ansible-playbook -i ceph-hosts site.yml

# 等着吧，执行完再去节点上查看: ceph status
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/kubernetes/ceph/ansibleceph-ji-qun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
