当前位置: 首页 > news >正文

CentOS 7 安装、测试和部署FastDFS

目录

FastDFS环境搭建

安装 libfastcommon 库

安装FastDFS

查看编译后的文件

FastDFS配置

 FastDFS启动

启动tracker服务

启动storage服务

查看storage是否已经注册到了tracker下

查看存储文件的目录

FastDFS重启

FastDFS关闭

使用fdfs_test进行测试

修改client.conf配置文件,修改两个配置

创建base_path指定的目录

fdfs命令格式

FastDFS的HTTP访问

安装Nginx并且添加FastDFS模块

nginx安装

将编译好的Nginx替换原有的Nginx

修改Nginx配置文件

重启Nginx

设置开机自启

FastDFS环境搭建

[root@centos_7_fastdfs01 ~]# yum install -y make cmake gcc gcc-c++ wget perl lrzsz

安装 libfastcommon 库

  • 链接: https://pan.baidu.com/s/1PS4fmN4D6Krwqc9a2tk5Yw 提取码: b66k

  • 将下载好的文件上传到Linux系统下

[root@centos_7_fastdfs01 ~]# tar -zxvf libfastcommon-1.0.75.tar.gz

  • 切换到解压后的libfastcommon目录,执行make脚本进行编译

[root@centos_7_fastdfs01 ~]# cd libfastcommon-1.0.75

[root@centos_7_fastdfs01 libfastcommon-1.0.75]# ./make.sh

  • 执行make install进行安装

[root@centos_7_fastdfs01 libfastcommon-1.0.39]# ./make.sh install

mkdir -p /usr/lib64

mkdir -p /usr/lib

mkdir -p /usr/include/fastcommon

install -m 755 libfastcommon.so /usr/lib64

install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h common_blocked_queue.h multi_socket_client.h skiplist_set.h fc_list.h /usr/include/fastcommon

if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi

[root@centos_7_fastdfs01 libfastcommon-1.0.39]# echo $?

0

[root@centos_7_fastdfs01 libfastcommon-1.0.39]#

安装FastDFS

  • 链接:https://pan.baidu.com/s/1AUlnfJAhSrji_vn8M_jOPQ 提取码: auae
  • 链接:https://pan.baidu.com/s/1auPbOU7Nwy_kUqy0mkGFSg?pwd=pq1v 提取码:pq1v

  • 将下载好的文件上传到Linux系统上

[root@centos_7_fastdfs01 ~]# ll fastdfs-6.12.2.tar.gz

-rw-r--r--. 1 root root 5312227 12月 21 09:07 fastdfs-6.12.2.tar.gz [root@centos_7_fastdfs01 ~]# tar xf fastdfs-6.12.2.tar.gz

[root@localhost ~]# tar xf libserverframe-1.2.5.tar.gz

[root@localhost ~]# cd libserverframe-1.2.5

[root@localhost libserverframe-1.2.5]#  ./make.sh

[root@localhost libserverframe-1.2.5]# ./make.sh install

  • 切换到解压后FastDFS的目录,执行make脚本进行编译

[root@centos_7_fastdfs01 fastdfs-6.12.2]# ./make.sh

  • 执行make install进行安装

[root@centos_7_fastdfs01 fastdfs-6.12.2]# ./make.sh install

查看编译后的文件

  • 查看FastDFS相关的可执行程序

[root@centos_7_fastdfs01 fastdfs-6.12.2]# ll /usr/bin/fdfs*

-rwxr-xr-x 1 root root  317424 12月 20 18:01 /usr/bin/fdfs_appender_test

-rwxr-xr-x 1 root root  317200 12月 20 18:01 /usr/bin/fdfs_appender_test1

-rwxr-xr-x 1 root root  304056 12月 20 18:01 /usr/bin/fdfs_append_file

-rwxr-xr-x 1 root root  303784 12月 20 18:01 /usr/bin/fdfs_crc32

-rwxr-xr-x 1 root root  304112 12月 20 18:01 /usr/bin/fdfs_delete_file

-rwxr-xr-x 1 root root  304840 12月 20 18:01 /usr/bin/fdfs_download_file

-rwxr-xr-x 1 root root  304440 12月 20 18:01 /usr/bin/fdfs_file_info

-rwxr-xr-x 1 root root  322336 12月 20 18:01 /usr/bin/fdfs_monitor

-rwxr-xr-x 1 root root 1111584 12月 20 18:01 /usr/bin/fdfs_storaged

-rwxr-xr-x 1 root root  327328 12月 20 18:01 /usr/bin/fdfs_test

-rwxr-xr-x 1 root root  326536 12月 20 18:01 /usr/bin/fdfs_test1

