-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1862 lines (935 loc) · 56.9 KB
/
index.html
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html class="theme-next muse use-motion">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />
<meta name="keywords" content="Hexo, NexT" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="OneStack">
<meta property="og:url" content="http://jessyon.com/index.html">
<meta property="og:site_name" content="OneStack">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="OneStack">
<meta name="twitter:description">
<script type="text/javascript" id="hexo.configuration">
var NexT = window.NexT || {};
var CONFIG = {
scheme: 'Muse',
sidebar: {"position":"left","display":"post"},
fancybox: true,
motion: true,
duoshuo: {
userId: 0,
author: '博主'
}
};
</script>
<link rel="canonical" href="http://jessyon.com/"/>
<title> OneStack </title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left
page-home
">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">OneStack</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">The Blog Powered By jessyon</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br />
首页
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
归档
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
标签
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/09/16/redis数据类型及命令/" itemprop="url">
redis数据类型及命令
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-09-16T13:59:39+08:00" content="2016-09-16">
2016-09-16
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/09/16/redis数据类型及命令/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/09/16/redis数据类型及命令/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="String类型"><a href="#String类型" class="headerlink" title="String类型"></a><strong>String类型</strong></h1><p>SET key value 赋值</p>
<pre><code>127.0.0.1:6379> set test 123
OK
</code></pre><p>GET key 取值</p>
<pre><code>127.0.0.1:6379> get test
"123“
</code></pre><p>GETSET key value 取值并赋值</p>
<pre><code>127.0.0.1:6379> getset s2 222
"111"
127.0.0.1:6379> get s2
"222"
</code></pre><p>DEL key 删除</p>
<pre><code>127.0.0.1:6379> del test
(integer) 1
</code></pre><p>incr key 递增数字 </p>
<p>当存储的字符串是整数时,Redis提供了一个实用的命令INCR,其作用是让当前键值递增,并返回递增后的值。</p>
<pre><code>127.0.0.1:6379> incr num
(integer) 1
127.0.0.1:6379> incr num
(integer) 2
127.0.0.1:6379> incr num
(integer) 3
</code></pre><p>INCRBY key increment 增加指定的整数 </p>
<pre><code>127.0.0.1:6379> incrby num 2
(integer) 5
127.0.0.1:6379> incrby num 2
(integer) 7
127.0.0.1:6379> incrby num 2
(integer) 9
</code></pre><p>DECR key 递减数值</p>
<pre><code>127.0.0.1:6379> decr num
(integer) 9
127.0.0.1:6379> decr num
(integer) 8
</code></pre><p>DECRBY key decrement 减少指定的整数 </p>
<pre><code>127.0.0.1:6379> decr num
(integer) 6
127.0.0.1:6379> decr num
(integer) 5
127.0.0.1:6379> decrby num 3
(integer) 2
127.0.0.1:6379> decrby num 3
(integer) -1
</code></pre><p>APPEND key value 向尾部追加值 </p>
<pre><code>127.0.0.1:6379> set str hello
OK
127.0.0.1:6379> append str " world!"
(integer) 12
127.0.0.1:6379> get str
"hello world!"
</code></pre><p>STRLEN key 获取字符串长度</p>
<pre><code>127.0.0.1:6379> strlen str
(integer) 0
127.0.0.1:6379> set str hello
OK
127.0.0.1:6379> strlen str
(integer) 5
</code></pre><p>MSET key value [key value …] 同时设置多个值</p>
<pre><code>127.0.0.1:6379> mset k1 v1 k2 v2 k3 v3
OK
</code></pre><p>MGET key [key …] 同时取多个值</p>
<pre><code>127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> mget k1 k3
1) "v1"
2) "v3"
</code></pre><h1 id="String应用"><a href="#String应用" class="headerlink" title="String应用"></a><strong>String应用</strong></h1><p>自增主键: 商品编号、订单号采用string的递增数字特性生成。</p>
<pre><code>定义商品编号key:items:id
192.168.101.3:7003> INCR items:id
(integer) 2
192.168.101.3:7003> INCR items:id
(integer) 3
</code></pre><h1 id="String存在的问题"><a href="#String存在的问题" class="headerlink" title="String存在的问题"></a><strong>String存在的问题</strong></h1><pre><code>假设有User对象以JSON序列化的形式存储到Redis中,User对象有id,username、password、age、name等属性,存储的过程如下:
保存、更新:
User对象 -> json(string) -> redis
如果在业务上只是更新age属性,其他的属性并不做更新我应该怎么做呢?
如果仍然采用上边的方法在传输、处理时会造成资源浪费,下边讲的hash可以很好的解决这个问题。
</code></pre><h1 id="Hash类型"><a href="#Hash类型" class="headerlink" title="Hash类型"></a><strong>Hash类型</strong></h1><p>hash叫散列类型,它提供了字段和字段值的映射。字段值只能是字符串类型,不支持散列类型、集合类型等其它类型。如下:<br><img src="https://raw.githubusercontent.com/minokoko/minokoko.github.io/master/images/redis_hash.jpg" alt=""></p>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/09/16/服务器搭建-四-redis配置/" itemprop="url">
服务器搭建-四-redis配置
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-09-16T11:55:31+08:00" content="2016-09-16">
2016-09-16
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/09/16/服务器搭建-四-redis配置/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/09/16/服务器搭建-四-redis配置/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="什么是NoSql"><a href="#什么是NoSql" class="headerlink" title="什么是NoSql"></a><strong>什么是NoSql</strong></h1><pre><code>为了解决高并发、高可扩展、高可用、大数据存储问题而产生的数据库解决方案,就是NoSql数据库。
NoSQL,泛指非关系型的数据库,NoSQL即Not-Only SQL,它可以作为关系型数据库的良好补充。
</code></pre><h1 id="什么是Redis"><a href="#什么是Redis" class="headerlink" title="什么是Redis"></a><strong>什么是Redis</strong></h1><p>Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库。它通过提供多种键值数据类型来适应不同场景下的存储需求,目前为止Redis支持的键值数据类型如<br>下:</p>
<pre><code>字符串类型
散列类型 (Hash类型)
列表类型 (List)
集合类型 (Set)
有序集合类型 (SortedSet)
在redis中的命令语句中,命令是忽略大小写的,而key是不忽略大小写的。
</code></pre><h1 id="redis的应用场景"><a href="#redis的应用场景" class="headerlink" title="redis的应用场景"></a><strong>redis的应用场景</strong></h1><pre><code>缓存(数据查询、短连接、新闻内容、商品内容等等)。(最多使用)
分布式集群架构中的session分离。
聊天室的在线好友列表。
任务队列。(秒杀、抢购、12306等等)
应用排行榜。
网站访问统计。
数据过期处理(可以精确到毫秒)
</code></pre><h1 id="Redis安装"><a href="#Redis安装" class="headerlink" title="Redis安装"></a><strong>Redis安装</strong></h1><p>第一步.在Linux下安装gcc环境</p>
<pre><code>yum install gcc-c++
</code></pre><p>第二步. 安装redis</p>
<pre><code>1.将下载的Redis源码包上传到Linux服务器中
2.解压缩Redis源码包到/usr/local tar -zxf redis-3.0.0.tar.gz -C /usr/local
3.进入/usr/local/redis-3.0.0目录
编译redis源码 make
安装redis make install PREFIX=/usr/local/redis0707
</code></pre><p>第三步. 后端启动redis</p>
<pre><code>1.将redis源码包中的redis.conf配置文件复制到/usr/local/redis/bin/下
cp redis.conf /usr/local/redis0707/bin/
2.修改redis.conf,将daemonize由no改为yes
37行 daemonize yes
3.启动redis-server
./redis-server redis.conf
4.关闭redis-server
./redis-cli shutdown
5.打开redis客户端 ./redis-cli -h 127.0.0.1 -p 6379
</code></pre><h1 id="修改访问端口"><a href="#修改访问端口" class="headerlink" title="修改访问端口"></a><strong>修改访问端口</strong></h1><pre><code>1.通过notepad++ 打开/etc/sysconfig/iptables
2.添加-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
3.重启防火墙 service iptables restart
</code></pre>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/09/16/Nosql之Redis/" itemprop="url">
服务器搭建-四-redis配置
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-09-16T11:55:31+08:00" content="2016-09-16">
2016-09-16
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/09/16/Nosql之Redis/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/09/16/Nosql之Redis/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="什么是NoSql"><a href="#什么是NoSql" class="headerlink" title="什么是NoSql"></a><strong>什么是NoSql</strong></h1><pre><code>为了解决高并发、高可扩展、高可用、大数据存储问题而产生的数据库解决方案,就是NoSql数据库。
NoSQL,泛指非关系型的数据库,NoSQL即Not-Only SQL,它可以作为关系型数据库的良好补充。
</code></pre><h1 id="什么是Redis"><a href="#什么是Redis" class="headerlink" title="什么是Redis"></a><strong>什么是Redis</strong></h1><p>Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库。它通过提供多种键值数据类型来适应不同场景下的存储需求,目前为止Redis支持的键值数据类型如<br>下:</p>
<pre><code>字符串类型
散列类型 (Hash类型)
列表类型 (List)
集合类型 (Set)
有序集合类型 (SortedSet)
在redis中的命令语句中,命令是忽略大小写的,而key是不忽略大小写的。
</code></pre><h1 id="redis的应用场景"><a href="#redis的应用场景" class="headerlink" title="redis的应用场景"></a><strong>redis的应用场景</strong></h1><pre><code>缓存(数据查询、短连接、新闻内容、商品内容等等)。(最多使用)
分布式集群架构中的session分离。
聊天室的在线好友列表。
任务队列。(秒杀、抢购、12306等等)
应用排行榜。
网站访问统计。
数据过期处理(可以精确到毫秒)
</code></pre><h1 id="Redis安装"><a href="#Redis安装" class="headerlink" title="Redis安装"></a><strong>Redis安装</strong></h1><p>第一步.在Linux下安装gcc环境</p>
<pre><code>yum install gcc-c++
</code></pre><p>第二步. 安装redis</p>
<pre><code>1.将下载的Redis源码包上传到Linux服务器中
2.解压缩Redis源码包到/usr/local tar -zxf redis-3.0.0.tar.gz -C /usr/local
3.进入/usr/local/redis-3.0.0目录
编译redis源码 make
安装redis make install PREFIX=/usr/local/redis0707
</code></pre><p>第三步. 后端启动redis</p>
<pre><code>1.将redis源码包中的redis.conf配置文件复制到/usr/local/redis/bin/下
cp redis.conf /usr/local/redis0707/bin/
2.修改redis.conf,将daemonize由no改为yes
37行 daemonize yes
3.启动redis-server
./redis-server redis.conf
4.关闭redis-server
./redis-cli shutdown
5.打开redis客户端 ./redis-cli -h 127.0.0.1 -p 6379
</code></pre><h1 id="修改访问端口"><a href="#修改访问端口" class="headerlink" title="修改访问端口"></a><strong>修改访问端口</strong></h1><pre><code>1.通过notepad++ 打开/etc/sysconfig/iptables
2.添加-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
3.重启防火墙 service iptables restart
</code></pre>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/09/16/服务器搭建-三-fastDFS图片服务器/" itemprop="url">
服务器搭建(三) fastDFS图片服务器
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-09-16T09:02:42+08:00" content="2016-09-16">
2016-09-16
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/09/16/服务器搭建-三-fastDFS图片服务器/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/09/16/服务器搭建-三-fastDFS图片服务器/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="fastDFS流程"><a href="#fastDFS流程" class="headerlink" title="fastDFS流程"></a>fastDFS流程</h2><p>可以使用一台虚拟机来模拟,只有一个Tracker、一个Storage服务。配置nginx访问图片。<br><img src="https://raw.githubusercontent.com/minokoko/minokoko.github.io/master/images/fastDFS.jpg" alt=""></p>
<h1 id="fastDFS搭建"><a href="#fastDFS搭建" class="headerlink" title="fastDFS搭建"></a><strong>fastDFS搭建</strong></h1><p>第一步:把fastDFS都上传到linux系统。</p>
<p>第二步:安装FastDFS之前,先安装libevent工具包。</p>
<pre><code>yum -y install libevent
</code></pre><p>第三步:安装libfastcommonV1.0.7工具包。</p>
<pre><code>1、解压缩
2、./make.sh
3、./make.sh install
4、把/usr/lib64/libfastcommon.so文件向/usr/lib/下复制一份
</code></pre><p>第四步:安装Tracker服务。</p>
<pre><code>1、解压缩fastDFS,将文件移动到/usr/local下
2、./make.sh
3、./make.sh install
安装后在/usr/bin/目录下有以fdfs开头的文件都是编译出来的。
配置文件都放到/etc/fdfs文件夹
4、把/usr/local/FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。
cp * /etc/fdfs/
5、配置tracker服务。修改/usr/local/FastDFS/conf/tracker.conf文件。
6、修改tracker.conf中22行,base_path=/home/fastdfs/tracker
7、启动tracker。/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
重启使用命令:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
</code></pre><p>第五步:安装storage服务。</p>
<p>1、如果是在不同的服务器安装,第四步的1~4需要重新执行。<br>2、配置storage服务。修改/usr/local/FastDFS/conf/storage.conf文件</p>
<pre><code>41行 base_path=/home/fastdfs/storage
109行 store_path0=/home/fastdfs/storage
118行 tracker_server=115.159.93.201:22122
</code></pre><p>3、启动storage服务。</p>
<pre><code>/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
</code></pre><p>第六步:测试服务。</p>
<p>1、修改配置文件/etc/fdfs/client.conf</p>
<pre><code>10行 base_path=/home/fastdfs/client
14行 tracker_server=115.159.93.201:22122
</code></pre><p>2、测试 </p>
<pre><code>/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg (在/etc/fdfs目录下)
生成 http://115.159.93.201/group1/M00/00/00/CmkaiVfbXw-ABpAJAABdrZgsqUU916_big.jpg 为图片的地址
</code></pre><p>第七步:搭建nginx提供http服务。</p>
<p>可以使用官方提供的nginx插件。要使用nginx插件需要重新编译。<br>fastdfs-nginx-module_v1.16.tar.gz</p>
<pre><code>1、解压插件压缩包,并移动到/usr/local
2、修改/usr/local/fastdfs-nginx-module/src/config文件,把其中的local去掉。
</code></pre><p>3、对nginx重新config</p>
<pre><code>./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src
</code></pre><p>4、make<br>5、make install<br>6、把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下。编辑:</p>
<pre><code>40行 tracker_server=115.159.93.201:22122
53行 url_have_group_name = true
62行 store_path0=/home/fastdfs/storage
</code></pre><p>7、nginx的配置<br> 在nginx的配置文件中添加一个Server:<br> server {<br> listen 80;<br> server_name 115.159.93.201;</p>
<pre><code> location /group1/M00/{
#root /home/FastDFS/fdfs_storage/data;
ngx_fastdfs_module;
}
}
</code></pre><p>8、将libfdfsclient.so拷贝至/usr/lib下<br>cp /usr/lib64/libfdfsclient.so /usr/lib/<br>9、启动nginx</p>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/09/15/服务器搭建-二-Nginx和fastDFS配置/" itemprop="url">
服务器搭建(二)Nginx和fastDFS配置
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-09-15T22:48:47+08:00" content="2016-09-15">
2016-09-15
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/09/15/服务器搭建-二-Nginx和fastDFS配置/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/09/15/服务器搭建-二-Nginx和fastDFS配置/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="Nginx反向代理"><a href="#Nginx反向代理" class="headerlink" title="Nginx反向代理"></a><strong>Nginx反向代理</strong></h1><p>Nginx的配置文件:</p>
<pre><code>upstream tomcats{
server 192.168.25.148:8080; //配置多个tomcat
server 192.168.25.148:8081;
}
server {
listen 80;
server_name tomcat.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcats; //设置代理
index index.html index.htm;
}
}
</code></pre><h1 id="Nginx负载均衡"><a href="#Nginx负载均衡" class="headerlink" title="Nginx负载均衡"></a><strong>Nginx负载均衡</strong></h1><p>只需要在upstream的server后面添加一个weight即可代表权重。权重越高,分配请求的数量(概率)就越多。默认权重是1</p>
<pre><code>upstream tomcats{
server 192.168.25.148:8080 weight=2; //设置权重为2
server 192.168.25.148:8081;
}
server {
listen 80;
server_name tomcat.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcats; //设置代理
index index.html index.htm;
}
}
</code></pre><h1 id="fastDFS"><a href="#fastDFS" class="headerlink" title="fastDFS"></a><strong>fastDFS</strong></h1><p>FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。</p>
<h2 id="fastDFS上传流程"><a href="#fastDFS上传流程" class="headerlink" title="fastDFS上传流程"></a>fastDFS上传流程</h2><p><img src="https://raw.githubusercontent.com/minokoko/minokoko.github.io/master/images/upload.jpg" alt=""></p>
<h2 id="fastDFS下载流程"><a href="#fastDFS下载流程" class="headerlink" title="fastDFS下载流程"></a>fastDFS下载流程</h2><p><img src="https://raw.githubusercontent.com/minokoko/minokoko.github.io/master/images/download.jpg" alt=""></p>
<p>客户端上传文件后存储服务器将文件ID返回给客户端,此文件ID用于以后访问该文件的索引信息。文件索引信息包括:组名,虚拟磁盘路径,数据两级目录,文件名。</p>
<pre><code>http://192.168.233.128/group1/M00/00/00/wKjpgFfGRCqAHIo6AADW-NO57MA805.jpg
组名:文件上传后所在的storage组名称,在文件上传成功后有storage服务器返回,需要客户端自行保存。
虚拟磁盘路径:storage配置的虚拟路径,与磁盘选项store_path*对应。如果配置了store_path0则是M00,如果配置了store_path1则是M01,以此类推。
数据两级目录:storage服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。
文件名:与文件上传时不同。是由存储服务器根据特定信息生成,文件名包含:源存储服务器IP地址、文件创建时间戳、文件大小、随机数和文件拓展名等信息。
</code></pre>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">