搭建FastDFS图片服务器

1.安装fastdfs

安装环境

yum install git gcc gcc-c++ make automake vim wget libevent -y 

安装git

yum install git 

git clone 项目时出现类似如下错误:

fatal: unable to access 'https://github.com/rancher/rancher.git/':Peer reports incompatible or unsupported protocol version.

解决办法 ==>

yum update -y nss curl libcurl 

安装依赖

mkdir /root/fastdfs

cd /root/fastdfs

git clone https://github.com/happyfish100/libfastcommon.git --depth 1

cd libfastcommon/

./make.sh && ./make.sh install

安装fastdfs

cd /root/fastdfs

wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz

tar -zxvf V5.11.tar.gz

cd fastdfs-5.11

./make.sh && ./make.sh install

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

cp /root/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs

cp /root/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs

配置tracker conf

vim /etc/fdfs/tracker.conf

base_path=/home/fastdfs

配置storage conf

vim /etc/fdfs/storage.conf

port=23000
# 数据和日志文件存储根目录
base_path=/home/fastdfs 
# 第一个存储目录
store_path0=/home/fastdfs 

tracker_server=192.168.47.4:22122
# http访问文件的端口(默认8888,看情况修改,和nginx中保持一致) 
http.server_port=8888

配置client conf

vim /etc/fdfs/client.conf

#需要修改的内容如下

base_path=/home/fastdfs

#tracker服务器IP和端口

tracker_server=192.168.47.4:22122

启动

mkdir /home/fastdfs -p

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

#查看所有运行的端口

netstat -ntlp

测试上传

#测试,返回ID表示成功 如:

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/fastdfs/1.png

#返回

group1/M00/00/00/wKgvBF95swaAH-4jAAZWw3obD9g730.png

2.安装fastdfs-nginx-module

下载安装

cd /root/fastdfs

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz

#解压

tar -xvf V1.20.tar.gz

cd fastdfs-nginx-module-1.20/src

vim config

#修改第5 行 和 15 行 修改成

ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

修改配置文件

cp mod_fastdfs.conf /etc/fdfs/

vim /etc/fdfs/mod_fastdfs.conf

#需要修改的内容如下
base_path=/tmp

tracker_server=192.168.47.4:22122

url_have_group_name=true

store_path0=/home/fastdfs

mkdir -p /var/temp/nginx/client

安装nginx并配置

cd /root/fastdfs
wget http://nginx.org/download/nginx-1.15.6.tar.gz
tar -zxvf nginx-1.15.6.tar.gz
cd nginx-1.15.6/
yum -y install pcre-devel openssl openssl-devel
# 添加fastdfs-nginx-module模块
./configure --add-module=/root/fastdfs/fastdfs-nginx-module-1.20/src

编译安装
make && make install
查看模块是否安装上
/usr/local/nginx/sbin/nginx -V

安装 LuaJIT-2.0.4

wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -zxvf LuaJIT-2.0.4.tar.gz

cd /root/fastdfs/LuaJIT-2.0.4
make && make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

安装 lua

wget http://www.lua.org/ftp/lua-5.1.tar.gz
tar -zxvf lua-5.1.tar.gz

# 前置依赖
yum install readline-devel

cd /root/fastdfs/lua-5.1
make linux && make install

安装GraphicsMagick

# 安装GraphicsMagick ⽀持的图⽚格式
yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel ncurses-devel

# 下载GraphicsMagick
wget http://ftp.icm.edu.pl/pub/unix/graphics/GraphicsMagick/1.3/G
raphicsMagick-1.3.18.tar.gz
tar -zxvf GraphicsMagick-1.3.18.tar.gz

cd GraphicsMagick-1.3.18
./configure --prefix=/usr/local/GraphicsMagick-1.3.18 --enable-shared
make && make install
ln -s /usr/local/GraphicsMagick-1.3.18 /usr/local/GraphicsMagick

设置lua脚本

git clone https://github.com/hpxl/nginx-lua-fastdfs-GraphicsMagick.git
cd nginx-lua-fastdfs-GraphicsMagick/lua
cp ./* /usr/local/nginx/conf/lua


vim /usr/local/nginx/conf/lua/fastdfs.lua

#在46⾏
fdfs:set_tracker("192.168.47.4", 22122)
#在72⾏
local command = "/usr/local/GraphicsMagick/bin/gm convert " .. originalFile .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.file;

nginx配置修改

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz

https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
tar -zxvf v0.10.9rc7.tar.gz

# 安装
cd /root/fastdfs/nginx-1.15.6

./configure --prefix=/usr/local/nginx 
--add-module=/root/fastdfs/fastdfs-nginx-module-1.20/src 
--add-module=/root/fastdfs/lua-nginx-module-0.10.9rc7 
--add-module=/root/fastdfs/ngx_devel_kit-0.3.0

make && make install

vim /usr/local/nginx/conf/nginx.conf

server {
		 listen 8888;
		 server_name localhost;

		 # LUA
		 location /hello {
			 default_type 'text/plain';
			 content_by_lua 'ngx.say("hello !!!")';
		 }

		 # fastdfs 缩略图⽣成
		 location ~/group[0-9]/ {
			alias /home/fastdfs/data;

			 set $image_root "/home/fastdfs/data";
			 if ($uri ~ "/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/(.*)") {
			 set $image_dir "$image_root/$3/$4/";
			 set $image_name "$5";
			 set $file "$image_dir$image_name";
		 }

		 if (!-f $file) {
			 #关闭代码缓存
			 lua_code_cache off;
			 content_by_lua_file "/usr/local/nginx/conf/lua/fastdfs.lua";
		 }
			 ngx_fastdfs_module;
		 }
	}

授权写的权限

# 修改权限,否则可能会出现缩略图404的情况
chmod -R 777 /home/fastdfs/data/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值