FastDFS是一个开源的高性能分布式文件系统。它的主要功能包括:文件存储,文件同步和文件访问(文件上传和文件下载),它可以解决高容量和负载平衡问题。FastDFS应该满足基于照片共享站点和视频共享站点等文件的网站的要求。
官方GitHub地址
使用 wget 命令下载压缩包,如果没有 wget 命令使用 yum 命令安装
yum install wget
文件存放位置:/usr/local/src
文件名 | 命令 |
---|---|
fastdfs-6.06.tar.gz | wget -c “https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz” -O fastdfs-6.06.tar.gz |
libfastcommon-1.0.43.tar.gz | wget -c “https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz” -O libfastcommon-1.0.43.tar.gz |
fastdfs-nginx-module-1.22.tar.gz | wget -c “https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz” -O fastdfs-nginx-module-1.22.tar.gz |
nginx-1.17.7.tar.gz | wget -c http://nginx.org/download/nginx-1.17.7.tar.gz |
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
cd /usr/local/src/libfastcommon-1.0.43
./make.sh && ./make.sh install
ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon
出现libfastcommon.so即成功
cd /usr/local/src/fastdfs-6.06
./make.sh && ./make.sh install
ls /usr/bin|grep fdfs
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vi /etc/fdfs/tracker.conf
配置文件是否不生效,false为生效
disabled = false
提供服务端口
port = 22122
Tracker 数据和日志目录地址(根目录必须存在,子目录会自动创建)
base_path = /fastdfs/tracker
HTTP 服务端口 默认8080,建议修改防止冲突
http.server_port = 8080
mkdir -p /fastdfs/tracker
# 启动
systemctl start fdfs_trackerd
# 重启
systemctl restart fdfs_trackerd
# 查看服务状态
systemctl status fdfs_trackerd
# 检查服务是否启动
ps -ef | grep fdfs
# 22122端口正在被监听,则算Tracker服务安装成功
netstat -tulnp | grep fdfs
# 关闭
systemctl stop fdfs_trackerd
systemctl enable fdfs_trackerd.service
cd /etc/fdfs/
cp storage.conf.sample storage.conf
vi /etc/fdfs/storage.conf
Storage 数据和日志目录地址(根目录必须存在,子目录会自动创建)
base_path = /fastdfs/storage/base
逐一配置 store_path_count 个路径,索引号基于 0
如果不配置,那就和base_path一样
store_path0 = /fastdfs/storage
tracker_server 的列表,多个时,每个写一行(会主动连接 tracker_server)
tracker_server = ip:22122
HTTP 服务端口 默认8888,建议修改防止冲突
http.server_port = 8888
# 对应base_path
mkdir -p /fastdfs/storage/base
# 对应store_path0,有多个要创建多个
mkdir -p /fastdfs/storage
# 启动
systemctl start fdfs_storaged
# 重启
systemctl restart fdfs_storaged
# 查看服务状态
systemctl status fdfs_storaged
# 检查服务是否启动
ps -ef | grep fdfs
# 22122端口正在被监听,则算Tracker服务安装成功
netstat -tulnp | grep fdfs
# 关闭
systemctl stop fdfs_storaged
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
systemctl enable fdfs_storaged.service
cd /etc/fdfs/
cp client.conf.sample client.conf
vi /etc/fdfs/client.conf
Client 的数据和日志目录
base_path= /fastdfs/client
Tracker 端口
tracker_server=ip:22122
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf xxx.jpg
上传成功返回文件ID号:
组名 | 磁盘 | 目录 | 文件名 |
---|---|---|---|
group1 | /M00 | /00 | /xxx.jpg |
cd /usr/local/src/nginx-1.17.7
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
cd /usr/local/src/fastdfs-nginx-module-1.22/src/
vi config
# 将config文件中的/usr/local替换成/usr
:%s+/usr/local+/usr
cd /usr/local/src/nginx-1.17.7
./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.22/src/
# 编译安装
make && make install
cp /usr/local/src/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
connect_timeout=10
tracker_server=192.168.0.154:22122
url_have_group_name = true
store_path0=/fastdfs/storage
cp http.conf mime.types /etc/fdfs/
ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;# 建议修改,防止冲突
server_name ip;
location ~/group([0-9])/M00 {
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
}
/usr/local/nginx/sbin/nginx
systemctl start ngnix