Fastdfs 集群搭建(centos8)

安装libevent(用于网络通讯)

[root@bogon ~]# yum install libevent libevent-devel -y
Last metadata expiration check: 0:00:32 ago on Wed 19 Feb 2020 03:12:07 AM EST.
Package libevent-2.1.8-5.el8.x86_64 is already installed.
Dependencies resolved.
==================================================================================================================================================================================
 Package                                       Architecture                          Version                                       Repository                                Size
==================================================================================================================================================================================
Installing:
 libevent-devel                                x86_64                                2.1.8-5.el8                                   AppStream                                104 k

Transaction Summary
==================================================================================================================================================================================
Install  1 Package

Total download size: 104 k
Installed size: 418 k
Downloading Packages:
libevent-devel-2.1.8-5.el8.x86_64.rpm                                                                                                              75 kB/s | 104 kB     00:01    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                              49 kB/s | 104 kB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                          1/1 
  Installing       : libevent-devel-2.1.8-5.el8.x86_64                                                                                                                        1/1 
  Running scriptlet: libevent-devel-2.1.8-5.el8.x86_64                                                                                                                        1/1 
  Verifying        : libevent-devel-2.1.8-5.el8.x86_64                                                                                                                        1/1 

Installed:
  libevent-devel-2.1.8-5.el8.x86_64                                                                                                                                               

Complete!
[root@bogon ~]#

安装libfastcommon

下载源码:

[root@bogon fastdfs]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
--2020-02-19 03:15:26--  https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
Resolving github.com (github.com)... 13.229.188.59
Connecting to github.com (github.com)|13.229.188.59|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.43 [following]
--2020-02-19 03:15:27--  https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.43
Resolving codeload.github.com (codeload.github.com)... 54.251.140.56
Connecting to codeload.github.com (codeload.github.com)|54.251.140.56|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘V1.0.43.tar.gz’

V1.0.43.tar.gz                                   [  <=>                                                                                        ] 162.62K   292KB/s    in 0.6s    

2020-02-19 03:15:29 (292 KB/s) - ‘V1.0.43.tar.gz’ saved [166526]

[root@bogon fastdfs]# ls
V1.0.43.tar.gz
[root@bogon fastdfs]

解压编译:

[root@bogon fastdfs]# tar -xzf V1.0.43.tar.gz 
[root@bogon fastdfs]# ll
total 164
drwxrwxr-x. 5 root root    153 Dec 25 07:35 libfastcommon-1.0.43
-rw-r--r--. 1 root root 166526 Feb 19 03:15 V1.0.43.tar.gz
[root@bogon fastdfs]# cd libfastcommon-1.0.43/
[root@bogon libfastcommon-1.0.43]# ll
total 32
drwxrwxr-x. 2 root root   114 Dec 25 07:35 doc
-rw-rw-r--. 1 root root 10301 Dec 25 07:35 HISTORY
-rw-rw-r--. 1 root root   674 Dec 25 07:35 INSTALL
-rw-rw-r--. 1 root root  1607 Dec 25 07:35 libfastcommon.spec
-rwxrwxr-x. 1 root root  3253 Dec 25 07:35 make.sh
drwxrwxr-x. 2 root root   191 Dec 25 07:35 php-fastcommon
-rw-rw-r--. 1 root root  2776 Dec 25 07:35 README
drwxrwxr-x. 3 root root  4096 Dec 25 07:35 src
[root@bogon libfastcommon-1.0.43]#
[root@bogon libfastcommon-1.0.43]# ./make.sh

安装

[root@bogon libfastcommon-1.0.43]# ./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 json_parser.h buffered_file_writer.h /usr/include/fastcommon
if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi
[root@bogon libfastcommon-1.0.43]#

安装Fastdfs

下载源码

[root@bogon fastdfs]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
--2020-02-19 03:25:08--  https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.06 [following]
--2020-02-19 03:25:09--  https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.06
Resolving codeload.github.com (codeload.github.com)... 13.229.189.0
Connecting to codeload.github.com (codeload.github.com)|13.229.189.0|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘V6.06.tar.gz’

