环境
系统:centos7.5 3台192.168.2.71 dfs01 tracker, storage, nginx192.168.2.72 dfs02 tracker, storage, nginx192.168.2.73 dfs03 storage, nginx
配置host解析
echo """192.168.2.71 dfs01192.168.2.72 dfs02192.168.2.73 dfs03""" >>/etc/hosts
安装依赖软件
yum install -y gcc gcc-c++ perl net-tools
安装libfastcommon
curl -SL https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -o libfastcommon-1.0.39.tar.gztar xvf libfastcommon-1.0.39.tar.gz -C /usr/local/srccd /usr/local/src/libfastcommon-1.0.39./make.sh && ./make.sh install
安装fastdfs
curl -SL https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -o fastdfs-5.11.tar.gztar xvf fastdfs-5.11.tar.gz -C /usr/local/srccd /usr/local/src/fastdfs-5.11./make.sh && ./make.sh installcp /usr/local/src/fastdfs-5.11/conf/* /etc/fdfs/
配置tracker(dfs01, dfs02)
mkdir -p /home/fastdfs/trackersed -i 's#store_group=.*#store_group=group1#' /etc/fdfs/tracker.confsed -i 's#base_path=.*#base_path=/home/fastdfs/tracker#' /etc/fdfs/tracker.conf
禁用 tracker (dfs03)
sed -i 's#disabled=.*#disabled=true#' /etc/fdfs/tracker.conf
配置 storage
mkdir -p /home/fastdfs/storagesed -i 's#base配置 storage_path=.*#base_path=/home/fastdfs/storage#' /etc/fdfs/storage.confsed -i 's#store_path0=.*#store_path0=/home/fastdfs/storage#' /etc/fdfs/storage.confsed -i 's#tracker_server=.*#tracker_server=dfs01:22122\ntracker_server=dfs02:22122#g' /etc/fdfs/storage.conf
启动 trackerd 服务(dfs01, dfs02)
# 配置防火墙firewall-cmd --zone=public --add-port=22122/tcp --permanentfirewall-cmd --reload# 启动服务/etc/init.d/fdfs_trackerd restartnetstat -ntaulp | grep :22122
启动 storage 服务
firewall-cmd --zone=public --add-port=23000/tcp --permanentfirewall-cmd --reload/etc/init.d/fdfs_storaged restartps -ef | grep fdfs
测试上传
# 配置连接 tracker 服务器参数sed -i 's#base_path=.*#base_path=/home/fastdfs/tracker#' /etc/fdfs/client.confsed -i 's#tracker_server=.*#tracker_server=dfs01:22122\ntracker_server=dfs02:22122#g' /etc/fdfs/client.conf# 测试上传/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /etc/passwd/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/passwd# 查看服务器状态fdfs_monitor /etc/fdfs/client.conf
安装nginx
curl -SLO http://nginx.org/download/nginx-1.14.2.tar.gzcurl -SLO https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gzcurl -SLO https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gzcurl -SL https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -o fastdfs-nginx-module-1.20.tar.gztar xvf pcre-8.42.tar.gz -C /usr/local/srctar xvf zlib-1.2.11.tar.gz -C /usr/local/src/tar xvf nginx-1.14.2.tar.gz -C /usr/local/srctar xvf fastdfs-nginx-module-1.20.tar.gz -C /usr/local/src/cd /usr/local/src/nginx-1.14.2export C_INCLUDE_PATH=/usr/include/fastcommon./configure --prefix=/usr/local/nginx \ --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src \ --with-pcre=/usr/local/src/pcre-8.42 \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-openssl=/usr/bin/opensslmake && make install# 验证/usr/local/nginx/sbin/nginx -v/usr/local/nginx/sbin/nginx -V
配置fastdfs模块 (storage)
cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/sed -i "s#base_path=.*p#base_path=/home/fastdfs/storage#" /etc/fdfs/mod_fastdfs.confsed -i "s#url_have_group_name = .*#url_have_group_name = true#" /etc/fdfs/mod_fastdfs.confsed -i "s#store_path0=.*#store_path0=/home/fastdfs/storage#" /etc/fdfs/mod_fastdfs.confsed -i "s#tracker_server=.*#tracker_server=dfs01:22122\ntracker_server=dfs02:22122#g" /etc/fdfs/mod_fastdfs.confsed -i "s#group_count =.*#group_count = 1#" /etc/fdfs/mod_fastdfs.conf# 增加 group1 组配置信息echo """[group1]group_name=group1storage_server_port=23000store_path_count=1store_path0=/home/fastdfs/storage""" >>/etc/fdfs/mod_fastdfs.conf
配置 nginx (storg)
cp /usr/local/nginx/conf/nginx.conf{,.bak}cat </usr/local/nginx/conf/nginx.confworker_processes 4;events { worker_connections 65535; use epoll;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8888; server_name localhost; location / { root html; index index.html index.htm; } location ~ /group1/M00 { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include /usr/local/nginx/conf.d/*.conf;}EOF# 配置防火墙,启动nginx服务firewall-cmd --zone=public --add-port=8888/tcp --permanentfirewall-cmd --reload/usr/local/nginx/sbin/nginx
配置 nginx 代理访问资源(tracker)
mkdir /usr/local/nginx/conf.dcat </usr/local/nginx/conf.d/dfs_proxy.confupstream fdfs_group1 { server dfs01:8888 weight=1 max_fails=2 fail_timeout=30s; server dfs02:8888 weight=1 max_fails=2 fail_timeout=30s; server dfs03:8888 weight=1 max_fails=2 fail_timeout=30s;}server { listen 80; server_name localhost; location /group1/M00{ proxy_pass http://fdfs_group1; }}EOF# 配置防火墙,重启nginx服务firewall-cmd --zone=public --add-port=80/tcp --permanentfirewall-cmd --reload/usr/local/nginx/sbin/nginx -s reload
测试
# shell 上传文件/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/share/kde4/apps/ksplash/Themes/CentOS7/2560x1600/background.jpg# 查看上传图片(替换实际文件地址)http://192.168.2.71/group1/M00/00/00/wKgCR1wYtoKAFGtqAA6q2_5cIME813_big.jpghttp://192.168.2.72/group1/M00/00/00/wKgCR1wYtoKAFGtqAA6q2_5cIME813_big.jpghttp://192.168.2.71:8888/group1/M00/00/00/wKgCR1wYtoKAFGtqAA6q2_5cIME813_big.jpghttp://192.168.2.72:8888/group1/M00/00/00/wKgCR1wYtoKAFGtqAA6q2_5cIME813_big.jpghttp://192.168.2.73:8888/group1/M00/00/00/wKgCR1wYtoKAFGtqAA6q2_5cIME813_big.jpg