第一步:安装依赖
# yum install gcc libevent libevent-devel -y
# rm -rf /etc/fdfs
需要的安装包:
1.fastdfs-5.12.tar.gz
2.libfastcommon-1.0.42.tar.gz -- 公共函数库
3.fastdfs-nginx-module-1.20.tar.gz
第二步:下载安装包(注意版本兼容性)
wget https://github.com/happyfish100/fastdfs/archive/V5.12.tar.gz
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.42.tar.gz
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
1.安装公共函数库
# tar -zxvf V1.0.42.tar.gz
# cd libfastcommon-1.0.42/
#
# ./make.sh --编译
# ./make.sh install -- 安装
2.安装fastdfs
# tar -zxvf V5.12.tar.gz
# cd fastdfs-5.12/
# ./make.sh --编译
# ./make.sh install -- 安装
# 检查/usr/bin
# cd /usr/bin
# 安装后该目录下会有如下几个以fdfs*开头的文件,都是命令脚本:
fdfs_appender_test
fdfs_appender_test1
fdfs_append_file
fdfs_crc32
fdfs_delete_file
fdfs_download_file
fdfs_file_info
fdfs_monitor
fdfs_storaged
fdfs_test
fdfs_test1
fdfs_trackerd
fdfs_upload_appender
fdfs_upload_file
# 检查:/etc/fdfs目录
# cd /etc/fdfs
# 该目录下会有如下配置文件:
总用量 24
-rw-r--r--. 1 root root 1461 10月 27 15:53 client.conf.sample
-rw-r--r--. 1 root root 7978 10月 27 15:53 storage.conf.sample
-rw-r--r--. 1 root root 105 10月 27 15:53 storage_ids.conf.sample
-rw-r--r--. 1 root root 7443 10月 27 15:53 tracker.conf.sample
[root@centos-node1 fdfs]#
client.conf.sample -- 客户端连接使用的配置文件
storage.conf.sample -- 存储器配置问文件
tracker.conf.sample -- 追踪器配置文件
# 拷贝fastdfs-5.12/conf目录下的http.conf与mime.types到/etc/fdfs目录
# cd fastdfs-5.12/conf
# cp http.conf /etc/fdfs/
# cp mime.types /etc/fdfs/
【配置】
0.创建相关配置目录
# mkdir -p /opt/fastdfs/tracker
# mkdir -p /opt/fastdfs/storage
# mkdir -p /opt/fastdfs/storage/files
# mkdir -p /opt/fastdfs/client
# cd /etc/fdfs/
1.配置:tracker
# cp tracker.conf.sample tracker.conf
# vim tracker.conf
base_path=/opt/fastdfs/tracker --日志文件保存位置
2.配置:storage
# cp storage.conf.sample storage.conf
# vim storage.conf
base_path=/opt/fastdfs/storage
store_path0=/opt/fastdfs/storage/files
tracker_server=192.168.199.227:22122
3.配置:client
# cp client.conf.sample client.conf
# vim client.conf
base_path=/opt/fastdfs/client
tracker_server=192.168.199.227:22122
【启动服务】
# fdfs_trackerd
[root@centos-node1 fdfs]# fdfs_trackerd
Usage: fdfs_trackerd <config_file> [start | stop | restart]
# fdfs_trackerd /etc/fdfs/tracker.conf start
# ps -ef|grep tracker|grep -v grep
root 2352 1904 0 15:31 ? 00:00:00 /usr/libexec/tracker-extract
root 2359 1904 0 15:31 ? 00:00:00 /usr/libexec/tracker-miner-fs
root 2364 1904 0 15:31 ? 00:00:00 /usr/libexec/tracker-miner-apps
root 2374 1904 0 15:31 ? 00:00:00 /usr/libexec/tracker-miner-user-guides
root 2382 1 0 15:31 ? 00:00:00 /usr/libexec/tracker-store
root 4000 1 0 16:26 ? 00:00:00 fdfs_trackerd /etc/fdfs/tracker.conf start
# fdfs_storaged /etc/fdfs/storage.conf start
# ps -ef|grep storage|grep -v grep
/opt/fastdfs/storage/files/data目录下会创建256个文件夹,然后每个文件夹下面还会创建256个文件夹
也即是:256*256=65536个文件夹下面
【查看FastDFS进程启动情况】
1.ps -ef|grep fdfs|grep -v grep
[root@centos-node1 data]# ps -ef|grep fdfs|grep -v grep
root 4000 1 0 16:26 ? 00:00:00 fdfs_trackerd /etc/fdfs/tracker.conf start
root 4059 1 2 16:30 ? 00:00:07 fdfs_storaged /etc/fdfs/storage.conf
[root@centos-node1 data]#
【关闭服务】
1.使用命令
step1:
# fdfs_trackerd /etc/fdfs/tracker.conf stop
step2:
# fdfs_storaged /etc/fdfs/storage.conf stop
2.直接kill进程 - 一般不建议这么做
【命令总结】
1.启动
# fdfs_trackerd /etc/fdfs/tracker.conf start
# fdfs_storaged /etc/fdfs/storage.conf start
2.停止
# fdfs_trackerd /etc/fdfs/tracker.conf stop
# fdfs_storaged /etc/fdfs/storage.conf stop
3.查看
# ps -ef|grep fdfs|grep -v grep
# ps -ef|grep tracker|grep -v grep
# ps -ef|grep storage|grep -v grep
【测试上传】
# fdfs_test /etc/fdfs/client.conf -- 获取提示信息
[root@centos-node1 usr]# fdfs_test /etc/fdfs/client.conf
Usage: fdfs_test <config_file> <operation>
operation: upload, download, getmeta, setmeta, delete and query_servers
#
[root@centos-node1 client]# fdfs_test /etc/fdfs/client.conf upload
This is FastDFS client test program v5.12
Usage: fdfs_test <config_file> upload <local_filename> [FILE | BUFF | CALLBACK]
最终命令格式:fdfs_test <config_file> upload <local_filename>
#
[root@node1 local]# fdfs_test /etc/fdfs/client.conf upload /usr/local/software/fastdfs/test_files/beaux0.jpg
This is FastDFS client test program v5.12
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2020-10-27 17:02:54] DEBUG - base_path=/opt/fastdfs/client, connect_timeout=10, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.199.227, port=23000
group_name=group1, ip_addr=192.168.199.227, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjH41-X4j6ADPlDAAFxsEtzmNo508.jpg
source ip address: 192.168.199.227
file timestamp=2020-10-27 17:02:54
file size=94640
file crc32=1265866970
example file url: http://192.168.199.227/group1/M00/00/00/wKjH41-X4j6ADPlDAAFxsEtzmNo508.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKjH41-X4j6ADPlDAAFxsEtzmNo508_big.jpg
source ip address: 192.168.199.227
file timestamp=2020-10-27 17:02:54
file size=94640
file crc32=1265866970
example file url: http://192.168.199.227/group1/M00/00/00/wKjH41-X4j6ADPlDAAFxsEtzmNo508_big.jpg
[root@centos-node1 client]#
# cd /opt/fastdfs/storage/files/data/00/00
-rw-r--r--. 1 root root 94640 10月 27 17:02 wKjH41-X4j6ADPlDAAFxsEtzmNo508_big.jpg
-rw-r--r--. 1 root root 49 10月 27 17:02 wKjH41-X4j6ADPlDAAFxsEtzmNo508_big.jpg-m
-rw-r--r--. 1 root root 94640 10月 27 17:02 wKjH41-X4j6ADPlDAAFxsEtzmNo508.jpg
-rw-r--r--. 1 root root 49 10月 27 17:02 wKjH41-X4j6ADPlDAAFxsEtzmNo508.jpg-m
说明:
1.*_big.jpg - 备份文件
2.*-m - 属性文件
【安装配置Nginx】
依赖安装:
# yum install pcre-devel zlib zlib-devel openssl openssl-devel -y
安装fastdfs-nginx-module模块:
0.准备fastdfs-nginx-module-{version}
# 下载fastdfs-nginx-module-{version}
# 解压
# cd /usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src -- 记住这个路径,用于集成到nginx
# cp mod_fastdfs.conf
# mkdir -p /opt/fastdfs/nginx_mod
1.下载:wget http://nginx.org/download/nginx-1.14.2.tar.gz
2.解压:
# tar -zxvf nginx-1.14.2.tar.gz
# cd nginx-1.14.2
# ./configure --prefix=/usr/local/nginx_fdfs --add-module=/usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src
# make
# make install
# cd /usr/local/nginx_fdfs/
# 配置fastdfs-nginx-module-1.22/src/mod_fastdfs.conf
# cd /usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src
# vim mod_fastdfs.conf
base_path=/opt/fastdfs/nginx_mod
tracker_server=192.168.199.227:22122
url_have_group_name = true
store_path_count=1
# 复制配置好的mod_fastdfs.conf文件到/etc/fdfs/目录下
# cp /usr/local/software/fastdfs/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
# 配置Nginx
# cd /usr/local/nginx_fdfs/conf
# vim nginx.conf - 在server中location下添加一个location,如下:
location ~ /group[1-9]/M0[0-9] {
ngx_fastdfs_module;
}
# /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
ngx_http_fastdfs_set pid=14374
nginx: the configuration file /usr/local/nginx_fdfs/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx_fdfs/conf/nginx.conf test is successful
# /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
# ps -ef|grep nginx|grep -v grep
# 防火墙配置
systemctl status firewalld -- 查看防火墙状态
systemctl stop firewalld -- 关闭防火墙
systemctl enable firewalld -- 启用防火墙服务
systemctl disable firewalld -- 禁用防火墙服务
netstat -unltp|grep fdfs
【添加FastDFS服务端口到防火墙白名单中】
storage服务端口:22122
tracker服务端口:23000
firewall-cmd --zone=public --add-port=22122/tcp --permanent
firewall-cmd --zone=public --add-port=23000/tcp --permanent