fastdfs集群

  1. 云栖社区>
  2. 博客>
  3. 正文

fastdfs集群

余二五 2017-11-15 21:15:00 浏览1255
展开阅读全文

fastdfs 简介看前面的博客

实战图解:

wKiom1iEEq_wWn6oAAE0wa3DxrI464.png-wh_50

上传文件交互过程:
1. client询问tracker上传到的storage,不需要附加参数;
2. tracker返回一台可用的storage;
3. client直接和storage通讯完成文件上传。
FastDFS file download
下载文件交互过程:
1. client询问tracker下载文件的storage,参数为文件标识(卷名和文件名);
2. tracker返回一台可用的storage;
3. client直接和storage通讯完成文件下载。

1.基础环境说明 6台服务器 两台tracker  4台storages

  

192.168.56.131 tracker 服务器
1
edu-dfs-tracker-1
192.168.56.132
tracker 服务器
1
edu-dfs-tracker-2
192.168.56.135 storage服务器
1
edu-dfs-storage-group1-1
192.168.56.136 storage服务器
1
edu-dfs-storage-group1-2
192.168.56.137 storage服务器
1
edu-dfs-storage-group2-1
192.168.56.138 storage服务器
1
edu-dfs-storage-group2-2


1
2
3
4
5
6
7
8
[root@edu-dfs-tracker-1 ~]# cat  /etc/hosts
192.168.56.131 edu-dfs-tracker-1
192.168.56.132 edu-dfs-tracker-2
192.168.56.135 edu-dfs-storage-group1-1
192.168.56.136 edu-dfs-storage-group1-2
192.168.56.137 edu-dfs-storage-group2-1
192.168.56.138 edu-dfs-storage-group2-2
[root@edu-dfs-tracker-1 ~]#

2.安装依赖(所有服务器)

1
yum  -y install perl perl-devel  make  gcc-c++  gcc  cmake

3.安装fastdfs所需要的common库(所有的服务器)

https://github.com/happyfish100/libfastcommon

1
2
3
4
5
cd  /usr/local/src
 unzip  libfastcommon-master.zip 
 cd libfastcommon-master
 ./make.sh 
 ./make.sh  install

4.做软连接(所有机器)

1
2
3
4
ln -s  /usr/lib64/libfastcommon.so   /usr/local/lib/libfastcommon.so
ln -s  /usr/lib64/libfastcommon.so   /usr/lib/libfastcommon.so
ln  -s  /usr/lib64/libfdfsclient.so  /usr/local/lib/libfdfsclient.so
ln  -s  /usr/lib64/libfdfsclient.so  /usr/lib/libfdfsclient.so

5.安装fastdfs(所有机器)

1
2
3
4
5
cd  /usr/local/src
tar xf fastdfs-5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install

6.修改启动脚本(启动脚本是在/usr/local/bin  实际是在/usr/bin)

1
2
3
4
 tracker服务器两台
 sed -i 's#/usr/local/bin#/usr/bin#g'  /etc/init.d/fdfs_trackerd
 storage服务器四台
 sed -i 's#/usr/local/bin#/usr/bin#g'  /etc/init.d/fdfs_storaged

7.下面来配置tracker服务器两台(tracker两台服务器全都要做)

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
cd  /etc/fdfs
cp tracker.conf.sample  tracker.conf
vi  tracker.conf
 
disabled=false
port=22122
base_path=/fastdfs/tracker 
 
保存以后
mkdir  -p  /fastdfs/tracker
/etc/init.d/fdfs_trackerd   start
chkconfig fdfs_trackerd  on
 
