Fastdfs集群搭建
1.关于集群,网上说最少要三台,其实也没必要,两台就够了
2.实验环境
192.168.2.201 tracker、storage、nginx + fastdfs-nginx-module-master + ngx_cache_purge keepalived
192.168.2.202 tracker、storage、nginx + fastdfs-nginx-module-master + ngx_cache_purge keepalived
结构如上图所示:
开始搭建
1.准备:
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel -y
2.安装libfastcommon
解压libfastcommon-master.zip [root@Node202 fastdfs-master]# cd /data/softwares/fastdfs [root@Node202 opt]# unzip -o libfastcommon-master.zip -d /usr/local [root@Node202 opt]# cd /usr/local/libfastcommon-master/ [root@Node202 libfastcommon-master]# ./make.sh [root@Node202 libfastcommon-master]# ./make.sh install
3.安装 fastdfs
cd /data/softwares/fastdfs unzip -o fastdfs-master.zip -d /usr/local cd /usr/local/fastdfs-master ./make.sh ./make.sh install
4.拷贝配置文件
将fastdfs安装目录下的conf下的文件拷贝到/etc/fdfs/下
root@Node202 fastdfs-master]# cp -r conf/* /etc/fdfs/ fdfs可执行命令 [root@Node202 fdfs]# ll /usr/bin/fdfs*
5.配置并启动trackerd
修改trackerd.conf [root@Node202 fdfs]# cd /etc/fdfs/ [root@Node202 fdfs]# vim tracker.conf base_path=/data/fastdfs # 存储日志和数据的根目录 其它参数保留默认配置, 具体配置解释可参考官方文档说明:http://bbs.chinaunix.net/thread-1941456-1-1.html 创建trackerd数据、日志目录 [root@Node202 fdfs]# mkdir -p /data/fastdfs 启动trackerd [root@Node202 fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart 日志:/data/fastdfs/logs/trackerd.log [root@Node202 fdfs]# ps -ef | grep fdfs
6.配置并启动storaged
修改storage.conf [root@Node202 fdfs]# cd /etc/fdfs/ [root@Node202 fdfs]# vim storage.conf base_path=/data/fastdfs store_path0=/data/fastdfs tracker_server=192.168.2.202:22122,这个ip改成自己的 启动storaged [root@Node202 fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 日志:/data/fastdfs/logs/storaged.log
7.FastDFS 和nginx整合
7.1 fastdfs-nginx-module模块,作用:通过nginx访问时,当访问的节点文件不存在时(没有同步过来),此模块会自动寻找源文件所属机器。
解压 [root@Node202 00]# cd /data/softwares/fastdfs [root@Node202 opt]# unzip -o fastdfs-nginx-module-master.zip -d /usr/local 拷贝配置文件 [root@Node202 opt]# cd /usr/local/fastdfs-nginx-module-master/src [root@Node202 src]# cp mod_fastdfs.conf /etc/fdfs/ 编辑配置文件 [root@Node202 src]# cd /etc/fdfs/ [root@Node202 fdfs]# vim mod_fastdfs.conf base_path=/data/fastdfs tracker_server=192.168.2.202:22122 url_have_group_name = true;#url中包含group名称 store_path0=/data/fastdfs
7.2 ngx_cache_purge模块 作用:删除缓存
解压缓存模块 [root@Node11 fdfs]# cd /data/softwares/fastdfs/ [root@Node11 fastdfs]# tar -zxvf ngx_cache_purge-2.3.tar.gz -C /usr/local/
8. 安装nginx
8.1 nginx依赖包安装
[root@Node202 fdfs]# cd /opt [root@Node202 opt]# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
8.2 安装nginx
解压nginx [root@Node202 opt]# tar -zxvf nginx-1.14.2.tar.gz 安装nginx并添加两个模块 [root@Node202 opt]# cd /data/softwares/fastdfs/nginx-1.14.2 [root@Node202 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src --add-module=/usr/local/ngx_cache_purge-2.3 [root@Node202 nginx-1.14.2]# make [root@Node202 nginx-1.14.2]# make install
8.3 检验nginx
检查nginx模块 [root@Node12 nginx-1.14.2]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.14.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src --add-module=/usr/local/ngx_cache_purge-2.3 [root@Node202 opt]# /usr/local/nginx/sbin/nginx -t ngx_http_fastdfs_set pid=13287 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
9.配置nginx配置文件
注意:创建文件夹:
mkdir -p /data/fastdfs/cache/nginx/proxy_cache/tmp
vim /usr/local/nginx/conf/nginx.conf proxy_cache_path /data/fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d; proxy_temp_path /data/fastdfs/cache/nginx/proxy_cache/tmp; upstream fdfs_group1{ server 192.168.0.115:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.0.244:8888 weight=1 max_fails=2 fail_timeout=30s; } server { listen 8888; server_name 192.168.0.244; location ~/group[0-9]/ { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group1; expires 30d; ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
10.启动nginx
启动 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 重启nginx /usr/local/nginx/sbin/nginx -s reload
11. 验证fastdfs上传功能
修改客户端文件: vim /etc/fdfs/client.conf base_path=/data/fastdfs tracker_server=192.168.0.115:22122 tracker_server=192.168.0.244:22122 上传: /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/fu2.jpg 192.168.2.202:23000 0 /usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/fu.jpg 访问: http://192.168.2.202:8888/group1/M00/00/00/wKgCylxQETeAZMTBAADsE2xyRuI261.jpg
12. 开机启动
将Tracker加入开机启动项 # cp /usr/fastdfs/FastDFS/init.d/fdfs_trackerd /etc/init.d/ # chkconfig --add fdfs_trackerd # chkconfig fdfs_trackerd on 将Storage加入开机启动项 # cp /usr/fastdfs/FastDFS/init.d/fdfs_storaged /etc/init.d/ # chkconfig --add fdfs_storaged # chkconfig fdfs_storaged on netstat -unltp | grep fdfs
如果对您有帮助,轻轻点个赞!