环境准备
测试环境是4台虚拟机,所有机器都是刚刚安装好系统(minimal),只配置完网卡和主机名的centos7.7,每个osd增加一块磁盘,/dev/sdb
- ceph-admin ---- admin+mon节点
- ceph-node1 ---- osd节点
- ceph-node2 ---- osd节点
- ceph-node3 ---- osd节点
1、首先在所有节点创建一个部署、管理ceph集群的用户,并授予sudo权限,不建议使用root来运行ceph,同时关闭防火墙和selinux
[root@ceph-admin ~]# useradd cephfsd [root@ceph-admin ~]# echo "ceph123"|passwd cephfsd --stdin Changing password for user cephfsd. passwd: all authentication tokens updated successfully. [root@ceph-admin ~]# echo "cephfsd ALL = (root,ceph) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephfsd cephfsd ALL = (root,ceph) NOPASSWD:ALL [root@ceph-admin ~]# chmod 0440 /etc/sudoers.d/cephfsd [root@ceph-admin ~]# setenforce 0 [root@ceph-admin ~]# sed -i 's/enforcing/disabled/g' /etc/selinux/config [root@ceph-admin ~]# systemctl stop firewalld.service [root@ceph-admin ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@ceph-admin ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.143.121 ceph-admin 172.16.143.122 ceph-node1 172.16.143.123 ceph-node2 172.16.143.124 ceph-node3 [root@ceph-admin ~]# ntpdate ntp1.aliyun.com [root@ceph-admin ~]# vim /etc/rc.local # sync time ntpdate ntp1.aliyun.com
之后,在admin节点使用cephfsd用户登录,开始下一步。
2、配置免密登录,并把秘钥推送到所有osd节点,包括admin自身。
# admin上配置免密登录 [root@ceph-admin ~]# su cephfsd [cephfsd@ceph-admin root]$ cd [cephfsd@ceph-admin ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/cephfsd/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/cephfsd/.ssh/id_rsa. Your public key has been saved in /home/cephfsd/.ssh/id_rsa.pub. The key fingerprint is: SHA256:pmFVNy8T8fw+HWvDFFEDUljFkjBvnd1lOk8L9/v/558 cephfsd@deploy The key's randomart image is: +---[RSA 2048]----+ | .+X==+=| | . o+O.+B| | . o+B=+| | . .oo=+| | o S ++| | . + o.=| | . Bo| | . *| | E@| +----[SHA256]-----+ [cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node1 [cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node2 [cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node3 [cephfsd@ceph-admin ~]$ ssh-copy-id ceph-admin
3、配置yum源,这里使用阿里云的源。(所有节点都要配置yum源。)
# 所有节点都要配置yum源。包括admin和osd和mon。 [cephfsd@ceph-admin ~]$ sudo vim /etc/yum.repos.d/ceph.repo [Ceph] name=Ceph packages for $basearch baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/$basearch enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [Ceph-noarch] name=Ceph noarch packages baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/noarch enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [ceph-source] name=Ceph source packages baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/SRPMS enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [cephfsd@ceph-admin ~]$ sudo yum clean all
4、在admin上安装ceph-deploy。
# admin节点上安装ceph-deploy [cephfsd@ceph-admin ~]$ sudo yum -y install epel-release [cephfsd@ceph-admin ~]$ sudo yum -y install ceph ceph-radosgw ceph-deploy # 如果不做osd,可以不需要安装ceph和ceph-radosgw,我们这里为了保险都安装上。 [cephfsd@ceph-admin ~]$ sudo yum -y install htop sysstat iotop iftop ntp ntpdate
5、在所有节点安装ceph。
如果其他osd节点不能上网,则需要使用自建yum源的方式来使用。
可以参考:http://www.strugglesquirrel.com/2019/04/23/centos7%E9%83%A8%E7%BD%B2ceph/
我们这里能上网,所以我们直接使用yum。
# osd节点配置yum源,这里使用外网的。 [root@ceph-node1 ~]# su cephfsd [cephfsd@ceph-node1 root]$ cd [cephfsd@ceph-node1 ~]$ [cephfsd@ceph-node1 ~]$ sudo vim /etc/yum.repos.d/ceph.repo [Ceph] name=Ceph packages for $basearch baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/$basearch enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [Ceph-noarch] name=Ceph noarch packages baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/noarch enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [ceph-source] name=Ceph source packages baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/SRPMS enabled=1 gpgcheck=0 type=rpm-md gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc priority=1 [cephfsd@ceph-node1 ~]$ sudo yum clean all [cephfsd@ceph-node1 ~]$ sudo yum -y install epel-release [cephfsd@ceph-node1 ~]$ sudo yum -y install ceph ceph-radosgw [cephfsd@ceph-node1 ~]$ sudo yum -y install htop sysstat iotop iftop ntp ntpdate # 其余osd节点也是一样的操作
也可以在ceph-admin节点,用ceph-deploy安装。
[cephfsd@ceph-admin ceph]$ cd /etc/ceph/ [cephfsd@ceph-admin ceph]$ setfacl -R -m u:cephfsd:rwx /etc/ceph [cephfsd@ceph-admin ceph]$ ceph-deploy install ceph-admin ceph-node1 ceph-node2 ceph-node3
6、使用ceph-deploy部署集群:
# 初始化集群配置 [cephfsd@ceph-admin ~]$ cd /etc/ceph [cephfsd@ceph-admin ceph]$ sudo chown -R cephfsd.cephfsd ./ # mon安装在ceph-admin上。 [cephfsd@ceph-admin ceph]$ ceph-deploy new ceph-admin [cephfsd@ceph-admin ceph]$ ls total 112 -rw-r--r--. 1 cephfsd cephfsd 289 Dec 5 20:21 ceph.conf -rw-r--r--. 1 cephfsd cephfsd 76854 Dec 5 20:24 ceph-deploy-ceph.log -rw-------. 1 cephfsd cephfsd 73 Dec 5 23:12 ceph.mon.keyring -rw-r--r--. 1 cephfsd cephfsd 92 Apr 11 2019 rbdmap
初始化集群主要是生成最基本的配置文件ceph.conf
和monitor key文件ceph.mon.keyring
,我们要手动修改ceph.conf
,添加集群公网和集群网络的配置
这里,我们测试环境,先不配置公网与集群网络。
7、修改副本数。
# 修改配置文件ceph.conf,设置osd_pool_default_size副本数为3. [cephfsd@ceph-admin ceph]$ cat ceph.conf [global] fsid = 6d3fd8ed-d630-48f7-aa8d-ed79da7a69eb mon_initial_members = ceph-admin mon_host = 172.16.143.121 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx osd_pool_default_size = 3
8、安装monitor服务。
# 我们这里就设置了一台mon节点。 [cephfsd@ceph-admin ceph]$ ceph-deploy mon create-initial [cephfsd@ceph-admin ceph]$ ls -l total 112 -rw-------. 1 cephfsd cephfsd 71 Dec 5 23:16 ceph.bootstrap-mds.keyring -rw-------. 1 cephfsd cephfsd 71 Dec 5 23:16 ceph.bootstrap-mgr.keyring -rw-------. 1 cephfsd cephfsd 71 Dec 5 23:16 ceph.bootstrap-osd.keyring -rw-------. 1 cephfsd cephfsd 71 Dec 5 23:16 ceph.bootstrap-rgw.keyring -rw-------. 1 cephfsd cephfsd 63 Dec 5 23:16 ceph.client.admin.keyring -rw-r--r--. 1 cephfsd cephfsd 289 Dec 5 20:21 ceph.conf -rw-r--r--. 1 cephfsd cephfsd 76854 Dec 5 20:24 ceph-deploy-ceph.log -rw-------. 1 cephfsd cephfsd 73 Dec 5 23:12 ceph.mon.keyring -rw-r--r--. 1 cephfsd cephfsd 92 Apr 11 2019 rbdmap
9、配置其他osd节点
# mon create-initial会根据ceph.conf进行创建mon,判断monitor都创建成功后,会进行keyring的收集,这些keyring在后续创建其他成员的时候要用到,接下来我们分发集群keyring
# 这个操作是将集群的admin.keyring分发给指定的节点,这样这些节点就可以使用ceph命令了,接下来创建mgr [cephfsd@ceph-admin ceph]$ ceph-deploy admin ceph-node1 ceph-node2 ceph-node3 [cephfsd@ceph-admin ceph]$ ceph-deploy mgr create ceph-admin
10、创建osd
mgr分担了很多原本monitor的工作,目前它也是重要的一个组件,根据集群规模,可以创建2-3个mgr,不过也没有必要太多,接下来可以开始创建osd了
删除磁盘数据(我们是新增的磁盘,可以跳过这步)
# 这里,我们使用的是之前新增的磁盘/dev/sdb,避免与os在同一个分区。 [cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node1 [cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node2 [cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node3
开始创建osd,这里一共创建了三个osd。
# 这里,我们使用的是之前新增的磁盘/dev/sdb,避免与os在同一个分区。 [cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node1 [cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node2 [cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node3
11、查看ceph状态:
[cephfsd@ceph-admin ceph]$ ceph health HEALTH_OK [cephfsd@ceph-admin ceph]$ [cephfsd@ceph-admin ceph]$ ceph -s cluster: id: 6d3fd8ed-d630-48f7-aa8d-ed79da7a69eb health: HEALTH_OK services: mon: 1 daemons, quorum ceph-admin mgr: ceph-admin(active) mds: cephfs-1/1/1 up {0=ceph-node3=up:active}, 2 up:standby osd: 3 osds: 3 up, 3 in data: pools: 2 pools, 128 pgs objects: 21 objects, 7.77KiB usage: 3.00GiB used, 27.0GiB / 30.0GiB avail pgs: 128 active+clean [cephfsd@ceph-admin ceph]$ ceph df GLOBAL: SIZE AVAIL RAW USED %RAW USED 30.0GiB 27.0GiB 3.00GiB 10.02 POOLS: NAME ID USED %USED MAX AVAIL OBJECTS cephfs_data 5 0B 0 8.49GiB 0 cephfs_metadata 6 7.77KiB 0 8.49GiB 21 rbd_data 7 0B 0 8.49GiB 0 [cephfsd@ceph-admin ceph]$
至此,osd全部创建成功了。
12、dashboard配置
dashboard其实就是ceph自带的一个web管理后台。
# 修改/etc/ceph/ceph.conf,增加如下配置。 [cephfsd@ceph-admin ceph]$ vim /etc/ceph/ceph.conf [mgr] mgr modules = dashboard
将主节点上的配置文件推送到从节点。
[cephfsd@ceph-admin ceph]$ ceph-deploy --overwrite-conf config push ceph-node1 ceph-node2 ceph-node3
查看当前集群在使用哪几个模块
[root@ceph-admin ~]# ceph mgr dump { "epoch": 10, "active_gid": 14099, "active_name": "ceph-admin", "active_addr": "172.16.143.121:6800/15303", "available": true, "standbys": [], "modules": [ "balancer", "restful", "status" ], "available_modules": [ "balancer", "dashboard", "influx", "localpool", "prometheus", "restful", "selftest", "status", "zabbix" ], "services": { "dashboard": "http://172.16.143.121:7000/" } } [root@ceph-admin ~]#
使dashboard可用
[cephfsd@ceph-admin ceph]$ ceph mgr module enable dashboard
查看是否支持dashboard
[root@ceph-admin ~]# ceph mgr module ls { "enabled_modules": [ "balancer", "dashboard", "restful", "status" ], "disabled_modules": [ "influx", "localpool", "prometheus", "selftest", "zabbix" ] }
设置dashboard web网页监控的ip及端口(根据需求配置)10.27.0.130为此主机外网ip
[cephfsd@ceph-admin ceph]$ ceph config-key put mgr/dashboard/server_addr 172.16.143.121 set mgr/dashboard/server_addr [cephfsd@ceph-admin ceph]$ ceph config-key put mgr/dashboard/server_port 7000 set mgr/dashboard/server_port
可以使用此命令查看当前设置的值
[cephfsd@ceph-admin ceph]$ ceph config-key dump { "mgr/dashboard/server_addr": "172.16.143.121", "mgr/dashboard/server_port": "7000" } [cephfsd@ceph-admin ceph]$
现在就可以访问了。
http://172.16.143.121:7000/health
13、其他
清理机器上的ceph相关配置:
停止所有进程: stop ceph-all
卸载所有ceph程序:ceph-deploy uninstall [{ceph-node}]
删除ceph相关的安装包:ceph-deploy purge {ceph-node} [{ceph-data}]
删除ceph相关的配置:ceph-deploy purgedata {ceph-node} [{ceph-data}]
删除key:ceph-deploy forgetkeys
卸载ceph-deploy管理:yum -y remove ceph-dep
部署过程中如果出现任何奇怪的问题无法解决,可以简单的删除一切从头再来:
# ceph-deploy purge ceph-mon1 ceph-mon2 ceph-mon3 ceph-osd1 ceph-osd2 # ceph-deploy purgedata ceph-mon1 ceph-mon2 ceph-mon3 ceph-osd1 ceph-osd2 # ceph-deploy forgetkeys
ceph使用的场景主要有三种,块存储场景、对象存储场景和文件系统存储场景,接下来会分别介绍。
http://www.strugglesquirrel.com/2019/04/23/centos7%E9%83%A8%E7%BD%B2ceph/