版权声明:本博客欢迎转载,转载时请以超链接形式标明文章原始出处!谢谢!
博客地址:http://blog.csdn.net/i_chips
Ubuntu下Ceph单节点和多节点安装小结
崔炳华
2014年2月26日
Ceph是一个分布式文件系统,在维持POSIX兼容性的同时加入了复制和容错功能。Ceph最大的特点是分布式的元数据服务器,通过CRUSH(Controlled Replication Under Scalable Hashing)这种拟算法来分配文件的location。Ceph的核心是RADOS(ReliableAutonomic Distributed Object Store),一个对象集群存储,本身提供对象的高可用、错误检测和修复功能。
Ceph生态系统架构可以划分为四部分:
Ceph支持成百上千甚至更多的节点,以上四个部分最好分布在不同的节点上。当然,对于基本的测试,可以把mon和mds装在一个节点上,也可以把四个部分全都部署在同一个节点上。
“网速较慢”或者“安装软件失败”的情况下,可以考虑替换成国内的镜像:
# sudo sed -i's#us.archive.ubuntu.com#mirrors.163.com#g' /etc/apt/sources.list
# sudo apt-get update
Ubuntu 12.04默认的Ceph版本为0.41,如果希望安装较新的Ceph版本,可以添加key到APT中,更新sources.list:
# sudo wget -q -O- 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'| sudo apt-key add -
# sudo echo deb http://ceph.com/debian/ $(lsb_release -sc) main | sudo tee/etc/apt/sources.list.d/ceph.list
# sudo apt-get update
# date # 查看系统时间是否正确,正确的话则忽略下面两步
# sudo date -s "2013-11-0415:05:57" # 设置系统时间
# sudo hwclock -w # 写入硬件时间
请确保已关闭SELinux(Ubuntu默认未开启)。
另外,建议关闭防火墙:
# sudo ufw disable # 关闭防火墙
# apt-get install ceph ceph-common ceph-mds
# ceph -v # 将显示ceph的版本和key信息
# vim /etc/ceph/ceph.conf
[global]
max open files = 131072
#For version 0.55 and beyond, you must explicitly enable
#or disable authentication with "auth" entries in [global].
auth cluster required = none
auth service required = none
auth client required = none
[osd]
osd journal size = 1000
#The following assumes ext4 filesystem.
filestore xattruse omap = true
#For Bobtail (v 0.56) and subsequent versions, you may
#add settings for mkcephfs so that it will create and mount
#the file system on a particular OSD for you. Remove the comment `#`
#character for the following settings and replace the values
#in braces with appropriate values, or leave the following settings
#commented out to accept the default values. You must specify the
#--mkfs option with mkcephfs in order for the deployment script to
#utilize the following settings, and you must define the 'devs'
#option for each osd instance; see below.
osd mkfs type = xfs
osd mkfs options xfs = -f #default for xfs is "-f"
osd mount options xfs = rw,noatime # default mount option is"rw,noatime"
#For example, for ext4, the mount option might look like this:
#osd mkfs options ext4 = user_xattr,rw,noatime
#Execute $ hostname to retrieve the name of your host,
#and replace {hostname} with the name of your host.
#For the monitor, replace {ip-address} with the IP
#address of your host.
[mon.a]
host = ceph1
mon addr = 192.168.73.129:6789
[osd.0]
host = ceph1
#For Bobtail (v 0.56) and subsequent versions, you may
#add settings for mkcephfs so that it will create and mount
#the file system on a particular OSD for you. Remove the comment `#`
#character for the following setting for each OSD and specify
#a path to the device if you use mkcephfs with the --mkfs option.
devs = /dev/sdb1
[osd.1]
host= ceph1
devs= /dev/sdb2
[mds.a]
host= ceph1
注意,对于较低的Ceph版本(例如0.42),需要在[mon]项下添加一行内容:mondata = /data/$name,以及在[osd]项下添加一行内容:osd data = /data/$name,以作为后续的数据目录;相应的,后续针对数据目录的步骤也需要调整。
# mkdir -p /var/lib/ceph/osd/ceph-0
# mkdir -p /var/lib/ceph/osd/ceph-1
# mkdir -p /var/lib/ceph/mon/ceph-a
# mkdir -p /var/lib/ceph/mds/ceph-a
对新分区进行xfs或者btrfs的格式化:
# mkfs.xfs -f /dev/sdb1
# mkfs.xfs -f /dev/sdb2
第一次必须先挂载分区写入初始化数据:
# mount /dev/sdb1 /var/lib/ceph/osd/ceph-0
# mount /dev/sdb2 /var/lib/ceph/osd/ceph-1
注意,每次执行初始化之前,都需要先停止Ceph服务,并清空原有数据目录:
# /etc/init.d/ceph stop
# rm -rf /var/lib/ceph/*/ceph-*/*
然后,就可以在mon所在的节点上执行初始化了:
# sudo mkcephfs -a -c /etc/ceph/ceph.conf -k /etc/ceph/ceph1.keyring
注意,一旦配置文件ceph.conf发生改变,初始化最好重新执行一遍。
在mon所在的节点上执行:
# sudo service ceph -a start
注意,执行上面这步时,可能会遇到如下提示:
=== osd.0 ===
Mounting xfs onceph4:/var/lib/ceph/osd/ceph-0
Error ENOENT: osd.0 does not exist. create it before updating the crush map
执行如下命令后,再重复执行上面那条启动服务的命令,就可以解决:
# ceph osd create
# sudo ceph health # 也可以使用ceph -s命令查看状态
如果返回的是HEALTH_OK,则代表成功!
注意,如果遇到如下提示:
HEALTH_WARN 576 pgs stuckinactive; 576 pgs stuck unclean; no osds
或者遇到如下提示:
HEALTH_WARN 178 pgs peering; 178pgs stuck inactive; 429 pgs stuck unclean; recovery 2/24 objects degraded(8.333%)
执行如下命令,就可以解决:
# ceph pg dump_stuck stale && cephpg dump_stuck inactive && ceph pg dump_stuck unclean
如果遇到如下提示:
HEALTH_WARN 384 pgs degraded; 384 pgs stuck unclean; recovery 21/42degraded (50.000%)
则说明osd数量不够,Ceph默认至少需要提供两个osd。
客户端挂载mon所在的节点:
# sudo mkdir /mnt/mycephfs
# sudo mount -t ceph 192.168.73.129:6789:/ /mnt/mycephfs
客户端验证:
# df -h #如果能查看到/mnt/mycephfs的使用情况,则说明Ceph安装成功。
对于多节点的情况,Ceph有如下要求:
在每个节点上设置相应的主机名,例如:
# vim /etc/hostname
ceph1
修改/etc/hosts,增加如下几行:
192.168.73.129 ceph1
192.168.73.130 ceph2
192.168.73.131 ceph3
在每个节点上创建RSA秘钥:
# ssh-keygen -t rsa # 一直按确定键即可
# touch /root/.ssh/authorized_keys
先配置ceph1,这样ceph1就可以无密码访问ceph2和ceph3了:
ceph1# scp /root/.ssh/id_rsa.pub ceph2:/root/.ssh/id_rsa.pub_ceph1
ceph1# scp /root/.ssh/id_rsa.pub ceph3:/root/.ssh/id_rsa.pub_ceph1
ceph1# ssh ceph2 "cat /root/.ssh/id_rsa.pub_ceph1>> /root/.ssh/authorized_keys"
ceph1# ssh ceph3 "cat /root/.ssh/id_rsa.pub_ceph1 >> /root/.ssh/authorized_keys"
节点ceph2和ceph3也需要参照上面的命令进行配置。
在每个节点上安装Ceph库:
# apt-get install ceph ceph-common ceph-mds
# ceph -v # 将显示ceph的版本和key信息
# vim /etc/ceph/ceph.conf
[global]
max open files = 131072
#For version 0.55 and beyond, you must explicitly enable
#or disable authentication with "auth" entries in [global].
auth cluster required = none
auth service required = none
auth client required = none
[osd]
osd journal size = 1000
#The following assumes ext4 filesystem.
filestore xattruse omap = true
#For Bobtail (v 0.56) and subsequent versions, you may
#add settings for mkcephfs so that it will create and mount
#the file system on a particular OSD for you. Remove the comment `#`
#character for the following settings and replace the values
#in braces with appropriate values, or leave the following settings
#commented out to accept the default values. You must specify the
#--mkfs option with mkcephfs in order for the deployment script to
#utilize the following settings, and you must define the 'devs'
#option for each osd instance; see below.
osd mkfs type = xfs
osd mkfs options xfs = -f #default for xfs is "-f"
osd mount options xfs = rw,noatime # default mount option is"rw,noatime"
#For example, for ext4, the mount option might look like this:
#osd mkfs options ext4 = user_xattr,rw,noatime
#Execute $ hostname to retrieve the name of your host,
#and replace {hostname} with the name of your host.
#For the monitor, replace {ip-address} with the IP
#address of your host.
[mon.a]
host = ceph3
mon addr = 192.168.73.131:6789
[osd.0]
host = ceph1
#For Bobtail (v 0.56) and subsequent versions, you may
#add settings for mkcephfs so that it will create and mount
#the file system on a particular OSD for you. Remove the comment `#`
#character for the following setting for each OSD and specify
#a path to the device if you use mkcephfs with the --mkfs option.
devs = /dev/sdb1
[osd.1]
host = ceph2
devs= /dev/sdb1
[mds.a]
host = ceph3
配置文件创建成功之后,还需要拷贝到除纯客户端之外的每个节点中(并且后续也要始终保持一致):
ceph1# scp /etc/ceph/ceph.conf ceph2:/etc/ceph/ceph.conf
ceph1# scp /etc/ceph/ceph.conf ceph3:/etc/ceph/ceph.conf
在每个节点上创建数据目录:
# mkdir -p /var/lib/ceph/osd/ceph-0
# mkdir -p /var/lib/ceph/osd/ceph-1
# mkdir -p /var/lib/ceph/mon/ceph-a
# mkdir -p /var/lib/ceph/mds/ceph-a
对于osd所在的节点ceph1和ceph2,需要对新分区进行xfs或者btrfs的格式化:
# mkfs.xfs -f /dev/sdb1
对于节点ceph1和ceph2,第一次必须先分别挂载分区写入初始化数据:
ceph1# mount /dev/sdb1 /var/lib/ceph/osd/ceph-0
ceph2# mount /dev/sdb1 /var/lib/ceph/osd/ceph-1
注意,每次执行初始化之前,都需要在每个节点上先停止Ceph服务,并清空原有数据目录:
# /etc/init.d/ceph stop
# rm -rf /var/lib/ceph/*/ceph-*/*
然后,就可以在mon所在的节点ceph3上执行初始化了:
# sudo mkcephfs -a -c /etc/ceph/ceph.conf -k /etc/ceph/ceph3.keyring
注意,一旦配置文件ceph.conf发生改变,初始化最好重新执行一遍。
在mon所在的节点ceph3上执行:
# sudo service ceph -a start
注意,执行上面这步时,可能会遇到如下提示:
=== osd.0 ===
Mounting xfs onceph4:/var/lib/ceph/osd/ceph-0
Error ENOENT: osd.0 does not exist. create it before updating the crush map
执行如下命令后,再重复执行上面那条启动服务的命令,就可以解决:
# ceph osd create
# sudo ceph health # 也可以使用ceph -s命令查看状态
如果返回的是HEALTH_OK,则代表成功!
注意,如果遇到如下提示:
HEALTH_WARN 576 pgs stuckinactive; 576 pgs stuck unclean; no osds
或者遇到如下提示:
HEALTH_WARN 178 pgs peering; 178pgs stuck inactive; 429 pgs stuck unclean; recovery 2/24 objects degraded(8.333%)
执行如下命令,就可以解决:
# ceph pg dump_stuck stale && cephpg dump_stuck inactive && ceph pg dump_stuck unclean
如果遇到如下提示:
HEALTH_WARN 384 pgs degraded; 384 pgs stuck unclean; recovery 21/42degraded (50.000%)
则说明osd数量不够,Ceph默认至少需要提供两个osd。
客户端(节点ceph3)挂载mon所在的节点(节点ceph3):
# sudo mkdir /mnt/mycephfs
# sudo mount -t ceph 192.168.73.131:6789:/ /mnt/mycephfs
客户端验证:
# df -h #如果能查看到/mnt/mycephfs的使用情况,则说明Ceph安装成功。
1) 《Ceph:一个 Linux PB 级分布式文件系统》,http://www.ibm.com/developerworks/cn/linux/l-ceph/
2) 《Ubuntu 12.04 Ceph分布式文件系统之部署》,http://hobbylinux.blog.51cto.com/2895352/1175932
3) 《How To Install CephOn FC12, FC上安装Ceph分布式文件系统》,http://blog.csdn.net/polisan/article/details/5624207
4) 《Ceph配置说明书》,http://www.doc88.com/p-9062058419946.html