启动以后的结果,会生成data  logs 这两个文件
[root@localhost fdfs]# cd  /fastdfs/tracker/
[root@localhost tracker]# ls
data  logs
[root@localhost tracker]
查看监听的端口22122
[root@localhost tracker]# netstat -lntup 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      19522/fdfs_trackerd 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      786/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      870/master          
tcp6       0      0 :::22                   :::*                    LISTEN      786/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      870/master          
[root@localhost tracker]
查看启动日志:
[root@localhost logs]# tail -f /fastdfs/tracker/logs/trackerd.log 
[2017-01-22 05:20:51] INFO - FastDFS v5.05, base_path=/fastdfs/tracker, run_by_grou


8.下面来配置storage服务器两台(storage四台服务器全都要做)(同一组的做的不一样)

1
2
cd  /etc/fdfs
cp storage.conf.sample  storage.conf

wKioL1iDbhCwP6wTAAVdTRT4-NA013.png-wh_50

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
group1 的服务器 group_name=group1
group2 的服务器 group_name=group2  其余的不变
mdkir  -p  /fastdfs/storage
监听日志
cd /fastdfs/storage/logs
[root@localhost logs]# tail -f storaged.log 
mkdir data path: FD ...
mkdir data path: FE ...
mkdir data path: FF ...
data path: /fastdfs/storage/datamkdir sub dir done.
[2017-01-22 06:07:17] 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=10.00%, 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
[2017-01-22 06:07:17] INFO - file: storage_func.c, line: 254, tracker_client_ip: 192.168.56.137, my_server_id_str: 192.168.56.137, g_server_id_in_filename: -1992775488
[2017-01-22 06:07:19] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.56.132:22122, as a tracker client, my ip is 192.168.56.137
[2017-01-22 06:07:19] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.56.131:22122, as a tracker client, my ip is 192.168.56.137
[2017-01-22 06:07:19] INFO - file: tracker_client_thread.c, line: 1235, tracker server 192.168.56.132:22122, set tracker leader: 192.168.56.132:22122
[2017-01-22 06:07:19] INFO - file: storage_sync.c, line: 2698, successfully connect to storage server 192.168.56.138:23000

特别说明:一台storage只会选择一个tracker服务器,一台tracker服务器挂掉,会接着选择另外一台tracker服务器

加入开机自启,以上所有的端口都要在防火墙允许放行

1
echo "/etc/init.d/fdfs_storaged  start " >>/etc/rc.local

9查看storage服务器的具体信心,可以用于监控,任意一台storage服务器

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
[root@localhost logs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2017-01-22 06:32:36] DEBUG - base_path=/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
 
server_count=2, server_index=0
 
tracker server is 192.168.56.131:22122
 
group count: 2
 
