单机版Fastdfs 安装部署在centos7.x 完整实操

1.安装依赖

    yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

2.安装libfastcommon

    mkdir -p /home/lwc
    cd /home/lwc
    wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
    mv V1.0.7.tar.gz libfastcommon-1.0.7.tar.gz
    tar zxvf libfastcommon-1.0.7.tar.gz
    cd libfastcommon-1.0.7/
    编译:./make.sh
    安装: ./make.sh install

    设置几个软连接, 方便后面nginx扩展

    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. 安装 tracker

    回到上一目录: cd ../
    wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
    mv V5.05.tar.gz FastDFS_v5.05.tar.gz
    tar zxvf FastDFS_v5.05.tar.gz
    cd fastdfs-5.05/
    ./make.sh
    ./make.sh install

    cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
    创建一个存放目录: mkdir -p /home/fastdfs
    vim /etc/fdfs/tracker.conf
    修改如下字段:
    base_path=/home/fastdfs
    http.server_port=80
    启动:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
    重启:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
    检查是否正常: ps -ef  |grep tracker

4.storage(存储节点)服务部署

    cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
    创建目录:mkdir -p  /home/fastdfs/storage/images-data
    vim /etc/fdfs/storage.conf
    修改如下:
    base_path=/home/fastdfs
    store_path0=/home/fastdfs/storage/images-data
    tracker_server=129.211.102.11:22122
           注意: (129.211.102.11)是你的server服务器ip、本机也可以使用(0.0.0.0:22122)、记得不可使用127.0.0.1
    http.server_port=80 //与后面nginx配置端口一样

5. 测试服务

    启动 storage 服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf,首次启动会很慢,因为它在创建预设存储文件的目录
    重启 storage 服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
    查看是否有 storage 进程:ps -ef | grep storage

    fdfs_monitor /etc/fdfs/storage.conf
    ...
    Storage 1:
        id = 192.168.2.231
        ip_addr = 192.168.2.231  ACTIVE --若看到ACTIVE这个字样、代表可以正常通信
    ...
    查看storage和tracker是否正常启动:
    ps -ef | grep fdfs

    

6. 使用fdfs_client测试
    复制一份配置:cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
    编辑:vim /etc/fdfs/client.conf

    base_path= /home/fastdfs
    tracker_server=129.211.102.11:22122

    echo tttddddd > ./test.txt
    测试:fdfs_test /etc/fdfs/client.conf upload ./test.txt 
    可以看到如下图所示、就是上传成功了

7. 安装Nginx和其插件
    wget http://nginx.org/download/nginx-1.11.8.tar.gz
    wget http://jaist.dl.sourceforge.NET/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
    tar zxvf fastdfs-nginx-module_v1.16.tar.gz
    cd fastdfs-nginx-module/
    vim src/config 
       修改:去掉local、因为实际安装fastdfs时、是放到了/usr/include下
       CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
       CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
       CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
       CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
    cd ../
    tar zxvf nginx-1.11.8.tar.gz 
    cd nginx-1.11.8/
    sudo ./configure  --prefix=/usr/local/nginx --sbin-path=/usr/local/bin/nginx --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --error-log-path=/usr/local/var/log/nginx/^Cror.log --http-log-path=/usr/local/var/log/nginx/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-file-aio --add-module=/home/lwc/fastdfs-nginx-module/src
    sudo make  && sudo  make install

8. 整合fastdfs-nginx-module和nginx 配置Nginx并测试

    cp /home/lwc/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
    vim /etc/fdfs/mod_fastdfs.conf 
    修改如下:
    base_path=/home/fastdfs
    tracker_server=129.211.102.11:22122
    url_have_group_name = true
    store_path0=/home/fastdfs/storage/images-data
    
    cp /home/lwc/fastdfs-5.05/conf/http.conf /etc/fdfs/
    cp /home/lwc/fastdfs-5.05/conf/mime.types /etc/fdfs/
    vim /etc/fdfs/http.conf 
    修改如下:
    http.anti_steal.token_check_fail=/home/lwc/fastdfs-5.05/conf/anti-steal.jpg
    

    vim /usr/local/etc/nginx/nginx.conf
    修改如下:
        ......
        server {
        listen       80;
        server_name  localhost;

        location ~/group[0-9]/ {

                ngx_fastdfs_module;

        }

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        ......

    
    /usr/local/bin/nginx  -t   //测试配置文件
    /usr/local/bin/nginx  -c /usr/local/etc/nginx/nginx.conf
    netstat -ntpl
    //上传图片测试
    fdfs_test /etc/fdfs/client.conf upload 2.jpg 

查看端口情况 

通过 浏览器查看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章