经费有限, 只准备了两台虚拟机搭建环境,
- 192.168.80.136 ceph-mon & ceph-admin & ceph-mds
- 192.168.80.137 ceph-osd
OS: CentOS 7.2
环境初始化
以下操作需要在集群中所有节点执行
创建用户
useradd -d /home/ceph -m ceph
passwd ceph
添加 ceph 官方 yum 源
cat >> /etc/yum.repos.d/ceph.repo <<eof
[ceph-noarch]
name=Ceph noarch packages
baseurl=https://download.ceph.com/rpm-{ceph-release}/{distro}/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
eof
同步时间
yum install -y ntpdate
cat > /etc/cron.daily/ntpdate <<eof
/usr/sbin/ntpdate cn.ntp.org.cn
eof
chmod +x /etc/cron.daily/ntpdate
sleep 2
/usr/sbin/ntpdate cn.ntp.org.cn && clock -w
为 ceph 用户添加 sudo 权限
echo "ceph ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/ceph
sudo chmod 0440 /etc/sudoers.d/ceph
配置主机名解析
cat >> /etc/hosts <<eof
192.168.80.136 ceph-mon
192.168.80.137 ceph-n1
eof
修改主机名
cat >> /etc/sysconfig/network <<eof
HOSTNAME=ceph-mon
eof
关闭防火墙
systemctl stop iptables.service
systemctl stop firewall.service
关闭 seliunx
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config # 最好重启系统
配置 ssh 无密码登录
以下操作只在 monitor 节点进行
生成 ssh key
ssh-keygen
Generating public/private key pair.
Enter file in which to save the key (/ceph-admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /ceph-admin/.ssh/id_rsa.
Your public key has been saved in /ceph-admin/.ssh/id_rsa.pub.
ssh-copy-id ceph@ceph-n1 # 部署 ssh key
设置 ssh 默认登录账户
cat >> /root/.ssh/config <<eof
Host ceph-n1
User ceph
Host ceph-mon
User ceph
eof
ceph 安装
安装 ceph-deploy
yum update && sudo yum install ceph-deploy
创建新 cluster
ceph-deploy new ceph-mon # 不能用 ip, 不能用 localhost
修改默认数据复制份数
cat >> ./ceph.conf <<eof
osd pool default size = 1 # 因为我们只有一台 osd 所以设置为1
eof
安装 ceph
ceph-deploy install ceph-mon ceph-n1
初始化 monitor
ceph-deploy mon create-initial
添加 osd (由于是测试环境, 我们添加的 osd 是基于目录的)
ssh ceph-n1
sudo mkdir /var/lib/ceph/osd/ceph-0/
exit
ceph-deploy osd prepare ceph-n1:/var/lib/ceph/osd/ceph-0/
ceph-deploy osd active ceph-n1:/var/lib/ceph/osd/ceph-0/
拷贝配置文件及 admin key
ceph-deploy admin ceph-mon ceph-n1
确认 ceph.client.admin.keyring 权限
chmod +r /etc/ceph/ceph.client.admin.keyring
查看集群状态
ceph health # 返回 HEALTH_OK 表示集群正常