单机版fastFDS安装配置

单机版fastFDS安装配置

1. 下载并解压如下包

2. 创建所需目录

mkdir /home/data/storage -p
mkdir /home/data/fastdfs -p
mkdir /home/data/client -p
mkdir /usr/local/nginx -p

3. 安装所需插件

1.nginx所需插件:yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2.运行时所需插件:yum ‐y install libevent----
3.fast所需插件:yum install -y per1 pcre pcre-devel

4. 安装libfastcommon

进入加压后的libfastcommon-1.0.38目录
执行编译:./make.sh
安装:./make.sh install
复制libfastcommon.so文件到usr/lib下
cp src/libfastcommon.so /usr/lib

5. 安装fastdfs

进入加压后的fastdfs-5.11目录
执行编译:./make.sh
安装:./make.sh install

6. 查看tracker和storage的可执行脚本(后面有用)

ll /etc/init.d/|grep fdfs

7. 准备配置文件 默认在/etc/fdfs/下面,备份原来的文件至backup目录下,并上传如下目录文件


更改后的文件如下

client.conf

connect_timeout=30
network_timeout=60
#存储目录
base_path=/home/data/client
#IP
tracker_server=192.168.2.111: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

mod_fastdfs.conf

#include http.conf
connect_timeout=10
network_timeout=30
#存储目录
base_path=/home/data/storage
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
#IP
tracker_server=192.168.2.111:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
#存储目录
store_path0=/home/data/storage
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0

storage.conf

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=/home/data/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=/home/data/storage
subdir_count_per_path=256
#IP
tracker_server=192.168.2.111: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

disabled=false
bind_addr=
port=22122
#端口
http.server_port=8888
connect_timeout=30
network_timeout=60
#存储目录
base_path=/home/data/fastdfs
max_connections=256
accept_threads=1
work_threads=4
min_buff_size = 8KB
max_buff_size = 128KB
store_lookup=2
store_group=group1
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

8. 启动tracker

#1.启动
[root@kht111 fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
#2.查看进程
[root@kht111 fdfs]# ps aux|grep tracker
root      12241  0.0  0.0  80060  1404 ?        Sl   09:23   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root      12561  0.0  0.0 112808   968 pts/0    S+   09:24   0:00 grep --color=auto tracker
#3.关闭
[root@kht111 fdfs]# service fdfs_trackerd stop
Reloading systemd:                                         [  OK  ]
Stopping fdfs_trackerd (via systemctl):                    [  OK  ]

8. 启动storage

#1.启动
[root@kht111 fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
#2.查看进程
[root@kht111 fdfs]# ps aux|grep storage
root      13682  0.0  0.0  12272   828 ?        S    09:27   0:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root      13822  0.0  0.0 112808   968 pts/0    S+   09:27   0:00 grep --color=auto storage
#3.关闭
[root@kht111 fdfs]# service fdfs_storaged stop
Stopping fdfs_storaged (via systemctl):                    [  OK  ]
#4.查看tracker和storage是不是在通信
[root@kht111 fdfs]# fdfs_monitor /etc/fdfs/storage.conf
#5.查看/home/fastdfsdata/tracker/下storage的日志和数据
[root@kht111 fdfs]# ls /home/data/storage/
data  logs
[root@kht111 fdfs]# ls /home/data/storage/data/
00  07  0E  15  1C  23  2A  31  38  3F  46  4D  54  5B  62  69  70  77  7E  85  8C  93  9A  A1  A8  AF  B6  BD  C4  CB  D2  D9  E0  E7  EE  F5  FC
01  08  0F  16  1D  24  2B  32  39  40  47  4E  55  5C  63  6A  71  78  7F  86  8D  94  9B  A2  A9  B0  B7  BE  C5  CC  D3  DA  E1  E8  EF  F6  FD
02  09  10  17  1E  25  2C  33  3A  41  48  4F  56  5D  64  6B  72  79  80  87  8E  95  9C  A3  AA  B1  B8  BF  C6  CD  D4  DB  E2  E9  F0  F7  fdfs_storaged.pid
03  0A  11  18  1F  26  2D  34  3B  42  49  50  57  5E  65  6C  73  7A  81  88  8F  96  9D  A4  AB  B2  B9  C0  C7  CE  D5  DC  E3  EA  F1  F8  FE
04  0B  12  19  20  27  2E  35  3C  43  4A  51  58  5F  66  6D  74  7B  82  89  90  97  9E  A5  AC  B3  BA  C1  C8  CF  D6  DD  E4  EB  F2  F9  FF
05  0C  13  1A  21  28  2F  36  3D  44  4B  52  59  60  67  6E  75  7C  83  8A  91  98  9F  A6  AD  B4  BB  C2  C9  D0  D7  DE  E5  EC  F3  FA  storage_stat.dat
06  0D  14  1B  22  29  30  37  3E  45  4C  53  5A  61  68  6F  76  7D  84  8B  92  99  A0  A7  AE  B5  BC  C3  CA  D1  D8  DF  E6  ED  F4  FB  sync

9. 使用FastDFS自带工具测试

#1.拷贝一张图片kht.png到Centos服务器上的 /kht/目录下,并运行测试
[root@kht111 kht]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /kht/kht.png
group1/M00/00/00/wKgCb2SOX4-AJCWXAAA-4-hc50I063.png
#2.以上图中的文件地址:
http://192.168.2.111/group1/M00/00/00/wKgCb2SOX4-AJCWXAAA-4-hc50I063.png
#3.对应storage服务器的
/home/data/storage/data/M00/00/00/wKgCb2SOX4-AJCWXAAA-4-hc50I063.png文件

10. FastDFS 和nginx整合

1.进入加压后的fastdfs-nginx-module-1.20/src目录下,修改config文件
将/usr/local路径中的local路径去除(共两处),该两行修改后的内容如下:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon"

config修改后的内容

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include/fastcommon"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    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/fastcommon"
    CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
2.将fastdfs-nginx-module-1.20/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下并修改
[root@kht1111 src]# cp mod_fastdfs.conf /etc/fdfs/
将mod_fastdfs.conf如下的内容做修改
40 tracker_server=tracker:22122 修改为tracker_server=192.168.2.111:22122
#tracker_server=192.168.172.20:22122 #(多个tracker配置多行)
53 url_have_group_name = false  修改为url_have_group_name = true
62 store_path0=/home/yuqing/fastdfs 修改为/home/data/storage
3.进入之前解压的fastdfs目录下,把http.conf、mime.conf移动至/etc/fdfs
[root@kht130 conf]# cp http.conf /etc/fdfs/
[root@kht130 conf]# cp mime.types /etc/fdfs/

11. Nginx的安装

#1.进入nginx的解压后的目录执行
./configure --prefix=/usr/local/nginx --add-module=/kht/fastdfs-nginx-module-1.20/src
#2.编译并安装  
make && make install
#3.查看模块是否加载成功
[root@kht111 sbin]# ./nginx -V
nginx version: nginx/1.21.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=/usr/local/nginx --add-module=/kht/fastdfs-nginx-module-1.20/src
#4.修改nginx的配置文件
location / {
           # root   html;
           # index  index.html index.htm;
            ngx_fastdfs_module;
        }
#5.启动nginx并在浏览器中输入图片的访问地址:
http://192.168.2.111/group1/M00/00/00/wKgCb2SOX4-AJCWXAAA-4-hc50I063.png
posted @ 2021-09-03 10:59  kht  阅读(1091)  评论(0编辑  收藏  举报