FastDFS的php和nginx模块配置

简介:

一、FastDFS和php整合

1、安装php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 安装依赖包
yum -y  install  gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel  bzip2  bzip2 -devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel  openssl openssl-devel openldap openldap-devel nss_ldap openldap_clients
 
# 安装epel,为了安装libmcrypt等包
yum   install  epel-release 
yum  install  libmcrypt libmcrypt-devel mcrypt mhash -y
 
#下载并解压php源码包
cd  /opt/tools
wget http: //cn2 .php.net /get/php-5 .6.26. tar .gz /from/this/mirror
tar  -zxf php-5.6.26. tar .gz
 
#编译安装
cd  php-5.6.26
. /configure  --prefix= /usr/local/php  --with-config- file -path= /usr/local/php/etc   --with-iconv- dir = /usr/local  --with-freetype- dir  --with-jpeg- dir  --with-png- dir  --with-zlib --with-libxml- dir = /usr  -- enable -xml --disable-rpath -- enable -discard-path -- enable -safe-mode -- enable -bcmath -- enable -shmop -- enable -sysvsem -- enable -inline-optimization --with-curl --with-curlwrappers -- enable -mbregex -- enable -fastcgi -- enable -fpm -- enable -force-cgi-redirect -- enable -mbstring --with-mcrypt --with-gd -- enable -gd-native-ttf --with-openssl --with-mhash -- enable -pcntl -- enable -sockets --with-ldap --with-ldap-sasl --with-xmlrpc -- enable -zip -- enable -soap --without-pear --with-zlib -- enable -pdo --with-pdo-mysql
make  &&  make  install

2、生成并配置fastdfs的php模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 进入fastdfs源码解压后的目录
cd  /opt/tools/fastdfs-5 .05 /php_client/
/usr/local/php/bin/phpize
 
# 测试php安装结果
[root@mylinux3 php_client] # /usr/local/php/bin/phpize
Configuring  for :
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
 
# 编译并安装fastdfs的php模块
. /configure  --with-php-config= /usr/local/php/bin/php-config 
make  &&  make  install
[root@mylinux3 php_client] # ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
total 1992
-rwxr-xr-x 1 root root  340037 Oct  5 17:26 fastdfs_client.so
-rwxr-xr-x 1 root root 1105024 Oct  5 17:13 opcache.a
-rwxr-xr-x 1 root root  586352 Oct  5 17:13 opcache.so

3、编辑php.ini

1
2
3
4
5
cp  /opt/tools/php-5 .6.26 /php .ini-production  /usr/locni-production  /usr/local/php/etc/php .ini
cd  /opt/tools/fastdfs-5 .05 /php_client
[root@mylinux3 php_client] # ll fastdfs_client.ini 
-rw-rw-r-- 1 root root 1403 Nov 22  2014 fastdfs_client.ini
cat  fastdfs_client.ini >>  /usr/local/php/etc/php .ini

4、测试通过php操作fastdfs

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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
/usr/local/php/bin/php  fastdfs_test.php 
 
