Ceph 單/多節點 安裝小結 power by CentOS 6.x

概述

Docs : http://docs.ceph.com/docs

Ceph是一個分佈式文件系統,在維持POSIX兼容性的同時加入了複製和容錯功能。Ceph最大的特點是分佈式的元數據服務器,通過CRUSH(Controlled Replication Under Scalable Hashing)這種擬算法來分配文件的location。Ceph的核心是RADOS(ReliableAutonomic Distributed Object Store),一個對象集羣存儲,本身提供對象的高可用、錯誤檢測和修復功能。

Ceph生態系統架構可以劃分爲四部分:

client:客戶端(數據用戶)。client向外export出一個POSIX文件系統接口,供應用程序調用,並連接mon/mds/osd,進行元數據及數據交互;最原始的client使用FUSE來實現的,現在寫到內核裏面了,需要編譯一個ceph.ko內核模塊才能使用。
mon:集羣監視器,其對應的daemon程序爲cmon(Ceph Monitor)。mon監視和管理整個集羣,對客戶端export出一個網絡文件系統,客戶端可以通過mount -t ceph monitor_ip:/ mount_point命令來掛載Ceph文件系統。根據官方的說法,3個mon可以保證集羣的可靠性。
mds:元數據服務器,其對應的daemon程序爲cmds(Ceph Metadata Server)。Ceph裏可以有多個MDS組成分佈式元數據服務器集羣,就會涉及到Ceph中動態目錄分割來進行負載均衡。
osd:對象存儲集羣,其對應的daemon程序爲cosd(Ceph Object StorageDevice)。osd將本地文件系統封裝一層,對外提供對象存儲的接口,將數據和元數據作爲對象存儲。這裏本地的文件系統可以是ext2/3,但Ceph認爲這些文件系統並不能適應osd特殊的訪問模式,它們之前自己實現了ebofs,而現在Ceph轉用btrfs。

Ceph支持成百上千甚至更多的節點,以上四個部分最好分佈在不同的節點上。當然,對於基本的測試,可以把mon和mds裝在一個節點上,也可以把四個部分全都部署在同一個節點上。


環境
hostname    ip             role           filesystem   release
master01    192.168.9.10   mon,mds,osd    xfs          CentOS release 6.7[2.6.32-573.8.1.el6.x86_64]
agent01     192.168.9.20   osd,[mon,mds]  xfs          CentOS release 6.7[2.6.32-573.8.1.el6.x86_64]
ocean-lab   192.168.9.70   client         xfs          CentOS release 6.7[4.3.0-1.el6.elrepo.x86_64]

版本
^_^[16:26:11][root@master01 ~]#ceph -v
ceph version 0.80.5 (38b73c67d375a2552d8ed67843c8a65c2c0feba6)


Repo
Epel
yum install ceph ceph-common python-ceph
yum install ceph-fuse        # for client

host 解析
192.168.9.10     master01.ocean.org   master01
192.168.9.20     agent01.ocean.org    agent01
192.168.9.70     ocean-lab.ocean.org  ocean-lab


Ceph 配置
^_^[16:26:15][root@master01 ~]#cat /etc/ceph/ceph.conf
[global]
public network = 192.168.9.0/24
pid file = /var/run/ceph/$name.pid
auth cluster required = none
auth service required = none
auth client required = none
keyring = /etc/ceph/keyring.$name
osd pool default size = 1
osd pool default min size = 1
osd pool default crush rule = 0
osd crush chooseleaf type = 1

[mon]
mon data = /var/lib/ceph/mon/$name
mon clock drift allowed = .15
keyring = /etc/ceph/keyring.$name

[mon.0]
host = master01
mon addr = 192.168.9.10:6789

[mds]
keyring = /etc/ceph/keyring.$name

[mds.0]
host = master01

[osd]
osd data = /ceph/osd$id
osd recovery max active = 5
osd mkfs type = xfs
osd journal = /ceph/osd$id/journal
osd journal size = 1000
keyring = /etc/ceph/keyring.$name

[osd.0]
host = master01
devs = /dev/sdc1
    
[osd.1]
host = master01
devs = /dev/sdc2


啓動ceph(在mon上執行)
初始化:
mkcephfs -a -c /etc/ceph/ceph.conf
/etc/init.d/ceph -a start

執行健康檢查
ceph health            #也可以使用ceph -s命令查看狀態
如果返回的是HEALTH_OK,則代表成功!


掛載ceph
mount
升級系統內核
kernel 2.6.34以前的版本是沒有Module rbd的,把系統內核版本升級到最新
rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-ml  -y

安裝完內核後修改/etc/grub.conf配置文件使
修改配置文件中的 Default=1 to Default=0

驗證內核支持
#modprobe -l|grep ceph
kernel/fs/ceph/ceph.ko
kernel/net/ceph/libceph.ko
#modprobe  ceph
 
機器重啓後生效 init 6

mount -t ceph 192.168.9.10:6789:/ /mnt/ceph
[17:07:39][root@ocean-lab ~]$ df -TH
Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/mapper/vg_oceani-lv_root
                     ext4    30G  7.7G   21G  28% /
tmpfs                tmpfs  111M     0  111M   0% /dev/shm
/dev/sda1            ext4   500M   94M  375M  21% /boot
192.168.9.10:/data2  nfs     30G   25G  4.0G  87% /mnt/log
192.168.9.10:6789:/  ceph   172G  5.4G  167G   4% /mnt/ceph

