1. 准备环境
我使用的是虚拟机,准备了3台虚拟机,安装CentOS 7 x86_64系统。每台机器是4核CPU,4 GB内存和80 GB存储空间。三台虚拟机hostname分别叫做node1,node2,node3。
存储空间中的50 GB单独分区作为ceph系统的OSD存储空间。划分步骤如下:
a) fdisk -l
查看分区表;
b) 如果分区表个数小于4可以按照如下步骤创建新的分区,linux最多允许4个primary分区。
i) fdisk -c /dev/vda
hit n -> for creating a new partition
hit p -> for creating a primary partition
hit Enter twice -> For selecting the entire available disk space to come under this new partition
hit w for saving the changes and quitting
ii) ### For Best Practice###
iii) Reboot the VM using reboot command OR run partprobe if don't want to reboot.fdisk -c /dev/vda
hit t -> For changing partition type
hit the partition number (1-4): 4 (According to the above example)
hit the hex code for the partition type: 8e -> For making the partition of type linux LVM
hit w for saving the changes and quitting
2. 安装ceps-deploy
我是采用的源码安装的方式:git clone https://github.com/ceph/ceph-deploy.git。也可以直接登录地址https://github.com/ceph/ceph-deploy下载压缩包版本。
run "yum install python-pip"
run "pip install ceph-deploy"
3. 配置
a) 安装ntp
sudo yum install ntp ntpdate ntp-doc
保证启动了NTP服务并且每个节点都使用相同的NTP server。
b) 安装ssh server
sudo yum install openssl-server
c) 创建ceph-deploy账号,这里为了防止后面权限出问题,我使用了root账号作为ceph-deploy的账号。使用root账号前三步可以略过。
ssh root@node1/node2/node3
sudo useradd -d /home/{username} -m {username}
sudo passwd {username}
echo "{username} ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/{username}
sudo chmod 0440 /etc/sudoers.d/{username}
d) 无需密码的ssh访问
在node1的/etc/hosts填入node1,node2,node3的IP地址与hostname的对应关系
run "ssh-keygen" on node1
ssh-copy-id root@node1
ssh-copy-id root@node2
ssh-copy-id root@node3
编辑文件~/.ssh/config, 内容如下:
Host node1
Hostname node1
User root
Host node2
Hostname node2
User root
Host node3
Hostname node3
User root
e) 网络配置
i) 关闭防火墙
sudo firewall-cmd --zone=public --add-service=ceph-mon --permanent
sudo firewall-cmd --zone=public --add-service=ceph --permanent
sudo firewall-cmd --reload
ii) 配置iptables
#port 6789 for ceps-monitors and port 6800:7300 for ceph OSDs#
sudo iptables -A INPUT -i {iface} -p tcp -s {ip-address}/{netmask} --dport 6789 -j ACCEPT
iii) 关闭selinux
sudo setenforce 0
iv) 配置yum源
sudo yum install yum-plugin-priorities
4. 创建集群
a) mkdir my-cluster
cd my-cluster/
b) # 如果想要删掉之前创建的集群,需要执行下面的操作 #
ceph-deploy purge {ceph-node} [{ceph-node}]
ceph-deploy purgedata {ceph-node} [{ceph-node}]
ceph-deploy forgetkeys
rm ceph.*
c) ceph-deploy new node1
d) 在ceph.conf文件的[global]字段中添加“public network = 192.168.42.72/16”,注意mon_host与public network要在同一网段
e) ceph-deploy install node1 node2 node3
# 还可以选择编译源代码的方式安装ceph,但是gcc需要安装4.9+,linux kernel需要安装3+,而且需要安装在/usr/bin目录下,而且需要手动做如下步骤 #
# 创建/etc/ceph #
# 创建/etc/systemd/system/ceph.target,文件内容在github上 #
# 升级libstdc++.so #
f) ceph-deploy mon create-initial
g) ceph-deploy admin node1 node2 node3
h) ceph-deploy osd create node1:vda4 node2:vda4 node3:vda4
ceph-deploy osd activate node1:vda4 node2:vda4 node3:vda4
i) ceph health
ceph -s
5. 扩展集群
a) ceph-deploy mon add node2 node3
检查monitor cluster状态:ceph quorum_status --format json-pretty
b) 安装对象存储gateway
对象存储gateway默认使用端口7480,如果想要修改,可以修改ceph.conf文件,添加如下内容:
[client]
rgw frontends = civetweb port=80
如果是ipv6,添加如下内容:
[client]
rgw frontends = civetweb port=[::]:80
6. 存储/获取对象:
a) 创建pool:
ceph osd pool create my_pool 100 100
ceph osd pool ls
b) 创建对象:
ceph osd map my_pool my_obj
7. Troubleshooting:
ceph -s 出现如下warnings:
a) clock skew detected on mon.node2
时间不同步,可以重设时间同步或者是改大时间同步的容忍阈值。
i) 重新同步:
systemctl stop ntpd
ntpdate #ntp server hostname#
重启mon服务:systemctl restart ceph-mon@node2.service
ii) ceph.conf中添加如下内容:
[mon.node2]
host = node2
mon_data = /var/lib/ceph/mon/ceph-node2
mon_addr = 192.168.42.73:6789
mon clock drift allowed = 2
mon clock drift warn backoff = 30
同步到node2:ceph-deploy --overwrite-conf admin node2
重启mon服务:systemctl restart ceph-mon@node2.service