[root@mylinux3 php_client] # /usr/local/php/bin/php fastdfs_test.php 
5.05
fastdfs_tracker_make_all_connections result: 1
array(1) {
   [ "group1" ]=>
   array(13) {
     [ "total_space" ]=>
     int(17944)
     [ "free_space" ]=>
     int(12476)
     [ "trunk_free_space" ]=>
     int(0)
     [ "server_count" ]=>
     int(2)
     [ "active_count" ]=>
     int(2)
     [ "storage_port" ]=>
     int(23000)
     [ "storage_http_port" ]=>
     int(8888)
     [ "store_path_count" ]=>
     int(1)
     [ "subdir_count_per_path" ]=>
     int(256)
     [ "current_write_server" ]=>
     int(0)
     [ "current_trunk_file_id" ]=>
     int(0)
     [ "192.168.100.181" ]=>
     array(61) {
       [ "ip_addr" ]=>
       string(15)  "192.168.100.181"
       [ "join_time" ]=>
       int(1475602195)
       [ "up_time" ]=>
       int(1475646224)
       [ "http_domain" ]=>
       string(0)  ""
       [ "version" ]=>
       string(4)  "5.05"
       [ "src_storage_id" ]=>
       string(0)  ""
       [ "if_trunk_server" ]=>
       bool( false )
       [ "upload_priority" ]=>
       int(10)
       [ "store_path_count" ]=>
       int(1)
       [ "subdir_count_per_path" ]=>
       int(256)
       [ "storage_port" ]=>
       int(23000)
       [ "storage_http_port" ]=>
       int(8888)
       [ "current_write_path" ]=>
       int(0)
       [ "status" ]=>
       int(7)
       [ "total_space" ]=>
       int(17944)
       [ "free_space" ]=>
       int(12476)
       [ "connection.alloc_count" ]=>
       int(256)
       [ "connection.current_count" ]=>
       int(1)
       [ "connection.max_count" ]=>
       int(2)
       [ "total_upload_count" ]=>
       int(1)
       [ "success_upload_count" ]=>
       int(1)
       [ "total_append_count" ]=>
       int(0)
       [ "success_append_count" ]=>
       int(0)
       [ "total_modify_count" ]=>
       int(0)
       [ "success_modify_count" ]=>
       int(0)
       [ "total_truncate_count" ]=>
       int(0)
       [ "success_truncate_count" ]=>
       int(0)
       [ "total_set_meta_count" ]=>
       int(0)
       [ "success_set_meta_count" ]=>
       int(0)
       [ "total_delete_count" ]=>
       int(1)
       [ "success_delete_count" ]=>
       int(1)
       [ "total_download_count" ]=>
       int(2)
       [ "success_download_count" ]=>
       int(2)
       [ "total_get_meta_count" ]=>
       int(0)
       [ "success_get_meta_count" ]=>
       int(0)
       [ "total_create_link_count" ]=>
       int(0)
       [ "success_create_link_count" ]=>
       int(0)
       [ "total_delete_link_count" ]=>
       int(0)
       [ "success_delete_link_count" ]=>
       int(0)
       [ "total_upload_bytes" ]=>
       int(13)
       [ "success_upload_bytes" ]=>
       int(13)
       [ "total_append_bytes" ]=>
       int(0)
       [ "success_append_bytes" ]=>
       int(0)
       [ "total_modify_bytes" ]=>
       int(0)
       [ "success_modify_bytes" ]=>
       int(0)
       [ "total_download_bytes" ]=>
       int(26)
       [ "success_download_bytes" ]=>
       int(26)
       [ "total_sync_in_bytes" ]=>
       int(12)
       [ "success_sync_in_bytes" ]=>
       int(12)
       [ "total_sync_out_bytes" ]=>
       int(0)
       [ "success_sync_out_bytes" ]=>
       int(0)
       [ "total_file_open_count" ]=>
       int(5)
       [ "success_file_open_count" ]=>
       int(5)
       [ "total_file_read_count" ]=>
       int(2)
       [ "success_file_read_count" ]=>
       int(2)
       [ "total_file_write_count" ]=>
       int(3)
       [ "success_file_write_count" ]=>
       int(3)
       [ "last_heart_beat_time" ]=>
       int(1475660266)
       [ "last_source_update" ]=>
       int(1475647676)
       [ "last_sync_update" ]=>
       int(1475648117)
       [ "last_synced_timestamp" ]=>
       int(1475648114)
     }
     [ "192.168.100.182" ]=>
     array(61) {
       [ "ip_addr" ]=>
       string(15)  "192.168.100.182"
       [ "join_time" ]=>
       int(1475602286)
       [ "up_time" ]=>
       int(1475648692)
       [ "http_domain" ]=>
       string(0)  ""
       [ "version" ]=>
       string(4)  "5.05"
       [ "src_storage_id" ]=>
       string(15)  "192.168.100.181"
       [ "if_trunk_server" ]=>
       bool( false )
       [ "upload_priority" ]=>
       int(10)
       [ "store_path_count" ]=>
       int(1)
       [ "subdir_count_per_path" ]=>
       int(256)
       [ "storage_port" ]=>
       int(23000)
       [ "storage_http_port" ]=>
       int(8888)
       [ "current_write_path" ]=>
       int(0)
       [ "status" ]=>
       int(7)
       [ "total_space" ]=>
       int(18717)
       [ "free_space" ]=>
       int(15808)
       [ "connection.alloc_count" ]=>
       int(256)
       [ "connection.current_count" ]=>
       int(1)
       [ "connection.max_count" ]=>
       int(1)
       [ "total_upload_count" ]=>
       int(1)
       [ "success_upload_count" ]=>
       int(1)
       [ "total_append_count" ]=>
       int(1)
       [ "success_append_count" ]=>
       int(1)
       [ "total_modify_count" ]=>
       int(0)
       [ "success_modify_count" ]=>
       int(0)
       [ "total_truncate_count" ]=>
       int(0)
       [ "success_truncate_count" ]=>
       int(0)
       [ "total_set_meta_count" ]=>
       int(0)
       [ "success_set_meta_count" ]=>
       int(0)
       [ "total_delete_count" ]=>
       int(0)
       [ "success_delete_count" ]=>
       int(0)
       [ "total_download_count" ]=>
       int(2)
       [ "success_download_count" ]=>
       int(2)
       [ "total_get_meta_count" ]=>
       int(0)
       [ "success_get_meta_count" ]=>
       int(0)
       [ "total_create_link_count" ]=>
       int(0)
       [ "success_create_link_count" ]=>
       int(0)
       [ "total_delete_link_count" ]=>
       int(0)
       [ "success_delete_link_count" ]=>
       int(0)
       [ "total_upload_bytes" ]=>
       int(6)
       [ "success_upload_bytes" ]=>
       int(6)
       [ "total_append_bytes" ]=>
       int(6)
       [ "success_append_bytes" ]=>
       int(6)
       [ "total_modify_bytes" ]=>
       int(0)
       [ "success_modify_bytes" ]=>
       int(0)
       [ "total_download_bytes" ]=>
       int(25)
       [ "success_download_bytes" ]=>
       int(25)
       [ "total_sync_in_bytes" ]=>
       int(13)
       [ "success_sync_in_bytes" ]=>
       int(13)
       [ "total_sync_out_bytes" ]=>
       int(0)
       [ "success_sync_out_bytes" ]=>
       int(0)
       [ "total_file_open_count" ]=>
       int(5)
       [ "success_file_open_count" ]=>
       int(5)
       [ "total_file_read_count" ]=>
       int(2)
       [ "success_file_read_count" ]=>
       int(2)
       [ "total_file_write_count" ]=>
       int(3)
       [ "success_file_write_count" ]=>
       int(3)
       [ "last_heart_beat_time" ]=>
       int(1475660272)
       [ "last_source_update" ]=>
       int(1475648114)
       [ "last_sync_update" ]=>
       int(1475647685)
       [ "last_synced_timestamp" ]=>
       int(0)
     }
   }
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "port" ]=>
   int(22122)
   [ "sock" ]=>
   int(4)
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "port" ]=>
   int(22122)
   [ "sock" ]=>
   int(5)
}
bool( true )
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "port" ]=>
   int(22122)
   [ "sock" ]=>
   int(-1)
}
array(2) {
   [0]=>
   array(4) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.181"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
     [ "store_path_index" ]=>
     int(0)
   }
   [1]=>
   array(4) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.182"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
     [ "store_path_index" ]=>
     int(0)
   }
}
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(44)  "M00/00/00/wKhktVf0yf2AVFhSAAB7UNInADc94328.h"
}
array(5) {
   [ "source_id" ]=>
   int(0)
   [ "create_timestamp" ]=>
   int(1475660285)
   [ "file_size" ]=>
   int(31568)
   [ "source_ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "crc32" ]=>
   int(-769195977)
}
file  exist: 1
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(50)  "M00/00/00/wKhktVf0yf2AVFhSAAB7UNInADc94328.part1.h"
}
delete slave  file  return : 1
delete  file  return : 1
string(57)  "group1/M00/00/00/wKhktVf0yf2AE52YAAB7UNInADc60554.part2.h"
delete  file  group1 /M00/00/00/wKhktVf0yf2AE52YAAB7UNInADc60554 .part2.h  return : 1
delete  file  group1 /M00/00/00/wKhktVf0yf2AE52YAAB7UNInADc60554 .h  return : 1
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(44)  "M00/00/00/wKhktlf0yf2AZjIKAAAAD5Ij_SY680.txt"
}
array(5) {
   [ "source_id" ]=>
   int(0)
   [ "create_timestamp" ]=>
   int(1475660285)
   [ "file_size" ]=>
   int(15)
   [ "source_ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "crc32" ]=>
   int(-1843135194)
}
file  exist: 1
token=984fd906825dec9b3e7cd560a44a97aa
file  content: this is a  test .(15)
storage_download_file_to_file result: 1
fastdfs_storage_set_metadata result: 1
array(3) {
   [ "color" ]=>
   string(0)  ""
   [ "font" ]=>
   string(8)  "MS Serif"
   [ "size" ]=>
   string(2)  "32"
}
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(50)  "M00/00/00/wKhktlf0yf2AZjIKAAAAD5Ij_SY680.part1.txt"
}
delete slave  file  return : 1
delete  file  return : 1
file  content: thisisatest.(15)
storage_download_file_to_file1 result: 1
fastdfs_storage_set_metadata1 result: 1
array(5) {
   [ "color" ]=>
   string(6)  "yellow"
   [ "font" ]=>
   string(8)  "MS Serif"
   [ "height" ]=>
   string(3)  "768"
   [ "size" ]=>
   string(10)  "1234567890"
   [ "width" ]=>
   string(4)  "1024"
}
string(57)  "group1/M00/00/00/wKhktVf0yf6AOjCBAAAAD_4E1BM090.part2.txt"
delete  file  group1 /M00/00/00/wKhktVf0yf6AOjCBAAAAD_4E1BM090 .part2.txt  return : 1
delete  file  group1 /M00/00/00/wKhktVf0yf6AOjCBAAAAD_4E1BM090 .bin  return : 1
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(1) {
   [0]=>
   array(3) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.182"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
   }
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(1) {
   [0]=>
   array(3) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.181"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
   }
}
fastdfs_tracker_close_all_connections result: 1
tracker_make_all_connections result: 1
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(22122)
   [ "sock" ]=>
   int(3)
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(22122)
   [ "sock" ]=>
   int(8)
}
bool( true )
array(2) {
   [0]=>
   array(4) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.181"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
     [ "store_path_index" ]=>
     int(0)
   }
   [1]=>
   array(4) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.182"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
     [ "store_path_index" ]=>
     int(0)
   }
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(3) {
   [ "ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "port" ]=>
   int(23000)
   [ "sock" ]=>
   int(-1)
}
array(1) {
   [0]=>
   array(3) {
     [ "ip_addr" ]=>
     string(15)  "192.168.100.181"
     [ "port" ]=>
     int(23000)
     [ "sock" ]=>
     int(-1)
   }
}
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(44)  "M00/00/00/wKhktVf0yf6ADI75AAB7UNInADc29189.h"
}
array(5) {
   [ "source_id" ]=>
   int(0)
   [ "create_timestamp" ]=>
   int(1475660286)
   [ "file_size" ]=>
   int(31568)
   [ "source_ip_addr" ]=>
   string(15)  "192.168.100.181"
   [ "crc32" ]=>
   int(-769195977)
}
file  exist: 1
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(50)  "M00/00/00/wKhktVf0yf6ADI75AAB7UNInADc29189.part1.h"
}
delete slave  file  return : 1
delete  file  return : 1
string(57)  "group1/M00/00/00/wKhktlf0yf6AGc7zAAB7UNInADc71931.part2.c"
delete  file  group1 /M00/00/00/wKhktlf0yf6AGc7zAAB7UNInADc71931 .part2.c  return : 1
delete  file  group1 /M00/00/00/wKhktlf0yf6AGc7zAAB7UNInADc71931 .c  return : 1
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(44)  "M00/00/00/wKhktVf0yf6AFavJAAAAAAAAAAA794.txt"
}
file  content: (0)
storage_download_file_to_file result: 1
storage_set_metadata result: 1
array(2) {
   [ "color" ]=>
   string(6)  "yellow"
   [ "size" ]=>
   string(2)  "32"
}
array(2) {
   [ "group_name" ]=>
   string(6)  "group1"
   [ "filename" ]=>
   string(50)  "M00/00/00/wKhktVf0yf6AFavJAAAAAAAAAAA794.part1.txt"
}
delete slave  file  return : 1
delete  file  return : 1
array(5) {
   [ "source_id" ]=>
   int(0)
   [ "create_timestamp" ]=>
   int(1475660286)
   [ "file_size" ]=>
   int(15)
   [ "source_ip_addr" ]=>
   string(15)  "192.168.100.182"
   [ "crc32" ]=>
   int(-1385915893)
}
file  exist: 1
token=1c19dc1cf1702db27bc956dd92827e41
file  content: thisisatest.(15)
storage_download_file_to_file1 result: 1
storage_set_metadata1 result: 1
string(57)  "group1/M00/00/00/wKhktlf0yf6AKcjvAAAAD61kmgs561.part2.txt"
delete  file  group1 /M00/00/00/wKhktlf0yf6AKcjvAAAAD61kmgs561 .part2.txt  return : 1
array(3) {
   [ "color" ]=>
   string(6)  "yellow"
   [ "font" ]=>
   string(4)  "Aris"
   [ "size" ]=>
   string(2)  "32"
}
delete  file  group1 /M00/00/00/wKhktlf0yf6AKcjvAAAAD61kmgs561 .bin  return : 1
bool( true )
tracker_close_all_connections result: 1