V6.06.tar.gz                                     [      <=>                                                                                    ] 790.36K   492KB/s    in 1.6s    

2020-02-19 03:25:13 (492 KB/s) - ‘V6.06.tar.gz’ saved [809328]

[root@bogon fastdfs]# ll
total 956
drwxrwxr-x. 5 root root    153 Feb 19 03:21 libfastcommon-1.0.43
-rw-r--r--. 1 root root 166526 Feb 19 03:15 V1.0.43.tar.gz
-rw-r--r--. 1 root root 809328 Feb 19 03:25 V6.06.tar.gz
[root@bogon fastdfs]#

解压编译

[root@bogon fastdfs]# tar -xzf V6.06.tar.gz 
[root@bogon fastdfs]# ll
total 960
drwxrwxr-x. 12 root root   4096 Dec 30 18:36 fastdfs-6.06
drwxrwxr-x.  5 root root    153 Feb 19 03:21 libfastcommon-1.0.43
-rw-r--r--.  1 root root 166526 Feb 19 03:15 V1.0.43.tar.gz
-rw-r--r--.  1 root root 809328 Feb 19 03:25 V6.06.tar.gz
[root@bogon fastdfs]# 
[root@bogon fastdfs-6.06]# ./make.sh

安装

[root@bogon fastdfs-6.06]# ./make.sh install
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_trackerd /usr/bin
if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi
if [ ! -f /etc/fdfs/storage_ids.conf.sample ]; then cp -f ../conf/storage_ids.conf /etc/fdfs/storage_ids.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_storaged  /usr/bin
if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
mkdir -p /usr/lib
cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender fdfs_regenerate_filename /usr/bin
if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; cp -f libfdfsclient.a /usr/lib/;fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib/;fi
mkdir -p /usr/include/fastdfs
cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../tracker/fdfs_server_id_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs
if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi
[root@bogon fastdfs-6.06]#

默认安装方式安装后的相应文件与目录

[root@bogon fastdfs-6.06]# ls /etc/init.d/fdfs_* -l
-rwxr-xr-x. 1 root root 961 Feb 19 03:27 /etc/init.d/fdfs_storaged
-rwxr-xr-x. 1 root root 963 Feb 19 03:27 /etc/init.d/fdfs_trackerd
[root@bogon fastdfs-6.06]

配置文件(这三个是作者给的样例配置文件)

