1, 系统环境

1.1, 操作系统

Gentoo 2007.0 with portage snapshot 20081022, update world in 2008.10.22

1.2, 服务器列表

修改/etc/hosts,加入下面的机器名和IP对应
数据库和track服务器: M-Gentoo IP:10.129.62.243
存储服务器01: S-Gentoo-01 IP:10.129.62.244
存储服务器02: S-Gentoo-02 IP:10.129.62.241

2, 解锁gentoo portage中安装mogilefs所需要的包

echo =dev-perl/mogilefs-server-2.20  ~x86 >> /etc/portage/package.keywords
echo =dev-perl/Danga-Socket-1.59 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/IO-AIO-3.07 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/Gearman-Server-1.09-r1 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/Gearman-1.09 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/Gearman-Client-Async-0.94 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/Perlbal-1.72 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/MogileFS-Utils-2.13 ~x86 >> /etc/portage/package.keywords
echo =dev-perl/MogileFS-Client-1.08 ~x86 >> /etc/portage/package.keywords

3, 安装

USE=”mysql” emerge mogile-server MogileFS-Client MogileFS-Utils
这个过程会将关联的包全部装好

4, 配置

4.1, 数据库

建立数据库
mogdbsetup –dbname=mogilefs –dbuser mogile –dbpass mogile

4.2, tracker

修改tracker服务器配置文件/etc/mogilefs/mogilefsd.conf
db_dsn = DBI:mysql:mogilefs
db_user = mogile
db_pass = mogile

4.3, storage server

修改storage服务器的配置文件/etc/mogilefs/mogstorage.conf
httplisten = 0.0.0.0:7500
mgmtlisten = 0.0.0.0:7501
docroot = /var/mogdata
server = perlbal

5, start server

M-Gentoo: /etc/init.d/mogilefsd start
S-Gentoo-01: /etc/init.d/mogstored start
S-Gentoo-02: /etc/init.d/mogstored start

6, 在tracker中注册存储服务器

mogadm –trackers=M-Gentoo:7001 host add S-Gentoo-01 -status=alive
mogadm –trackers=M-Gentoo:7001 host add S-Gentoo-02 -status=alive

7, 添加设备

建立保存文件的目录,分别在S-Gentoo-01和S-Gentoo-02中的/var/mogdata/下建立dev1和dev2的目录,并在tracker中添加这些device:
mogadm –trackers=M-Gentoo:7001 device add S-Gentoo-01 1 –status=alive
mogadm –trackers=M-Gentoo:7001 device add S-Gentoo-02 2 –status=alive
察看device: mogadm –trackers=M-Gentoo:7001 device list

8, 添加domain和class

增加一个domain: mogadm –trackers=M-Gentoo:7001 domain add project
增加一个class并且设定replication为2份: mogadm –trackers=M-Gentoo:7001 class add project class01 –mindevcount=2

9,测试

http://capoune.net/mogilefs/ 这里提供的php的module在php 5.2.6上面不work,所以改用http://www.sbw.org/File_Mogile/提供的pear的包进行测试.
pear的File_Mogile的类需要Validate的支持,分别下载安装之:
wget http://www.sbw.org/File_Mogile/File_Mogile-0.0.7.tgz
wget http://download.pear.php.net/package/Validate-0.8.1.tgz
pear install Validate-0.8.1.tgz
pear install File_Mogile-0.0.7.tgz

<?php require_once('File/Mogile.php'); $hosts = array('127.0.0.1:7001'); $domain = 'project'; $class = 'class01'; $key = 'file_storage'; //这个为文件的唯一标识! $mogile = new File_Mogile($hosts, $domain,array('socketTimeout' => 0.01,'streamTimeout' =>1.0,'commandTimeout' => 4,)); $mogile->storeData($key, $class, 'I am the walrus.' . "\n"); $paths = $mogile->getPaths($key); var_dump($paths); ?>

参考:

http://mogilefs.pbwiki.com/HowTo

http://danga.com/mogilefs/usage.bml

http://capoune.net/mogilefs/

转自 http://i.19830102.com/archives/55