zoukankan      html  css  js  c++  java
  • 【FastDFS】FastDFS在CentOS的搭建

    准备安装软件

    [root@blog third_package]# cp fastdfs-nginx-module_v1.16.tar.gz FastDFS_v5.08.tar.gz libfastcommon-master.zip nginx-1.8.0.tar.gz  /opt
    

    安装libfastcommon-master

    [root@blog opt]# unzip /opt/libfastcommon-master.zip
    Archive:  /opt/libfastcommon-master.zip
    [root@blog opt]# 
    [root@blog opt]# cd libfastcommon-master
    [root@blog libfastcommon-master]#
    [root@blog libfastcommon-master]# ./make.sh 
    [root@blog libfastcommon-master]# ./make.sh install
    

    安装FastDFS

    [root@blog opt]# tar -zxvf /opt/FastDFS_v5.08.tar.gz
    [root@blog opt]# cd FastDFS
    [root@blog FastDFS]# ./make.sh
    [root@blog FastDFS]# ./make.sh install
    

    拷贝配置文件

    [root@blog fdfs]# ll /etc/fdfs/
    total 20
    -rw-r--r-- 1 root root 1461 May 23 11:02 client.conf.sample
    -rw-r--r-- 1 root root 7927 May 23 11:02 storage.conf.sample
    -rw-r--r-- 1 root root 7200 May 23 11:02 tracker.conf.sample
    [root@blog fdfs]# cp /opt/FastDFS/conf/storage.conf /opt/FastDFS/conf/tracker.conf /etc/fdfs/
    [root@blog /]# cp /opt/FastDFS/conf/client.conf /etc/fdfs/
    [root@blog conf]# cp /opt/FastDFS/conf/http.conf /etc/fdfs/
    [root@blog fdfs]# rm ./*.sample
    rm: remove regular file `./client.conf.sample'? y
    rm: remove regular file `./storage.conf.sample'? y
    rm: remove regular file `./tracker.conf.sample'? y
    

    创建存放数据和日志的文件夹

    [root@blog /]# mkdir -p /my_fastdfs/{storage,tracker}
    

    修改后的storage.conf,主要修改base_path、store_path0、tracker_server:

    [root@blog /]# grep -v "^#"  /etc/fdfs/storage.conf | grep -v "^$"
    disabled=false
    group_name=group1
    bind_addr=
    client_bind=true
    port=23000
    connect_timeout=30
    network_timeout=60
    heart_beat_interval=30
    stat_report_interval=60
    base_path=/my_fastdfs/storage
    max_connections=256
    buff_size = 256KB
    accept_threads=1
    work_threads=4
    disk_rw_separated = true
    disk_reader_threads = 1
    disk_writer_threads = 1
    sync_wait_msec=50
    sync_interval=0
    sync_start_time=00:00
    sync_end_time=23:59
    write_mark_file_freq=500
    store_path_count=1
    store_path0=/my_fastdfs/storage
    subdir_count_per_path=256
    tracker_server=IP:22122
    log_level=info
    run_by_group=
    run_by_user=
    allow_hosts=*
    file_distribute_path_mode=0
    file_distribute_rotate_count=100
    fsync_after_written_bytes=0
    sync_log_buff_interval=10
    sync_binlog_buff_interval=10
    sync_stat_file_interval=300
    thread_stack_size=512KB
    upload_priority=10
    if_alias_prefix=
    check_file_duplicate=0
    file_signature_method=hash
    key_namespace=FastDFS
    keep_alive=0
    use_access_log = false
    rotate_access_log = false
    access_log_rotate_time=00:00
    rotate_error_log = false
    error_log_rotate_time=00:00
    rotate_access_log_size = 0
    rotate_error_log_size = 0
    log_file_keep_days = 0
    file_sync_skip_invalid_record=false
    use_connection_pool = false
    connection_pool_max_idle_time = 3600
    http.domain_name=
    http.server_port=8888
    

    修改后的tracker.conf,主要修改base_path:

    [root@blog /]# grep -v "^#"  /etc/fdfs/tracker.conf | grep -v "^$"
    disabled=false
    bind_addr=
    port=22122
    connect_timeout=30
    network_timeout=60
    base_path=/my_fastdfs/tracker
    max_connections=256
    accept_threads=1
    work_threads=4
    store_lookup=2
    store_group=group2
    store_server=0
    store_path=0
    download_server=0
    reserved_storage_space = 10%
    log_level=info
    run_by_group=
    run_by_user=
    allow_hosts=*
    sync_log_buff_interval = 10
    check_active_interval = 120
    thread_stack_size = 64KB
    storage_ip_changed_auto_adjust = true
    storage_sync_file_max_delay = 86400
    storage_sync_file_max_time = 300
    use_trunk_file = false 
    slot_min_size = 256
    slot_max_size = 16MB
    trunk_file_size = 64MB
    trunk_create_file_advance = false
    trunk_create_file_time_base = 02:00
    trunk_create_file_interval = 86400
    trunk_create_file_space_threshold = 20G
    trunk_init_check_occupying = false
    trunk_init_reload_from_binlog = false
    trunk_compress_binlog_min_interval = 0
    use_storage_id = false
    storage_ids_filename = storage_ids.conf
    id_type_in_filename = ip
    store_slave_file_use_link = false
    rotate_error_log = false
    error_log_rotate_time=00:00
    rotate_error_log_size = 0
    log_file_keep_days = 0
    use_connection_pool = false
    connection_pool_max_idle_time = 3600
    http.server_port=8080
    http.check_alive_interval=30
    http.check_alive_type=tcp
    http.check_alive_uri=/status.html
    
    

    修改后的client.conf
    主要修改base_path、tracker_server:

    [root@blog /]# grep -v "^#"  /etc/fdfs/client.conf | grep -v "^$"
    connect_timeout=30
    network_timeout=60
    base_path=/my_fastdfs/storage
    tracker_server=IP:22122
    log_level=info
    use_connection_pool = false
    connection_pool_max_idle_time = 3600
    load_fdfs_parameters_from_tracker=false
    use_storage_id = false
    storage_ids_filename = storage_ids.conf
    http.tracker_server_port=80
    

    启动FastDFS

    [root@blog /]# /etc/init.d/fdfs_storaged start
    Starting FastDFS storage server: 
    [root@blog /]# /etc/init.d/fdfs_trackerd start
    Starting FastDFS tracker server: 
    [root@blog /]# ps -ef | grep -E fdfs
    root     23485     1  0 11:24 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
    root     23596     1  0 11:26 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
    root     23656 20047  0 11:27 pts/3    00:00:00 grep -E fdfs
    

    测试上传、下载文件

    [root@blog tmp]# cd /tmp/ && echo '123' > hello.html
    [root@blog tmp]# fdfs_upload_file /etc/fdfs/client.conf hello.html
    group1/M00/00/00/rBIlOFkjrW2Ac6TAAAAABFqCAvc47.html
    [root@blog tmp]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/rBIlOFkjrW2Ac6TAAAAABFqCAvc47.html hello.html.bak
    [root@blog tmp]# cat hello.html.bak 
    123
    

    安装fastdfs-nginx-module

    [root@blog opt]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
    

    查找fastfds、fastcommon在哪

    [root@blog fastdfs-nginx-module]# find /usr/ -name fastdfs
    /usr/include/fastdfs
    ^C
    [root@blog fastdfs-nginx-module]# find /usr/ -name fastcommon
    /usr/include/fastcommon
    

    根据上述查得的实际路径修改config

    [root@blog fastdfs-nginx-module]# cat /opt/fastdfs-nginx-module/src/config
    ngx_addon_name=ngx_http_fastdfs_module
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'"
    

    安装nginx和添加fastdfs-nginx-module

    [root@blog opt]# tar -zxvf nginx-1.8.0.tar.gz
    [root@blog opt]# cd nginx-1.8.0
    [root@blog nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --add-module=/opt/fastdfs-nginx-module/src
    [root@blog nginx-1.8.0]# make
    [root@blog nginx-1.8.0]# make install
    

    拷贝、修改mod_fastdfs.conf
    主要修改base_path、tracker_server、store_path0、url_have_group_name:

    [root@blog nginx-1.8.0]# cp /opt/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
    [root@blog nginx-1.8.0]# grep -v "^#"  /etc/fdfs/mod_fastdfs.conf | grep -v "^$"
    connect_timeout=2
    network_timeout=30
    base_path=/my_fastdfs/storage
    load_fdfs_parameters_from_tracker=true
    storage_sync_file_max_delay = 86400
    use_storage_id = false
    storage_ids_filename = storage_ids.conf
    tracker_server=IP:22122
    storage_server_port=23000
    group_name=group1
    url_have_group_name = true
    store_path_count=1
    store_path0=/my_fastdfs/storage
    log_level=info
    log_filename=
    response_mode=proxy
    if_alias_prefix=
    flv_support = true
    flv_extension = flv
    group_count = 0
    

    在/usr/local/nginx/conf/nginx.conf添加此段

    	location /group1/M00 {
                # root html;
                ngx_fastdfs_module;
        }
    

    启动nginx

    拷贝需要的文件

    [root@blog conf]# cp /usr/local/nginx/conf/mime.types /etc/fdfs
    

    启动nginx,并查看错误日志是否报错

    [root@blog conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ngx_http_fastdfs_set pid=27789
    [root@blog conf]# less /usr/local/nginx/logs/error.log
    

    查看是否能访问:
    http://IP/group1/M00/00/00/rBIlOFkjrW2Ac6TAAAAABFqCAvc47.html

  • 相关阅读:
    Android 获取内存信息
    Android上基于libgdx的游戏开发资料
    Android使用http协议与服务器通信
    Android 下载zip压缩文件并解压
    2014年终总结
    OSG 坑爹的Android example
    支持Android 的几款开源3D引擎调研
    利用Android NDK编译lapack
    Django 中实现连接多个数据库并实现读写分离
    Git之多人协同开发
  • 原文地址:https://www.cnblogs.com/nick-huang/p/6893525.html
Copyright © 2011-2022 走看看