title: 04.FastDFS安装配置 CreateTime: 2019-06-19 14:05:00 UpdateTime: 2024-04-15 16:34:55 CategoryName: Web --- --- title: "04.FastDFS安装配置" date: 2019-06-19T14:05:00+08:00 draft: false tags: ["web"] categories: ["web"] author: "springrain" --- ## 1.软件介绍 FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等. FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage).跟踪器主要做调度工作,在访问上起负载均衡的作用. 存储节点存储文件,完成文件管理的所有功能:存储.同步和提供存取接口. 参考资料: ## 2.下载 我使用的操作系统是 CentOS 6.7 64位 FastDFS: Libfastcommon: Nginx: fastdfs-nginx-module: Pcre: Zlib: ## 3.安装 ### 3.1关闭防火墙 ```shell service iptables stop chkconfig iptables off vi /etc/selinux/config 修改 selinux=disable ``` ### 3.2安装GCC ```shell yum install -y gcc gcc-c++ perl zip unzip wget ``` ### 3.3安装Libfastcommon ```shell tar -zxvf libfastcommon-1.0.7.tar.gz cd libfastcommon-1.0.7 ./make.sh ./make.sh install #由于FastDFS主程序设置的lib目录是/usr/local/lib,所以需要创建软链接. ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so ``` ### 3.4安装FastDFS ```shell #1. 解压 tar -zxvf fastdfs-5.05.tar.gz -C /usr/local #2. 修改文件夹名称 cd /usr/local mv fastdfs-5.05 fastdfs #3. 编译安装 cd /usr/local/fastdfs ./make.sh ./make.sh install ``` ### 3.5安装Nginx ```shell tar -zxvf pcre-8.37.tar.gz tar -zxvf nginx-1.10.0.tar.gz tar -zxvf zlib-1.2.8.tar.gz unzip fastdfs-nginx-module-master.zip cd nginx-1.10.0 ./configure --add-module=/root/fastdfs-nginx-module-master/src --with-pcre=/root/pcre-8.37 --with-zlib=/root/zlib-1.2.8 make make install ``` ## 4.配置 ### 4.1创建目录 ```shell mkdir /usr/local/fastdfs/fastdfs_tracker mkdir /usr/local/fastdfs/fastdfs_storage ``` ### 4.2创建配置文件 ```shell cd /etc/fdfs cp tracker.conf.sample tracker.conf cp storage.conf.sample storage.conf cp client.conf.sample client.conf ``` ### 4.3修改配置文件 cd /etc/fdfs 1. 修改 tracker.conf 把 base_path=/home/yuqing/fastdfs 修改为 base_path=/usr/local/fastdfs/fastdfs_tracker 2. 修改storage.conf 把 base_path=/home/yuqing/fastdfs 修改为 base_path=/usr/local/fastdfs/fastdfs_storage 把 store_path0=/home/yuqing/fastdfs 修改为 store_path0=/usr/local/fastdfs/fastdfs_storage 把 tracker_server=xx.xx.xx.xx:22122 修改为服务器IP地址,不能是127.0.0.1,例如: tracker_server=10.0.8.137:22122 3. 修改client.conf 把 base_path=/home/yuqing/fastdfs 修改为 base_path=/usr/local/fastdfs/fastdfs_storage 把 tracker_server=xx.xx.xx.xx:22122 修改为服务器IP地址,不能是127.0.0.1,例如: tracker_server=10.0.8.137:22122 ## 5.启动 ### 5.1启动tracker ```shell fdfs_trackerd /etc/fdfs/tracker.conf ``` ### 5.2启动storage ```shell fdfs_storaged /etc/fdfs/storage.conf ``` 第一次启动有点慢,请耐心等待 ### 5.3测试 ```shell fdfs_test /etc/fdfs/client.conf upload storage.conf ``` 若可以正常返回访问路径,类似 ![](/public/04/image1.png) 查看日志路径:/usr/local/fastdfs/fastdfs_storage/logs ## 6.配置Nginx ### 6.1将FastDFS的nginx插件配置copy到FastDFS配置目录 ```shell cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ cp /usr/local/fastdfs/conf/http.conf /etc/fdfs/ cp /usr/local/fastdfs/conf/mime.types /etc/fdfs/ ``` ### 6.2编辑Nginx配置 vi /usr/local/nginx/conf/nginx.conf 在server段中添加: ``` location ~ /group1/M00 { root /usr/local/fastdfs/fastdfs_storage; ngx_fastdfs_module; } ``` ### 6.3配置扩展模块 vi /etc/fdfs/mod_fastdfs.conf 一般只需改动以下几个参数即可: ```shell base_path=/usr/local/fastdfs/fastdfs_storage #保存日志目录 tracker_server=主机IP:22122 #tracker服务器的IP地址以及端口号 storage_server_port=23000 #storage服务器的端口号 group_name=group1 #当前服务器的group名 url_have_group_name = true #文件url中是否有group名 store_path_count=1 #存储路径个数,需要和store_path个数匹配 store_path0=/usr/local/fastdfs/fastdfs_storage #存储路径 http.need_find_content_type=true #从文件扩展名查找文件类型(nginx时为true),有的版本没有该选项不要管它. #根据你上面设置的组个数设置 group_count = 1 #设置组的个数 #在末尾增加1个组的具体信息:(设置几组就添加几组) [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/usr/local/fastdfs/fastdfs_storage ``` ### 6.4测试 ------- ![](/public/04/image2.png) ![](/public/04/image3.png) ## 7.双机集群 集群主要是第二台storage(10.0.8.138)的/etc/fdfs/storage.conf 修改为tracker_server=10.0.8.137:22122 在10.0.8.137上,可以通过fdfs_monitor查看集群的情况,即storage是否已经注册到tracker服务器中  /usr/bin/fdfs_monitor /etc/fdfs/storage.conf