There are several dependences of zimg you should build and install before using zimg. And the version of cmake should >= 2.8, libevent should >= 2.0, libmemcached should >= 1.0.18.
yum install openssl-devel cmake libevent-devel libjpeg-devel giflib-devel libpng-devel libwebp-devel ImageMagick-devel libmemcached-devel
安装需要的软件,但是libwebp-devel yum上没有
libwebp-devel、libevent和libmemcached需要重新编译,因为yum 上的版本过低
1、安装libevent
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tarzxvf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable
./configure --prefix=/usr/local
make&& make install
2、安装libmemcached
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tarzxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure -prefix=/usr/local
make && make install
3、安装libwebp-devel
wget http://downloads.webmproject.org/releases/webp/libwebp-0.4.1.tar.gz(此文件暂时下载不下来 )
tarzxvf libwebp-0.4.1.tar.gz
cd libwebp-0.4.1
./configure
make
sudo make install
Now you can build zimg itself. If you want to gdbzimg, you can use make debug option.
git clone https://github.com/buaazp/zimg -b master --depth=1
cdzimg
make
If you want to enable cache to improve performance, or you want to store the images to a distributed storage backend, the softwares below is optional.
wget http://www.memcached.org/files/memcached-1.4.19.tar.gz
tarzxvf memcached-1.4.19.tar.gz
cd memcached-1.4.19
./configure --prefix=/usr/local
make
make install
git clone https://github.com/douban/beansdb
cdbeansdb
./configure --prefix=/usr/local
make
git clone git@github.com:douban/beanseye.git
cdbeanseye
make
wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
unzip master
cdssdb-master
make
git clone git@github.com:twitter/twemproxy.git
cdtwemproxy
autoreconf -fvi
./configure --enable-debug=log
make
src/nutcracker -h
在运行zimg之前,你需要按照《Install文档》的说明进行安装,zimg安装成功之后,即可简单修改配置文件后启动。zimg本身的所有选项都在配置文件中进行配置,你可以根据自己的需要修改配置文件:
--zimg server config
--server config
--是否后台运行
is_daemon = 1
--绑定IP
ip = '0.0.0.0'
--端口
port = 4869
--运行线程数,默认值为服务器CPU数
--thread_num=4
backlog_num = 1024
max_keepalives = 1
retry = 3
system = io.popen('uname -sn'):read('*l')
pwd = io.popen('pwd'):read('*l')
--header config
--返回时所带的HTTP header
headers = 'Cache-Control:max-age=7776000'
--是否启用etag缓存
etag = 1
--access config
--support mask rules like 'allow 10.1.121.138/24'
--NOTE: remove rule can improve performance
--上传接口的IP控制权限,将权限规则注释掉可以提升服务器处理能力,下同
--upload_rule = 'allow all'
--下载接口的IP控制权限
--download_rule = 'allow all'
--管理接口的IP控制权限
admin_rule = 'allow 127.0.0.1'
--cache config
--是否启用memcached缓存
cache = 1
--缓存服务器IP
mc_ip = '127.0.0.1'
--缓存服务器端口
mc_port = 11211
--log config
--log_level output specified level of log to logfile
--[[
LOG_FATAL 0 System is unusable
LOG_ALERT 1 Action must be taken immediately
LOG_CRIT 2 Critical conditions
LOG_ERROR 3 Error conditions
LOG_WARNING 4 Warning conditions
LOG_NOTICE 5 Normal, but significant
LOG_INFO 6 Information
LOG_DEBUG 7 DEBUG message
]]
--输出log级别
log_level = 6
--输出log路径
log_name = pwd .. '/log/zimg.log'
--htdocconfig
--默认主页html文件路径
root_path = pwd .. '/www/index.html'
--admin页面html文件路径
admin_path = pwd .. '/www/admin.html'
--image process config
--禁用URL图片处理
disable_args = 0
--禁用lua脚本图片处理
disable_type = 0
--lua process script
--lua脚本文件路径
script_name = pwd .. '/script/process.lua'
--format value: 'none' for original or other format names
--默认保存新图的格式,字符串'none'表示以原有格式保存,或者是期望使用的格式名
format = 'jpeg'
--quality value: 1~100(default: 75)
--默认保存新图的质量
quality = 75
--storage config
--zimg support 3 ways for storage images
--存储后端类型,1为本地存储,2为memcached协议后端如beansdb,3为redis协议后端如SSDB
mode = 1
--save_new value: 0.don't save any 1.save all 2.only save types in lua script
--新文件是否存储,0为不存储,1为全都存储,2为只存储lua脚本产生的新图
save_new = 1
--上传图片大小限制,默认100MB
max_size = 100*1024*1024
--允许上传图片类型列表
allowed_type = {'jpeg', 'jpg', 'png', 'gif', 'webp'}
--mode[1]: local disk mode
--本地存储时的存储路径
img_path = pwd .. '/img'
--mode[2]: beansdb mode
--beansdb服务器IP
beansdb_ip = '127.0.0.1'
--beansdb服务器端口
beansdb_port = 7900
--mode[3]: ssdb mode
--SSDB服务器IP
ssdb_ip = '127.0.0.1'
--SSDB服务器端口
ssdb_port = 8888
然后启动zimg:
cd bin
./zimgconf/zimg.lua
zimg启动之后就可以开始上传和下载图片了,上传方式有两种:
第一种是通过浏览器上传,启动zimg后的默认地址就是一个简单的图片上传页:
http://127.0.0.1:4869/
大约是这个样子的:
上传成功之后会以HTML的格式返回该图片的MD5:
使用到的命令
http://zimg.buaa.us/documents/guidebookcn/免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。