FASTDFS安装步骤
FastDFS结构图
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ASzDTamq-1596872528655)(file:///C:\Users\zzy\AppData\Local\Temp\ksohtml14572\wps1.jpg)]
1.环境准备
使用的系统软件
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3gn18YV9-1596872528657)(file:///C:\Users\zzy\AppData\Local\Temp\ksohtml14572\wps2.jpg)]
编译环境安装:(复制命令到Linux操作系统安装所需要的软件(保持连网状态))
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim –y
2. 创建指定目录用于存储文件
mkdir /home/dfs #创建数据存储目录
cd /usr/local/src #切换到安装目录准备下载安装包
3.安装libfatscommon
# 克隆libfatscommon到系统中
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
# 切换到目录中
cd libfastcommon/
# 执行编译安装
./make.sh && ./make.sh install
4.安装FastDFS
# 回到上一层( /usr/local/src )目录
cd ../
# 克隆FastDFS到本地
git clone https://github.com/happyfish100/fastdfs.git --depth 1
# 进入fastdfs目录中
cd fastdfs/
# 编译安装
./make.sh && ./make.sh install
5.准备配置文件
cp /usr/etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /usr/etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
# 客户端文件,测试用
cp /usr/etc/fdfs/client.conf.sample /etc/fdfs/client.conf
#供nginx访问使用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/
#供nginx访问使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/
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/fdfs
7. 安装nginx
# 下载nginx压缩包
wget http://nginx.org/download/nginx-1.15.4.tar.gz
# 解压
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
8. tracker配置
# 修改配置文件
vi /etc/fdfs/tracker.conf
# 需要修改的内容如下
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs # 存储日志和数据的根目录
启动tracker:
/usr/local/src/fastdfs/init.d/ fdfs_trackerd start
启动成功如下
Starting FastDFS tracker server:
9. storage配置
# 修改配置文件
vi /etc/fdfs/storage.conf
# 需要修改的内容如下
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/home/dfs # 数据和日志文件存储根目录
store_path0=/home/dfs # 第一个存储目录
tracker_server=192.168.xxx.xxx:22122 # tracker服务器IP和端口
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
/usr/local/src/fastdfs/init.d/fdfs_storaged start # 启动
启动成功如下
Starting FastDFS storage server:
# 查看进程是否存在tracker与storage连个服务(缺一不可)
ps aux|grep fdfs
10. client测试
# 修改 client 配置文件
vi /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/home/dfs
tracker_server=192.168.52.1:22122 #tracker服务器IP和端口
#保存后测试,返回ID表示成功 如: group1/M00/00/00/wKi8gF8uMlmAOPVTAA-itrfn0m4.jpg
测试代码:
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/12.jpg
10. 配置nginx访问
# 修改配置文件
vi /etc/fdfs/mod_fastdfs.conf
# 需要修改的内容如下
tracker_server=192.168.xxx.xxx:22122 #tracker服务器IP和端口
url_have_group_name=true
store_path0=/home/dfs
# 配置nginx.config (这里是nginx安装目录,不是在git拉取的文件夹中)
vi /usr/local/nginx/conf/nginx.conf
# 添加如下配置
server {
# 该端口为storage.conf中的http.server_port相同
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
11.启动Nginx :
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
( nginx启动文件 -c nginx配置文件 )
测试下载,用外部浏览器访问刚才已传过的nginx安装包,引用返回的ID
http://192.168.xxx.xxx:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.jpg
图片如果正常显示,则表示单机部署完成
注意事项:需要关闭Linux防火墙
#不关闭防火墙的话 nginx无法使用
systemctl stop firewalld.service #关闭
systemctl disable firewalld.service #禁用防火墙
systemctl restart firewalld.service #重启
12.设置fastDFS开机自启
# fdfs_tracker 设置开机启动
cp FastDFS/init.d/fdfs_trackerd /etc/init.d/
chkconfig –add fdfs_trackerd
chkconfig fdfs_trackerd on
# fdfs_storafed 设置开机启动
cp FastDFS/init.d/fdfs_storaged /etc/init.d/
chkconfig –add fdfs_storaged
chkconfig fdfs_storaged on
13.设置nginx开机自启
略…