Fastdfs+nginx+lua+GraphicsMagick生成缩略图
Fastdfs+nginx+lua+GraphicsMagick
版本描述
Nginx1.4.2
LuaJIT2.0
NDK0.2.18
lua-nginx-module-0.8.6
安装nginx
- 安装编译环境
yum install gcc gcc-c++ ncurses-devel perl
- 下载安装pcre
yum install -y pcre-devel
- 安装zlib
yum -y install zlib zlib-devel
- 下载tar包
http://nginx.org/en/download.html
解压
tar zxf nginx-1.4.2.tar.gz
- 配置安装目录
./configure –prefix=/usr/local/nginx
- 编译安装
make
make install
- 测试安装状态
./sbin/nginx –t
安装Lua模块
- 下载LuaJIT
2.0为稳定版,2.1性能有较大幅度提升
http://luajit.org/download.html
- 编译安装
make install PREFIX=/usr/local/luajit
- 建立软连
echo “/usr/local/luajit/lib” > /etc/ld.so.conf.d/usr_local_luajit_lib.conf
ldconfig
- 配置环境变量
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
- 下载NDK
https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.8.6
tar xzvf v0.2.18
tar xzvf v0.8.6
- Nginx添加NDK模块
./configure –add-module=../ngx_devel_kit-0.2.18/ –add-module=../lua-nginx-module-0.8.6/
*libluajit-5.1.so.2不存在
cp /data/software/luajit/lib/libluajit-5.1.so.2 /usr/local/lib/libluajit-5.1.so.2
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
- Nginx命令
重启 nginx -s reload
停止 kill -QUIT PID nginx -s stop nginx -quit stop
启动 nginx -c /usr/local/nginx/conf/nginx.conf
安装fastdfs
- 下载libfastcommon
下载地址:https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
解压 libfastcommon
tar -zxvf V1.0.7.tar.gz
编译
cd libfastcommon-1.0.7
./make.sh
安装
./mark.sh install
- 下载fastDFS
下载地址:https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
解压
tar -zxvf V5.05.tar.gz
编译
cd fastfds-5.05
./make.sh
安装
./mark.sh install
- 配置tracker服务
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim tracker.conf
修改以下bast_path,目录确认已被创建
# the base path to store data and log files
base_path=/data/fastdfs
启动tracer服务
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
#创建软链接
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
#启动
service fdfs_trackerd start
查看监听
netstat -unltp|grep fdfs
- 配置storage服务
cp storage.conf.sample storage.conf
vim storage.conf
找到以下参数并进行修改
base_path=/data/fastdfs/storage
store_path0=/data/fastdfs/storage
tracker_server=192.168.0.82:22122
启动
ln -s /usr/bin/fdfs_storaged /usr/local/bin
service fdfs_storaged start
- 查看运行状态
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
- 测试上传
cp client.conf.sample client.conf
配置client.conf
base_path=/data/fastdfs
tracker_server=192.168.0.82:22122
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/index.html
配置fdfs支持http请求
- 添加软连
ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/include/fastdfs /usr/local/include/fastdfs
ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
- 编译nginx
./configure –add-module=/usr/local/fastdfs-nginx-module/src/
make
make install
- 拷贝并修改fastdfs-nginx-module的配置文件
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fdfs
vim 修改/usr/local/fdfs/mod_fastdfs.conf 保存退出
修改如下几项:
tracker_server=192.168.0.81:22122
store_path0=/data/fastdfs/storage
base_path=/data/fastdfs/storage/data
url_have_group_name = true(配置多个tracker时,应该将此项设置为true)
- 建立软连接(配置文件中storage存放数据的路径)
ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00
- 配置nginx访问路径
location /group1/M00{
#/usr/local/fdfs/mod_fastdfs.conf中store_path0配置的路径
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}
nginx_ngx_cache_purge(缓存未配置)
nginx缓存
http://labs.frickle.com/nginx_ngx_cache_purge/
安装GraphicsMagick
- 安装GraphicsMagick
./configure –prefix=/usr/local/GraphicsMagick
make
make install
- 安装libjpeg(支持jpg)
官网地址
ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/delegates/
./configure –prefix=/usr/local/GraphicsMagick-1.3.25/
make
make install
或者
yum install -y libjpeg-devel libjpeg
- 安装libpng(支持png)
./configure –prefix=/usr/local/GraphicsMagick-1.3.25/
make
make install
报错
libjpeg.so.9: cannot open shared object file: No such file or directory
cp /usr/local/lib/libjpeg.so.9 /usr/lib64/
libjpeg.so.9: cannot open shared object file: No such file or directory
cp /usr/local/lib/libpng16.so /usr/lib64/
或者
yum install -y libpng-devel libpng
重新安装编译GraphicsMagick
- 命令
batch – issue multiple commands in interactive or batch mode
benchmark – benchmark one of the other commands
compare – compare two images
composite – composite images together
conjure – execute a Magick Scripting Language (MSL) XML script
convert – convert an image or sequence of images
help – obtain usage message for named command
identify – describe an image or image sequence
mogrify – transform an image or sequence of images
montage – create a composite image (in a grid) from separate images
time – time one of the other commands
version – obtain release version
gm –version可以看到支持的格式
配置GraphicsMagick
参考nginx+lua-nginx-module+fastdfs.conf配置nginx
需要注意文件存放路径以及fdfs的trackerid
/data/images 需要给nginx缓存目录赋权限 chmod –R 777
如果提示无法找到module ‘restyfastdfs’ not found
需要将luajit
Lua相关
lua调试可以通过ngx.log(ngx.ERR,area);
输出变量到nginx日志,
error_log logs/error.log notice;
lua使用..连接字符串
发表评论