-rwxr-xr-x 1 root root  453848 12月 20 18:01 /usr/bin/fdfs_trackerd

-rwxr-xr-x 1 root root  305040 12月 20 18:01 /usr/bin/fdfs_upload_appender

-rwxr-xr-x 1 root root  306064 12月 20 18:01 /usr/bin/fdfs_upload_file

[root@centos_7_fastdfs01 fastdfs-6.12.2]#

  • 查看FastDFS的配置文件

[root@centos_7_fastdfs01 fastdfs-6.12.2]# ll /etc/fdfs/

总用量 24

-rw-r--r-- 1 root root 1461 12月 20 18:01 client.conf.sample

-rw-r--r-- 1 root root 7927 12月 20 18:01 storage.conf.sample

-rw-r--r-- 1 root root  105 12月 20 18:01 storage_ids.conf.sample

-rw-r--r-- 1 root root 7389 12月 20 18:01 tracker.conf.sample

[root@centos_7_fastdfs01 fastdfs-5.11]#

  • 解压后将fastdfs-6.12.2/conf目录下的两个文件拷贝到/etc/fdfs/

[root@centos_7_fastdfs01 conf]# pwd

/root/fastdfs-6.12.2/conf

[root@centos_7_fastdfs01 conf]# cp -av http.conf /etc/fdfs/

"http.conf" -> "/etc/fdfs/http.conf"

[root@centos_7_fastdfs01 conf]# cp -av mime.types /etc/fdfs/

"mime.types" -> "/etc/fdfs/mime.types"

[root@centos_7_fastdfs01 conf]#

FastDFS配置

  • 去掉/etc/fdfs/目录下FastDFS配置文件的后缀名 .sample

[root@centos_7_fastdfs01 conf]# cd /etc/fdfs/

[root@centos_7_fastdfs01 fdfs]# ll

\总用量 60

-rw-r--r-- 1 root root  1461 12月 20 18:01 client.conf.sample

-rw-rw-r-- 1 root root   955 6月   3 2017 http.conf

-rw-rw-r-- 1 root root 31172 6月   3 2017 mime.types

-rw-r--r-- 1 root root  7927 12月 20 18:01 storage.conf.sample

-rw-r--r-- 1 root root   105 12月 20 18:01 storage_ids.conf.sample

-rw-r--r-- 1 root root  7389 12月 20 18:01 tracker.conf.sample

[root@centos_7_fastdfs01 fdfs]# mv -v ./tracker.conf.sample ./tracker.conf

"./tracker.conf.sample" -> "./tracker.conf"

[root@centos_7_fastdfs01 fdfs]# mv -v ./storage.conf.sample ./storage.conf

"./storage.conf.sample" -> "./storage.conf"

[root@centos_7_fastdfs01 fdfs]# ll

总用量 60

-rw-r--r-- 1 root root  1461 12月 20 18:01 client.conf.sample

-rw-rw-r-- 1 root root   955 6月   3 2017 http.conf

-rw-rw-r-- 1 root root 31172 6月   3 2017 mime.types

-rw-r--r-- 1 root root  7927 12月 20 18:01 storage.conf

-rw-r--r-- 1 root root   105 12月 20 18:01 storage_ids.conf.sample

-rw-r--r-- 1 root root  7389 12月 20 18:01 tracker.conf

[root@centos_7_fastdfs01 fdfs]#

  • 修改tracker.conf文件

[root@localhost fdfs]# grep 'base_path' /etc/fdfs/tracker.conf

base_path = /opt/fastdfs

[root@localhost fdfs]# sed -i 's@base_path = \/opt\/fastdfs@base_path = \/opt\/fastdfs\/tracker@g' /etc/fdfs/tracker.conf

[root@localhost fdfs]# grep 'base_path' /etc/fdfs/tracker.conf

base_path = /opt/fastdfs/tracker

[root@localhost fdfs]#

  • 修改storage.conf文件

[root@localhost fdfs]# grep 'base_path' /etc/fdfs/storage.conf

base_path = /opt/fastdfs

# if store_path0 not exists, it's value is base_path (NOT recommended)

#       the base_path should be independent (different) of the store paths

[root@localhost fdfs]# sed -i 's@base_path = \/opt\/fastdfs@base_path = \/opt\/fastdfs\/storage@g' /etc/fdfs/storage.conf

[root@localhost fdfs]# grep 'base_path' /etc/fdfs/storage.conf

base_path = /opt/fastdfs/storage

# if store_path0 not exists, it's value is base_path (NOT recommended)

#       the base_path should be independent (different) of the store paths

[root@localhost fdfs]#

