1. FastDFS安装
安装环境准备:
CentOS Linux release 7.2.1511 (Core)
fastdfs-5.11
nginx-1.10.1
php 5.6.22
fastdfs-nginx-module Version 1.20
libfastcommon Version 1.36
服务器名称 | IP地址和端口 | 备注 |
fastdfs-tracker | 192.168.56.11:22122 192.168.56.12:22122 | 跟踪服务器/调度服务器 |
fastdfs-storage | 192.168.56.11:23000 192.168.56.12:23000 | 存储服务器 |
安装依赖包
[root@linux-node1 ~]# cd /usr/local/src/ [root@linux-node1 /usr/local/src]# git clone https://github.com/happyfish100/libfastcommon.git [root@linux-node1 /usr/local/src/libfastcommon]# ./make.sh [root@linux-node1 /usr/local/src/libfastcommon]# cd libfastcommon/ && ./make.sh && ./make.sh install
安装最新版FastDFS(v5.11版本)
[root@linux-node1 /usr/local/src/libfastcommon]# cd .. [root@linux-node1 /usr/local/src]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz [root@linux-node1 /usr/local/src]# tar xf V5.11.tar.gz && cd fastdfs-5.11/ && ./make.sh && ./make.sh install
配置文件目录:/etc/fdfs
[root@linux-node1 /usr/local/src/fastdfs-5.11]# tree /etc/fdfs/ /etc/fdfs/ ├── client.conf.sample ├── storage.conf.sample ├── storage_ids.conf.sample └── tracker.conf.sample
软件安装目录:/usr/bin
[root@linux-node1 /usr/local/src/fastdfs-5.11]# ll /usr/bin/fdfs* -rwxr-xr-x 1 root root 317442 Sep 11 00:33 /usr/bin/fdfs_appender_test -rwxr-xr-x 1 root root 317219 Sep 11 00:33 /usr/bin/fdfs_appender_test1 -rwxr-xr-x 1 root root 304067 Sep 11 00:33 /usr/bin/fdfs_append_file -rwxr-xr-x 1 root root 303817 Sep 11 00:33 /usr/bin/fdfs_crc32 -rwxr-xr-x 1 root root 304126 Sep 11 00:33 /usr/bin/fdfs_delete_file -rwxr-xr-x 1 root root 304861 Sep 11 00:33 /usr/bin/fdfs_download_file -rwxr-xr-x 1 root root 304451 Sep 11 00:33 /usr/bin/fdfs_file_info -rwxr-xr-x 1 root root 322376 Sep 11 00:33 /usr/bin/fdfs_monitor -rwxr-xr-x 1 root root 1111634 Sep 11 00:33 /usr/bin/fdfs_storaged -rwxr-xr-x 1 root root 327378 Sep 11 00:33 /usr/bin/fdfs_test -rwxr-xr-x 1 root root 326595 Sep 11 00:33 /usr/bin/fdfs_test1 -rwxr-xr-x 1 root root 453868 Sep 11 00:33 /usr/bin/fdfs_trackerd -rwxr-xr-x 1 root root 305053 Sep 11 00:33 /usr/bin/fdfs_upload_appender -rwxr-xr-x 1 root root 306073 Sep 11 00:33 /usr/bin/fdfs_upload_file
启动文件
[root@linux-node1 /usr/local/src/fastdfs-5.11]# ll /etc/init.d/fdfs* -rwxr-xr-x 1 root root 961 Sep 11 00:33 /etc/init.d/fdfs_storaged -rwxr-xr-x 1 root root 963 Sep 11 00:33 /etc/init.d/fdfs_trackerd
2. FastDFS配置启动
创建存储路径:node1,node2上都执行以下操作
mkdir -p /data/{fdfs_tracker,fdfs_storage} mkdir /data/fdfs_storage/base mkdir /data/fdfs_storage/store cd /etc/fdfs/ cp tracker.conf.sample tracker.conf cp storage.conf.sample storage.conf
tracker服务配置文件
[root@linux-node1 /etc/fdfs]# egrep -v "^$|^#" tracker.conf disabled=false #配置开启 bind_addr= #地址绑定 port=22122 #默认端口 connect_timeout=30 #连接超时 network_timeout=60 #网络反应超时 # the base path to store data and log files base_path=/data/fdfs_tracker #最大连接数及启动线程数 max_connections=256 accept_threads=1 work_threads=4 min_buff_size = 8KB max_buff_size = 128KB #上传策略: # the method of selecting group to upload files # 0: round robin # 1: specify group # 2: load balance, select the max free space group to upload file store_lookup=2 #选择最大空闲的group上传文件 # which storage server to upload file # 0: round robin (default) # 1: the first server order by ip address # 2: the first server order by priority (the minimal) # Note: if use_trunk_file set to true, must set store_server to 1 or 2 store_server=0 #多个目录会轮流存放 # which path(means disk or mount point) of the storage server to upload file # 0: round robin # 2: load balance, select the max free space path to upload file store_path=0 #下载策略: # which storage server to download file # 0: round robin (default) # 1: the source storage server which the current file uploaded to download_server=0 # reserved storage space for system or other applications. # if the free(available) space of any stoarge server in # a group <= reserved_storage_space, # no file can be uploaded to this group. # bytes unit can be one of follows: ### G or g for gigabyte(GB) ### M or m for megabyte(MB) ### K or k for kilobyte(KB) ### no unit for byte(B) ### XX.XX% as ratio such as reserved_storage_space = 10% reserved_storage_space = 10% #多个服务器存储空间以最小的为准 #日志级别 #standard log level as syslog, case insensitive, value list: ### emerg for emergency ### alert ### crit for critical ### error ### warn for warning ### notice ### info ### debug log_level=info #运行用户和组(要用非root用户启动) run_by_group= run_by_user= #允许连接的主机,会影响存储端和客户端 # allow_hosts can ocur more than once, host can be hostname or ip address, # "*" (only one asterisk) means match all ip addresses # we can use CIDR ips like 192.168.5.64/26 # and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com # for example: # allow_hosts=10.0.1.[1-15,20] # allow_hosts=host[01-08,20-25].domain.com # allow_hosts=192.168.5.64/26 allow_hosts=* #刷新日志到磁盘的时间间隔 sync_log_buff_interval = 10 #检察服务器存活的时间间隔 check_active_interval = 120 thread_stack_size = 64KB #存储IP改变是是否自动调整 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
启动追踪服务
[root@linux-node1 /etc/fdfs]# [root@linux-node1 /etc/fdfs]# /etc/init.d/fdfs_trackerd start Reloading systemd: [ OK ] Starting fdfs_trackerd (via systemctl): [ OK ] [root@linux-node1 /etc/fdfs]# netstat -tunpl | grep 22122 tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 4231/fdfs_trackerd #在node2上也安装启动追踪服务,配置与node1相同
storage存储服务配置
#每30秒向追踪服务器发送心跳信息 # heart beat interval in seconds heart_beat_interval=30 磁盘使用的状态报告 # disk usage report interval in seconds stat_report_interval=60 #存储路径 # the base path to store data and log files base_path=/data/fdfs_storage/base #存储的路径统计,有多个硬盘可以写多个 # path(disk or mount point) count, default value is 1 store_path_count=1 # store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist store_path0=/data/fdfs_storage/store #store_path1=/home/yuqing/fastdfs2 #子目录数设定 # subdir_count * subdir_count directories will be auto created under each # store_path (disk), value can be 1 to 256, default value is 256 subdir_count_per_path=256 #设置追踪服务器地址 # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.56.11:22122 tracker_server=192.168.56.12:22122
启动服务
[root@linux-node1 /etc/fdfs]# /etc/init.d/fdfs_storaged start Starting fdfs_storaged (via systemctl): [ OK ] [root@linux-node1 /etc/fdfs]# netstat -tunpl|grep 23000 tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 4768/fdfs_storaged #启动,node2也采用相同配置