FastDFS 搭建和部署
1.环境准备
1.1 所需系统软件(以 ubuntu 为例)
1.2 配置编译环境——基于 ubuntu
sudo apt-get install gcc g++ make automake autoconf libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev 1.3 配置数据存储位置(自己确定和命名)
mkdir /data/fastdfs #创建数据存储目录
cd /usr/local/src #切换到安装目录准备下载安装包1.4 安装 libfatscommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #编译安装1.5 安装 FastDFS
cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #编译安装
#配置文件准备
#供nginx访问使用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ 1.6 安装 fastdfs-nginx-module
cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
#配置文件
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs1.7 安装 nginx
wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包
tar -zxvf nginx-1.15.4.tar.gz #解压
cd nginx-1.15.4/
#添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install #编译安装2.单机部署
服务器ip:124.XXX.XX.XXX 2.1 tracker 配置
#服务器ip为 124.XXX.XX.XXX
#建议用ftp下载下来这些文件 本地修改
vim /etc/fdfs/tracker.conf 需要修改的内容如下 :
port=22122
# tracker服务器端口(默认22122,一般不修改)
base_path=/data/fastdfs # 存储日志和数据的根目录2.2 storage 配置
vim /etc/fdfs/storage.conf 需要修改的内容如下 :
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/data/fastdfs # 数据和日志文件存储根目录
store_path0=/data/fastdfs # 第一个存储目录
tracker_server=10.0.4.13:22122 # tracker服务器IP和端口
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)2.3 启动服务
#关闭防火墙
systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf #启动tracker服务
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart #重启动tracker服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf #启动storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart #重启动storage服务
ps -ef|grep xxxx2.4 client 测试
vim /etc/fdfs/client.conf修改如下:
base_path=/data/fastdfs
tracker_server=10.0.4.13:22122 #tracker服务器
#上传文件
fdfs_upload_file /etc/fdfs/client.conf /usr/local/pic/wx.jpg
#删除文件
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/CgAEDWf2kPWAdJnwAAI0Gqq8V5U777.jpg2.5 配置 nginx 访问(client)
1.配置mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf 需要修改的内容如下 :
tracker_server=10.0.14.3:22122 #tracker服务器IP和端口
url_have_group_name=true
store_path0=/data/fastdfs 2.配置nginx.config
vim /usr/local/nginx/conf/nginx.conf 添加如下配置 :
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
/usr/local/nginx/sbin/nginx #启动nginx
/usr/local/nginx/sbin/nginx -s reload #重启nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx测试通讯(访问上传的)
http://starryv.top: 8888/group1/M00/00/00/CgAEDWf2kPWAdJnwAAI0Gqq8V5U777.jpg
3.中途遇到的问题
3.1 新建目录权限问题
报错:
`mkdir: cannot create directory ‘/home/Fastdfs’: Permission denied`解决方案:
使用 linux 的 sudo 操作
cd /home
sudo mkdir Fastdfs切换 root 用户(不推荐)/普通用户
sudo passwd root输入注册密码
输入命令 su
输入密码后进入 root
3.2 git 问题
前置命令:
git clone https://github.com/happyfish100/fastdfs.git --depth 1报错:
fatal: unable to access 'https://github.com/happyfish100/fastdfs.git/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.解决方案:
执行下面命令
git config --global --unset http.proxy
git config --global --unset https.proxy再次 git 成功
3.3 git 项目出现问题
前置命令:
root@hcss-ecs-6208:/usr/local/src# git clone git://github.com/happyfish100/libfastcommon.git --depth 1报错:
Cloning into 'libfastcommon'...
fatal: unable to connect to github.com:
github.com[0: 20.205.243.166]: errno=Connection timed out解决方案:
进入 GitHub 项目地址,下载解压后将文件通过 FTP 上传至服务器路径进行后续操作
同步仓库索引
sudo apt-get update
再次执行 git 命令成功
3.4 安装权限问题
报错:
-bash: ./make.sh: Permission denied解决方案:
方法一:(未解决)
cd /usr/local/src ll /usr/local/src/libfastcommon sudo chmod +777 /usr/local/src/libfastcommon方法二:(已解决)
chmod -R 777 /usr/local/src
3.5 安装包获取错误
前置命令:
sudo apt-get install gcc g++ make automake autoconf libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev 报错:
404 Not Found [IP: 203.193.226.94 80]
Fetched 2,426 kB in 1s (4,006 kB/s)
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/o/openssl/libssl-dev_3.0.2-0ubuntu1.16_amd64.deb 404 Not Found [IP: 203.193.226.94 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?解决方案:
同步仓库索引——已解决
sudo apt-get update3.6 安装 fastdfs 时报错
前置命令:
root@hcss-ecs-6208:/usr/local/src# cd fastdfs
root@hcss-ecs-6208:/usr/local/src/fastdfs# ./make.sh && ./make.sh install #编译安装报错:
gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/local/include
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:17:10: fatal error: sf/sf_global.h: No such file or directory
17 | #include "sf/sf_global.h"
| ^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:28: ../common/fdfs_global.o] Error 1
gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:17:10: fatal error: sf/sf_global.h: No such file or directory
17 | #include "sf/sf_global.h"
| ^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:38: ../common/fdfs_global.o] Error 1
gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I../tracker -I/usr/include/fastcommon
In file included from ../common/fdfs_global.c:21:
../common/fdfs_global.h:17:10: fatal error: sf/sf_global.h: No such file or directory
17 | #include "sf/sf_global.h"解决方案:
fastdfs 缺少相关组件,安装 libserverframe——已解决
git clone https://github.com/happyfish100/libserverframe.git --depth 1
cd libserverframe/
./make.sh&./make.sh install#编译安装安装完成后再次执行 fastdfs 编译安装成功
4. 其他问题
4.1 查看 storage 的状态
fdfs_monitor /etc/fdfs/client.conf