二、fastdfs的nginx模块部署和配置

1、下载pcre

1
2
3
cd  /opt/tools
wget https: //sourceforge .net /projects/pcre/files/pcre/8 .37 /pcre-8 .37. tar .gz /download  --no-check-certificate
tar  -zxf pcre-8.37. tar .gz

2、下载fastdfs nginx模块

1
2
3
4
5
6
7
8
9
10
11
12
13
cd  /opt/tools/
git clone https: //github .com /happyfish100/fastdfs-nginx-module .git 
[root@mylinux3 tools] # tree fastdfs-nginx-module/
fastdfs-nginx-module/
├── HISTORY
├── INSTALL
└── src
     ├── common.c
     ├── common.h
     ├── config
     ├── mod_fastdfs.conf
     └── ngx_http_fastdfs_module.c
1 directory, 7 files

3、编译安装nginx

1
2
3
4
5
6
wget http: //nginx .org /download/nginx-1 .10.1. tar .gz
tar  -zxf nginx-1.10.1. tar .gz 
cd  nginx-1.10.1
. /configure  --prefix= /usr/local/nginx  --user=nginx --group=nginx --with-http_ssl_module --with-pcre= /opt/tools/pcre-8 .37 --add-module= /opt/tools/fastdfs-nginx-module/src/
make  &&  make  install 
useradd  -s  /sbin/nologin  -M nginx

