现在的位置: 首页 > 综合 > 正文

HOWTO Install Ceph On FC12, FC上安装Ceph分布式文件系统

2017年12月14日 ⁄ 综合 ⁄ 共 6095字 ⁄ 字号 评论关闭
文章目录
HOWTO Install Ceph On FC12, FC上安装Ceph分布式文件系统

Ceph是一个比较新的分布式文件系统,由USSC的存储小组完成,是一个基于OSD(对象存储设备)的网络文件系统;相关文章发表在OSDI'06,MSST03,04等上.最近又Ceph文件系统的客户端部分已经进入了Linux Kernel 2.6.34里. 
最近花了些时间用VMWare虚拟机搭了一个Ceph.现把搭建的过程,以及其间遇到并解决的问题写在这里.

1.设计一个Ceph集群

Ceph主要分为4个部分,客户端/monitor/mds/osd 
客户端向外export出一个POSIX文件系统接口,共应用程序调用,并连接monitor/mds/osd,进行元数据及数据交互;最原始的客户端使用Fuse来实现的,现在写到内核里面了,需要编译一个ceph.ko内核模块才能使用. 
monitor:管理整个集群,对客户端export出一个网络文件系统,客户端可以通过mount –t ceph monitor_ip:/ mount_point,来挂在ceph文件系统.根据官方的说法,3个monitor可以保证集群的可靠性.对应一个daemon程序,cmon 
mds: 元数据服务器,Ceph里可以有多个MDS,组成元数据服务器集群,就会涉及到Ceph中动态目录分割,来进行负载均衡.对应的daemon: cmds 
osd: osd模拟器,将本地文件系统封装一层对外提供对象存储的接口.这里本地的文件系统可以是ext2,ext3,但ceph认为这些文件系统并不能适应osd特殊的访问模式;它们之前自己实现了ebofs;而现在ceph转用btrfs(google btrfs吧). osd端对应的daemon: cosd. 

ceph支持成百上千甚至更多的节点,那种情况下,4个模块最好分布在不同的机器上;也可以都全部部署在同一台机器上. 
在我的测试环境中,使用4台虚拟机来搭建,1个客户端,monitor/mds在一个节点上;另外两个节点各作一个osd. 
具体的配置如下:

HOSTNAME IP_Addr ROLE
ceph_client 192.168.233.180 Ceph Client
ceph_mds 192.168.233.182 Monitor & MDS
ceph_osd 192.168.233.181 OSD
ceph_osd1 192.168.233.183 OSD

Ceph还要求对四个节点做些操作 
1.修改各自的hostname,并能够通过hostname来互相访问(见附录1) 
2.能够ssh互相访问而不输入密码(具体的方法见附录2);

2.在各个节点上安装Ceph 

2.1 客户端

客户端主要需要ceph.ko这个模块;方式有两种:一种In-tree,一种out-tree;前者在下载最新的linux内核,修改编译选项,编译;后者下载ceph的客户端源码,在内核外编译. 
第一种方法:

$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

第二种方法: 

#下载源代码
$ 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

2.2 其它节点安装ceph

其它节点的代码都是用户态的,在ceph官网上下载较新的代码(目前最新的版本是0.20.1).常规的办法编译即可. 

3.配置ceph集群

除客户端外,其它的节点都需一个配置文件,并需要是完全一样的. 

3.1 ceph.config

这个文件位于/etc/ceph下面,如果在./configure时没有修改prefix的话,应该是在/usr/local/etc/ceph下. 

[root@ceph_mds ceph]# cat ceph.conf 

; Sample ceph ceph.conf file. 

; This file defines cluster membership, the various locations 
; that Ceph stores data, and any other runtime options.

; If a 'host' is defined for a daemon, the start/stop script will 
; verify that it matches the hostname (or else ignore it).  If it is 
; not defined, it is assumed that the daemon is intended to start on 
; the current host (e.g., in a setup with a startup.conf on each 
; node).

; 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

        ; some minimal logging (just message traffic) to aid debugging 
        debug ms = 1

[mon0] 
        host = ceph_mds 
        mon addr = 192.168.233.182: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.alpha] 
        host = ceph_mds

; 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 = /data/osd$id

        ; Ideally, make this a separate disk or partition.  A few GB 
        ; is usually enough; more if you have fast 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. 
        ;osd journal = /data/osd$id/journal

[osd0] 
        host = ceph_osd 
        btrfs devs = /dev/sdb1

