Centos系统FastDFS搭建与排错

FastDFS中Tracker server主要是负载均衡和调度,Storage server主要是文件存储。
1.1 系统环境
[root@ centos fastdfs]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

1.2 软件包(需要包的话可以在评论区留言)
FastDFS                            v5.05
libfastcommon                      v1.0.7
fastdfs-nginx-module               v1.16
nginx                              v1.12.1

1.3 安装依赖
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

1.4 安装libfastcommon
tar zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7/
./make.sh 
./make.sh install

1.5 安装FastDFS
tar zxvf FastDFS_v5.05.tar.gz
cd FastDFS/
./make.sh 
./make.sh install
cp -r conf/* /etc/fdfs/

1.5.1 配置tracker
cd /etc/fdfs
mkdir -p /data/fastdfs
vi tracker.conf
修改
    base_path=/data/fastdfs
    http.server_port=80
启动tracker
    /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
建立软链
    ln -s /usr/bin/fdfs_trackerd /usr/local/bin
    ln -s /usr/bin/stop.sh /usr/local/bin
    ln -s /usr/bin/restart.sh /usr/local/bin
          
1.5.2 配置 Storage 服务
mkdir -p /data/fastdfs/storage
vim storage.conf
修改
    base_path=/data/fastdfs/storage
    store_path0=/data/fastdfs/storage
    tracker_server=本机IP:22122
       
ln -s /usr/bin/fdfs_storaged /usr/local/bin
       service fdfs_storaged start
       
1.5.3 重启服务
service fdfs_trackerd restart
service fdfs_storaged restart
netstat -unltp|grep fdfs
       
1.5.4 监控tracker与storage的通信
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
        ip_addr = ip(hm)  ACTIVE
            
1.5.5 配置client.conf
vim client.conf
    base_path=/data/fastdfs/storage
tracker_server=本机IP:22122

1.5.6 上传文件测试
    /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/2.txt
1.5.7 文件存储位置
    /data/fastdfs/storage/data/00/00

1.6 安装nginx与fastdfs-nginx-module
tar zxvf fastdfs-nginx-module_v1.16.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
cd nginx
./configure --prefix=/usr/local/nginx --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-openssl=/usr/local/src/lnmp1.4-full/src/openssl-1.0.2l --add-module=/root/fastdfs/fastdfs-nginx-module/src

1.6.1 查看安装的模块
/usr/local/nginx/sbin/nginx -V

cd /解压目录/fastdfs-nginx-module-1.17/src/
vim mod_fastdfs.conf
修改
            tracker_server=192.168.198.129:22122    
            url_have_group_name = true
            store_path0=/data/fastdfs/storage
cp mod_fastdfs.conf /etc/fdfs

1.6.2 配置文件
vim nginx.conf
user  www www;
include /usr/local/nginx/conf.d/*.conf;

fastdfs.conf
    server {
        listen       80;
        server_name  域名/IP;
        rewrite ^(.*) https://$server_name$1 permanent;
}
    server {
        listen       443;
        server_name  域名/IP;
    ssl on;
    ssl_certificate /usr/local/nginx/conf/vhost/Nginx/server.crt;
    ssl_certificate_key /usr/local/nginx/conf/vhost/Nginx/server.key;
    access_log /usr/local/nginx/logs/acc_fastdfs.log;
        error_log /usr/local/nginx/logs/err_fastdfs.log;
        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location ~/group([0-9])/M00   {

           root /data/fastdfs/storage/;
            ngx_fastdfs_module;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

1.6.3 重启nginx(不用reload,不生效)
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

设置开机自启(/etc/rc.local)
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/local/nginx/sbin/nginx

1.7 问题
1.7.1 问题1
nginx fastdfs 配置后 上传成功 但访问报404 bad request 两种解决方法
方法一:修改nginx.conf配置文件加上一行 user www
        chown -R www:www /data/fastdfs/storage

方法二:配置 /etc/fdfs/mod_fastdfs.conf 
url_have_group_name = false 改为true(使用组名访问)
 

两种方法最后都要 执行 /usr/local/nginx/sbin/nginx -s reload 重新加载配置文件生效,最后就可以访问了
注意 如果两者都用了还没效果后 就很可能是防火墙没关闭
关闭防火墙:
service firewalld stop           停止防火墙
service firewalld disable        永久停止
selinux:    getenforce

1.7.2 问题2
fastdfs升级为https加密存取
    server {
        listen       80;
        server_name  域名/IP;
        rewrite ^(.*) https://$server_name$1 permanent;
}
    server {
        listen       443;
        server_name  域名/IP;
    ssl on;
    ssl_certificate /usr/local/nginx/conf/vhost/Nginx/server.crt;
    ssl_certificate_key /usr/local/nginx/conf/vhost/Nginx/server.key;
    access_log /usr/local/nginx/logs/acc_fastdfs.log;
        error_log /usr/local/nginx/logs/err_fastdfs.log;
        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location ~/group([0-9])/M00   {

           root /data/fastdfs/storage/;
            ngx_fastdfs_module;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

附加:
# grep http |grep server_port tracker.conf
http.server_port=443
# grep http |grep server_port storage.conf
http.server_port=443
# grep http |grep server_port client.conf 
http.tracker_server_port=443

1.7.3 问题3
root/fastdfs-nginx-module/src//common.c:21:25: fatal error: fdfs_define.h: No such file or directory
 #include "fdfs_define.h"
cp /usr/lib64/libfdfsclient.so /usr/lib/
vim /usr/local/src/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
(把CORE_INCS和CORE_LIBS的所有路径都修改为/usr/include和/usr/lib)
    

 

posted @ 2019-04-26 12:38  Frank-hui  阅读(480)  评论(0编辑  收藏  举报