4、准备配置文件

1
2
3
4
5
cd  /opt/tools/fastdfs-nginx-module/src/
cp  mod_fastdfs.conf  /etc/fdfs/   #拷贝fastdfs nginx模块目录下的mod_fastdfs.conf到/etc/fdfs下
cp  /opt/tools/fastdfs-5 .05 /conf/ {anti-steal.jpg,http.conf,mime.types}  /etc/fdfs/   #把fastdfs安装源文件中/conf目录下的这三个文件拷贝到/etc/fdfs下
touch  /var/log/mod_fastdfs .log   #创建fastdfs nginx模块日志,方便后面排错
chown  nginx:nginx  /var/log/mod_fastdfs .log

5、修改配置文件

1)修改nginx配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
cd  /usr/local/nginx/conf/
cp  nginx.conf nginx.conf.bak
vi  nginx.conf
[root@mylinux3 conf] # diff nginx.conf.bak  nginx.conf
37c37
<         server_name  localhost;
---
>         server_name  192.168.100.181;
41a42,45
>         location  /group1/M00  {      #这段内容是新增的,需要放在默认location / 段的前面
>             root  /data/fdfs_storage/store/ ;
>             ngx_fastdfs_module;
>         }

2)修改fastdfs nginx模块的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cp  /etc/fdfs/mod_fastdfs .conf  /etc/fdfs/mod_fastdfs .conf.bak
vi  /etc/fdfs/mod_fastdfs .conf
[root@mylinux3 conf] # diff /etc/fdfs/mod_fastdfs.conf.bak /etc/fdfs/mod_fastdfs.conf
40c40,41
< tracker_server=tracker:22122
---
> tracker_server=192.168.100.181:22122    #修改tracker的IP地址
> tracker_server=192.168.100.182:22122
53c54
< url_have_group_name =  false
---
> url_have_group_name =  true     #允许包含组名,这个与nginx的配置对应,因为nginx上的配置没有把路径写全,所以这里要允许包含组名
62c63
< store_path0= /home/yuqing/fastdfs
---
> store_path0= /data/fdfs_storage/store   #修改存储路径为实际的文件路径
78c79
< log_filename=
---
> log_filename= /var/log/mod_fastdfs .log   #指定fastdfs nginx的日志路径