[root@centos_7_fastdfs01 fdfs]# mkdir -pv /opt/fastdfs/storage

[root@centos_7_fastdfs01 fdfs]# ll /opt/fastdfs/storage

总用量 0

[root@centos_7_fastdfs01 fdfs]#

[root@centos_7_fastdfs01 fdfs]# grep 'store_path_count' /etc/fdfs/storage.conf

store_path_count=1

[root@centos_7_fastdfs01 fdfs]#

[root@localhost fdfs]# grep 'store_path0' /etc/fdfs/storage.conf

# if store_path0 not exists, it's value is base_path (NOT recommended)

store_path0 = /opt/fastdfs

[root@localhost storage]# sed -i 's@store_path0 = \/opt\/fastdfs\/storage\/files@store_path0 = \/opt\/fastdfs\/storage@' /etc/fdfs/storage.conf

[root@localhost storage]#  grep 'store_path0' /etc/fdfs/storage.conf

# if store_path0 not exists, it's value is base_path (NOT recommended)

store_path0 = /opt/fastdfs/storage

[root@localhost storage]#

[root@localhost fdfs]# grep 'tracker_server' /etc/fdfs/storage.conf

# tracker_server can ocur more than once for multi tracker servers.

# the value format of tracker_server is "HOST:PORT",

tracker_server = 192.168.209.121:22122

tracker_server = 192.168.209.122:22122

[root@localhost fdfs]# sed -i 's@tracker_server = 192.168.209.121:22122@tracker_server=192.168.80.69:22122@' /etc/fdfs/storage.conf

[root@localhost fdfs]# grep 'tracker_server' /etc/fdfs/storage.conf

# tracker_server can ocur more than once for multi tracker servers.

# the value format of tracker_server is "HOST:PORT",

tracker_server=192.168.80.69:22122

tracker_server = 192.168.209.122:22122

[root@localhost fdfs]# sed -i 's@tracker_server = 192.168.209.122:22122@tracker_server=192.168.80.69:22122@' /etc/fdfs/storage.conf

[root@localhost fdfs]# grep 'tracker_server' /etc/fdfs/storage.conf

# tracker_server can ocur more than once for multi tracker servers.

# the value format of tracker_server is "HOST:PORT",

tracker_server=192.168.80.69:22122

tracker_server=192.168.80.69:22122

[root@localhost fdfs]#

[root@centos_7_fastdfs01 fdfs]# mkdir -pv /opt/fastdfs/storage/files

mkdir: 已创建目录 "/opt/fastdfs/storage/files"

[root@centos_7_fastdfs01 fdfs]#

 FastDFS启动

启动tracker服务

