简述
zimg是图像存储和处理服务器。您可以使用URL参数从zimg获取压缩和缩放的图像。
zimg的并发I / O,分布式存储和时间处理能力非常出色。
您不再需要在图像服务器中使用nginx。在基准测试中,zimg可以在高并发级别上处理每秒3000+图像下载任务和每秒90000+ HTTP回应请求。
性能高于PHP或其他图像处理服务器。
安装依赖库
sudo yum install -y wget openssl-devel cmake libevent-devel libjpeg-devel giflib-devel libpng-devel libwebp-devel ImageMagick-devel libmemcached-devel
sudo yum install -y glibc-headers gcc-c++
sudo yum install -y build-essential nasm
安装依赖(比较多)
openssl
mkdir -p /usr/local/zimg/openssl
cd /usr/local/zimg/openssl
wget http://www.openssl.org/source/openssl-1.0.1i.tar.gz
tar zxvf openssl-1.0.1i.tar.gz
cd openssl-1.0.1i
./config shared --prefix=/usr/local --openssldir=/usr/ssl
make && make install
cmake
mkdir -p /usr/local/zimg/cmake
cd /usr/local/zimg/cmake
wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz
tar xzvf cmake-3.0.1.tar.gz
cd cmake-3.0.1
./bootstrap --prefix=/usr/local
make && make install
libevent
mkdir -p /usr/local/zimg/libevent
cd /usr/local/zimg/libevent
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local
make && make install
libjpeg-turbo
mkdir -p /usr/local/zimg/libjpeg-turbo
cd /usr/local/zimg/libjpeg-turbo
wget https://downloads.sourceforge.net/project/libjpeg-turbo/1.3.1/libjpeg-turbo-1.3.1.tar.gz
tar zxvf libjpeg-turbo-1.3.1.tar.gz
cd libjpeg-turbo-1.3.1
./configure --prefix=/usr/local --with-jpeg8
make && make install
webp
mkdir -p /usr/local/zimg/webp
cd /usr/local/zimg/
wget http://downloads.webmproject.org/releases/webp/libwebp-0.4.1.tar.gz
tar zxvf libwebp-0.4.1.tar.gz
cd libwebp-0.4.1
./configure
make
sudo make install
jpegsrc
mkdir -p /usr/local/zimg/jpegsrc
cd /usr/local/zimg/
wget http://www.ijg.org/files/jpegsrc.v8b.tar.gz
tar -xf jpegsrc.v8b.tar.gz
cd jpeg-8b
./configure --prefix=/usr/local --enable-shared --enable-static
make && make install
imageMagick
mkdir -p /usr/local/zimg/imageMagick
cd /usr/local/zimg/
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.9.1-10
./configure --prefix=/usr/local
make && make install
libmemcached
mkdir -p /usr/local/zimg/libmemcached
cd /usr/local/zimg/
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure -prefix=/usr/local
make && make install
构建zimg
cd /usr/local/zimg
##此处不要根据下面链接去下载,自己去zimg github地址库区下载最新 版;
#git clone https://github.com/buaazp/zimg -b master --depth=1
# github:https://github.com/buaazp/zimg
cd zimg
make
安装成功后
cd /usr/local/zimg/zimg/bin
./zimg conf/zimg.lua
ctrl+z 退出
curl http://localhost:4869
如果出现html代码 则说明安装启动成功。
然后可以直接访问http://localhost:4869 ,如果访问失败可以查看防火墙端口是否开启。
可能会出现的错误
安装zimg最后一步make时报错make[1]: 进入目录“/usr/local/zimg/deps/libjpeg-turbo” make[1]: ***
解决方法:
yum install libtool –y
Centos 7 firewall 命令
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
Python调用上传接口
img_path = "C:\Users\Administrator\Desktop\centos7.jpg"
url = 'http://127.0.0.1:4869/upload'
files = {'file': ('centos7.jpg', open(img_path, 'rb'), 'image/jpeg')}
rsp = requests.post(url, files=files)
print(rsp.text)
参考资料
# zimg官网
http://zimg.buaa.us/
# zimg官方github
https://github.com/buaazp/zimg
# 搭建指南
https://blog.csdn.net/weixin_43834425/article/details/100679009
# 防火墙相关
https://www.linuxidc.com/Linux/2016-12/138979.htm
# curl安装
https://blog.csdn.net/qq_43523315/article/details/109450135