Group 1:
group name = group1
disk total space = 38345 MB
disk free space = 36848 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
 
    Storage 1:
        id = 192.168.56.135
        ip_addr = 192.168.56.135 (edu-dfs-storage-group1-1)  ACTIVE
        http domain = 
        version = 5.05
        join time = 2017-01-22 05:59:38
        up time = 2017-01-22 06:15:24
        total storage = 38345 MB
        free storage = 36849 MB
        upload priority = 10
        store_path_count = 1
        subdir_count_per_path = 256
        storage_port = 23000
        storage_http_port = 8888
        current_write_path = 0
        source storage id = 192.168.56.136
        if_trunk_server = 0
        connection.alloc_count = 256
        connection.current_count = 1
        connection.max_count = 1
        total_upload_count = 0
        success_upload_count = 0
        total_append_count = 0
        success_append_count = 0
        total_modify_count = 0
        success_modify_count = 0
        total_truncate_count = 0
        success_truncate_count = 0
        total_set_meta_count = 0
        success_set_meta_count = 0
        total_delete_count = 0
        success_delete_count = 0
        total_download_count = 0
        success_download_count = 0
        total_get_meta_count = 0
        success_get_meta_count = 0
        total_create_link_count = 0
        success_create_link_count = 0
        total_delete_link_count = 0
        success_delete_link_count = 0
        total_upload_bytes = 0
        success_upload_bytes = 0
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 0
        success_file_open_count = 0
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 0
        success_file_write_count = 0
        last_heart_beat_time = 2017-01-22 06:32:26
        last_source_update = 1970-01-01 08:00:00
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00 
    Storage 2:
        id = 192.168.56.136
        ip_addr = 192.168.56.136 (edu-dfs-storage-group1-2)  ACTIVE
        http domain = 
        version = 5.05
        join time = 2017-01-22 06:00:33
        up time = 2017-01-22 06:15:17
        total storage = 38345 MB
        free storage = 36848 MB
        upload priority = 10
        store_path_count = 1
        subdir_count_per_path = 256
        storage_port = 23000
        storage_http_port = 8888
        current_write_path = 0
        source storage id 
        if_trunk_server = 0
        connection.alloc_count = 256
        connection.current_count = 1
        connection.max_count = 1
        total_upload_count = 0
        success_upload_count = 0
        total_append_count = 0
        success_append_count = 0
        total_modify_count = 0
        success_modify_count = 0
        total_truncate_count = 0
        success_truncate_count = 0
        total_set_meta_count = 0
        success_set_meta_count = 0
        total_delete_count = 0
        success_delete_count = 0
        total_download_count = 0
        success_download_count = 0
        total_get_meta_count = 0
        success_get_meta_count = 0
        total_create_link_count = 0
        success_create_link_count = 0
        total_delete_link_count = 0
        success_delete_link_count = 0
        total_upload_bytes = 0
        success_upload_bytes = 0
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 0
        success_file_open_count = 0
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 0
        success_file_write_count = 0
        last_heart_beat_time = 2017-01-22 06:32:18
        last_source_update = 1970-01-01 08:00:00
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00 
 
Group 2:
group name = group2
disk total space = 38345 MB
disk free space = 36849 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
 
    Storage 1:
        id = 192.168.56.137
        ip_addr = 192.168.56.137 (edu-dfs-storage-group2-1)  ACTIVE
        http domain = 
        version = 5.05
        join time = 2017-01-22 06:07:15
        up time = 2017-01-22 06:07:15
        total storage = 38345 MB
        free storage = 36849 MB
        upload priority = 10
        store_path_count = 1
        subdir_count_per_path = 256
        storage_port = 23000
        storage_http_port = 8888
        current_write_path = 0
        source storage id = 192.168.56.138
        if_trunk_server = 0
        connection.alloc_count = 256
        connection.current_count = 1
        connection.max_count = 1
        total_upload_count = 0
        success_upload_count = 0
        total_append_count = 0
        success_append_count = 0
        total_modify_count = 0
        success_modify_count = 0
        total_truncate_count = 0
        success_truncate_count = 0
        total_set_meta_count = 0
        success_set_meta_count = 0
        total_delete_count = 0
        success_delete_count = 0
        total_download_count = 0
        success_download_count = 0
        total_get_meta_count = 0
        success_get_meta_count = 0
        total_create_link_count = 0
        success_create_link_count = 0
        total_delete_link_count = 0
        success_delete_link_count = 0
        total_upload_bytes = 0
        success_upload_bytes = 0
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 0
        success_file_open_count = 0
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 0
        success_file_write_count = 0
        last_heart_beat_time = 2017-01-22 06:32:20
        last_source_update = 1970-01-01 08:00:00
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00 
    Storage 2:
        id = 192.168.56.138
        ip_addr = 192.168.56.138 (edu-dfs-storage-group2-2)  ACTIVE
        http domain = 
        version = 5.05
        join time = 2017-01-22 06:06:09
        up time = 2017-01-22 06:06:09
        total storage = 38345 MB
        free storage = 36849 MB
        upload priority = 10
        store_path_count = 1
        subdir_count_per_path = 256
        storage_port = 23000
        storage_http_port = 8888
        current_write_path = 0
        source storage id 
        if_trunk_server = 0
        connection.alloc_count = 256
        connection.current_count = 1
        connection.max_count = 1
        total_upload_count = 0
        success_upload_count = 0
        total_append_count = 0
        success_append_count = 0
        total_modify_count = 0
        success_modify_count = 0
        total_truncate_count = 0
        success_truncate_count = 0
        total_set_meta_count = 0
        success_set_meta_count = 0
        total_delete_count = 0
        success_delete_count = 0
        total_download_count = 0
        success_download_count = 0
        total_get_meta_count = 0
        success_get_meta_count = 0
        total_create_link_count = 0
        success_create_link_count = 0
        total_delete_link_count = 0
        success_delete_link_count = 0
        total_upload_bytes = 0
        success_upload_bytes = 0
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 0
        success_file_open_count = 0
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 0
        success_file_write_count = 0
        last_heart_beat_time = 2017-01-22 06:32:11
        last_source_update = 1970-01-01 08:00:00
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00


