一、配置Fastdfs(fastdfs 5.11 +fast-nginx-modul version 1.20)
1.工具准备
(1)libfastcommon-master 下载地址
https://github.com/happyfish100/libfastcommon
(2)fastdfs 5.11 下载地址
https://github.com/happyfish100/fastdfs/releases
(3)fastdfs-nginx-module-master 下载地址
https://github.com/happyfish100/fastdfs-nginx-module
2.配置Fastdfs
2.1安装libfastcommon
a.
unzip libfastcommon-master.zip
b.进入目录,执行如下命令 ./make.sh
./make.sh install
2.2安装Fastdfs
2.2.1
解压下载的fastdfs-5.11.zip
unzip fastdfs-5.11.zip
进入目录,执行编译安装指令:
-
cd fastdfs-5.11
-
./make.sh
-
./make.sh install
2.2.2
创建文件存储目录:
mkdir ~/data
mkdir ~/data/fastdfs
2.2.3
tracker配置:
创建tracker目录:
mkdir ~/data/fastdfs/tracker
修改/etc/fdfs/tracker.conf配置文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
修改配置为:
# the base path to store data and log files
base_path=/home/{user}/data/fastdfs/tracker
2.2.4
storage配置:
创建storage目录:
mkdir ~/data/fastdfs/storage
修改/etc/fdfs/storage.conf配置文件
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
修改配置为:
# the base path to store data and log files
base_path=/home/{user}/data/fastdfs/storage
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/{user}/data/fastdfs/storage
# 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.181.53:22122
2.2.5
client配置:
创建tracker目录:
mkdir ~/data/fastdfs/client
修改/etc/fdfs/tracker.conf配置文件
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
修改配置为:
# the base path to store log files
base_path=/home/{netsin}/data/fastdfs/client
# 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.181.53:22122
2.2.6 启动tracker ,测试tracker 是否启动成功
fdfs_trackerd /etc/fdfs/tracker.conf start
随后,前往 /home/toolrd/data/fastdfs/tracker/logs 目录下,查看trackerd.log
正常启动的log如下:
[2019-10-10 08:54:52] INFO - file: tracker_relationship.c, line: 401, I am the new tracker leader 192.168.2.112:22122
[2019-10-10 11:05:13] INFO - FastDFS v5.08, base_path=/home/toolrd/data/fastdfs/tracker, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, accept_threads=1, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=0 MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, use_storage_id=0, id_type_in_filename=ip, storage_id_count=0, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, log_file_keep_days=0, store_slave_file_use_link=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2019-10-10 11:05:28] INFO - file: tracker_relationship.c, line: 383, selecting leader...
[2019-10-10 11:05:28] INFO - file: tracker_relationship.c, line: 401, I am the new tracker leader 192.168.2.112:2212
2.2.7启动storage 查看log 判断storage是否启动成功
fdfs_storaged /etc/fdfs/storage.conf start
随后,前往 /home/toolrd/data/fastdfs/storage/logs 目录下,查看storage.log
正常的log如下:
[2019-10-10 11:05:27] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=0 MB, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0
[2019-10-10 11:05:27] INFO - file: storage_func.c, line: 254, tracker_client_ip: 192.168.2.112, my_server_id_str: 192.168.2.112, g_server_id_in_filename: 1879222464
[2019-10-10 11:05:27] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.2.112:22122, as a tracker client, my ip is 192.168.2.112
[2019-10-10 11:05:58] INFO - file: tracker_client_thread.c, line: 1235, tracker server 192.168.2.112:22122, set tracker leader: 192.168.2.112:22122
2.2.8 随后上传文件测试Fastdfs配置是否正确
具体上传文件的方法两种:
(1) fdfs_upload_file + 配置路径 +需要上传的文件路径(全路径)
fdfs_upload_file /etc/fdfs/client.conf /home/toolrd/Desktop/Test.jpg
配置正常的话显示:group1/M00/00/00/wKgCcF2e1B6AMyNsAAHgWzbNIqY789.jpg
a.打开 ls /home/toolrd/data/fastdfs/storage/data
显示
00 11 22 33 44 55 66 77 88 99 AA BB CC DC ED fdfs_storaged.pid
01 12 23 34 45 56 67 78 89 9A AB BC CD DD EE FE
02 13 24 35 46 57 68 79 8A 9B AC BD CE DE EF FF
03 14 25 36 47 58 69 7A 8B 9C AD BE CF DF F0 M00
04 15 26 37 48 59 6A 7B 8C 9D AE BF D0 E0 F1 storage_stat.dat
05 16 27 38 49 5A 6B 7C 8D 9E AF C0 D1 E1 F2 sync
06 17 28 39 4A 5B 6C 7D 8E 9F B0 C1 D2 E2 F3
07 18 29 3A 4B 5C 6D 7E 8F A0 B1 C2 D3 E3 F4
08 19 2A 3B 4C 5D 6E 7F 90 A1 B2 C3 D4 E4 F5
09 1A 2B 3C 4D 5E 6F 80 91 A2 B3 C4 D5 E5 F6
0A 1B 2C 3D 4E 5F 70 81 92 A3 B4 C5 D6 E6 F7
0B 1C 2D 3E 4F 60 71 82 93 A4 B5 C6 D7 E7 F8
0C 1D 2E 3F 50 61 72 83 94 A5 B6 C7 D8 E8 F9
0D 1E 2F 40 51 62 73 84 95 A6 B7 C8 D9 E9 FA
0E 1F 30 41 52 63 74 85 96 A7 B8 C9 DA EA FB
0F 20 31 42 53 64 75 86 97 A8 B9 CA data EB FC
10 21 32 43 54 65 76 87 98 A9 BA CB DB EC FD
b.ls /home/toolrd/data/fastdfs/storage/data/00/00 可以找到刚存储的文件路径。
(1)方法直接使用指令上传文件,没有显示更多的信息,仅仅显示hash存储的文件位置信息,没有直接显示出文件网页形式访问的地址信息,(2)方法可以直接显示出存储文件的地址信息。
(2)
此时直接网页访问example file 路径是无法完成的,因为但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,余庆老师,为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块)。
待更新。。。。
fdfs_trackerd /etc/fdfs/tracker.conf