- FastDFS 结合 GraphicsMagick
- 单机安装部署(CentOS 6.7 环境)
- 先安装 FastDFS
- 安装 nginx-lua-GraphicsMagick
- 单机安装部署(CentOS 6.7 环境)
- 注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
- 多机安装部署(CentOS 6.7 环境)
- 资料
FastDFS 结合 GraphicsMagick
单机安装部署(CentOS 6.7 环境)
先安装 FastDFS
- 软件准备:
- 我这边统一提供了一个压缩包,方便使用。
- 下载地址:http://pan.baidu.com/s/1hsg2brA
- 我这边统一提供了一个压缩包,方便使用。
- 安装依赖包:
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel libevent - 安装 libfastcommon-1.0.7.tar.gz
- 解压:
tar zxvf libfastcommon-1.0.7.tar.gz - 进入解压后目录:
cd libfastcommon-1.0.7/ - 编译:
./make.sh - 安装:
./make.sh install - 设置几个软链接:
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
- 解压:
- 安装 tracker (跟踪器)服务 FastDFS_v5.08.tar.gz
- 解压:
tar zxvf FastDFS_v5.05.tar.gz - 进入解压后目录:
cd FastDFS/ - 编译:
./make.sh - 安装:
./make.sh install
- 解压:
- 配置 tracker 服务
- 复制一份配置文件:
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf - 编辑:
vim /etc/fdfs/tracker.conf,编辑内容看下面中文注释disabled=falsebind_addr=port=22122connect_timeout=30network_timeout=60# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录# 创建目录:mkdir -p /opt/fastdfs/tracker/data-and-logbase_path=/opt/fastdfs/tracker/data-and-logmax_connections=256accept_threads=1work_threads=4store_lookup=2store_group=group2store_server=0store_path=0download_server=0reserved_storage_space = 10%log_level=inforun_by_group=run_by_user=allow_hosts=*sync_log_buff_interval = 10check_active_interval = 120thread_stack_size = 64KBstorage_ip_changed_auto_adjust = truestorage_sync_file_max_delay = 86400storage_sync_file_max_time = 300use_trunk_file = falseslot_min_size = 256slot_max_size = 16MBtrunk_file_size = 64MBtrunk_create_file_advance = falsetrunk_create_file_time_base = 02:00trunk_create_file_interval = 86400trunk_create_file_space_threshold = 20Gtrunk_init_check_occupying = falsetrunk_init_reload_from_binlog = falsetrunk_compress_binlog_min_interval = 0use_storage_id = falsestorage_ids_filename = storage_ids.confid_type_in_filename = ipstore_slave_file_use_link = falserotate_error_log = falseerror_log_rotate_time=00:00rotate_error_log_size = 0log_file_keep_days = 0use_connection_pool = falseconnection_pool_max_idle_time = 3600http.server_port=8080http.check_alive_interval=30http.check_alive_type=tcphttp.check_alive_uri=/status.html
- 启动 tracker 服务:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf - 重启 tracker 服务:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart - 查看是否有 tracker 进程:
ps aux | grep tracker
- 复制一份配置文件:
- storage (存储节点)服务部署
- 一般 storage 服务我们会单独装一台机子,但是这里为了方便我们安装在同一台。
- 如果 storage 单独安装的话,那上面安装的步骤都要在走一遍,只是到了编辑配置文件的时候,编辑的是 storage.conf 而已
- 复制一份配置文件:
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf - 编辑:
vim /etc/fdfs/storage.conf,编辑内容看下面中文注释disabled=falsegroup_name=group1bind_addr=client_bind=trueport=23000connect_timeout=30network_timeout=60heart_beat_interval=30stat_report_interval=60# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录# 创建目录:mkdir -p /opt/fastdfs/storage/data-and-logbase_path=/opt/fastdfs/storage/data-and-logmax_connections=256buff_size = 256KBaccept_threads=1work_threads=4disk_rw_separated = truedisk_reader_threads = 1disk_writer_threads = 1sync_wait_msec=50sync_interval=0sync_start_time=00:00sync_end_time=23:59write_mark_file_freq=500store_path_count=1# 图片实际存放路径,如果有多个,这里可以有多行:# store_path0=/opt/fastdfs/storage/images-data0# store_path1=/opt/fastdfs/storage/images-data1# store_path2=/opt/fastdfs/storage/images-data2# 创建目录:mkdir -p /opt/fastdfs/storage/images-datastore_path0=/opt/fastdfs/storage/images-datasubdir_count_per_path=256# 指定 tracker 服务器的 IP 和端口tracker_server=192.168.1.114:22122log_level=inforun_by_group=run_by_user=allow_hosts=*file_distribute_path_mode=0file_distribute_rotate_count=100fsync_after_written_bytes=0sync_log_buff_interval=10sync_binlog_buff_interval=10sync_stat_file_interval=300thread_stack_size=512KBupload_priority=10if_alias_prefix=check_file_duplicate=0file_signature_method=hashkey_namespace=FastDFSkeep_alive=0use_access_log = falserotate_access_log = falseaccess_log_rotate_time=00:00rotate_error_log = falseerror_log_rotate_time=00:00rotate_access_log_size = 0rotate_error_log_size = 0log_file_keep_days = 0file_sync_skip_invalid_record=falseuse_connection_pool = falseconnection_pool_max_idle_time = 3600http.domain_name=http.server_port=8888
- 启动 storage 服务:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf,首次启动会很慢,因为它在创建预设存储文件的目录 - 重启 storage 服务:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart - 查看是否有 storage 进程:
ps aux | grep storage
- 测试是否部署成功
- 利用自带的 client 进行测试
- 复制一份配置文件:
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf - 编辑:
vim /etc/fdfs/client.conf,编辑内容看下面中文注释connect_timeout=30network_timeout=60# 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录# 创建目录:mkdir -p /opt/fastdfs/client/data-and-logbase_path=/opt/fastdfs/client/data-and-log# 指定 tracker 服务器的 IP 和端口tracker_server=192.168.1.114:22122log_level=infouse_connection_pool = falseconnection_pool_max_idle_time = 3600load_fdfs_parameters_from_tracker=falseuse_storage_id = falsestorage_ids_filename = storage_ids.confhttp.tracker_server_port=80
- 在终端中通过 shell 上传 opt 目录下的一张图片:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg - 如下图箭头所示,生成的图片地址为:
http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg - 即使我们现在知道图片的访问地址我们也访问不了,因为我们还没装 FastDFS 的 Nginx 模块
安装 nginx-lua-GraphicsMagick
- 来源:https://github.com/yanue/nginx-lua-GraphicsMagick/blob/master/nginx-install.md
- 添加专用用户,后面有用
groupadd wwwuseradd -g www www -s /bin/false
- 安装依赖包
yum install -y gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-develyum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-develyum install -y GraphicsMagick GraphicsMagick-devel
- 下面的这些软件都在本文在开头的那个压缩包里面。现在我们需要解压这些压缩包
cd /opt/setupstar -zxvf nginx-1.8.0.tar.gztar -zxvf LuaJIT-2.0.4.tar.gztar -zxvf GraphicsMagick-1.3.21.tar.gztar -zxvf zlib-1.2.8.tar.gz
- 安装 LuaJIT
cd /opt/setups/LuaJIT-2.0.4makemake installexport LUAJIT_LIB=/usr/local/libexport LUAJIT_INC=/usr/local/include/luajit-2.0ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
- 修改一些配置文件
- 编辑 Nginx 模块的配置文件:
vim /opt/setups/fastdfs-nginx-module/src/config - 找到下面一行包含有
local字眼去掉,因为这三个路径根本不是在 local 目录下的。(如果你的配置文件没有这个 local,那这一步跳过)CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
- 改为如下:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
- 复制文件:
cp /opt/setups/FastDFS/conf/http.conf /etc/fdfs - 复制文件:
cp /opt/setups/FastDFS/conf/mime.types /etc/fdfs
- 编辑 Nginx 模块的配置文件:
- 开始安装 Nginx
cd /opt/setups/nginx-1.8.0mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx- 执行下面编译语句:
./configure --prefix=/usr/local/nginx \--user=www \--group=www \--pid-path=/var/local/nginx/nginx.pid \--lock-path=/var/lock/nginx/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--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 \--sbin-path=/usr/local/nginx/sbin/nginx \--with-http_ssl_module \--with-http_realip_module \--with-http_sub_module \--with-http_flv_module \--with-http_dav_module \--with-http_gzip_static_module \--with-http_stub_status_module \--with-http_addition_module \--with-http_spdy_module \--with-pcre \--with-zlib=/opt/setups/zlib-1.2.8 \--add-module=/opt/setups/nginx-http-concat \--add-module=/opt/setups/lua-nginx-module \--add-module=/opt/setups/ngx_devel_kit \--add-module=/opt/setups/fastdfs-nginx-module/src
makemake install
- 修改一下配置
- 复制 Nginx 模块的配置文件:
cp /opt/setups/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs - 编辑 Nginx 模块的配置文件:
vim /etc/fdfs/mod_fastdfs.conf,编辑内容看下面中文注释 - 如果在已经启动 Nginx 的情况下修改下面内容记得要重启 Nginx。
connect_timeout=2network_timeout=30# 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录# 创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-logbase_path=/opt/fastdfs/fastdfs-nginx-module/data-and-logload_fdfs_parameters_from_tracker=truestorage_sync_file_max_delay = 86400use_storage_id = falsestorage_ids_filename = storage_ids.conf# 指定 tracker 服务器的 IP 和端口tracker_server=192.168.1.114:22122storage_server_port=23000group_name=group1# 因为我们访问图片的地址是:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg# 该地址前面是带有 /group1/M00,所以我们这里要使用 true,不然访问不到(原值是 false)url_have_group_name = truestore_path_count=1# 图片实际存放路径,如果有多个,这里可以有多行:# store_path0=/opt/fastdfs/storage/images-data0# store_path1=/opt/fastdfs/storage/images-data1# store_path2=/opt/fastdfs/storage/images-data2store_path0=/opt/fastdfs/storage/images-datalog_level=infolog_filename=response_mode=proxyif_alias_prefix=flv_support = trueflv_extension = flvgroup_count = 0
- 创建文件夹:
mkdir -p /opt/fastdfs/thumb - 编辑 Nginx 配置文件
vim /usr/local/nginx/conf/nginx.conf
``` nginx注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
user root;
worker_processes 1;
- 复制 Nginx 模块的配置文件:
events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server{listen 80;server_name 192.168.1.112;set $img_thumbnail_root /opt/fastdfs/thumb;set $img_file $img_thumbnail_root$uri;# like:/pic/M00/xx/xx/xx.jpg_200x100.jpg# /group1/M00location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png))$ {root $img_thumbnail_root;set $fdfs_group_root /opt/fastdfs/storage/images-data/data;# 如果缩略图不存在if (!-f $img_file) {add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue';add_header file-path $request_filename;set $request_filepath $fdfs_group_root$4;set $img_width $6;set $img_height $7;set $img_ext $5;content_by_lua_file /opt/setups/lua/cropSize.lua;}}location /group1/M00 {alias /opt/fastdfs/storage/images-data/data;ngx_fastdfs_module;}}}```- 启动 Nginx- 停掉防火墙:`service iptables stop`- 启动:`/usr/local/nginx/sbin/nginx`,启动完成 shell 是不会有输出的- 访问:`192.168.1.114`,如果能看到:`Welcome to nginx!`,即可表示安装成功- 检查 时候有 Nginx 进程:`ps aux | grep nginx`,正常是显示 3 个结果出来- 刷新 Nginx 配置后重启:`/usr/local/nginx/sbin/nginx -s reload`- 停止 Nginx:`/usr/local/nginx/sbin/nginx -s stop`- 如果访问不了,或是出现其他信息看下错误立即:`vim /var/log/nginx/error.log`
多机安装部署(CentOS 6.7 环境)
- 多机部署的情况,对生成大小图的 Nginx 也有地方要修改。
- 资料:http://blog.csdn.net/ricciozhang/article/details/49402273
资料
- fastdfs+nginx安装配置

