FastDFS--tracker安装
在192.168.101.3上安装tracker。
下载
tracker和storage使用相同的安装包,下载地址:http://sourceforge.net/projects/FastDFS/ 或https://github.com/happyfish100/FastDFS(推荐)
本教程下载:FastDFS_v5.05.tar.gz
FastDFS安装环境
FastDFS是C语言开发,建议在linux上运行,本教程使用Centos6.4作为安装环境。
安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++
安装libevent
FastDFS依赖libevent库,需要安装:
yum -y install libevent
安装libfastcommon
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。
将libfastcommonV1.0.7.tar.gz拷贝至/usr/local/下
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。
要拷贝的文件如下:
tracker编译安装
将FastDFS_v5.05.tar.gz拷贝至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下。
配置
安装成功后进入/etc/fdfs目录:
拷贝一份新的tracker配置文件:
cp tracker.conf.sample tracker.conf
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改为:
base_path=/home/FastDFS
启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动的日志显示先停止5619进程(实际环境不是5619)再启动,如下图:
注意:如果没有显示上图要注意是否正常停止原有进程。
设置开机自动启动。
[root@tracker FastDFS]# vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
FastDFS--storage安装
在192.168.101.3上安装storage。
安装libevent
同tracker安装
安装libfastcommon
同tracker安装。
storage编译安装
同tracker编译安装。
配置
安装成功后进入/etc/fdfs目录:
拷贝一份新的storage配置文件:
cp storage.conf.sample storage.conf
修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改为:base_path=/home/FastDFS
store_path0=/home/yuqing/FastDFS改为:store_path0=/home/FastDFS/fdfs_storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......
tracker_server=192.168.101.3:22122 #配置tracker服务器:IP
#如果有多个则配置多个tracker
tracker_server=192.168.101.4:22122
启动
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
启动的日志显示先停止8931进程(实际环境不是8931)再启动,如下图:
注意:如果没有显示上图要注意是否正常停止原有进程。
设置开机自动启动。
[root@storage1 FastDFS]# vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
FastDFS 和nginx整合
- 在tracker上安装nginx
nginx的安装细节参考nginx文档。
在每个tracker上安装nginx,的主要目的是做负载均衡及实现高可用。如果只有一台tracker服务器可以不配置nginx。
- 在Storage上安装nginx
- FastDFS-nginx-module
将FastDFS-nginx-module_v1.16.tar.gz传至/usr/local/下
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
cd FastDFS-nginx-module/src
修改config文件将/usr/local/路径改为/usr/
将FastDFS-nginx-module/src下的mod_FastDFS.conf拷贝至/etc/fdfs/下
cp mod_FastDFS.conf /etc/fdfs/
并修改mod_FastDFS.conf的内容:
vi /etc/fdfs/mod_FastDFS.conf
base_path=/home/FastDFS
tracker_server=192.168.101.3:22122
#tracker_server=192.168.101.4:22122(多个tracker配置多行)
url_have_group_name=true #url中包含group名称
store_path0=/home/FastDFS/fdfs_storage #指定文件存储路径
将libfdfsclient.so拷贝至/usr/lib下
cp /usr/lib64/libfdfsclient.so /usr/lib/
创建nginx/client目录
mkdir -p /var/temp/nginx/client
- nginx安装
添加FastDFS-nginx-module模块
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/root/fastdfs-nginx-module/src
make
make install
- nginx配置文件
新建一个nginx配置文件nginx-fdfs.conf.
添加server:
server {
listen 80;
server_name 192.168.101.3;
location /group1/M00/{
#root /home/FastDFS/fdfs_storage/data;
ngx_fastdfs_module;
}
}
说明:
server_name指定本机ip
location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定义store_path1,这里就是M01