最近在研究负载均衡和集群,其中涉及到一个主要的问题是,如何让集群中的real server共享一套文件系统。在网上查到FastDFS,国人(happy fish,感谢他的开源精神)开发的一套轻量级分布式文件系统。实际搭建了一下,感觉还不错,小巧易用,支持http下载。
虽然FastDFS官方网站上已经有比较详细的安装使用手册,但在实际搭建过程中,还是遇到了很多问题,希望我的记录可以让后来的同学们少走一些弯路:)
下面进入正题。
FastDFS安装使用实战(安装篇)
Keywords:FastDFS、分布式文件系统、Ubuntu
Author:soartju
转载请注明出处:http://soartju.iteye.com/blog/803477
目前FastDFS支持Unix系统,在Linux和FreeBSD下测试过,本文使用的是Ubuntu10.4,建议安装之前先简单了解一下FastDFS的原理,这对后继的配置部分会有很好的理解。
一、准备工作-安装libevent
FastDFS内部绑定了libevent作为http服务器,在V2.X版本必须安装libevent,本文安装的是V2.2版本,因此必须安装libevent。(官方也推荐使用http方式下载文件)
如果已经安装了libevent,请确认安装路径是/usr,因为FastDFS在编译源程序时,需要到此目录下查找一些依赖文件,否则编译FastDFS会出错。如果不是,建议首先卸载libevent。Ubuntu10.4默认是安装了libevent,可以到软件中心卸载掉然后按照下面介绍的方式安装。
安装步骤:
1、fastDFS需要安装libevent比较新的版本,首先将本机的比较低的版本卸载了:
rpm -qa libevent
tar zxvf libevent-2.0.18-stable.tar.gz
cd libevent-2.0.18-stable
3、可是注意一点儿,就是如果有需要HTTP连接的需要在make.sh中将#WITH_HTTPD=1改成WITH_HTTPD=1,然后在安装。
4、当我在安装FastDFS时报错了:
- /home/FastDFS/FastDFS/tracker/../common/sched_thread.c:493: undefined reference to `pthread_create' ../common/pthread_func.o:
- In function `init_pthread_lock': /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:32: undefined reference to `pthread_mutexattr_init'
- /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:40: undefined reference to `pthread_mutexattr_settype'
- /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:57: undefined reference to `pthread_mutexattr_destroy' ../common/pthread_func.o:
- In function `init_pthread_attr': /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:84: undefined reference to `pthread_attr_getstacksize'
- /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:115: undefined reference to `pthread_attr_setstacksize' ../common/pthread_func.o:
- In function `create_work_threads': /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:156: undefined reference to `pthread_create'
- ../common/pthread_func.o:
- In function `kill_work_threads': /home/FastDFS/FastDFS/tracker/../common/pthread_func.c:182: undefined reference to `pthread_kill'
- collect2: ld 返回 1 make: *** [fdfs_monitor] 错误 1
经过在网上的查找得知:其实是不同的系统中pthread位置不一样,做法就是找到你的系统中所需要的libpthread.so文件位置,直接find就可以找到了;
- root@ www.linuxidc.com:~# find / -name 'libpthread.a'
- /usr/lib/i386-linux-gnu/xen/libpthread.a
- /usr/lib/i386-linux-gnu/libpthread.a
- root@ www.linuxidc.com:~# find / -name 'libpthread.so'
- /usr/lib/i386-linux-gnu/libpthread.so
接着直接在make.sh中找到这句话然后替换掉就可以了:
- if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then LIBS="$LIBS -lpthread"
然后在进行编译就OK了。
- ./make.sh
- ./make.sh install
- Cd /home/FastDFS/FastDFS/conf/