1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
我的博客已迁移到xdoujiang.com请去那边和我交流
FastDFS是一个开源的轻量级应用级的分布式文件存储服务,它对文件进行管理,功能包括:
文件存储、文件同步、文件访问(文件上传、文件下载)等解决了大容量存储和负载均衡的问题。
特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS有三个角色:跟踪服务器(tracker server)、存储服务器(storage server)和客户端(client)。
1)跟踪服务器:主要做调度工作 起负载均衡的作用
2)存储服务器:存储节点存储文件 完成文件管理的所有功能:存储、同步和提供存取接口
3)客户端:可以使用fdfs_upload_file、c、php、java、python、.net等api接口
使用TCP
/IP
协议与跟踪器服务器或存储节点进行数据交互
一、基础环境
1、角色、ip、版本、内核、fastdfs、fastdfs-nginx-module、nginx
serverA 10.1.10.117 3.2.0-4-amd64 7.8 tracker nginx
serverB 10.1.10.185 3.2.0-4-amd64 7.8 storage fastdfs-nginx-module nginx group1
serverC 10.1.10.194 3.2.0-4-amd64 7.8 storage fastdfs-nginx-module nginx group1
client 10.1.10.117
fastdfs版本5.05
fastdfs-nginx-module版本1.15
nginx版本1.4.7
libfastcommon版本1.3
2、安装基础包
apt-get -y
install
git wget gcc
make
libpcre3-dev libpcre3 libssl-dev zlib1g-dev
axel libc6-dev libc-bin curl
二、在serverA上安装fastdfs的tracker角色
1、git方式下载
git clone https:
//github
.com
/happyfish100/libfastcommon
.git libfastcommon
git clone https:
//github
.com
/happyfish100/fastdfs
.git fastdfs
2、编译安装
1)
cd
libfastcommon
bash
make
.sh
bash
make
.sh
install
2)
cd
fastdfs
bash
make
.sh
bash
make
.sh
install
3、查看相应命令具体在哪里
ll
/usr/bin/fdfs
*
-rwxr-xr-x 1 root root 349008 Aug 21 14:12
/usr/bin/fdfs_appender_test
-rwxr-xr-x 1 root root 348193 Aug 21 14:12
/usr/bin/fdfs_appender_test1
-rwxr-xr-x 1 root root 333057 Aug 21 14:12
/usr/bin/fdfs_append_file
-rwxr-xr-x 1 root root 333109 Aug 21 14:12
/usr/bin/fdfs_crc32
-rwxr-xr-x 1 root root 333164 Aug 21 14:12
/usr/bin/fdfs_delete_file
-rwxr-xr-x 1 root root 334435 Aug 21 14:12
/usr/bin/fdfs_download_file
-rwxr-xr-x 1 root root 333737 Aug 21 14:12
/usr/bin/fdfs_file_info
-rwxr-xr-x 1 root root 351638 Aug 21 14:12
/usr/bin/fdfs_monitor
-rwxr-xr-x 1 root root 1211424 Aug 21 14:12
/usr/bin/fdfs_storaged
-rwxr-xr-x 1 root root 358392 Aug 21 14:12
/usr/bin/fdfs_test
-rwxr-xr-x 1 root root 357073 Aug 21 14:12
/usr/bin/fdfs_test1
-rwxr-xr-x 1 root root 491214 Aug 21 14:12
/usr/bin/fdfs_trackerd
-rwxr-xr-x 1 root root 334835 Aug 21 14:12
/usr/bin/fdfs_upload_appender
-rwxr-xr-x 1 root root 336773 Aug 21 14:12
/usr/bin/fdfs_upload_file
4、创建数据目录
mkdir
-p
/opt/fastdfs/tracker
5、创建组和用户
groupadd fastdfs
useradd
-s
/bin/bash
-d
/opt/fastdfs/
-g fastdfs fastdfs
6、修改相关目录权限
chown
-R fastdfs.fastdfs
/opt/fastdfs
7、修改配置
1)备份配置
cp
/etc/fdfs/tracker
.conf.sample
/etc/fdfs/tracker
.conf
2)修改配置
/etc/fdfs/tracker
.conf(serverA)
sed
-i
's/bind_addr=.*/bind_addr=10.1.10.117/'
/etc/fdfs/tracker
.conf
sed
-i
's!base_path=.*!base_path=/opt/fastdfs/tracker/!g'
/etc/fdfs/tracker
.conf
sed
-i
's!run_by_group=.*!run_by_group=fastdfs!g'
/etc/fdfs/tracker
.conf
sed
-i
's!run_by_user=.*!run_by_user=fastdfs!g'
/etc/fdfs/tracker
.conf
8、启动服务tracker
1)使用ldd命令检查相应支持模块
ldd
/usr/bin/fdfs_trackerd
linux-vdso.so.1 => (0x00007ffd4abb3000)
libpthread.so.0 =>
/lib/x86_64-linux-gnu/libpthread
.so.0 (0x00007f5dd7c48000)
libdl.so.2 =>
/lib/x86_64-linux-gnu/libdl
.so.2 (0x00007f5dd7a44000)
libfastcommon.so => not found
libc.so.6 =>
/lib/x86_64-linux-gnu/libc
.so.6 (0x00007f5dd76b8000)
/lib64/ld-linux-x86-64
.so.2 (0x00007f5dd7e6a000)
PS:查看到libfastcommon.so => not found 目前不找到
2)先找下libfastcommon.so这个文件在哪里
find
/ -name
"libfastcommon.so"
/root/libfastcommon/src/libfastcommon
.so
/usr/lib64/libfastcommon
.so
2)加载libfastcommon.so
echo
"/usr/lib64"
>
/etc/ld
.so.conf.d
/libfastcommon
.conf
ldconfig
3)再次查看下
ldd
/usr/bin/fdfs_trackerd
linux-vdso.so.1 => (0x00007ffebedd2000)
libpthread.so.0 =>
/lib/x86_64-linux-gnu/libpthread
.so.0 (0x00007f3732ddb000)
libdl.so.2 =>
/lib/x86_64-linux-gnu/libdl
.so.2 (0x00007f3732bd7000)
libfastcommon.so =>
/usr/lib64/libfastcommon
.so (0x00007f37329ae000)
libc.so.6 =>
/lib/x86_64-linux-gnu/libc
.so.6 (0x00007f3732623000)
/lib64/ld-linux-x86-64
.so.2 (0x00007f3732ffd000)
libm.so.6 =>
/lib/x86_64-linux-gnu/libm
.so.6 (0x00007f37323a1000)
PS:都OK了
4)启动tracker服务
fdfs_trackerd
/etc/fdfs/tracker
.conf
9、查看端口和进程tracker
1)查看端口tracker
netstat
-tupnl|
grep
trackerd
tcp 0 0 10.1.10.117:22122 0.0.0.0:* LISTEN 11461
/fdfs_trackerd
2)查看进程tracker
ps
-ef |
grep
track
root 11461 1 0 17:32 ? 00:00:00 fdfs_trackerd
/etc/fdfs/tracker
.conf
10、查看日志
1)查看trackerd日志
cat
/opt/fastdfs/tracker/logs/trackerd
.log
[2015-08-27 14:51:15] INFO - FastDFS v5.07, base_path=
/opt/fastdfs/tracker
, run_by_group=fastdfs, run_by_user=fastdfs, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=10.1.10.117, max_connections=256, accept_threads=1, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, 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
[2015-08-27 14:51:15] INFO - local_host_ip_count: 2, 127.0.0.1 10.1.10.117
11、设置开机启动
echo
"/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf"
>>
/etc/rc
.
local
三、 分别在serverB和C上安装fastdfs的storage角色和nginx和fastdfs-nginx-module模块
1、git方式下载
git clone https:
//github
.com
/happyfish100/libfastcommon
.git libfastcommon
git clone https:
//github
.com
/happyfish100/fastdfs
.git fastdfs
git clone https:
//github
.com
/happyfish100/fastdfs-nginx-module
fastdfs-nginx-module
2、编译安装(serverB和serverC)
1)
cd
libfastcommon
bash
make
.sh
bash
make
.sh
install
2)
cd
fastdfs
bash
make
.sh
bash
make
.sh
install
3、创建数据目录(serverB和serverC)
mkdir
-p
/opt/fastdfs/storage
4、创建组和用户(serverB和serverC)
groupadd fastdfs
useradd
-s
/bin/bash
-d
/opt/fastdfs/
-g fastdfs fastdfs
5、修改相关目录权限(serverB和serverC)
chown
-R fastdfs.fastdfs
/opt/fastdfs
6、修改配置
/etc/fdfs/storage
.conf(serverB和serverC)
1)备份配置
cp
/etc/fdfs/storage
.conf.sample
/etc/fdfs/storage
.conf
2)修改配置
/etc/fdfs/storage
.conf
sed
-i
's/bind_addr=.*/bind_addr=10.1.10.185/'
/etc/fdfs/storage
.conf
sed
-i
's!base_path=.*!base_path=/opt/fastdfs/storage/!g'
/etc/fdfs/storage
.conf
sed
-i
's!store_path0=.*!store_path0=/opt/fastdfs/storage/!g'
/etc/fdfs/storage
.conf
sed
-i
's!tracker_server=.*!tracker_server=10.1.10.117:22122!g'
/etc/fdfs/storage
.conf
sed
-i
's!run_by_group=.*!run_by_group=fastdfs!g'
/etc/fdfs/storage
.conf
sed
-i
's!run_by_user=.*!run_by_user=fastdfs!g'
/etc/fdfs/storage
.conf
sed
-i
's!http.server_port=.*!http.server_port=80!g'
/etc/fdfs/storage
.conf
PS:这里bind_addr的IP如果是serverB那么就是10.1.10.185
这里bind_addr的IP如果是serverC那么就是10.1.10.194
7、加载libfastcommon.so(serverB和serverC)
echo
"/usr/lib64"
>
/etc/ld
.so.conf.d
/libfastcommon
.conf
ldconfig
8、启动storage服务(serverB和serverC)
fdfs_storaged
/etc/fdfs/storage
.conf
9、查看端口和进程storage(serverB和serverC)
1)查看端口storage
netstat
-tupnl|
grep
storage
tcp 0 0 10.1.10.194:23000 0.0.0.0:* 、 LISTEN 9665
/fdfs_storaged
2)查看进程storage
ps
-ef |
grep
storage
fastdfs 9665 1 3 17:48 ? 00:00:02 fdfs_storaged
/etc/fdfs/storage
.conf
10、查看日志(serverB和serverC)
1)查看storage日志
cat
/opt/fastdfs/storage/logs/storaged
.log
[2015-08-31 13:58:39] INFO - FastDFS v5.07, base_path=
/opt/fastdfs/storage
, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=fastdfs, run_by_user=fastdfs, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=10.1.10.194, client_bind=1, max_connections=256, accept_threads=1, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=
hash
, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=80, domain name=, use_access_log=0, rotate_access_log=0, access_log_rotate_time=00:00, rotate_error_log=0, 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=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
data path:
/opt/fastdfs/storage//data
,
mkdir
sub
dir
...
data path:
/opt/fastdfs/storage//data
,
mkdir
sub
dir
done
.
|