[root@centos_7_fastdfs01 fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf

[root@centos_7_fastdfs01 fdfs]#

启动storage服务

[root@centos_7_fastdfs01 fdfs]# fdfs_storaged /etc/fdfs/storage.conf

[root@centos_7_fastdfs01 fdfs]#

查看storage是否已经注册到了tracker下

[root@centos_7_fastdfs01 fdfs]# fdfs_monitor /etc/fdfs/storage.conf

[2024-12-20 18:39:04] DEBUG - base_path=/opt/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

server_count=1, server_index=0

tracker server is 192.168.80.69:22122

group count: 1

Group 1:

group name = group1

disk total space = 30705 MB

disk free space = 28376 MB

trunk free space = 0 MB

storage server count = 1

active server count = 1

storage server port = 23000

storage HTTP port = 8888

store path count = 1

subdir count per path = 256

current write server index = 0

current trunk file id = 0

       Storage 1:

              id = 192.168.80.69

              ip_addr = 192.168.80.69 (centos_7_fastdfs01)  ACTIVE

              http domain =

              version = 5.11

              join time = 2024-12-20 18:38:13

              up time = 2024-12-20 18:38:13

              total storage = 30705 MB

              free storage = 28376 MB

              upload priority = 10

              store_path_count = 1

              subdir_count_per_path = 256

              storage_port = 23000

              storage_http_port = 8888

              current_write_path = 0

              source storage id =

              if_trunk_server = 0

              connection.alloc_count = 256

              connection.current_count = 0

              connection.max_count = 0

              total_upload_count = 0

              success_upload_count = 0

              total_append_count = 0

              success_append_count = 0

              total_modify_count = 0

              success_modify_count = 0

              total_truncate_count = 0

              success_truncate_count = 0

              total_set_meta_count = 0

              success_set_meta_count = 0

              total_delete_count = 0

              success_delete_count = 0

              total_download_count = 0

              success_download_count = 0

              total_get_meta_count = 0

              success_get_meta_count = 0

              total_create_link_count = 0

              success_create_link_count = 0

              total_delete_link_count = 0

              success_delete_link_count = 0

              total_upload_bytes = 0

              success_upload_bytes = 0

              total_append_bytes = 0

              success_append_bytes = 0

              total_modify_bytes = 0

              success_modify_bytes = 0

              stotal_download_bytes = 0

              success_download_bytes = 0

              total_sync_in_bytes = 0

              success_sync_in_bytes = 0

              total_sync_out_bytes = 0

              success_sync_out_bytes = 0

              total_file_open_count = 0

              success_file_open_count = 0

              total_file_read_count = 0

              success_file_read_count = 0

              total_file_write_count = 0

              success_file_write_count = 0

              last_heart_beat_time = 2024-12-20 18:38:44

              last_source_update = 1970-01-01 08:00:00

              last_sync_update = 1970-01-01 08:00:00

              last_synced_timestamp = 1970-01-01 08:00:00

[root@centos_7_fastdfs01 fdfs]#

查看存储文件的目录

[root@centos_7_fastdfs01 fdfs]# cd /opt/fastdfs/storage/

[root@centos_7_fastdfs01 storage]# ls

data  files  logs

[root@centos_7_fastdfs01 storage]# cd data/

[root@centos_7_fastdfs01 data]# ls

fdfs_storaged.pid  storage_stat.dat  sync

[root@centos_7_fastdfs01 data]# cd ../logs/

[root@centos_7_fastdfs01 logs]# ls

storaged.log

[root@centos_7_fastdfs01 logs]# cd ../files/

[root@centos_7_fastdfs01 files]# ls

data

[root@centos_7_fastdfs01 files]# cd data/

[root@centos_7_fastdfs01 data]# ls

00  0C  18  24  30  3C  48  54  60  6C  78  84  90  9C  A8  B4  C0  CC  D8  E4  F0  FC

01  0D  19  25  31  3D  49  55  61  6D  79  85  91  9D  A9  B5  C1  CD  D9  E5  F1  FD

02  0E  1A  26  32  3E  4A  56  62  6E  7A  86  92  9E  AA  B6  C2  CE  DA  E6  F2  FE

03  0F  1B  27  33  3F  4B  57  63  6F  7B  87  93  9F  AB  B7  C3  CF  DB  E7  F3  FF

04  10  1C  28  34  40  4C  58  64  70  7C  88  94  A0  AC  B8  C4  D0  DC  E8  F4

05  11  1D  29  35  41  4D  59  65  71  7D  89  95  A1  AD  B9  C5  D1  DD  E9  F5

06  12  1E  2A  36  42  4E  5A  66  72  7E  8A  96  A2  AE  BA  C6  D2  DE  EA  F6

07  13  1F  2B  37  43  4F  5B  67  73  7F  8B  97  A3  AF  BB  C7  D3  DF  EB  F7

08  14  20  2C  38  44  50  5C  68  74  80  8C  98  A4  B0  BC  C8  D4  E0  EC  F8

09  15  21  2D  39  45  51  5D  69  75  81  8D  99  A5  B1  BD  C9  D5  E1  ED  F9

0A  16  22  2E  3A  46  52  5E  6A  76  82  8E  9A  A6  B2  BE  CA  D6  E2  EE  FA

0B  17  23  2F  3B  47  53  5F  6B  77  83  8F  9B  A7  B3  BF  CB  D7  E3  EF  FB

[root@centos_7_fastdfs01 data]#

FastDFS重启

  • 重启tracker

[root@centos_7_fastdfs01 data]# fdfs_trackerd /etc/fdfs/tracker.conf restart

waiting for pid [12493] exit ...

starting ...

[root@centos_7_fastdfs01 data]#

  • 重启storage

[root@centos_7_fastdfs01 data]# fdfs_storaged /etc/fdfs/storage.conf restart

waiting for pid [12502] exit ...

starting ...

[root@centos_7_fastdfs01 data]#

FastDFS关闭

  • 关闭tracker执行命令

[root@centos_7_fastdfs01 data]# fdfs_trackerd /etc/fdfs/tracker.conf stop

waiting for pid [12525] exit ...

pid [12525] exit.

[root@centos_7_fastdfs01 data]#

  • 关闭storage执行命令

[root@centos_7_fastdfs01 data]# fdfs_storaged /etc/fdfs/storage.conf stop

waiting for pid [12536] exit ...

pid [12536] exit.

[root@centos_7_fastdfs01 data]#

使用fdfs_test进行测试

修改client.conf配置文件,修改两个配置

[root@localhost data]# find / -name client.conf

/etc/fdfs/client.conf

/root/fastdfs-6.12.2/conf/client.conf

/root/fastdfs-6.12.2/docker/dockerfile_local-v6.0.9/build_image-v6.0.8/conf/client.conf

/root/fastdfs-6.12.2/docker/dockerfile_local-v6.0.9/build_image-v6.0.9/conf/client.conf

/root/fastdfs-6.12.2/docker/dockerfile_local-v6.0.9/fastdfs-conf/conf/client.conf

/root/fastdfs-6.12.2/docker/dockerfile_local/conf/client.conf

/root/fastdfs-6.12.2/docker/dockerfile_network/conf/client.conf

[root@localhost data]# grep 'base_path' /root/fastdfs-6.12.2/conf/client.conf

base_path = /opt/fastdfs

[root@localhost data]# sed -i 's@base_path = \/opt\/fastdfs@base_path = \/opt\/fastdfs\/client@' /root/fastdfs-6.12.2/conf/client.conf

[root@localhost data]# grep 'base_path' /root/fastdfs-6.12.2/conf/client.conf

base_path = /opt/fastdfs/client

[root@localhost data]# [root@centos_7_fastdfs01 data]#

[root@localhost data]# grep 'tracker_server' /root/fastdfs-6.12.2/conf/client.conf

# tracker_server can ocur more than once for multi tracker servers.

# the value format of tracker_server is "HOST:PORT",

tracker_server = 192.168.0.196:22122

tracker_server = 192.168.0.197:22122

http.tracker_server_port = 80

[root@localhost data]# sed -i 's@tracker_server = 192.168.0.196:22122@tracker_server = 192.168.80.69:22122@' /root/fastdfs-6.12.2/conf/client.conf

[root@localhost data]# sed -i 's@tracker_server = 192.168.0.197:22122@tracker_server = 192.168.80.69:22122@' /root/fastdfs-6.12.2/conf/client.conf

[root@localhost data]# grep 'tracker_server' /root/fastdfs-6.12.2/conf/client.conf

# tracker_server can ocur more than once for multi tracker servers.

# the value format of tracker_server is "HOST:PORT",

tracker_server = 192.168.80.69:22122

tracker_server = 192.168.80.69:22122

http.tracker_server_port = 80

[root@localhost data]#

创建base_path指定的目录

[root@centos_7_fastdfs01 data]# mkdir -pv /opt/fastdfs/client

mkdir: 已创建目录 "/opt/fastdfs/client"

[root@centos_7_fastdfs01 data]#

fdfs命令格式

  • 上传文件:fdfs_test <config_file> <operation> <local_filename>

  • config_file:配置文件的位置
  • operation:upload,download,getmeta,setmeta,delete and query_servers,上传使用的是upload
  • local_filename:要上传的文件名字

[root@localhost data]# touch /opt/1.txt

[root@localhost data]# /usr/bin/fdfs_test /root/fastdfs-6.12.2/conf/client.conf upload /opt/1.txt

This is FastDFS client test program v6.12.2

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General

Public License V3, which may be found in the FastDFS source kit.

Please visit the FastDFS Home Page http://www.fastken.com/

for more detail.

tracker_query_storage_store_list_without_group:

       server 1. group_name=, ip_addr=192.168.80.69, port=23000

group_name=group1, ip_addr=192.168.80.69, port=23000

storage_upload_by_filename

group_name=group1, remote_filename=M00/00/00/wKhQRWdmHnKAfVHQAAAAAAAAAAA048.txt

source ip address: 192.168.80.69

file timestamp=2024-12-21 09:48:34

file size=0

file crc32=0

example file url: http://192.168.80.69/group1/M00/00/00/wKhQRWdmHnKAfVHQAAAAAAAAAAA048.txt

storage_upload_slave_by_filename

group_name=group1, remote_filename=M00/00/00/wKhQRWdmHnKAfVHQAAAAAAAAAAA048_big.txt

source ip address: 192.168.80.69

file timestamp=2024-12-21 09:48:34

file size=0

file crc32=0

example file url: http://192.168.80.69/group1/M00/00/00/wKhQRWdmHnKAfVHQAAAAAAAAAAA048_big.txt

[root@localhost data]#

  • 下载文件命令:fdfs_test <config_file> download <group_name> <remote_filename>

  • group_name: 要下载的文件所在的组名
  • remote_filename:要下载的文件名(要指定在fastDFS中存储的名字)

  • 删除文件命令:fdfs_test <config_file> delete <group_name> <remote_filename>

FastDFS的HTTP访问

安装Nginx并且添加FastDFS模块

  • 检查并安装 Nginx 依赖的库

[root@centos_7_fastdfs01 opt]# yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel –y

  • 压缩包下载链接:https://pan.baidu.com/s/1oyAGij2RxO5fE89Rn2hDXA 提取码: 9vhm
  • 将Fastdfs的Nginx扩展模块源代码上传到Linux上,并解压

[root@centos_7_fastdfs01 ~]# ll fastdfs-nginx-module-1.24.tar.gz

-rw-r--r-- 1 root root 23002 12月 20 19:15 fastdfs-nginx-module-1.24.tar.gz

[root@centos_7_fastdfs01 ~]# tar xf fastdfs-nginx-module-1.24.tar.gz

[root@centos_7_fastdfs01 ~]# ll fastdfs-nginx-module-1.24

总用量 16

-rw-rw-r-- 1 root root 3208 12月  5 2023 HISTORY

-rw-rw-r-- 1 root root 2584 12月  5 2023 INSTALL

-rw-rw-r-- 1 root root 7816 12月  5 2023 LICENSE

drwxrwxr-x 2 root root  109 12月  5 2023 src

[root@centos_7_fastdfs01 ~]#

  • 压缩包下载链接:https://pan.baidu.com/s/1IvqllSyAUkI1OQRp0FIMjg 提取码: gjmb
  • 将Nginx的tar包上传到Linux上,并解压

[root@centos_7_fastdfs01 ~]# ll nginx-1.26.2.tar.gz

-rw-r--r-- 1 root root 1244789 12月 20 19:19 nginx-1.26.2.tar.gz

[root@centos_7_fastdfs01 ~]# tar xf nginx-1.26.2.tar.gz

[root@centos_7_fastdfs01 ~]# ll nginx-1.26.2

总用量 828

drwxr-xr-x 6 502 games    326 12月 20 19:19 auto

-rw-r--r-- 1 502 games 327851 8月  13 00:39 CHANGES

-rw-r--r-- 1 502 games 501527 8月  13 00:39 CHANGES.ru

drwxr-xr-x 2 502 games    168 12月 20 19:19 conf

-rwxr-xr-x 1 502 games   2611 8月  12 22:28 configure

drwxr-xr-x 4 502 games     72 12月 20 19:19 contrib

drwxr-xr-x 2 502 games     40 12月 20 19:19 html

-rw-r--r-- 1 502 games   1397 8月  12 22:28 LICENSE

drwxr-xr-x 2 502 games     21 12月 20 19:19 man

-rw-r--r-- 1 502 games     49 8月  12 22:28 README

drwxr-xr-x 9 502 games     91 8月  13 00:39 src

[root@centos_7_fastdfs01 ~]#

  • 切换至解压后的Nginx主目录,执行配置操作

[root@centos_7_fastdfs01 src]# pwd

/root/fastdfs-nginx-module-1.24/src

[root@centos_7_fastdfs01 src]# ll

总用量 84

-rw-rw-r-- 1 root root 43458 12月  5 2023 common.c

-rw-rw-r-- 1 root root  3995 12月  5 2023 common.h

-rw-rw-r-- 1 root root  1078 12月  5 2023 config

-rw-rw-r-- 1 root root  3725 12月  5 2023 mod_fastdfs.conf

-rw-rw-r-- 1 root root 28668 12月  5 2023 ngx_http_fastdfs_module.c

[root@localhost src]# grep 'CORE_INCS' config

    CORE_INCS="$CORE_INCS /usr/local/include"

[root@localhost src]# sed -i 's@CORE_INCS="$CORE_INCS /usr/local/include"@CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"@' config

[root@localhost src]# grep 'CORE_INCS' config

    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

[root@localhost src]#

[root@centos_7_fastdfs01 src]# grep 'CORE_LIBS=' config

    CORE_LIBS="$CORE_LIBS -lfastcommon -lserverframe -lfdfsclient"

[root@centos_7_fastdfs01 src]# sed -i 's@CORE_LIBS="$CORE_LIBS -lfastcommon -lserverframe -lfdfsclient"@CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"@' config

[root@centos_7_fastdfs01 src]# grep 'CORE_LIBS=' config

    CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"

[root@centos_7_fastdfs01 src]#

  • 复制fastdfs-nginx-module/src/mod_fastdfs.conf 到/etc/fdfs目录下

[root@centos_7_fastdfs01 src]# cd /root/fastdfs-nginx-module-1.24/src/

[root@centos_7_fastdfs01 src]# cp -av mod_fastdfs.conf /etc/fdfs

"mod_fastdfs.conf" -> "/etc/fdfs/mod_fastdfs.conf"

[root@centos_7_fastdfs01 src]#

  • 在/etc/fdfs目录下修改mod_dastdfs.conf文件

[root@centos_7_fastdfs01 src]# grep 'tracker_server=' /etc/fdfs/mod_fastdfs.conf

tracker_server=tracker:22122

[root@centos_7_fastdfs01 src]# grep 'storage_server_port=' /etc/fdfs/mod_fastdfs.conf

storage_server_port=23000

#storage_server_port=23000

#storage_server_port=23000

[root@centos_7_fastdfs01 src]# grep 'group_name=' /etc/fdfs/mod_fastdfs.conf

group_name=group1

#group_name=group1

#group_name=group2

[root@centos_7_fastdfs01 src]# grep 'url_have_group_name =' /etc/fdfs/mod_fastdfs.conf

url_have_group_name = false

[root@centos_7_fastdfs01 src]# sed -i 's@url_have_group_name = false@url_have_group_name = true@' /etc/fdfs/mod_fastdfs.conf

[root@centos_7_fastdfs01 src]# grep 'url_have_group_name =' /etc/fdfs/mod_fastdfs.conf

url_have_group_name = true

[root@centos_7_fastdfs01 src]#

[root@centos_7_fastdfs01 src]# grep 'store_path0=' /etc/fdfs/mod_fastdfs.conf

store_path0=/home/yuqing/fastdfs

#store_path0=/home/yuqing/fastdfs

#store_path0=/home/yuqing/fastdfs

[root@centos_7_fastdfs01 src]# sed -i 's@store_path0=\/home\/yuqing\/fastdfs@store_path0=\/opt\/fastdfs\/storage@' /etc/fdfs/mod_fastdfs.conf

[root@centos_7_fastdfs01 src]# grep 'store_path0=' /etc/fdfs/mod_fastdfs.conf

store_path0=/opt/fastdfs/storage

#store_path0=/opt/fastdfs/storage

#store_path0=/opt/fastdfs/storage

[root@centos_7_fastdfs01 src]#

  • store_path0=你上面设置的默认数据存储目录(我这里是/opt/fastdfs/storage)

[root@centos_7_fastdfs01 src]# grep -nE -B2 '^tracker_server|^storage_server_port|^group_name|^url_have_group_name|^store_path0' /etc/fdfs/mod_fastdfs.conf

38-#  "host:port", host can be hostname or ip address

39-# valid only when load_fdfs_parameters_from_tracker is true

40:tracker_server=tracker:22122

--

42-# the port of the local storage server

43-# the default value is 23000

44:storage_server_port=23000

45-

46-# the group name of the local storage server

47:group_name=group1

--

51-# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx

52-# default value is false

53:url_have_group_name = true

--

60-# the paths must be exist

61-# must same as storage.conf

62:store_path0=/opt/fastdfs/storage

[root@centos_7_fastdfs01 src]#

nginx安装

[root@centos_7_fastdfs01 nginx-1.26.2]# ./configure --add-module=/root/fastdfs-nginx-module-1.24/src/ ; echo $?

[root@localhost nginx-1.26.2]# make ; echo $?

[root@localhost nginx-1.26.2]# make install ; echo $?

将编译好的Nginx替换原有的Nginx

[root@localhost nginx-1.26.2]# cp -av ./objs/nginx /usr/local/nginx/sbin/

cp:是否覆盖"/usr/local/nginx/sbin/nginx"? y

"./objs/nginx" -> "/usr/local/nginx/sbin/nginx"

[root@localhost nginx-1.26.2]#

修改Nginx配置文件

[root@localhost nginx-1.26.2]# vim /usr/local/nginx/conf/nginx.conf

[root@localhost nginx-1.26.2]#

  • 编辑内容如下:

location /group1/M00/{

            ngx_fastdfs_module;

        }

  • 检测配置语法:

[root@localhost nginx-1.26.2]# /usr/local/nginx/sbin/nginx -t

ngx_http_fastdfs_set pid=48551

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost nginx-1.26.2]#

