可扩展的缩略图服务,使用 Thumbor 和 Ceph
laurentbarbe
一个使用 python-ceph 库进行缩略图服务的示例。
Thumbor 是 globo 开发的一个开源缩略图生成工具。
该工具允许通过 URL 直接进行许多操作(裁剪、调整大小、滤镜等)。它还使用人脸检测算法或兴趣点来增强裁剪或自动调整大小。原始图像通过 URL 或使用 Restful API 直接导入。
为了与 Ceph 接口,有两种方法:- 使用 S3 API(通过 Rados GW)- 使用 librados 和 python 包装器用于 librados。
在本例中,我展示的是第二种情况,因为它优化了应用程序和存储集群之间的延迟。

安装:¶
Thumbor 安装
apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libcurl4-gnutls-dev libwebp-dev
apt-get install python-dev python-pycurl python-opencv
apt-get install python-pip
pip install thumbor
thumbor_ceph 存储插件安装
apt-get install python-ceph
pip install thumbor_ceph
配置:¶
生成初始 thumbor 配置文件
thumbor-config > /etc/thumbor.conf
更多配置选项:https://github.com/thumbor/thumbor/wiki/Configuration
将 ceph.conf 和 admin keyring 填充到 /etc/ceph/ 中
为 thumbor 创建一个 ceph 池
ceph osd pool create thumbor 128 128
文件存储部分在 /etc/thumbor.conf 中
################################# File Storage #################################
STORAGE = 'thumbor_ceph.storages.ceph_storage'
CEPH_STORAGE_POOL = 'thumbor'
上传部分
#################################### Upload ####################################
UPLOAD_PHOTO_STORAGE = 'thumbor_ceph.storages.ceph_storage'
结果存储部分
################################ Result Storage ################################
RESULT_STORAGE = 'thumbor_ceph.result_storages.ceph_storage'
CEPH_RESULT_STORAGE_POOL = 'thumbor'
启动 thumbor ¶
# thumbor -l debug
2014-05-27 10:27:24 thumbor:DEBUG INIT RADOS Storage (ID:c3eb3343-d06c-438f-ae49-cf998468824d)
2014-05-27 10:27:24 thumbor:DEBUG INIT RADOS Result Storage (ID:c3eb3343-d06c-438f-ae49-cf998468824d)
2014-05-27 10:27:24 root:DEBUG thumbor running at 0.0.0.0:8888
用法 ¶
现在您可以轻松调整 ceph logo
的大小,从这些图像
使用此 URL
https://:8888/unsafe/0x0:36x36/https://ceph.net.cn/wp-content/themes/ceph/images/logo.png
https://github.com/thumbor/thumbor/wiki/Usage