环境准备
1、三台os,centos 7
2、关掉firewalld ,selinux
shell> systemctl stop firewalld && systemctl disable firewalld
shell> sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
3、修改hostsname and /etc/hosts
shell> hostname {ceph_admin,ceph_osd01,ceph_osd02}
shell> echo "127.0.0.1 ceph_admin" >> /etc/hosts
shell> echo "127.0.0.1 ceph_osd01" >> /etc/hosts
shell> echo "127.0.0.1 ceph_osd02" >> /etc/hosts
4、创建ceph的用户 cephd(默认安装ceph的时候会创建ceph,所以这里我们使用一个普通用户,普通用户名称随意设定,这里设置的cephd)
shell> useradd -d /home/cephd -m cephd
shell> ssh ceph_osd01 "useradd -d /home/cephd -m cephd"
shell> ssh ceph_osd02 "useradd -d /home/cephd -m cephd"
shell> echo "cephd ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephd
shell> ssh ceph_osd01 "echo "cephd ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephd"
shell> ssh ceph_osd02 "echo "cephd ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephd"
5、通过普通用户创建免ssh密钥登陆
shell> su - cephd
shell> ssh-keygen
shell> ssh-copy-id -i cephd@ceph_admin
shell> ssh-copy-id -i cephd@ceph_osd01
shell> ssh-copy-id -i cephd@ceph_osd02
shell> ssh cephd@cephd_osd01
shell> ssh cephd@cephd_osd02
6、修改ssh的连接方式,ceph-deploy会读取配置,并使用设置好的用户名进行处理
shell> sudo cat >> ~/.ssh/config << EOF
HOST ceph_admin
Hostname ceph_admin
User cephd
HOST ceph_osd01
Hostname ceph_osd01
User cephd
HOST ceph_osd02
Hostname ceph_osd02
User cephd
EOF
shell> sudo chmod 644 ~/.ssh/config
shell> sudo scp ~/.ssh/config cephd@ceph_osd01:~/.ssh
shell> sudo ssh cephd@ceph_osd01 "sudo chmod 644 ~/.ssh.config"
shell> sudo scp ~/.ssh/config cephd@ceph_osd02:~/.ssh
shell> sudo ssh cephd@ceph_osd02 "sudo chmod 644 ~/.ssh.config"
7、配置yum epel源,默认centos7 不带有这样的仓库,需要额外的添加
shell> sudo yum install -y yum-utils && sudo yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/7/x86_64/ && sudo yum install --nogpgcheck -y epel-release && sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 && sudo rm /etc/yum.repos.d/dl.fedoraproject.org
8、增加repo的仓库
shell> cat >> /etc/yum.repos.d/intceph.repo << EOF
[Ceph]
name=Ceph packages for $basearch
baseurl=http://mirrors.aliyun.com/ceph/rpm-jewel/el7/x86_64/
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-jewel/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-jewel/el7/SRPMS/
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
EOF
shell> sudo scp /etc/yum.repos.d/intceph.repo cephd@cephd_osd01:/etc/yum.repos.d/
shell> sudo scp /etc/yum.repos.d/intceph.repo cephd@cephd_osd02:/etc/yum.repos.d/
9、更新新增repo仓库,让系统缓存新增的仓库
shell> sudo yum update -y && yum install yum-plugin-priorities -y
shell> sudo ssh cephd@cephd_osd01 "sudo yum update -y && yum install yum-plugin-priorities -y"
shell> sudo ssh cephd@cephd_osd02 "sudo yum update -y && yum install yum-plugin-priorities -y"
10、安装ceph-deploy,只需要在ceph_admin节点安装,通过admin节点管理下面的osd节点,以下的所有操作只需要ceph_admin节点操作,特殊情况会说明
shell> sudo yum install -y ceph-deploy
11、清理所有节点的环境,保证os是干净的节点,仅在第一次安装ceph的时候使用,以下的操作在ceph_admin上操作
shell> ceph-deploy purgedata ceph_admin ceph_osd01 ceph_osd02
shell> ceph-deploy forgetkeys
sehll> ceph-deploy purge ceph_admin ceph_osd01 ceph_osd02
12、创建一个目录存ceph配置和密钥,此操作在ceph_admin上操作
shell> sudo mkdir ~/ceph-cluster && sudo cd ~/ceph-cluster
13、创建监听节点,此操作在ceph_admin上操作
shell> ceph-deploy new ceph_admin
14、增加副本数节点,默认是3个节点,实验环境是2个节点,所以这里修改下配置ceph.conf,此操作在ceph_admin上操作
shell> sudo vi ceph.conf
...
...
osd pool default size = 2
15、安装ceph集群,此操作在ceph_admin上操作,如果节点遇到安装超时,可以选择手动安装,复制失败的command命令,安装后,再使用下面的命令
shell> ceph-deploy install ceph_admin ceph_osd01 ceph_osd02
16、安装成功后,初始化监控节点,此操作在监控节点上操作,实验环境是ceph_admin
shell> ceph-deploy --overwrite-conf mon create-initial
17、安装osd存储节点,首先osd是持久存储磁盘,所以要使用大容量的磁盘,可以通过iSCSI,NAS等外界存储使用,这里使用的是外挂的磁盘,此操作在OSD节点上操作
shell> sudo fdisk /etc/sdb
shell> sudo mkfs.xfs /etc/sdb1
shell> sudo mkdir /dataOsd
shell> sudo mount /etc/sdb1 /dataOsd
shell> sudo cat >> /etc/fstab << EOF
/dev/sdb1 /dataOsd xfs defaults 0 0
EOF
18、授予路径权限,此操作在OSD节点上操作
shell> suod chown -R ceph.ceph /cephOsd
19、准备OSD节点初始化,此操作在ceph_admin上操作
shell> ceph-deploy --overwrite-conf osd prepare ceph_osd01:/cephOsd ceph_osd02:/cephOsd
20、激活OSD节点,此操作在ceph_admin上操作
shell> ceph-deploy --overwrite-conf osd activate ceph02:/cephOsd ceph03:/cephOsd
21、将配置文件和密钥拷贝到其他OSD节点,此操作在ceph_admin上操作
shell> ceph-deploy admin ceph_admin ceph_osd01 ceph_osd02
22、修改权限具有可读权限,在所有节点上操作
shell> sudo chmod +r /etc/ceph/ceph.client.admin.keyring
23、检查ceph集群状态,此操作在ceph_admin上操作
shell> ceph -s
shell> ceph health
shell> ceph osd tree
最后:
在实验的过程中总会遇到错误,希望看到这篇blog的同学,不要气馁,学会思考问题.可以通过baidu,Google,ceph doc等方式尝试解决问题。在真实的生产环境使用,请考虑各种常见的问题,持久磁盘的大小,使用场景,io,网络传输等其他问题.希望此篇blog能给你带来帮助。