[root@localhost nginx-1.26.2]# /usr/local/nginx/sbin/nginx

ngx_http_fastdfs_set pid=48588

[root@localhost nginx-1.26.2]#

[root@localhost nginx-1.26.2]# ps aux | grep nginx

root      48589  0.0  0.0  30500   672 ?        Ss   10:07   0:00 nginx: master process /usr/local/nginx/sbin/nginx

root      48615  0.0  0.0 112824   988 pts/0    S+   10:07   0:00 grep --color=auto nginx

[root@localhost nginx-1.26.2]#

[root@localhost nginx-1.26.2]# grep -Ev '^$|#' /usr/local/nginx/conf/nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  localhost;

       

        location /group1/M00/{

            ngx_fastdfs_module;

        }

        location / {

            root   html;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

}

[root@localhost nginx-1.26.2]#

重启Nginx

  • 重启Nginx

[root@localhost storage]# /usr/local/nginx/sbin/nginx -s reload

ngx_http_fastdfs_set pid=1892

  • 访问这个随机生成的URL地址

  • 查看上传文件

[root@localhost ~]# find / ! -path "/usr/share/*" ! -path "/home/*" -type f -name '*.jpg'

/root/fastdfs-6.12.2/conf/anti-steal.jpg

/root/fastdfs-6.12.2/docker/dockerfile_local-v6.0.9/build_image-v6.0.9/conf/anti-steal.jpg