[root@bogon fastdfs-6.06]# ls /etc/fdfs/ -l
total 32
-rw-r--r--. 1 root root  1909 Feb 19 03:27 client.conf.sample
-rw-r--r--. 1 root root 10246 Feb 19 03:27 storage.conf.sample
-rw-r--r--. 1 root root   620 Feb 19 03:27 storage_ids.conf.sample
-rw-r--r--. 1 root root  9138 Feb 19 03:27 tracker.conf.sample
[root@bogon fastdfs-6.06

命令工具在 /usr/bin/ 目录下:

[root@bogon fastdfs-6.06]# ls /usr/bin/fdfs_* -l
-rwxr-xr-x. 1 root root  443040 Feb 19 03:27 /usr/bin/fdfs_appender_test
-rwxr-xr-x. 1 root root  442872 Feb 19 03:27 /usr/bin/fdfs_appender_test1
-rwxr-xr-x. 1 root root  429624 Feb 19 03:27 /usr/bin/fdfs_append_file
-rwxr-xr-x. 1 root root  427960 Feb 19 03:27 /usr/bin/fdfs_crc32
-rwxr-xr-x. 1 root root  429656 Feb 19 03:27 /usr/bin/fdfs_delete_file
-rwxr-xr-x. 1 root root  430632 Feb 19 03:27 /usr/bin/fdfs_download_file
-rwxr-xr-x. 1 root root  430264 Feb 19 03:27 /usr/bin/fdfs_file_info
-rwxr-xr-x. 1 root root  450736 Feb 19 03:27 /usr/bin/fdfs_monitor
-rwxr-xr-x. 1 root root  429824 Feb 19 03:27 /usr/bin/fdfs_regenerate_filename
-rwxr-xr-x. 1 root root 1572928 Feb 19 03:27 /usr/bin/fdfs_storaged
-rwxr-xr-x. 1 root root  452544 Feb 19 03:27 /usr/bin/fdfs_test
-rwxr-xr-x. 1 root root  451864 Feb 19 03:27 /usr/bin/fdfs_test1
-rwxr-xr-x. 1 root root  629424 Feb 19 03:27 /usr/bin/fdfs_trackerd
-rwxr-xr-x. 1 root root  430376 Feb 19 03:27 /usr/bin/fdfs_upload_appender
-rwxr-xr-x. 1 root root  431760 Feb 19 03:27 /usr/bin/fdfs_upload_file
[root@bogon fastdfs-6.06]#

配置FastDFS跟踪器(Tracker)

进入 /etc/fdfs,复制 FastDFS 跟踪器样例配置文件 tracker.conf.sample,并重命名为 tracker.conf。

[root@bogon fastdfs-6.06]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[root@bogon fastdfs-6.06]# ll /etc/fdfs/
total 44
-rw-r--r--. 1 root root  1909 Feb 19 03:27 client.conf.sample
-rw-r--r--. 1 root root 10246 Feb 19 03:27 storage.conf.sample
-rw-r--r--. 1 root root   620 Feb 19 03:27 storage_ids.conf.sample
-rw-r--r--. 1 root root  9138 Feb 19 03:32 tracker.conf
-rw-r--r--. 1 root root  9138 Feb 19 03:27 tracker.conf.sample
[root@bogon fastdfs-6.06]#

创建tracker工作目录

[root@bogon tracker]# mkdir -p /root/fastdfs/work_dir/tracker/
[root@bogon tracker]#

修改配置文件

  1 # is this config file disabled
  2 # false for enabled
  3 # true for disabled
  4 disabled = false
  5 
  6 # bind an address of this host
  7 # empty for bind all addresses of this host
  8 bind_addr =
  9 
 10 # the tracker server port
 11 port = 22122
 12 
 13 # connect timeout in seconds
 14 # default value is 30
 15 # Note: in the intranet network (LAN), 2 seconds is enough.
 16 connect_timeout = 5
 17 
 18 # network timeout in seconds for send and recv
 19 # default value is 30
 20 network_timeout = 60
 21 
 22 # the base path to store data and log files
 23 base_path = /home/yuqing/fastdfs
 24 base_path = /root/fastdfs/work_dir/tracker

/etc/init.d旧的启动方法,启动Tracker

[root@bogon tracker]# /etc/init.d/fdfs_trackerd start
Starting fdfs_trackerd (via systemctl):                    [  OK  ]
[root@bogon tracker]#

systemctl 启动Tracker

[root@bogon tracker]# systemctl stop fdfs_trackerd
[root@bogon tracker]# systemctl start fdfs_trackerd
[root@bogon tracker]# systemctl status fdfs_trackerd
● fdfs_trackerd.service - LSB: FastDFS tracker server
   Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd; generated)
   Active: active (running) since Wed 2020-02-19 03:40:42 EST; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 6570 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS)
    Tasks: 7 (limit: 11332)
   Memory: 5.0M
   CGroup: /system.slice/fdfs_trackerd.service
           └─6577 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

Feb 19 03:40:42 node1 systemd[1]: Starting LSB: FastDFS tracker server...
Feb 19 03:40:42 node1 fdfs_trackerd[6570]: Starting FastDFS tracker server:
Feb 19 03:40:42 node1 systemd[1]: Started LSB: FastDFS tracker server.
[root@bogon tracker]#

设置tracker开机启动

[root@bogon tracker]# chkconfig fdfs_trackerd on
[root@bogon tracker]#

或修改文件为以下内容:

[root@bogon tracker]# vim /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
/etc/init.d/fdfs_trackerd start

Tracker服务第一次启动成功后,会在base_path下创建data、logs两个目录。目录结构如下:

[root@bogon tracker]# tree
.
├── data
│   ├── fdfs_trackerd.pid			# 保存tracker进程id的文件
│   ├── storage_changelog.dat
│   ├── storage_groups_new.dat
│   ├── storage_servers_new.dat
│   └── storage_sync_timestamp.dat
└── logs
    └── trackerd.log

