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,如需转载请自行联系原作者

相关文章
|
3月前
|
编解码 应用服务中间件 Linux
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
403 1
|
7月前
|
应用服务中间件 Linux 网络安全
Centos 8.0中Nginx配置文件和https正书添加配置
这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
778 87
|
7月前
|
负载均衡 应用服务中间件 nginx
Nginx配置与命令
Nginx 是一款高性能的 HTTP 和反向代理服务器,其配置文件灵活且功能强大。本文介绍了 Nginx 配置的基础结构和常用指令,包括全局块、Events 块、HTTP 块及 Server 块的配置方法,以及静态资源服务、反向代理、负载均衡、HTTPS 和 URL 重写等功能实现。此外,还提供了常用的 Nginx 命令操作,如启动、停止、重载配置和日志管理等,帮助用户高效管理和优化服务器性能。
|
3月前
|
Ubuntu 安全 应用服务中间件
详细指南:配置Nginx服务器在Ubuntu平台上
以上步骤涵盖了基本流程:从软件包管理器获取 Ngnix, 设置系统服务, 调整UFW规则, 创建并激活服务器块(也称作虚拟主机), 并进行了初步优化与加固措施。这些操作都是建立在命令行界面上,并假设用户具有必要权限(通常是root用户)来执行这些命令。每个操作都有其特定原因:例如,设置开机启动确保了即使重启后也能自动运行 Ngnix;而编辑server block则定义了如何处理进入特定域名请求等等。
296 18
|
3月前
|
Ubuntu 安全 应用服务中间件
详细指南:配置Nginx服务器在Ubuntu平台上
以上步骤涵盖了基本流程:从软件包管理器获取 Ngnix, 设置系统服务, 调整UFW规则, 创建并激活服务器块(也称作虚拟主机), 并进行了初步优化与加固措施。这些操作都是建立在命令行界面上,并假设用户具有必要权限(通常是root用户)来执行这些命令。每个操作都有其特定原因:例如,设置开机启动确保了即使重启后也能自动运行 Ngnix;而编辑server block则定义了如何处理进入特定域名请求等等。
385 17
|
10月前
|
应用服务中间件 PHP nginx
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
简介: 本教程介绍如何基于 Dragonwell 的 Ubuntu 镜像创建一个运行 Nginx 的 Docker 容器。首先从阿里云容器镜像服务拉取基础镜像,然后编写 Dockerfile 确保 Nginx 作为主进程运行,并暴露 80 端口。最后,在包含 Dockerfile 的目录下构建自定义镜像并启动容器,确保 Nginx 在前台运行,避免容器启动后立即退出。通过 `docker build` 和 `docker run` 命令完成整个流程。
401 25
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
|
4月前
|
数据建模 应用服务中间件 PHP
配置nginx容器和php容器协同工作成功,使用ip加端口的方式进行通信
本示例演示如何通过Docker挂载同一宿主目录至Nginx与PHP容器,实现PHP项目运行环境配置。需注意PHP容器中监听地址修改为0.0.0.0:9000,并调整Nginx配置中fastcgi_pass指向正确的IP与端口。同时确保Nginx容器中/var/www/html权限正确,以避免访问问题。
配置nginx容器和php容器协同工作成功,使用ip加端口的方式进行通信
|
5月前
|
应用服务中间件 网络安全 nginx
配置Nginx以支持Websocket连接的方法。
通过上述配置,Nginx将能够理解WebSocket协议的特殊要求,代理Websocket流量到合适的后端服务器。注意,Websocket并不是HTTP,尽管它最初是通过HTTP请求启动的连接升级,因此保证Nginx了解并能够妥善处理这种升级流程是关键。
1315 10
|
4月前
|
Ubuntu 应用服务中间件 Linux
在Ubuntu上配置Nginx实现开机自启功能
至此,Nginx应该已经被正确地设置为开机自启。在Ubuntu中利用 `systemd`对服务进行管理是一种高效的方式,为系统管理员提供了强大的服务管理能力,包括但不限于启动、停止、重启服务,以及配置服务的开机自启动。通过这些简洁的命令,即使是对Linux不太熟悉的用户也能轻松地进行配置。
223 0
|
6月前
|
安全 应用服务中间件 网络安全
Nginx SSL/TLS协议栈中配置深度解析与实践指南-优雅草卓伊凡
Nginx SSL/TLS协议栈中配置深度解析与实践指南-优雅草卓伊凡
450 0
Nginx SSL/TLS协议栈中配置深度解析与实践指南-优雅草卓伊凡