/root/fastdfs-6.12.2/docker/dockerfile_local-v6.0.9/fastdfs-conf/conf/anti-steal.jpg

/opt/fastdfs/storage/files/data/00/00/wKhQRWdmJpiAfePhAALWLpLaytE611.jpg

/opt/fastdfs/storage/files/data/00/00/wKhQRWdmJpiAfePhAALWLpLaytE611_big.jpg

/opt/fastdfs/storage/files/data/00/00/wKhQRWdmKlyAaTPUAALWLpLaytE578.jpg

/opt/fastdfs/storage/files/data/00/00/wKhQRWdmKlyAaTPUAALWLpLaytE578_big.jpg

/opt/fastdfs/storage/data/00/00/wKhQRWdmLPCAEuWyAALWLpLaytE221.jpg

/opt/fastdfs/storage/data/00/00/wKhQRWdmLPCAEuWyAALWLpLaytE221_big.jpg

/opt/1.jpg

[root@localhost ~]#

设置开机自启

[root@localhost storage]# cat >>/etc/rc.d/rc.local<<EOF

>

> ### hanyw $(date +%F_%T)

> /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

> /usr/bin/fdfs_storaged /etc/fdfs/storage.conf

> /usr/local/nginx/sbin/nginx

> ### hanyw $(date +%F_%T)

