记录一次离线环境下安装高可用 FastDFS 的过程
FastDFS安装文档
需准备2台机器(安装Centos7操作系统),A,B
A:安装tracker,storage(group1),nginx
B:安装tracker,storage(group2),nginx
默认选择A服务器的tracker作为leader,tracker为从
1.安装libfastcommon包
解压libfastcommon-1.0.40.tar.gz
cd libfastcommon-1.0.40 | ./make.sh | ./make.sh install
ibfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/usr/local/lib,所以此处重新设置软链接:
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
2.安装FastDFS
解压fastdfs-5.11
cd fastdfs-5.11 | ./make.sh | ./make.sh install
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
cd /etc/fdfs
对三个配置文件进行拷贝,备用
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
进入 fastdfs-5.11/conf目录,复制以下文件,http.conf和mime.types为了跟nginx模块整合使用,client.conf是fastdfs的客户端测试文件
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
cp client.conf /etc/fdfs/
3.安装tracker
新建tracker的目录数据文件和日志文件 mkdir /home/face/FastDFS/tracker
编辑tracker配置文件/etc/fdfs/tracker.conf,主要配置参数如下:
port=22122
base_path= /home/face/FastDFS/tracker
work_thread=4 #最好和cpu核数保持一致
store_lookup=0 #选择上传文件模式 0代表group轮询 1指定特定group 2选择空间最大的group
通过命令启动tracker: systemctl start fdfs_trackerd
查看/home/face/fastDFS/tracker目录下的data和logs目录,看是否启动成功
通过netstat命令查看端口监听情况:netstat -unltp|grep fdfs 检测22122
4.安装storage
新建storage的目录数据文件和日志文件 mkdir /home/face/FastDFS/storage | mkdir /home/face/FastDFS/storage/data
编辑storage配置文件/etc/fdfs/storage.conf,主要配置参数如下:
A机器:group_name=group1 B机器:group_name=group2
port=23000
base_path=/home/face/FastDFS/storage
store_path_count=1
store_path0=/home/face/FastDFS/storage/data
tracker_server=A机器ip:22122
tracker_server=B机器ip:22122
通过命令启动storage: systemctl start fdfs_storaged
查看/home/face/fastDFS/storage目录下的data和logs目录,看是否启动成功
看storage服务器是否已经登记到 tracker服务器,运行以下命令:/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
5.安装fastdfs-nginx-module
上面的4个步骤已经可以上传和下载文件,但是fastdfs自己提供的http服务比较简洁,而且会出现数据同步不及时导致的读取数据不存在的情况,所以需要安装nginx模块来解决这个问题。
解压fastdfs-nginx-module-master包
cd fastdfs-nginx-module/src
复制文件到/etc/fdfs/目录下,
cp mod_fastdfs.conf /etc/fdfs/进入/etc/fdfs/,编辑mod_fastdfs.conf,主要配置参数如下:
base_path=/home/face/FastDFS/storage
tracker_server=A机器ip:22122
tracker_server=B机器ip:22122
A机器:group_name=group1 B机器:group_name=group2
url_have_group_name = true
store_path_count=1
store_path0=/home/face/FastDFS/storage/data
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/face/FastDFS/storage/data
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/face/FastDFS/storage/data进入fastdfs-nginx-module/src目录,编辑conf文件,修改如下:
1
ngx_addon_name=ngx_http_fastdfs_module
2
3
if test -n "${ngx_module_link}"; then
4
ngx_module_type=HTTP
5
ngx_module_name=$ngx_addon_name
6
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
7
ngx_module_libs="-lfastcommon -lfdfsclient"
8
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
9
ngx_module_deps=
10
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
11
. auto/module
12
else
13
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
14
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
15
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
16
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
17
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
18
fi
6.安装nginx
解压nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure –prefix=/usr/local/nginx –add-module=/usr/src/fastdfs-nginx-module-master/src
make && make install编辑nginx.conf配置文件,配置如下:
1
upstream fdfs_group1 {
2
server A:8080 weight=1 max_fails=2 fail_timeout=30s;
3
}
4
5
upstream fdfs_group2 {
6
server B:8080 weight=1 max_fails=2 fail_timeout=30s;
7
}
8
9
include /usr/local/nginx/conf/conf.d/*.conf;
创建conf.d文件夹,进入该文件夹,创建tracker.conf和storage.conf
编辑tracker.conf
1
server {
2
listen 80;
3
server_name A;
4
5
location ~ /group1/M00 {
6
proxy_next_upstream http_502 http_504 error timeout invalid_header;
7
proxy_pass http://fdfs_group1;
8
expires 30d;
9
}
10
11
location ~ /group2/M00 {
12
proxy_next_upstream http_502 http_504 error timeout invalid_header;
13
proxy_pass http://fdfs_group2;
14
expires 30d;
15
}
16
}
编辑stroage.conf
A机器:
1
server {
2
listen 8080;
3
server_name A;
4
location ~ /group1/M00 {
5
root /home/face/FastDFS/storage/data;
6
index index.html index.htm;
7
ngx_fastdfs_module;
8
}
9
}
B机器:
1
server {
2
listen 8080;
3
server_name B;
4
location ~ /group2/M00 {
5
root /home/face/FastDFS/storage/data;
6
index index.html index.htm;
7
ngx_fastdfs_module;
8
}
9
}
启动nginx:/usr/local/nginx/sbin/nginx
7.测试文件上传,浏览器访问数据
编辑3个文件: echo “1111” >>/opt/1.txt && echo “2222” >>/opt/2.txt && echo “3333” >>/opt/3.txt
编辑client.conf文件,配置如下:
tracker_server=A机器ip:22122
tracker_server=B机器ip:22122
上传文件:
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 1.txt
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 2.txt
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 3.txt
- 返回结果中会把上传完成的url 打印出来,复制URL在浏览器打开是否正常