10.上传文件测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
在tracker服务器上测试(任意一台)
cd  /etc/fdfs
[root@localhost fdfs]# pwd
/etc/fdfs
[root@localhost fdfs]# ls
client.conf  client.conf.sample  storage.conf.sample  tracker.conf  tracker.conf.sample
[root@localhost fdfs]# cp client.conf.sample  client.conf
[root@localhost fdfs]#vi  client.conf
base_path=/fastdfs/tracker
tracker_server=192.168.56.131:22122
tracker_server=192.168.56.132:22122
 
 
[root@localhost fdfs]# /usr/bin/fdfs_upload_file   /etc/fdfs/client.conf  /usr/local/src/fastdfs-5.05.tar.gz 
group2/M00/00/00/wKg4iViD5pGASNhIAAUggSnIHZU.tar.gz
[root@localhost fdfs]# /usr/bin/fdfs_upload_file   /etc/fdfs/client.conf  /usr/local/src/libfastcommon-master.zip 
group1/M00/00/00/wKg4h1iD5rGATHRxAAKe64wyZIg888.zip
 
storage服务器检测一下:
[root@localhost logs]# cd  /fastdfs/storage/data/00/00
[root@localhost 00]# ls
wKg4h1iD5rGATHRxAAKe64wyZIg888.zip
[root@localhost 00]#

11.在每个storage服务器安装nginx

 wKioL1iDeLKiJUL-AAIp7yDXZpw115.png-wh_50

fastdfs-nginx-module 安装

1
2
3
4
5
cd  /usr/local/src/
tar xf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src/
vi config 
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"  #改成如下

12.nginx的安装,每个storage服务器都得安装

1
2
3
4
5
6
yum -y  install openssl openssl-devel  pcre* zlib libtool autoconf  automke
 cd  /usr/local/src/
 tar xf  nginx-1.6.2.tar.gz 
 cd  nginx-1.6.2
 ./configure  --add-module=/usr/local/src/fastdfs-nginx-module/src/
 make &&  make  install

13.拷贝nginx-module配置文件   storage服务器

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
 cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf   /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf 
 
group1的配置文件
[root@localhost fdfs]# grep  -r  "^[a-Z]" mod_fastdfs.conf 
connect_timeout=2
network_timeout=30
base_path=/tmp
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=192.168.56.131:22122
tracker_server=192.168.56.132:22122
storage_server_port=23000
group_name=group1    #group1 的配置文件为group1  group2的配置文件为group2  其余不变
url_have_group_name = true
store_path_count=1
store_path0=/fastdfs/storage
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
[root@localhost fdfs]
 
 
group2的配置文件
[root@localhost fdfs]# grep  -r "^[a-Z]" mod_fastdfs.conf 
connect_timeout=2
network_timeout=30
base_path=/tmp
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=192.168.56.131:22122
tracker_server=192.168.56.132:22122
storage_server_port=23000
group_name=group2
url_have_group_name = true
store_path_count=1
store_path0=/fastdfs/storage
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 2
[group1]
group_name=group1
storage_server_port=23
000
store_path_count=1
store_path0=/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
[root@localhost fdfs]
 
 
所有的storage服务器的nginx加入开机自启
 echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local


