FastDFS文件服务器的安装

    技术2022-07-12  93

    1.步骤:

    环境依赖的安装配置安装路径安装相关组件进行环境配置常见问题汇总
    1-1. 环境依赖的安装
    yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
    2-1 配置安装路径
    storage 安装目录 /home/fastdfs/storagetracker 安装目录 /home/fastdfs/tracker应用安装目录 /service/applicaetion组件下载目录 /service/tools
    3.1 安装相关组件
    3.1.1 创建目录
    mkdir -p service/{application,tools}
    3.1.2 下载安装 libfatscommon 模块
    cd /service/tools #资源下载 git clone https://github.com/happyfish100/libfastcommon.git --depth 1 #进入目录进行安装 cd libfastcommon/ ./make.sh && ./make.sh install #编译安装 #创建软连接 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.1.3 下载安装 FastDFS 模块
    #进入到下载目录 cd ~ /service/tools git clone https://github.com/happyfish100/fastdfs.git --depth 1 cd fastdfs/ ./make.sh && ./make.sh install #编译安装
    3.1.4 复制配置文件
    #配置文件准备 cp /service/tools/fastdfs/conf/tracker.conf.sample /etc/fdfs/tracker.conf cp /service/tools/fastdfs/conf/storage.conf.sample /etc/fdfs/storage.conf cp /service/tools/fastdfs/conf/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试使用 cp /service/tools/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用 cp /service/tools/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用
    3.1.5 安装 fastdfs-nginx-module 模块
    cd ~ /service/tools git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1 cp /service/tools/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs #nginx 模块访问使用的配置
    3.1.6 安装nginx 模块

    请参考我之前的文章 Nginx 安装

    注意!!! 需要在配置项中添加 FastDFS模块

    ./configure --prefix=/home/nginx --with-http_ssl_module --add-module=/service/tools/fastdfs-nginx-module/src
    4.1 进行环境配置
    4.1.1 tracker的配置
    #服务器ip为 10.155.11.10 #我建议用ftp下载下来这些文件 本地修改 vim /etc/fdfs/tracker.conf #需要修改的内容如下 port=22122 # tracker服务器端口(默认22122,一般不修改) base_path=/home/fastdfs/tracker # 存储日志和数据的根目录 #全部配置如下 disabled = false bind_addr = port = 22122 connect_timeout = 5 network_timeout = 60 base_path = /home/fastdfs/tracker max_connections = 1024 accept_threads = 1 work_threads = 4 min_buff_size = 8KB max_buff_size = 128KB store_lookup = 2 store_group = group2 store_server = 0 store_path = 0 download_server = 0 reserved_storage_space = 20% log_level = info run_by_group= run_by_user = allow_hosts = * sync_log_buff_interval = 1 check_active_interval = 120 thread_stack_size = 256KB 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 = 1MB trunk_alloc_alignment_size = 256 trunk_free_space_merge = true delete_unused_trunk_files = false 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 = 86400 trunk_compress_binlog_interval = 86400 trunk_compress_binlog_time_base = 03:00 trunk_binlog_max_backups = 7 use_storage_id = false storage_ids_filename = storage_ids.conf id_type_in_filename = id store_slave_file_use_link = false rotate_error_log = false error_log_rotate_time = 00:00 compress_old_error_log = false compress_error_log_days_before = 7 rotate_error_log_size = 0 log_file_keep_days = 0 use_connection_pool = true 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
    4.1.2 storage的配置
    vim /etc/fdfs/storage.conf #需要修改的内容如下 port=23000 # storage服务端口(默认23000,一般不修改) base_path=/home/fastdfs/storage # 数据和日志文件存储根目录 store_path0=/home/fastdfs/storage/data # 第一个存储目录 tracker_server=10.155.11.10:22122 # tracker服务器IP和端口 http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致) #全部配置如下 disabled = false group_name = group1 bind_addr = client_bind = true port = 23000 connect_timeout = 5 network_timeout = 60 heart_beat_interval = 30 stat_report_interval = 60 base_path = /home/fastdfs/storage max_connections = 1024 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 disk_recovery_threads = 3 store_path_count = 1 store_path0 = /home/fastdfs/storage/data subdir_count_per_path = 256 tracker_server = 10.211.11.10:22122 tracker_server = 10.211.11.10: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 = 1 sync_binlog_buff_interval = 1 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 compress_old_access_log = false compress_access_log_days_before = 7 rotate_error_log = false error_log_rotate_time = 00:00 compress_old_error_log = false compress_error_log_days_before = 7 rotate_access_log_size = 0 rotate_error_log_size = 0 log_file_keep_days = 0 file_sync_skip_invalid_record = false use_connection_pool = true connection_pool_max_idle_time = 3600 compress_binlog = true compress_binlog_time = 01:30 check_store_path_mark = true http.domain_name = http.server_port = 8888
    4.2 开启服务
    #启动 tracker 服务 systemctl start fdfs_trackerd Starting fdfs_trackerd (via systemctl): [ OK ] #启动 storaged 服务 systemctl start fdfs_storaged Starting fdfs_storaged (via systemctl): [ OK ] #同时设置开机自启动 vim /etc/rc.d/rc.local #加到最后一行 systemctl start fdfs_trackerd systemctl start fdfs_storaged
    4.3 配置客户端
    vim /etc/fdfs/client.conf #需要修改的内容如下 base_path=/home/fastdfs/storage tracker_server=10.155.11.10:22122 #tracker服务器IP和端口 #保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz 上传成功会显示文件目录: http://10.155.11.10:8888/group1/M00/00/00/CtM3C178dCuAVe0IAAEtoZaCs2c959.jpg
    4.4 Nginx 的相关配置
    vim /etc/fdfs/mod_fastdfs.conf #需要修改的内容如下 tracker_server=10.155.11.10:22122 #tracker服务器IP和端口 url_have_group_name=true #请求中允许出现 group store_path0=/home/fastdfs/storage #配置nginx.config vim /usr/local/nginx/conf/nginx.conf #添加如下配置 server { listen 8888; ## 该端口为storage.conf中的http.server_port相同 server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } #进入到Nginx sbin目录进行重启 ./nginx -s reload
    4.5 进行访问测试
    如果 访问不了 就修改防火墙 firewall-cmd --zone=public --add-port=23000/tcp --permanent #开户端口号 或者 systemctl enable firewalld.service #开启防火墙 systemctl stop firewalld.service #关闭防火墙(开机会仍会启动) systemctl disable firewalld.service #禁用防火墙(开机后不再启动)

    在浏览器上输入 地址 http://10.211.55.11:8888/group1/M00/00/00/CtM3C178dCuAVe0IAAEtoZaCs2c959.jpg

    恭喜安装成功 !!!

    5.1 常见问题

    如配置文件配置 错误, 则会报如下错误, 请安装上面的流程重新梳理一遍

    [2015-04-28 11:30:14] ERROR - file: ini_file_reader.c, line: 315, include file "http.conf" not exists, line: "#include http.conf" [2015-04-28 11:30:14] ERROR - file: /root/fastdfs-nginx-module-master/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2 2015/04/28 11:30:14 [alert] 19969#0: worker process 2753 exited with fatal code 2 and cannot be respawned
    Processed: 0.014, SQL: 9