> EOF

[root@localhost storage]# cat /etc/rc.d/rc.local

#!/bin/bash

# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES

#

# It is highly advisable to create own systemd services or udev rules

# to run scripts during boot instead of using this file.

#

# In contrast to previous versions due to parallel execution during boot

# this script will NOT be run after all other services.

#

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

# that this script will be executed during boot.

touch /var/lock/subsys/local

### hanyw 2024-12-21_11:06:54

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

/usr/local/nginx/sbin/nginx

### hanyw 2024-12-21_11:06:54

[root@localhost storage]#

http://www.lryc.cn/news/507316.html

相关文章:

  • 全志H618 Android12修改doucmentsui选中图片资源详情信息
  • 【083】基于51单片机智能烘手器【Proteus仿真+Keil程序+报告+原理图】
  • uniApp使用腾讯地图提示未添加maps模块
  • 未来趋势系列 篇五:自主可控科技题材解析和股票梳理
  • Springboot 学习 之 logback-spring.xml 日志压缩 .tmp 临时文件问题
  • maven-resources-production:ratel-fast: java.lang.IndexOutOfBoundsException
  • K8s docker-compose的入门
  • 去雾Cycle-GAN损失函数
  • word实现两栏格式公式居中,编号右对齐
  • vtie项目中使用到了TailwindCSS,如何打包成一个单独的CSS文件(优化、压缩)
  • shell脚本案例
  • 完整微服务设计 功能实现
  • JWT令牌与微服务
  • C# WinForm移除非法字符的输入框
  • 智慧商城:基于请求数据动态渲染购物车列表
  • 医疗信息化浪潮下 SSM+Vue 医院预约挂号系统的崛起
  • QScreen在Qt5.15与Qt6.8版本下的区别
  • 模具生产过程中的标签使用流程图
  • Unity-URP设置单独渲染UI相机
  • 如何使用java来解析一个pdf文件呢?
  • asp.net core发布配置端口号,支持linux
  • M3D: 基于多模态大模型的新型3D医学影像分析框架,将3D医学图像分析从“看图片“提升到“理解空间“的层次,支持检索、报告生成、问答、定位和分割等8类任务
  • JavaScript中,常用crypto模块进行rsa加密,crypto-js模块进行md5算法
  • 机器学习04-为什么Relu函数
  • 基于Arduino的自动开瓶系统
  • 通过使用 contenteditable=“true“,我们彻底防止了 iOS 系统键盘的弹出
  • 20241217使用M6000显卡在WIN10下跑whisper来识别中英文字幕
  • 搜索召回:召回聚合
  • NTFS 文件搜索库
  • 【GoF23种设计模式】02_单例模式(Singleton Pattern)