2 directories, 6 files
[root@bogon tracker]#

pid文件用于cli查找daemon进程进行通讯

[root@bogon tracker]# cat data/fdfs_trackerd.pid 
6577[root@bogon tracker]# 
[root@bogon tracker]# 
[root@bogon tracker]# ps -aux | grep tracker
root       6577  0.0  0.3  90160  6972 ?        Sl   03:40   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root       6925  0.0  0.0  12108  1052 pts/0    S+   03:48   0:00 grep --color=auto tracker
[root@bogon tracker]#

查看tracker网络监听

[root@bogon fastdfs]#  netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      6577/fdfs_trackerd  
[root@bogon fastdfs]#

配置 FastDFS 存储 (Storage)

[root@bogon ~]# yum install libevent libevent-devel -y
[root@bogon ~]# mkdir -p /root/fastdfs/
[root@bogon fastdfs]# wget wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
[root@bogon fastdfs]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz

安装方法同tracker

创建storage工作目录

[root@bogon fastdfs]# mkdir -p /root/fastdfs/work_dir/storage/

修改配置文件

[root@bogon fastdfs]# vim /etc/fdfs/storage.conf

修改以下字段:

#base_path = /home/yuqing/fastdfs
base_path = /root/fastdfs/work_dir/storage/
#tracker_server = 192.168.209.121:22122
#tracker_server = 192.168.209.122:22122
tracker_server = 192.168.31.101:22122
# store path (disk or mount point) count, default value is 1
store_path_count = 1

# store_path#, based on 0, to configure the store paths to store files
# if store_path0 not exists, it's value is base_path (NOT recommended)
# the paths must be exist.
#
# IMPORTANT NOTE:
#       the store paths' order is very important, don't mess up!!!
#       the base_path should be independent (different) of the store paths

store_path0 = /root/fastdfs/work_dir/storage/
#store_path0 = /home/yuqing/fastdfs
#store_path1 = /home/yuqing/fastdfs

启动storage节点

[root@bogon fastdfs]# /etc/init.d/fdfs_storaged start
Reloading systemd:                                         [  OK  ]
Starting fdfs_storaged (via systemctl):                    [  OK  ]
[root@bogon fastdfs]# 

设置storage开机启动

[root@bogon fastdfs]# chkconfig fdfs_storaged on
[root@bogon fastdfs]#

查看storage启动状态

[root@bogon storage]# netstat -unltp|grep fdfs
[root@bogon storage]#

发现无网络连接,通过查看日志,发现原因是storage作为客户端,连接到tracker失败

[root@bogon storage]# tail logs/storaged.log 
[2020-02-19 04:17:32] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:17:47] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:18:02] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:18:17] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:18:32] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:18:47] ERROR - file: storage_ip_changed_dealer.c, line: 163, connect to tracker server 192.168.31.101:22122 fail, errno: 113, error info: No route to host
[2020-02-19 04:18:52] ERROR - file: storage_func.c, line: 1199, mkdir "/home/yuqing/fastdfs/data" fail, errno: 2, error info: No such file or directory
[2020-02-19 04:18:52] CRIT - file: storage_func.c, line: 2273, storage_check_and_make_data_dirs fail, program exit!
[2020-02-19 04:18:52] CRIT - exit abnormally!

[root@bogon storage]#

ping tracker节点192.168.31.101成功,说明是端口失败,一般来说是防火墙设置问题(也有可能是tracker端口重用),
可以通过设置端口,但是这里简单期间,之间关闭防火墙

关闭tracker防火墙

[root@bogon fastdfs]# systemctl stop firewalld
[root@bogon fastdfs]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2020-02-19 04:18:47 EST; 1min 35s ago
     Docs: man:firewalld(1)
  Process: 976 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 976 (code=exited, status=0/SUCCESS)

Feb 19 02:25:28 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Feb 19 02:25:29 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Feb 19 04:18:47 node1 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Feb 19 04:18:47 node1 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@bogon fastdfs]#

再次启动storage