ceph-fuse [未測]
mon推薦有至少3個,假如掛掉一個、服務也能正常使用
ceph-fuse -m 192.168.9.10:6789,192.168.9.20:6789 /mnt/ceph



增加OSD

http://docs.ceph.com/docs/master/rados/operations/add-or-rm-osds/

這裏在agent01新增硬盤
[15:58:07][root@agent01 ~]$ cat /etc/ceph/ceph.conf
[global]
public network = 192.168.9.0/24
pid file = /var/run/ceph/$name.pid
auth cluster required = none
auth service required = none
auth client required = none
keyring = /etc/ceph/keyring.$name
osd pool default size = 1
osd pool default min size = 1
osd pool default crush rule = 0
osd crush chooseleaf type = 1

[mon]
mon data = /var/lib/ceph/mon/$name
mon clock drift allowed = .15
keyring = /etc/ceph/keyring.$name

[mon.0]
host = master01
mon addr = 192.168.9.10:6789

[mds]
keyring = /etc/ceph/keyring.$name

[mds.0]
host = master01

[osd]
osd data = /ceph/osd$id
osd recovery max active = 5
osd mkfs type = xfs
osd journal = /ceph/osd$id/journal
osd journal size = 1000
keyring = /etc/ceph/keyring.$name

[osd.2]
host = agent01
devs = /dev/sdc1

[osd.3]
host = agent01
devs = /dev/sdc2


master01 ~ $ cd /etc/ceph; scp keyring.client.admin  agent01:/etc/ceph/
以下操作都在新增OSD節點上操作
初始化新增osd節點,需要在新增的節點機器上運行,這裏在10.2.180.180上運行
ceph-osd -i 2 --mkfs --mkkey;
ceph-osd -i 3 --mkfs --mkkey;

加入節點
ceph auth add osd.2 osd 'allow *' mon 'allow rwx' -i /etc/ceph/keyring.osd.2;
ceph auth add osd.3 osd 'allow *' mon 'allow rwx' -i /etc/ceph/keyring.osd.3;
ceph osd create #added key for osd.2
ceph osd create #added key for osd.3
ceph osd rm osd_num    # 刪除osd

/etc/init.d/ceph -a start osd.2 #啓動osd.2
/etc/init.d/ceph -a start osd.3 #啓動osd.3
/etc/init.d/ceph -a start osd   #啓動所有osd
ceph -s #查看狀態
ceph auth list #能查看所有認證節點



增加MDS


增加agent01 MDS到節點
將以下配置增加到配置文件,並同步到節點
[mds.1]
host = agent01
以下操作都在新增OSD節點上操作
生成key
ceph-authtool --create-keyring --gen-key -n mds.1 /etc/ceph/keyring.mds.1
加入認證
ceph auth add mds.1 osd 'allow *' mon 'allow rwx' mds 'allow' -i /etc/ceph/keyring.mds.1
啓動新增MDS
/etc/init.d/ceph -a start mds.1

查看mds

^_^[10:06:51][root@master01 ~]# ceph mds stat

e50: 1/1/1 up {0=0=up:active}, 1 up:standby





增加MON

http://docs.ceph.com/docs/master/rados/operations/add-or-rm-mons/

增加agent01 MDS到節點
將以下配置增加到配置文件,並同步到節點
[mon.1]
host = agent01
mon addr = 192.168.9.20:6789

導出key及mon map
mkdir /tmp/ceph
ceph auth get mon. -o /tmp/ceph/keyring.mon
ceph mon getmap -o /tmp/ceph/monmap

初始化新mon
ceph-mon -i 1 --mkfs --monmap /tmp/ceph/monmap --keyring /tmp/ceph/keyring.mon

啓動新mon
ceph-mon -i 1 --public-addr 192.168.9.20:6789

加入quorum votes
ceph mon add 1 192.168.9.20:6789

查看mon

^_^[10:13:44][root@master01 ~]#ceph mon  stat

e2: 2 mons at {0=192.168.9.10:6789/0,1=192.168.9.20:6789/0}, election epoch 2, quorum 0,1 0,1



FAQ:

^_^[11:19:10][root@master01 ~]#/etc/init.d/ceph  -a start

=== mon.0 === 

Starting Ceph mon.0 on master01...already running

=== mds.0 === 

Starting Ceph mds.0 on master01...already running

=== osd.0 === 

Mounting xfs on master01:/ceph/osd0

Error ENOENT: osd.0 does not exist.  create it before updating the crush map

failed: 'timeout 30 /usr/bin/ceph -c /etc/ceph/ceph.conf --name=osd.0 --keyring=/etc/ceph/keyring.osd.0 osd crush create-or-move -- 0 0.04 host=master01 root=default'

@_@[11:20:59][root@master01 ~]#ceph osd create

0

@_@[11:21:11][root@master01 ~]#ceph osd create

1

^_^[11:21:20][root@master01 ~]#/etc/init.d/ceph start osd.1

=== osd.1 === 

Mounting xfs on master01:/ceph/osd1

create-or-move updated item name 'osd.1' weight 0.04 at location {host=master01,root=default} to crush map

Starting Ceph osd.1 on master01...

starting osd.1 at :/0 osd_data /ceph/osd1 /ceph/osd1/journal




參考:

http://docs.ceph.com/docs/master/rados/configuration/

http://sdwang.blog.51cto.com/8432181/1537530

http://blog.csdn.net/i_chips/article/details/19985795


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章