[osd1] 
        host = ceph_osd1 
        btrfs devs = /dev/sdb1

; 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

3.2 fetch_config 脚本

该文件同样位于刚才ceph.conf所在目录里面,用来把ceph.conf文件复制到集群里面的各个节点上. 

[root@ceph_mds ceph]# cat 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 root@ceph_mds:/usr/local/etc/ceph/ceph.conf $conf

在这个文件里面,我们使用scp的方法,除此还可以使用nfs把ceph.conf文件共享,总之目的就是将在整个集群里面使用同一份ceph.conf

3.3 /etc/init.d/ceph 脚本

该脚本在编译ceph的时候,会在src/里生成一个init-ceph文件,由init-ceph.in模板来生成 
如果需要开机自动启动ceph集群的话,将该脚本复制到/etc/init.d/目录下,并使用chkconfig命令来添加该服务. 
这个服务应该只需要在monitor端上安装即可. 

4. 让Ceph工作起来

 

4.1 创建ceph文件系统

在monitor端执行 

$ mkcephfs -c /etc/ceph/ceph.conf --allhosts --mkbtrfs -k /etc/ceph/keyring.bin

它会根据ceph.conf里面的配置自动的去各个节点上进行相应的配置. 

4.2 启动ceph文件系统

在monitor端执行 
$ /etc/init.d/ceph –a start 

4.3 客户端挂载ceph文件系统

首先加载ceph.ko 
$ modprobe ceph.ko 
$ mount –t ceph ceph_mds:/ /mnt/ceph 

这样一个ceph集群就搭建起来了. 

5. 搭建过程遇到的问题

当然在这个过程中也遇到了很多问题.如在客户端挂载ceph文件系统时,一直挂载失败,dmesg出以下信息

[root@ceph_client ~]# dmesg -c 
ceph: loaded (mon/mds/osd proto 15/32/24, osdmap 5/5 5/5) 
ceph: mon0 192.168.233.182:6789 connection failed 
ceph: mon0 192.168.233.182:6789 connection failed 
ceph: mon0 192.168.233.182:6789 connection failed 
ceph: mon0 192.168.233.182:6789 connection failed 
ceph: mon0 192.168.233.182:6789 connection failed 
ceph: mon0 192.168.233.182:6789 connection failed

然后我使用netstat命令在monitor端查看6789端口是否已经打开(netstat -anp,可以看到数字形式的端口,还可以看到对应的进程),发现端口已经打开了,如果没有(-n)选项的话,6789端口会以(smc-https)的名称显示. 
接着在客户端扫描6789端口是否已经打开,命令为

[root@ceph_client ~]# nmap -p 6789 192.168.233.182        

Starting Nmap 5.00 ( http://nmap.org ) at 2010-05-25 16:19 CST 
Interesting ports on ceph_mds (192.168.233.182): 
PORT     STATE    SERVICE 
6789/tcp filtered ibm-db2-admin 
MAC Address: 00:0C:29:41:D2:12 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.14 seconds

发现该端口为filtered状态,没有关防火墙...查看iptables服务...禁用iptables服务...然后就ok了.花了好长时间才找出是这个错.不过发现了netstat,nmap这两个非常有用的命令. 
再比如,在创建和启动ceph文件系统时,去osd端去创建btrfs文件系统时打出的log信息里面有 

/sdb1 /data/osd1" 
Scanning for Btrfs filesystems 
failed to read /dev/fd0 
Starting Ceph osd1 on ceph_osd1...

这个failed没有关系,里面的一个脚本,要在osd节点上扫描所有的设备,看下哪个磁盘上创建的是btrfs,我的虚拟机里面都是sata硬盘,没有/dev/fd0,至于为什么有这个设备,我就不知道了. 
总之不是报错.

附录1 修改hostname

google 百度一下吧 
这里主要涉及 /etc/sysconfig/network文件, hostname命令, /etc/hosts文件 

附录2 无需密码ssh访问

原理就是公私钥机制,我要向让别人访问我,那么就要把自己的公钥发给别人,这样他就可以凭该公钥来访问我了.

$ ssh-keygen –d 
#该命令会在~/.ssh下面生成几个文件,这里有用的是id_dsa.pub,为该节点(甲)的公钥,然后把里面的内容添加到对方节点(乙) 
#~/.ssh/目录下的authorized_keys文件中,如果没有则创建一个,这样就从乙节点不需要密码ssh登陆到甲上了.

   

抱歉!评论已关闭.