[root@bogon storage]# /etc/init.d/fdfs_storaged restart
Restarting fdfs_storaged (via systemctl):                  [  OK  ]
[root@bogon storage]# 

查看storage启动状态

[root@bogon storage]# netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      7226/fdfs_storaged  
[root@bogon storage]#

23000端口是storage的服务端口

查看Storage和Tracker是否在通信

[root@bogon storage]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2020-02-19 04:31:03] DEBUG - base_path=/root/fastdfs/work_dir/storage, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=1, 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.31.101:22122

group count: 1

Group 1:
group name = group1
disk total space = 17,394 MB
disk free space = 10,928 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.31.100
		ip_addr = 192.168.31.100  ACTIVE
		http domain = 
		version = 6.06
		join time = 2020-02-19 04:14:17
		up time = 2020-02-19 04:28:20
		total storage = 17,394 MB
		free storage = 10,928 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 = 2020-02-19 04:30:55
		last_source_update = 1969-12-31 19:00:00
		last_sync_update = 1969-12-31 19:00:00
		last_synced_timestamp = 1969-12-31 19:00:00 
[root@bogon storage]#

同 Tracker,Storage 启动成功后,在base_path 下创建了data、logs目录,记录着 Storage Server 的信息。
在 store_path0/data 目录下,创建了256*256个子目录:

[root@bogon storage]# ls 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
[root@bogon storage]# 
[root@bogon storage]# ls data/A1
00  06  0C  12  18  1E  24  2A  30  36  3C  42  48  4E  54  5A  60  66  6C  72  78  7E  84  8A  90  96  9C  A2  A8  AE  B4  BA  C0  C6  CC  D2  D8  DE  E4  EA  F0  F6  FC
01  07  0D  13  19  1F  25  2B  31  37  3D  43  49  4F  55  5B  61  67  6D  73  79  7F  85  8B  91  97  9D  A3  A9  AF  B5  BB  C1  C7  CD  D3  D9  DF  E5  EB  F1  F7  FD
02  08  0E  14  1A  20  26  2C  32  38  3E  44  4A  50  56  5C  62  68  6E  74  7A  80  86  8C  92  98  9E  A4  AA  B0  B6  BC  C2  C8  CE  D4  DA  E0  E6  EC  F2  F8  FE
03  09  0F  15  1B  21  27  2D  33  39  3F  45  4B  51  57  5D  63  69  6F  75  7B  81  87  8D  93  99  9F  A5  AB  B1  B7  BD  C3  C9  CF  D5  DB  E1  E7  ED  F3  F9  FF
04  0A  10  16  1C  22  28  2E  34  3A  40  46  4C  52  58  5E  64  6A  70  76  7C  82  88  8E  94  9A  A0  A6  AC  B2  B8  BE  C4  CA  D0  D6  DC  E2  E8  EE  F4  FA
05  0B  11  17  1D  23  29  2F  35  3B  41  47  4D  53  59  5F  65  6B  71  77  7D  83  89  8F  95  9B  A1  A7  AD  B3  B9  BF  C5  CB  D1  D7  DD  E3  E9  EF  F5  FB
[root@bogon storage]
[root@bogon storage]# ls data/2D
00  06  0C  12  18  1E  24  2A  30  36  3C  42  48  4E  54  5A  60  66  6C  72  78  7E  84  8A  90  96  9C  A2  A8  AE  B4  BA  C0  C6  CC  D2  D8  DE  E4  EA  F0  F6  FC
01  07  0D  13  19  1F  25  2B  31  37  3D  43  49  4F  55  5B  61  67  6D  73  79  7F  85  8B  91  97  9D  A3  A9  AF  B5  BB  C1  C7  CD  D3  D9  DF  E5  EB  F1  F7  FD
02  08  0E  14  1A  20  26  2C  32  38  3E  44  4A  50  56  5C  62  68  6E  74  7A  80  86  8C  92  98  9E  A4  AA  B0  B6  BC  C2  C8  CE  D4  DA  E0  E6  EC  F2  F8  FE
03  09  0F  15  1B  21  27  2D  33  39  3F  45  4B  51  57  5D  63  69  6F  75  7B  81  87  8D  93  99  9F  A5  AB  B1  B7  BD  C3  C9  CF  D5  DB  E1  E7  ED  F3  F9  FF
04  0A  10  16  1C  22  28  2E  34  3A  40  46  4C  52  58  5E  64  6A  70  76  7C  82  88  8E  94  9A  A0  A6  AC  B2  B8  BE  C4  CA  D0  D6  DC  E2  E8  EE  F4  FA
05  0B  11  17  1D  23  29  2F  35  3B  41  47  4D  53  59  5F  65  6B  71  77  7D  83  89  8F  95  9B  A1  A7  AD  B3  B9  BF  C5  CB  D1  D7  DD  E3  E9  EF  F5  FB
[root@bogon storage]# 

