花了很長時間安裝ceph,中間走得彎路實在走得太多太多,確實有必要記下來總結一下。期間我也參考不少他人的資料,最後還是在ceph官網的mail-list上熱心人的幫助下才順利把雛形搭建起來。
Ceph系統總共有4個角色,client、mon、mds和osd,我看的資料mon和mds都是裝在了一起。我在Vmware上進行搭建測試。本來搭了三台機子,後來為了中間遇到了些問題,為了排除osd的連接的問題,把mon、mds和osd直接都裝在了一台機子上。這個不影響初期的安裝探索。
准備條件:要求幾台主機能夠免密碼且能根據hostname訪問。具體實現可以參考http://www.linuxidc.com/Linux/2011-01/31579.htm
步驟如下:
1, 首先是client,這是需要ceph.ko這個模塊的支持的。對於老版本的內核,可能要自己手動編譯,把模塊加載進來。如果想知道正在運行著的OS是否已經包含該模塊,cd到目錄/lib/modules/***/kernel/fs/查看當前內核支持的文件類型,如果有ceph這個文件那表示已經包含了該模塊。modprobe ceph加載一下就可以了。$modprobe -l|grep ceph,
kernel/fs/ceph/ceph.ko //返回類似這樣的信息就表示已經加載成功了,客戶端這邊ok了。
2, 如果step 1 已經ok,可以跳過這一步。對於諸如RedHat這樣的系統,選用的內核比較老,需要升級內核至少到2.6.34。因為新版本的內核對ceph提供直接支持。方法有兩個都是直接從別人那裡cpoy來的。
第一種方法
$git clone git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
$cd ceph-client
$make menuconfig
//搜索ceph,可以發現有兩個關於ceph的選項,選上就好.編譯內核的方法這裡//就不在贅述,直接上命令了
$make && make modules && make modules_install && make install && reboot
//上述編譯內核的命令只在redhat系列系統上試過有效,其他發行版可能稍有不同,自己google一下吧。
第二種方法:
$下載源代碼
$ git clone git://ceph.newdream.net/git/ceph-client-standalone.git
$ git branch master-backport origin/master-backport
$ git checkout master-backport
$編譯
$ make or make KERNELDIR=/usr/src/… $前者表示用於當前在用內核,後者其它路徑
$ 編譯成功後會產生ceph.ko
$ make install
$ modprobe ceph or inmod ceph.ko
安裝OSD,這些步驟需要在每個OSD上重復操作。
3.1,去官網下載最新版本源代碼http://ceph.newdream.net/
3.2,解壓安裝。
$tar –xzvf ceph-0.24.tar.gz
$ ./autogen.sh
$ ./configure
$ make
在configure時一般會提示缺少一些包,一次安裝一下就行了,Fedora 14基本都可以用yum來直接安裝。
3.3,准備OSD空間,用fdisk之類的工具分配出一塊獨立分區
3.4,對新分區進行btrfs的格式化
$yum install btrfs-progs.i686
$mkfs.btrfs /dev/sda3
3.5掛載分區
$mkdir –p /mnt/btrfs/osd0
$ mount -t btrfs /dev/cciss/c0d2p1 /mnt/btrfs/osd0/
$ df –h
/dev/sda1 9.7G 4.6G 5.0G 48% /
/dev/sda3 9.3G 4.4M 9.3G 1% /mnt/btrfs/osd0
4, mon和mds安裝
4.1,重復3.1和3.2
4.2,配置ceph.conf和fetch_config配置文件
ceph.conf:
; global
[global]
; enable secure authentication
;auth supported = cephx
; monitors
; You need at least one. You need at least three if you want to
; tolerate any node failures. Always create an odd number.
[mon]
mon data = /data/mon$id
; logging, for debugging monitor crashes, in order of
; their likelihood of being helpful :)
;debug ms = 1
;debug mon = 20
;debug paxos = 20
;debug auth = 20
[mon0]
host = cephosd
mon addr = 192.168.178.160:6789
; mds
; You need at least one. Define two to get a standby.
[mds]
; where the mds keeps it's secret encryption keys
;keyring = /data/keyring.$name
; mds logging to debug issues.
;debug ms = 1
;debug mds = 20
[mds.alpha]
host = cephosd
; osd
; You need at least one. Two if you want data to be replicated.
; Define as many as you like.
[osd]
sudo = true
; This is where the btrfs volume will be mounted.
osd data =/mnt/btrfs/osd0$id
; Ideally, make this a separate disk or partition. A few
; hundred MB should be enough; more if you have fast or many
; disks. You can use a file under the osd data dir if need be
; (e.g. /data/osd$id/journal), but it will be slower than a
; separate disk or partition.
; This is an example of a file-based journal.
osd journal = /mnt/btrfs/osd$id/journal
osd journal size = 1000 ; journal size, in megabytes
; osd logging to debug osd issues, in order of likelihood of being
; helpful
;debug ms = 1
;debug osd = 20
;debug filestore = 20
;debug journal = 20
[osd0]
host = cephosd
; if 'btrfs devs' is not specified, you're responsible for
; setting up the 'osd data' dir. if it is not btrfs, things
; will behave up until you try to recover from a crash (which
; usually fine for basic testing).
btrfs devs = /dev/sda3
osd data = /mnt/btrfs/osd0
; access control
[group everyone]
; you probably want to limit this to a small or a list of
; hosts. clients are fully trusted.
addr = 0.0.0.0/0
[mount /]
allow = %everyone
fetch_config:
#!/bin/sh
conf="$1"
## fetch ceph.conf from some remote location and save it to $conf.
##
## make sure this script is executable (chmod +x fetch_config)
##
## examples:
##
## from a locally accessible file
# cp /path/to/ceph.conf $conf
## from a URL:
# wget -q -O $conf http://somewhere.com/some/ceph.conf
## via scp
# scp -i /path/to/id_dsa user@host:/path/to/ceph.conf $conf
scp qw@cephosd:/qw/ceph-0.24/src/ceph.conf .
Ceph.config是比較重要的,mon要通過他來連接各個osd所以一定要配置正確,很多功能也需要在這裡設置。由於先在測試安裝,所以就選擇了最簡單的配置。fetch_config:在這個文件裡面,我們使用scp的方法,除此還可以使用nfs把ceph.conf文件共享,總之目的就是將在整個集群裡面使用同一份ceph.conf。安裝完了之後,會在/etc/local/etc/下產生ceph文件夾,把這兩個配置文件放在這裡。
4.3 /etc/init.d/ceph 腳本
該腳本在編譯ceph的時候,會在src/裡生成一個init-ceph文件,由init-ceph.in模板來生成
如果需要開機自動啟動ceph集群的話,將該腳本復制到/etc/init.d/目錄下,並使用chkconfig命令來添加該服務.
這個服務應該只需要在monitor端上安裝即可.
4.4創建文件系統,在monitor端執行
$ mkcephfs -c /etc/local/etc/ceph/ceph.conf --allhosts --mkbtrfs -k keyring.bin
它會根據ceph.conf裡面的配置自動的去各個節點上進行相應的配置. 這裡要說一下的是keyring.bin文件,他一開始不存在,其實默認配置下並不需要,可以在src目錄下運行./vstart.sh -n -x會自動產生。
4.5 啟動ceph文件系統
在mon執行
$/etc/init.d/ceph –a start
5.客戶端,掛在系統
$ mkdir /mnt/ceph
$ mount –t ceph 192.168.178.160:/ /mnt/ceph
$df –h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_client-lv_root
18G 9.0G 8.3G 53% /
/dev/sda1 485M 51M 409M 12% /boot
192.168.178.160:/ 9.3G 5.0M 9.3G 1% /mnt/ceph
很多問題會導致出在mount時,無法掛載成功。
1) mount error 5 = Input/output error,這個問題很可能是因為在虛擬機上安裝時host OS的防火牆導致的。
2) can’t read superblock,出現這個問題原因很��,可能是osd和mon的防火牆沒關,也可能端口配置文檔裡修改。還有就是一旦配置文檔發生改變的話,最好mkcephfs重新執行一遍,因為這個命令會生成一些文件還是對應著原先的配置文件。
3) 有問題實在解決不了,還是去ceph的mail-list問,只要你把問題描述清楚。作者還是很熱心的。