6、启动nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@mylinux3 conf] # /usr/local/nginx/sbin/nginx -t
ngx_http_fastdfs_set pid=8782
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@mylinux3 conf] # /usr/local/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=8783
[root@mylinux3 conf] # lsof -i :80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE /OFF  NODE NAME
nginx   8784  root    6u  IPv4  44777      0t0  TCP *:http (LISTEN)
nginx   8785 nginx    6u  IPv4  44777      0t0  TCP *:http (LISTEN)
[root@mylinux3 conf] # netstat -lnt|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
[root@mylinux3 conf] # ps -ef|grep nginx
root       8784      1  0 23:07 ?        00:00:00 nginx: master process  /usr/local/nginx/sbin/nginx
nginx      8785   8784  0 23:07 ?        00:00:00 nginx: worker process      
root       8791   1793  0 23:07 pts /0     00:00:00  grep  nginx

7、上传文件

1
2
3
4
5
6
[root@mylinux3 tools] # cat /root/a.txt 
Hello,world.
[root@mylinux3 tools] # fdfs_upload_file /etc/fdfs/client.conf /root/a.txt 
group1 /M00/00/00/wKhktVf1GFaATxhVAAAADUwC04E708 .txt
[root@mylinux3 tools] # fdfs_upload_file /etc/fdfs/client.conf /root/test.gif 
group1 /M00/00/00/wKhktlf1GcKALtFFAAAlbU5-NyE685 .gif