在tracker节点上面(由于是虚拟机,电脑性能没有那么强悍,因此客户端与tracker公用一个节点),使用cli命令行上传文件到fastdfs

修改fastdfs客户端配置文件,vim /etc/fdfs/client.conf

# the base path to store log files
#base_path = /home/yuqing/fastdfs
base_path = /root/fastdfs/work_dir/client
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122

#tracker_server = 192.168.0.196:22122
#tracker_server = 192.168.0.197:22122
tracker_server = 192.168.31.101:2212

预先上传一张图片在客户端节点:

[root@bogon client]# pwd
/root/fastdfs/work_dir/client
[root@bogon client]# ll
total 44
-rw-r--r--. 1 root root 42462 Feb 19 04:39 my-****-photo.png
[root@bogon client]# 

在客户端节点上传一张图片:

[root@bogon client]# fdfs_upload_file /etc/fdfs/client.conf my-****-photo.png 
group1/M00/00/00/wKgfZF5NAsuAYchbAACl3t8kljo919.png
[root@bogon client]#

上传成功后返回文件ID号:group1/M00/00/00/wKgfZF5NAsuAYchbAACl3t8kljo919.png

从fastdfs下载文件:

[root@bogon client]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgfZF5NBH2AMXY-AACl3t8kljo625.png
[root@bogon client]# ls
my-****-photo.png  wKgfZF5NBH2AMXY-AACl3t8kljo625.png
[root@bogon client]# ll
total 88
-rw-r--r--. 1 root root 42462 Feb 19 04:39 my-****-photo.png
-rw-r--r--. 1 root root 42462 Feb 19 04:49 wKgfZF5NBH2AMXY-AACl3t8kljo625.png
[root@bogon client]#

下载后的文件内容与之前上传的文件相同,但是文件名不是原来的文件名(文件名由storage节点根据 源存储服务器IP地址、文件创建时间戳、文件大小、随机数和文件拓展名等信息生成),所以客户端需要在mysql或sqlite3中记录文件路径和前后文件名。

由于我们是一个storage节点,所以可以看到直接到192.168.31.100(storage所在节点)节点查看刚才在客户端上传的图片

[root@bogon storage]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.100  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::3ac6:926b:b2a:49af  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::f060:4c0c:c1f:c97d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:93:9a:33  txqueuelen 1000  (Ethernet)
        RX packets 73401  bytes 39687148 (37.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20104  bytes 5200423 (4.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:92:d6:66  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@bogon storage]# pwd
/root/fastdfs/work_dir/storage
[root@bogon storage]# ls data/00/00/ -l
total 44
-rw-r--r--. 1 root root 42462 Feb 19 04:41 wKgfZF5NAsuAYchbAACl3t8kljo919.png
[root@bogon storage]#

一般来说,社区开源的项目(包括我自己写的项目,也是参照这模式),都会提供两套接口:
cli 命令行接口、api接口
命令行接口用于运维。对于fastdfs的应用来说,提供给第三方程序员的接口是api接口。

查看专栏详情 立即解锁全部专栏 Fastdfs 集群搭建(centos8)Fastdfs 集群搭建(centos8) jacky画笔 发布了70 篇原创文章 · 获赞 66 · 访问量 2万+ 私信 关注
上一篇:服务器(centos6.5)安装和配置FastDFS


下一篇:FasterDFS基础配置安装