ceph分布式存储
概述:
1、ceph是一个统一的分布式存储系统,设计初衷是提供较好的性能、可靠性和可扩展性。(Ceph项目最早起源于Sage就读博士期间的工作,最早的成果于2004年发表,并随后贡献给开源社区。在经过了数年的发展之后,目前已得到众多云计算厂商的支持并被广泛应用。RedHat及OpenStack都可与Ceph整合以支持虚拟机镜像的后端存储)
Monitor (centos1) IP:192.168.115.128
OSD (centos2) IP:192.168.115.130
OSD (centos3) IP:192.168.115.131
Client (centos4) IP:192.168.115.132
一、准备工作
1、关闭防火墙,关闭Selinux
systemctl stop firewalld #停止
systemctl disable firewalld #禁用
setenforce 0
2、关闭图形网络管理器
systemctl stop NetworkManager #停止
systemctl disable NetworkManager #禁用
3、配置IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33 #四台虚拟机依次更改
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.115.128
PTRFIX=24
GATEWAY=192.168.115.2
DNS1=192.168.115.2
systemctl restart network #重启网络
4、主机名修改
hostnamectl set-hostname centos1 #按顺序依次更改主机名
5、hosts文件修改
vim /etc/hosts #添加如下:
192.168.115.128 centos1
192.168.115.130 centos2
192.168.115.131 centos3
192.168.115.132 centos4
#传至其他虚拟机,并依次验证域名登录
scp /etc/hosts 192.168.115.130:/etc/hosts
scp /etc/hosts 192.168.115.131:/etc/hosts
scp /etc/hosts 192.168.115.132:/etc/hosts
#域名登录(每个节点主机都需要操作验证)
ssh centos1
ssh centos2
ssh centos3
6、修改ssh配置
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config #不使用DNS反向解析,加快SSH服务器连接速度
systemctl restart sshd #重启服务
7、ssh免密配置
#centos1:
ssh-keygen #一直回车生成密钥对
ssh-copy-id 192.168.115.130 #传送公钥
ssh-copy-id 192.168.115.131
ssh-copy-id 192.168.115.132
#centos2:
ssh-keygen #一直回车生成密钥对
ssh-copy-id 192.168.115.128 #传送公钥
ssh-copy-id 192.168.115.131
ssh-copy-id 192.168.115.132
#centos3:
ssh-keygen #一直回车生成密钥对
ssh-copy-id 192.168.115.128 #传送公钥
ssh-copy-id 192.168.115.130
ssh-copy-id 192.168.115.132
#centos4:
ssh-keygen #一直回车生成密钥对
ssh-copy-id 192.168.115.128 #传送公钥
ssh-copy-id 192.168.115.130
ssh-copy-id 192.168.115.131
8、时间同步
#centos1:
yum install -y ntp #安装ntp
vim /etc/ntp.conf #配置
server 127.127.1.0 #定义时间服务器
fudge 127.127.1.0 stratum 8 #定义时间层次
systemctl start ntpd #开启
systemctl enable ntpd #开机自启
#centos2:
ntpdate 192.168.115.128 #同步centos1时间
#centos3:
ntpdate 192.168.115.128 #同步centos1时间
#centos4:
ntpdate 192.168.115.128 #同步centos1时间
9、添加磁盘
#新添加的磁盘扫描一下:
echo "- - -" > /sys/class/scsi_host/host0/scan #扫描
lsblk #查看
centos1..4:
mkfs.xfs /dev/sdb #格式化成xfs
二、安装ceph
1、安装ceph
#以下操作全部在sentos1虚拟机操作:
yum install epel-release -y #安装源
yum install lttng-ust -y #安装跟踪工具
vim /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
wq #保存退出
yum -y install ceph ceph-deploy #安装ceph与ceph-deploy
2、集群构建
1、创建集群目录
mkdir -p /usr/local/soft/cephcluster #创建目录
cd /usr/local/soft/cephcluster #进入目录
2、创建集群
ceph-deploy new centos1 centos2 centos3
3、修改配置文件
[global]
fsid = 9172fba6-abe8-4328-b61b-abaf39ae43fd
mon_initial_members = centos1, centos2, centos3
mon_host = 192.168.115.128,192.168.115.130,192.168.115.131
auth_cluster_required = cephx
auth_service_required = cephx
auth_client_required = cephx
#对外开放网段
public network = 192.168.115.0/24
# 设置pool池默认分配数量
osd pool default size = 2
# 容忍更多的时钟误差
mon clock drift allowed = 2
mon clock drift warn backoff = 30
# 允许删除pool
mon_allow_pool_delete = true
[mgr]
# 开启WEB仪表盘
mgr modules = dashboard
4、安装
ceph-deploy install centos1 centos2 centos3
5、初始化monitor
ceph-deploy mon create-initial
6、同步管理信息
ceph-deploy admin centos1 centos2 centos3
7、安装mgr(管理守护进程)
ceph-deploy mgr create centos1 centos2 centos3
8、安装rgw
ceph-deploy rgw create centos1 centos2 centos3
9、创建mds服务
ceph-deploy mds create centos1 centos2 centos3
10、OSD安装,创建OSD
ceph-deploy osd create --data /dev/sdb centos1
ceph-deploy osd create --data /dev/sdb centos2
ceph-deploy osd create --data /dev/sdb centos3
11、查看集群状态
ceph -s
3、dashboard
1、开启dashboard模块
ceph mgr module enable dashboard
2、生成签名
ceph dashboard create-self-signed-cert
3、创建目录
mkdir -p /usr/local/jx/cephcluster/mgr-dashboard
cd /usr/local/jx/cephcluster/mgr-dashboard
4、生成证书
openssl req -new -nodes -x509 -subj "/O=IT/CN=ceph-mgr-dashboard" -days 3650 -keyout dashboard.key -out dashboard.crt -extensions v3_ca
5、启动服务
ceph mgr module disable dashboard
ceph mgr module enable dashboard
6、设置访问地址与端口
ceph config set mgr mgr/dashboard/server_addr 192.168.115.128
ceph config set mgr mgr/dashboard/server_port 9001
7、关闭https
ceph config set mgr mgr/dashboard/ssl false
8、查看守护进程
ceph mgr services
9、设置管理面板登录凭证
ceph dashboard set-login-credentials jx123 123.com
10、登录面板
https://192.168.115.128:8443
4、ceph文件系统创建
1、创建存储池
ceph osd pool create cephfs_data 128
ceph osd pool create cephfs_metadata 64
2、查看存储池
ceph osd lspools
3、创建文件系统
ceph fs new fs_test cephfs_metadata cephfs_data
4、查看文件系统
ceph fs ls
5、查看mds状态
ceph mds stat
三、客户端挂载
#centos1:
cd /usr/local/soft/cephcluster #进入目录
ceph-deploy install centos4 #安装
ceph-deploy admin centos4 #同步管理信息
#centos4:
ls /etc/ceph #在客户端查看是否有ceph.client.admin.keyring
mkdir /ceph #创建挂载目录
yum -y install ceph-fuse #安装
ceph-fuse -k /etc/ceph/ceph.client.admin.keyring -m 192.168.115.128:6789 /ceph #挂载ceph文件系统
df -hT #查看