Giter Site home page Giter Site logo

ngx-lua-images's Introduction

ngx-lua-images

OpenResty (nginx+lua) + ceph + GraphicsMagick ,一个类似于 zimg, 动态生成处理图片的图片服务器。

Getting Started

整个架构类似于zimg, 在http层加了redis缓存,处理后的保存为文件也算是个缓存,可以写个crontab脚本定期清理不常访问的缓存图片。

图片存储路径的规划方案。

借鉴 zimg 的方案,存储路径采用2级子目录的方案。由于 Linux 同目录下的子目录数最好不要超过2000个,再加上 MD5 的值本身就是32位十六进制数,zimg就采取了一种非常取巧的方式:根据 MD5 的前六位进行哈希,1-3位转换为十六进制数后除以4,范围正好落在1024以内,以这个数作为第一级子目录;4-6位同样处理,作为第二级子目录;二级子目录下是以 MD5 命名的文件夹,每个MD5文件夹内存储图片的原图和其他根据需要存储的版本,假设一个图片平均占用空间200KB,一台服务器支持的总容量就可以计算出来了:

1024 * 1024 * 1024 * 200KB = 200TB

Ceph

一个 Linux PB 级分布式文件系统

  • 可轻松扩展到数 PB 容量
  • 对多种工作负载的高性能(每秒输入/输出操作[IOPS]和带宽)
  • 高可靠性

Installing

GraphicsMagick OpenResty

sudo apt-get install GraphicsMagick libgraphicsmagick1-dev

or 

yum install GraphicsMagick GraphicsMagick-devel -y

## openresty
tar xvf ngx_openresty-VERSION.tar.gz
cd ngx_openresty-VERSION/
./configure
make
make install

And

cd /usr/local/openresty/nginx/conf
mkdir conf.d

add "include conf.d/*.conf;" into nginx.conf

# last, in ngx-lua_images folder.

bash deploy.sh

# and add images folder, change it at config.lua if you need.

mkdir /home/files/images/
chown -R {nginx_user}/home/fiels/images

上传图片

http://localhost:8000/static/image-upload/ 

上传成功。

如果没有错误,就可以访问了。

http://localhost:8000/fffc929444a9fb7eb754217cfd7b0d58?w=500&h=500&g=1&x=0&y=0&r=45&q=75&f=jpeg
http://localhost:8000/get_info?md5=fffc929444a9fb7eb754217cfd7b0d58

ceph

  1. 安装:略
  2. configure:
    • 修改./vendor/cephs3.lua的配置文件。
    • 修改confi.json的ceph_mode为true。
    • 删除nginx.conf的location /upload 段。

上传文件请使用ceph(s3 or swift) sdk上传文件和管理bucket.

Authors

  • Linsir - Initial work - Linsir

See also the list of contributors who participated in this project.

Benchmark

see the Benchmark.md file for details

License

This project is licensed under the MIT License

Acknowledgments

ngx-lua-images's People

Contributors

linsir avatar vi5i0n avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.