Skip to content

Commit bf436eb

Browse files
committed
2016-04-24增加FastDFS 结合 GraphicsMagick文章
1 parent a698508 commit bf436eb

File tree

4 files changed

+376
-1
lines changed

4 files changed

+376
-1
lines changed

FastDFS-Install-And-Settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# FastDFS 安装和配置
1+
# FastDFS 安装和配置
22

33

44
## 它是什么

FastDFS-Nginx-Lua-GraphicsMagick.md

Lines changed: 373 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,373 @@
1+
# FastDFS 结合 GraphicsMagick
2+
3+
4+
## 单机安装部署(CentOS 6.7 环境)
5+
6+
7+
8+
### 先安装 FastDFS
9+
10+
- 软件准备:
11+
- 我这边统一提供了一个压缩包,方便使用。
12+
- 下载地址:<http://pan.baidu.com/s/1hsg2brA>
13+
- 安装依赖包:`yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel libevent`
14+
- 安装 **libfastcommon-1.0.7.tar.gz**
15+
- 解压:`tar zxvf libfastcommon-1.0.7.tar.gz`
16+
- 进入解压后目录:`cd libfastcommon-1.0.7/`
17+
- 编译:`./make.sh`
18+
- 安装:`./make.sh install`
19+
- 设置几个软链接:`ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so`
20+
- 设置几个软链接:`ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so`
21+
- 设置几个软链接:`ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so`
22+
- 设置几个软链接:`ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so`
23+
- 安装 tracker (跟踪器)服务 **FastDFS_v5.08.tar.gz**
24+
- 解压:`tar zxvf FastDFS_v5.05.tar.gz`
25+
- 进入解压后目录:`cd FastDFS/`
26+
- 编译:`./make.sh`
27+
- 安装:`./make.sh install`
28+
- 配置 tracker 服务
29+
- 复制一份配置文件:`cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf`
30+
- 编辑:`vim /etc/fdfs/tracker.conf`,编辑内容看下面中文注释
31+
``` ini
32+
disabled=false
33+
bind_addr=
34+
port=22122
35+
connect_timeout=30
36+
network_timeout=60
37+
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
38+
# 创建目录:mkdir -p /opt/fastdfs/tracker/data-and-log
39+
base_path=/opt/fastdfs/tracker/data-and-log
40+
max_connections=256
41+
accept_threads=1
42+
work_threads=4
43+
store_lookup=2
44+
store_group=group2
45+
store_server=0
46+
store_path=0
47+
download_server=0
48+
reserved_storage_space = 10%
49+
log_level=info
50+
run_by_group=
51+
run_by_user=
52+
allow_hosts=*
53+
sync_log_buff_interval = 10
54+
check_active_interval = 120
55+
thread_stack_size = 64KB
56+
storage_ip_changed_auto_adjust = true
57+
storage_sync_file_max_delay = 86400
58+
storage_sync_file_max_time = 300
59+
use_trunk_file = false
60+
slot_min_size = 256
61+
slot_max_size = 16MB
62+
trunk_file_size = 64MB
63+
trunk_create_file_advance = false
64+
trunk_create_file_time_base = 02:00
65+
trunk_create_file_interval = 86400
66+
trunk_create_file_space_threshold = 20G
67+
trunk_init_check_occupying = false
68+
trunk_init_reload_from_binlog = false
69+
trunk_compress_binlog_min_interval = 0
70+
use_storage_id = false
71+
storage_ids_filename = storage_ids.conf
72+
id_type_in_filename = ip
73+
store_slave_file_use_link = false
74+
rotate_error_log = false
75+
error_log_rotate_time=00:00
76+
rotate_error_log_size = 0
77+
log_file_keep_days = 0
78+
use_connection_pool = false
79+
connection_pool_max_idle_time = 3600
80+
http.server_port=8080
81+
http.check_alive_interval=30
82+
http.check_alive_type=tcp
83+
http.check_alive_uri=/status.html
84+
```
85+
- 启动 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf`
86+
- 重启 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart`
87+
- 查看是否有 tracker 进程:`ps aux | grep tracker`
88+
- storage (存储节点)服务部署
89+
- 一般 storage 服务我们会单独装一台机子,但是这里为了方便我们安装在同一台。
90+
- 如果 storage 单独安装的话,那上面安装的步骤都要在走一遍,只是到了编辑配置文件的时候,编辑的是 storage.conf 而已
91+
- 复制一份配置文件:`cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf`
92+
- 编辑:`vim /etc/fdfs/storage.conf`,编辑内容看下面中文注释
93+
``` ini
94+
disabled=false
95+
group_name=group1
96+
bind_addr=
97+
client_bind=true
98+
port=23000
99+
connect_timeout=30
100+
network_timeout=60
101+
heart_beat_interval=30
102+
stat_report_interval=60
103+
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
104+
# 创建目录:mkdir -p /opt/fastdfs/storage/data-and-log
105+
base_path=/opt/fastdfs/storage/data-and-log
106+
max_connections=256
107+
buff_size = 256KB
108+
accept_threads=1
109+
work_threads=4
110+
disk_rw_separated = true
111+
disk_reader_threads = 1
112+
disk_writer_threads = 1
113+
sync_wait_msec=50
114+
sync_interval=0
115+
sync_start_time=00:00
116+
sync_end_time=23:59
117+
write_mark_file_freq=500
118+
store_path_count=1
119+
# 图片实际存放路径,如果有多个,这里可以有多行:
120+
# store_path0=/opt/fastdfs/storage/images-data0
121+
# store_path1=/opt/fastdfs/storage/images-data1
122+
# store_path2=/opt/fastdfs/storage/images-data2
123+
# 创建目录:mkdir -p /opt/fastdfs/storage/images-data
124+
store_path0=/opt/fastdfs/storage/images-data
125+
subdir_count_per_path=256
126+
# 指定 tracker 服务器的 IP 和端口
127+
tracker_server=192.168.1.114:22122
128+
log_level=info
129+
run_by_group=
130+
run_by_user=
131+
allow_hosts=*
132+
file_distribute_path_mode=0
133+
file_distribute_rotate_count=100
134+
fsync_after_written_bytes=0
135+
sync_log_buff_interval=10
136+
sync_binlog_buff_interval=10
137+
sync_stat_file_interval=300
138+
thread_stack_size=512KB
139+
upload_priority=10
140+
if_alias_prefix=
141+
check_file_duplicate=0
142+
file_signature_method=hash
143+
key_namespace=FastDFS
144+
keep_alive=0
145+
use_access_log = false
146+
rotate_access_log = false
147+
access_log_rotate_time=00:00
148+
rotate_error_log = false
149+
error_log_rotate_time=00:00
150+
rotate_access_log_size = 0
151+
rotate_error_log_size = 0
152+
log_file_keep_days = 0
153+
file_sync_skip_invalid_record=false
154+
use_connection_pool = false
155+
connection_pool_max_idle_time = 3600
156+
http.domain_name=
157+
http.server_port=8888
158+
```
159+
- 启动 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf`,首次启动会很慢,因为它在创建预设存储文件的目录
160+
- 重启 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart`
161+
- 查看是否有 storage 进程:`ps aux | grep storage`
162+
- 测试是否部署成功
163+
- 利用自带的 client 进行测试
164+
- 复制一份配置文件:`cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf`
165+
- 编辑:`vim /etc/fdfs/client.conf`,编辑内容看下面中文注释
166+
``` ini
167+
connect_timeout=30
168+
network_timeout=60
169+
# 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录
170+
# 创建目录:mkdir -p /opt/fastdfs/client/data-and-log
171+
base_path=/opt/fastdfs/client/data-and-log
172+
# 指定 tracker 服务器的 IP 和端口
173+
tracker_server=192.168.1.114:22122
174+
log_level=info
175+
use_connection_pool = false
176+
connection_pool_max_idle_time = 3600
177+
load_fdfs_parameters_from_tracker=false
178+
use_storage_id = false
179+
storage_ids_filename = storage_ids.conf
180+
http.tracker_server_port=80
181+
```
182+
- 在终端中通过 shell 上传 opt 目录下的一张图片:`/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg`
183+
- 如下图箭头所示,生成的图片地址为:`http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg`
184+
- ![FastDFS](images/FastDFS-a-1.jpg)
185+
- 即使我们现在知道图片的访问地址我们也访问不了,因为我们还没装 FastDFS 的 Nginx 模块
186+
187+
188+
### 安装 nginx-lua-GraphicsMagick
189+
190+
- 来源:<https://github.com/yanue/nginx-lua-GraphicsMagick/blob/master/nginx-install.md>
191+
- 添加专用用户,后面有用
192+
- `groupadd www`
193+
- `useradd -g www www -s /bin/false`
194+
- 安装依赖包
195+
- `yum install -y gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel`
196+
- `yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel`
197+
- `yum install -y GraphicsMagick GraphicsMagick-devel`
198+
- 下面的这些软件都在本文在开头的那个压缩包里面。现在我们需要解压这些压缩包
199+
- `cd /opt/setups`
200+
- `tar -zxvf nginx-1.8.0.tar.gz`
201+
- `tar -zxvf LuaJIT-2.0.4.tar.gz`
202+
- `tar -zxvf GraphicsMagick-1.3.21.tar.gz`
203+
- `tar -zxvf zlib-1.2.8.tar.gz`
204+
- 安装 LuaJIT
205+
- `cd /opt/setups/LuaJIT-2.0.4`
206+
- `make`
207+
- `make install`
208+
- `export LUAJIT_LIB=/usr/local/lib`
209+
- `export LUAJIT_INC=/usr/local/include/luajit-2.0`
210+
- `ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2`
211+
- 修改一些配置文件
212+
- 编辑 Nginx 模块的配置文件:`vim /opt/setups/fastdfs-nginx-module/src/config`
213+
- 找到下面一行包含有 `local` 字眼去掉,因为这三个路径根本不是在 local 目录下的。(如果你的配置文件没有这个 local,那这一步跳过)
214+
``` nginx
215+
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
216+
```
217+
- 改为如下:
218+
``` nginx
219+
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
220+
```
221+
- 复制文件:`cp /opt/setups/FastDFS/conf/http.conf /etc/fdfs`
222+
- 复制文件:`cp /opt/setups/FastDFS/conf/mime.types /etc/fdfs`
223+
- 开始安装 Nginx
224+
- `cd /opt/setups/nginx-1.8.0`
225+
- `mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx`
226+
- 执行下面编译语句:
227+
``` nginx
228+
./configure --prefix=/usr/local/nginx \
229+
--user=www \
230+
--group=www \
231+
--pid-path=/var/local/nginx/nginx.pid \
232+
--lock-path=/var/lock/nginx/nginx.lock \
233+
--error-log-path=/var/log/nginx/error.log \
234+
--http-log-path=/var/log/nginx/access.log \
235+
--http-client-body-temp-path=/var/temp/nginx/client \
236+
--http-proxy-temp-path=/var/temp/nginx/proxy \
237+
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
238+
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
239+
--http-scgi-temp-path=/var/temp/nginx/scgi \
240+
--sbin-path=/usr/local/nginx/sbin/nginx \
241+
--with-http_ssl_module \
242+
--with-http_realip_module \
243+
--with-http_sub_module \
244+
--with-http_flv_module \
245+
--with-http_dav_module \
246+
--with-http_gzip_static_module \
247+
--with-http_stub_status_module \
248+
--with-http_addition_module \
249+
--with-http_spdy_module \
250+
--with-pcre \
251+
--with-zlib=/opt/setups/zlib-1.2.8 \
252+
--add-module=/opt/setups/nginx-http-concat \
253+
--add-module=/opt/setups/lua-nginx-module \
254+
--add-module=/opt/setups/ngx_devel_kit \
255+
--add-module=/opt/setups/fastdfs-nginx-module/src
256+
```
257+
- `make`
258+
- `make install`
259+
- 修改一下配置
260+
- 复制 Nginx 模块的配置文件:`cp /opt/setups/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs`
261+
- 编辑 Nginx 模块的配置文件:`vim /etc/fdfs/mod_fastdfs.conf`,编辑内容看下面中文注释
262+
- 如果在已经启动 Nginx 的情况下修改下面内容记得要重启 Nginx。
263+
``` ini
264+
connect_timeout=2
265+
network_timeout=30
266+
# 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录
267+
# 创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-log
268+
base_path=/opt/fastdfs/fastdfs-nginx-module/data-and-log
269+
load_fdfs_parameters_from_tracker=true
270+
storage_sync_file_max_delay = 86400
271+
use_storage_id = false
272+
storage_ids_filename = storage_ids.conf
273+
# 指定 tracker 服务器的 IP 和端口
274+
tracker_server=192.168.1.114:22122
275+
storage_server_port=23000
276+
group_name=group1
277+
# 因为我们访问图片的地址是:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg
278+
# 该地址前面是带有 /group1/M00,所以我们这里要使用 true,不然访问不到(原值是 false)
279+
url_have_group_name = true
280+
store_path_count=1
281+
# 图片实际存放路径,如果有多个,这里可以有多行:
282+
# store_path0=/opt/fastdfs/storage/images-data0
283+
# store_path1=/opt/fastdfs/storage/images-data1
284+
# store_path2=/opt/fastdfs/storage/images-data2
285+
store_path0=/opt/fastdfs/storage/images-data
286+
log_level=info
287+
log_filename=
288+
response_mode=proxy
289+
if_alias_prefix=
290+
flv_support = true
291+
flv_extension = flv
292+
group_count = 0
293+
```
294+
- 创建文件夹:`mkdir -p /opt/fastdfs/thumb`
295+
- 编辑 Nginx 配置文件
296+
- `vim /usr/local/nginx/conf/nginx.conf`
297+
``` nginx
298+
# 注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
299+
user root;
300+
worker_processes 1;
301+
302+
303+
events {
304+
worker_connections 1024;
305+
}
306+
307+
308+
http {
309+
include mime.types;
310+
default_type application/octet-stream;
311+
312+
sendfile on;
313+
314+
keepalive_timeout 65;
315+
316+
317+
server{
318+
listen 80;
319+
server_name 192.168.1.112;
320+
321+
set $img_thumbnail_root /opt/fastdfs/thumb;
322+
set $img_file $img_thumbnail_root$uri;
323+
324+
# like:/pic/M00/xx/xx/xx.jpg_200x100.jpg
325+
# /group1/M00
326+
location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png))$ {
327+
root $img_thumbnail_root;
328+
set $fdfs_group_root /opt/fastdfs/storage/images-data/data;
329+
330+
# 如果缩略图不存在
331+
if (!-f $img_file) {
332+
add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue';
333+
add_header file-path $request_filename;
334+
335+
set $request_filepath $fdfs_group_root$4;
336+
set $img_width $6;
337+
set $img_height $7;
338+
set $img_ext $5;
339+
content_by_lua_file /opt/setups/lua/cropSize.lua;
340+
}
341+
}
342+
343+
location /group1/M00 {
344+
alias /opt/fastdfs/storage/images-data/data;
345+
ngx_fastdfs_module;
346+
}
347+
348+
}
349+
}
350+
```
351+
- 启动 Nginx
352+
- 停掉防火墙:`service iptables stop`
353+
- 启动:`/usr/local/nginx/sbin/nginx`,启动完成 shell 是不会有输出的
354+
- 访问:`192.168.1.114`,如果能看到:`Welcome to nginx!`,即可表示安装成功
355+
- 检查 时候有 Nginx 进程:`ps aux | grep nginx`,正常是显示 3 个结果出来
356+
- 刷新 Nginx 配置后重启:`/usr/local/nginx/sbin/nginx -s reload`
357+
- 停止 Nginx:`/usr/local/nginx/sbin/nginx -s stop`
358+
- 如果访问不了,或是出现其他信息看下错误立即:`vim /var/log/nginx/error.log`
359+
360+
361+
362+
### 多机安装部署(CentOS 6.7 环境)
363+
364+
- 多机部署的情况,对生成大小图的 Nginx 也有地方要修改。
365+
- 资料:<http://blog.csdn.net/ricciozhang/article/details/49402273>
366+
367+
368+
369+
## 资料
370+
371+
- [fastdfs+nginx安装配置](http://blog.csdn.net/ricciozhang/article/details/49402273)
372+
373+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- [TeamCity 安装和配置](TeamCity-Install-And-Settings.md)
5050
- [Nginx 安装和配置](Nginx-Install-And-Settings.md)
5151
- [FastDFS 安装和配置](FastDFS-Install-And-Settings.md)
52+
- [FastDFS 结合 GraphicsMagick](FastDFS-Nginx-Lua-GraphicsMagick.md)
5253
- [RabbitMQ 安装和配置](RabbitMQ-Install-And-Settings.md)
5354
- [黑客入侵检查](Was-Hacked.md)
5455

TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
- [TeamCity 安装和配置](TeamCity-Install-And-Settings.md)
3838
- [Nginx 安装和配置](Nginx-Install-And-Settings.md)
3939
- [FastDFS 安装和配置](FastDFS-Install-And-Settings.md)
40+
- [FastDFS 结合 GraphicsMagick](FastDFS-Nginx-Lua-GraphicsMagick.md)
4041
- [RabbitMQ 安装和配置](RabbitMQ-Install-And-Settings.md)
4142
- [黑客入侵检查](Was-Hacked.md)

0 commit comments

Comments
 (0)