复制fastdfs的配置文件到/etc/fdfs下

1
2
3
4
5
[root@localhost conf]# pwd
/usr/local/src/fastdfs-5.05/conf
[root@localhost conf]
[root@localhost conf]# \cp http.conf  /etc/fdfs/
[root@localhost conf]# \cp  mime.types   /etc/fdfs/

做软连接:

1
ln -s  /fastdfs/storage/data   /fastdfs/storage/data/M00


修改nginx的配置文件

1
2
3
4
5
6
7
8
9
10
[root@edu-dfs-storage-01 conf]# pwd
/usr/local/nginx/conf
  
vim  nginx.conf  修改如下位置
  
user  root;
 listen       8888;
    location ~/group([0-9])/M00 {
           ngx_fastdfs_module;
        }

启动nginx

1
2
3
4
5
6
7
[root@localhost conf]# /usr/local/nginx/sbin/nginx   -t 
ngx_http_fastdfs_set pid=19562
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
 
/usr/local/nginx/sbin/nginx   启动nginx
echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

测试:刚才上传文件的路径 看上面

http://192.168.56.138:8888/group2/M00/00/00/wKg4iViD5pGASNhIAAUggSnIHZU.tar.gz

http://192.168.56.135:8888/group1/M00/00/00/wKg4h1iD5rGATHRxAAKe64wyZIg888.zip

可以看出两组文件都可以下载

wKiom1iDjzOTMRaDAADmIFJ9RPs097.png-wh_50

wKiom1iDj8vBI98KAADmIFJ9RPs606.png-wh_50


fastdfs的高可用 在安装一台nginx分别代理所有group的nginx

  1. 此台nginx 可以安装在两台tracker上面,用keepalived做高可用,目的反向代理

  2. 所有storage上面的nginx 是目标重定向用的防止找不到下载文件,因为同步延迟

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
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    upstream  group1 {
     server 192.168.56.135:8888;
     server 192.168.56.136:8888;
  }
   upstream  group2 {
     server 192.168.56.137:8888;
     server 192.168.56.138:8888;
}
    server {
        listen       80 default_server;
        location /group1/M00 {
         proxy_pass http://group1;
         }
        location /group2/M00 {
          proxy_pass http://group2;
        }
   }
}

wKiom1nDJTTSw5uEAAK20a8SX40454.png-wh_50

http://192.168.56.131/group2/M00/00/00/wKg4iVnDlLWATq2jAWF12KFAJ44732.rpm 

192.168.56.131可以用keepalived做成VIP


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
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    upstream  group1 {
     server 192.168.56.135:8888;
     server 192.168.56.136:8888;
  }
   upstream  group2 {
     server 192.168.56.137:8888;
     server 192.168.56.138:8888;
}
    server {
        listen       80 default_server;
       location /group1/M00 {
           if ($arg_attname ~* \.(doc|docx|txt|pdf|zip|rar|txt|rpm)$) {
               add_header Content-Disposition "attachment;filename=$arg_attname";
           }
           proxy_pass http://group1;
         }
        location /group2/M00 {
            if ($arg_attname ~* \.(doc|docx|txt|pdf|zip|rar|txt|rpm)$) {
            add_header Content-Disposition "attachment;filename=$arg_attname";
         }  
         proxy_pass http://group2;
        }
   }
}
[root@edu-dfs-tracker-1 ~]#

下载的时候写成就可以下载了

http://192.168.56.131/group2/M00/00/00/wKg4iVnDlLWATq2jAWF12KFAJ44732.rpm?attname=MySQL-client-5.6.29-1.rhel5.x86_64.rpm










本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1893646,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
余二五
+ 关注