搭建fastdfs集群
1,安装libfastcommongithub选择需要安装的release版本https://github.com/happyfish100/libfastcommon/releases下载安装包[root@ecs-7bc6-0002 src]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39....
1,安装libfastcommon
github选择需要安装的release版本
https://github.com/happyfish100/libfastcommon/releases
下载安装包
[root@ecs-7bc6-0002 src]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
解压
[root@ecs-7bc6-0002 src]# tar -zxvf V1.0.39.tar.gz
安装
[root@ecs-7bc6-0002 src]# cd libfastcommon-1.0.39/
[root@ecs-7bc6-0002 libfastcommon-1.0.39]# ./make.sh
[root@ecs-7bc6-0002 libfastcommon-1.0.39]# ./make.sh install
2,安装fastdfs
1)下载fastdfs
github选择需要安装的release版本
https://github.com/happyfish100/fastdfs/releases
下载安装包
[root@ecs-7bc6-0002 package]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
2)解压
[root@ecs-7bc6-0002 package]# tar -zxvf V5.11.tar.gz
3)编译
[root@ecs-7bc6-0002 fastdfs-5.11]# ./make.sh
4)安装
[root@ecs-7bc6-0002 fastdfs-5.11]# ./make.sh install
5)拷贝配置文件,修改配置
[root@ecs-7bc6-0002 fastdfs-5.11]# cd /etc/fdfs/
[root@ecs-7bc6-0002 fdfs]# cp client.conf.sample client.conf
[root@ecs-7bc6-0002 fdfs]# cp storage.conf.sample storage.conf
[root@ecs-7bc6-0002 fdfs]# cp tracker.conf.sample tracker.conf
6)修改client.conf
# the base path to store log files,日志和数据存储位置,存在的路径
base_path=/home/work/fastdfs
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address tracker_server的ip端口
tracker_server=192.168.1.57:22122
修改trackerd.conf
# the base path to store data and log files
base_path=/home/work/fastdfs
修改storaged.conf
# the base path to store data and log files
base_path=/home/work/fastdfs
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/work/fastdfs
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.57:22122
7)启动
[root@ecs-7bc6-0002 fdfs]# service fdfs_trackerd start
Starting fdfs_trackerd (via systemctl): [ OK ]
[root@ecs-7bc6-0002 fdfs]# service fdfs_storaged start
Starting fdfs_storaged (via systemctl): [ OK ]
[root@ecs-7bc6-0002 fdfs]#
8)测试
上传
[root@ecs-7bc6-0002 fdfs]# fdfs_upload_file /etc/fdfs/client.conf client.conf
group1/M00/00/00/wKgBOVvulymAC1_kAAAFspt4Ii458.conf
下载
[root@ecs-7bc6-0002 fdfs]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgBOVvulymAC1_kAAAFspt4Ii458.conf
[root@ecs-7bc6-0002 fdfs]# ls
client.conf client.conf.sample storage.conf storage.conf.sample storage_ids.conf.sample tracker.conf tracker.conf.sample wKgBOVvulymAC1_kAAAFspt4Ii458.conf
删除
[root@ecs-7bc6-0002 fdfs]# fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgBOVvulymAC1_kAAAFspt4Ii458.conf
3,下载fdfs nginx module
github选择需要安装的release版本
https://github.com/happyfish100/fastdfs-nginx-module/releases
下载安装包
[root@ecs-7bc6-0002 src]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
解压
[root@ecs-7bc6-0002 src]# tar -zxvf V1.20.tar.gz
拷贝配置文件
[root@ecs-7bc6-0002 fdfs]# cd /etc/fdfs
[root@ecs-7bc6-0002 fdfs]# cp /home/work/package/fastdfs-5.11/conf/http.conf ./
[root@ecs-7bc6-0002 fdfs]# cp /home/work/package/fastdfs-5.11/conf/mime.types ./
[root@ecs-7bc6-0002 fdfs]# cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf ./
4,安装nginx
下载安装包
在官网下载nginx最新stable版本
官网:http://nginx.org/en/download.html
下载:
[root@ecs-7bc6-0001 package]# wget http://nginx.org/download/nginx-1.14.1.tar.gz
安装依赖
[root@ecs-7bc6-0001 package]# yum install pcre-devel zlib zlib-devel openssl openssl-devel
安装nginx,配置增加--add-module参数,是下载的fdfs nginx模块目录的src目录
[root@ecs-7bc6-0001 package]# cd nginx-1.14.1
[root@ecs-7bc6-0001 nginx-1.14.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@ecs-7bc6-0002 nginx-1.14.1]# ./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src/
[root@ecs-7bc6-0001 nginx-1.14.1]#make
[root@ecs-7bc6-0001 nginx-1.14.1]#make install
编译错误
/usr/local/src/fastdfs-nginx-module-1.20/src//ngx_http_fastdfs_module.c
In file included from /usr/local/src/fastdfs-nginx-module-1.20/src//common.c:26:0,
from /usr/local/src/fastdfs-nginx-module-1.20/src//ngx_http_fastdfs_module.c:6:
/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory
#include "common_define.h"
^
compilation terminated.
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/home/work/package/nginx-1.14.1'
make: *** [build] Error 2
修改fdfs nginx模块src目录下config文件
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon"#修改
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon"#修改
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
继续编译nginx
5,修改nginx配置,修改nginx安装目录下的conf/nginx.conf,增加server
server {
listen 18000;
server_name localhost;
location ~/group[0-9]/{
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
修改/etc/fdfs/mod
# the base path to store log files
base_path=/home/work/fastdfs
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.1.57:22122
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/work/fastdfs
启动nginx
[root@ecs-7bc6-0002 nginx]# ./sbin/nginx
6,nginx测试,使用文件上传返回的文件id测试
[root@ecs-7bc6-0002 ~]# wget http://127.0.0.1:18000/group1/M00/00/00/wKgBOVvuoLWAcOcVAAAADZGNloA692.txt
7,集群配置
前提是先搭建两个以上的fdfs服务
每个服务stroage.conf增加两个tracker_server
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.57:22122
tracker_server=192.168.1.211:22122
每个服务的client.conf中配置两个tracker_server
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.57:22122
tracker_server=192.168.1.211:22122
同样nginx模块mod_fastdfs.conf
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.1.57:22122
tracker_server=192.168.1.211:22122
8,集群测试
配置ok后,重启每个服务的trackerd server和storaged server
查看trackerd.log日志
[2018-11-19 14:14:56] INFO - file: tracker_relationship.c, line: 389, selecting leader...
[2018-11-19 14:14:58] INFO - file: tracker_service.c, line: 979, the tracker leader is 192.168.1.57:22122
查看storaged.log日志
[2018-11-19 14:14:58] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.1.57:22122, as a tracker client, my ip is 192.168.1.211
[2018-11-19 14:14:58] INFO - file: storage_sync.c, line: 2732, successfully connect to storage server 192.168.1.57:23000
[2018-11-19 14:15:28] INFO - file: tracker_client_thread.c, line: 1263, tracker server 192.168.1.57:22122, set tracker leader: 192.168.1.57:22122
上传文件后,通过nginx下载文件,测试。
恭喜你完成基本的fdfs和集群配置安装(^_^)
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)