天天看点

Censos_fdfs

前言

安装前置软件

unzip libfastcommon-master.zip
yum -y install unzip zip
yum -y install gcc-c++
./make.sh && ./make.sh install 
           

设置软链接

至此libfastcommon就已经安装成功了,但注意一下上图中红色框标注的内容,libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/usr/local/lib,所以此处需要重新设置软链接(类似于Windows的快捷方式):

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
           

安装fastfs5.12

tar -zxvf fastdfs-.tar.gz 
./make.sh
./make.sh install

cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf

mkdir /opt/fastdfs_tracker
           

修改/etc/fdfs/tracker.conf

disabled=false #启用配置文件(默认启用)
    port= #设置tracker的端口号,通常采用22122这个默认端口
    base_path=/opt/fastdfs_tracker #设置tracker的数据文件和日志目录
    http.server_port= #设置http端口号,默认为8080
    service fdfs_trackerd start
    ## netstat -unltp|grep fdfs
           
mkdir /opt/fastdfs_storage
mkdir /opt/fastdfs_storage_data
           

修改/etc/fdfs/storage.conf

disabled=false #启用配置文件(默认启用)
    group_name=group1 #组名,根据实际情况修改
    port= #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
    base_path=/opt/fastdfs_storage #设置storage数据文件和日志目录
    store_path_count= #存储路径个数,需要和store_path个数匹配
    store_path=/opt/fastdfs_storage_data #实际文件存储路径
    tracker_server=.: #tracker 服务器的 IP地址和端口号,如果是单机搭建,IP不要写127.0.0.1,否则启动不成功(此处的ip是我的CentOS虚拟机ip)
    http.server_port= #设置 http 端口号
           
ln -s /usr/bin/fdfs_storaged /usr/local/bin
service fdfs_storaged start
           

查看data验证命令

### 修改/etc/fdfs/client.conf
    base_path=/opt/fastdfs_tracker #tracker服务器文件路径
    tracker_server=.: #tracker服务器IP地址和端口号
    http.tracker_server_port= # tracker 服务器的 http 端口号,必须和tracker的设置对应起来
           

安装Nginx服务

yum -y install pcre pcre-devel  
yum -y install zlib zlib-devel  
yum -y install openssl openssl-devel

tar -zxvf nginx-.tar.gz
unzip fastdfs-nginx-module-master.zip
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
make
make install

cp -r /usr/local/fastdfs-/conf/http.conf /etc/fdfs/
cp -r /usr/local/fastdfs-/conf/mime.types /etc/fdfs/
           

修改 /etc/fdfs/client.conf

base_path=/opt/fastdfs_storage #保存日志目录
    tracker_server=.: #tracker服务器的IP地址以及端口号
    storage_server_port= #storage服务器的端口号
    url_have_group_name = true #文件 url 中是否有 group 名
    store_path=/opt/fastdfs_storage_data # 存储路径
    group_count =  #设置组的个数,事实上这次只使用了group1

    ## 追加
    [group1]
    group_name=group1
    storage_server_port=
    store_path_count=
    store_path=/opt/fastdfs_storage_data

    [group2]
    group_name=group2
    storage_server_port=
    store_path_count=
    store_path=/opt/fastdfs_storage_data

    [group3]
    group_name=group3
    storage_server_port=
    store_path_count=
    store_path=/opt/fastdfs_storage_data
           

修改 复制并修改 mod_fastdfs.conf

## 修改
base_path=/data/fastdfs_storage  #日志存放路径
tracker_server=.:  #tracker 服务器 IP 地址和端口号
http.tracker_server_port=  # tracker 服务器的 http 端口号,必须和tracker的设置对应起来
server {

        listen ;
        server_name localhost;

charset     utf-;
access_log      /var/log/nginx/fdfs_access.log;
error_log       /var/log/nginx/fdfs_error.log;

client_max_body_size M;

        location ~/group([0-9])/M0 {
    root /opt/fastdfs_storage_data/data;
            ngx_fastdfs_module;
        }

        error_page     /x.html;

        location = /50x.html {
           root html;
        }
    }
           

验证查看

访问 ##http://47.90.101.11:10077/group1/M00/00/00/rB_aY1nochWAERaUAADjEX1yNvg421.jpg

python3-fdfs-client 客户端使用

>>> from fdfs_client.client import *
>>> client = Fdfs_client('/etc/fdfs/client.conf')
>>>> ret = client.upload_by_filename('/root/d.jpg')
>>> ret
{'Local file name': '/root/d.jpg', 'Status': 'Upload successed.', 'Uploaded size': '56.77KB', 'Remote file_id': b'group1/M00/00/00/rB_aY1nochWAERaUAADjEX1yNvg421.jpg', 'Group name': b'group1', 'Storage IP': b'172.31.218.99'}
>>> 
           
Censos_fdfs

“`

PS: 香港云主机一键搭建 ss

bash <(curl -s http://morning.work/examples/2015-12/install-shadowsocks.sh)

最后小飞机连接

来源 http://www.linuxidc.com/Linux/2016-09/135537.htm