8、使用浏览器测试

wKioL1f1HvzyDXI3AAC21uvlfNg628.jpg-wh_50

wKiom1f1Hv-yFwBkAAC9K7DBYX4346.jpg-wh_50



本文转自 jerry1111111 51CTO博客,原文链接:http://blog.51cto.com/jerry12356/1858887,如需转载请自行联系原作者

相关文章
|
5天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
63 0
|
5天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
26 0
|
5天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
67 0
|
1天前
|
负载均衡 安全 应用服务中间件
nginx配置ssl和反向代理的配置代码
【5月更文挑战第2天】nginx配置ssl和反向代理的配置代码
11 3
|
4天前
|
负载均衡 应用服务中间件 nginx
解决nginx配置负载均衡时invalid host in upstream报错
在Windows环境下,配置Nginx 1.11.5进行负载均衡时遇到问题,服务无法启动。错误日志显示“invalid host in upstream”。检查发现上游服务器列表中,192.168.29.128的主机地址无效。负载均衡配置中,两个服务器地址前误加了&quot;http://&quot;。修正方法是删除上游服务器列表和proxy_pass中的&quot;http://&quot;。问题解决后,Nginx服务应能正常启动。
38 4
解决nginx配置负载均衡时invalid host in upstream报错
|
5天前
|
应用服务中间件 nginx
nginx配置集群轮训策略
nginx配置集群轮训策略
420 0
|
5天前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
5天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
28 3
|
5天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
55 3
|
5天前
|
编译器 API PHP
深入PHP扩展开发:打造高效自定义模块
【4月更文挑战第30天】 在追求性能优化和特定功能实现的道路上,PHP提供了一种强大机制——扩展。本文将引导读者通过编写一个简单的PHP扩展来探索扩展开发的世界。我们将涉及从环境搭建到代码实现,再到扩展的编译与加载的完整流程,确保读者能够理解并实践如何创建高效的自定义PHP模块。