Skip to content

Commit

Permalink
Merge branch 'dev' for v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
buaazp committed May 18, 2014
1 parent 70c432a commit 97059ec
Show file tree
Hide file tree
Showing 12 changed files with 599 additions and 177 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Homepage: [zimg.buaa.us](http://zimg.buaa.us/)
Author: [@招牌疯子](http://weibo.com/819880808)
Contact me: zp@buaa.us

[![Build Status](https://travis-ci.org/buaazp/zimg.svg?branch=master)](https://travis-ci.org/buaazp/zimg)
[![Build Status](https://travis-ci.org/buaazp/zimg.svg?branch=master)](https://travis-ci.org/buaazp/zimg)
[![Build Status](https://drone.io/github.com/buaazp/zimg/status.png)](https://drone.io/github.com/buaazp/zimg/latest)

### Versions:
- 05/18/2014 - zimg 2.1.0 Release.
- 04/26/2014 - zimg 2.0.0 Beta Release. *Important milestone for zimg.*
- 03/10/2014 - zimg 1.1.0 Release.
- 08/01/2013 - zimg 1.0.0 Release.
Expand Down Expand Up @@ -41,15 +43,14 @@ Process resized and grayed image by request parameter.
Use memcached to improve performance.
Multi-thread support for multi-core processor server.
Use lua for conf and other functions.
**Support beansdb/SSDB mode to save images into distributed storage backends.**
**Support beansdb/SSDB mode to save images into distributed storage backends.**
IP access control for uploading and downloading images.

### In Planning:
Performance optimization.
Security measures.

### Documentation:
A guide book of zimg:
[Guide Book of zimg](http://zimg.buaa.us/guidebook.html)
There is an architecture design document of zimg v1.0. It is written in Chinese.
[Architecture Design of zimg](http://zimg.buaa.us/arch_design.html)
And this document is to introduce zimg v2.0.
Expand All @@ -73,6 +74,10 @@ make
cd bin
./zimg conf/zimg.lua
````

More infomation of building zimg in guide book:
[Guide Book of zimg](http://zimg.buaa.us/guidebook.html)

### Config:

````
Expand All @@ -84,6 +89,14 @@ port=4869
thread_num=4
backlog_num=1024
max_keepalives=1
retry=3
system=io.popen("uname -s"):read("*l")
--access config
--support mask rules like "allow 10.1.121.138/24"
--note: remove rule can improve performance
download_rule="allow all"
upload_rule="allow 127.0.0.1;deny all"
--cache config
cache=1
Expand Down
6 changes: 6 additions & 0 deletions bin/conf/zimg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ max_keepalives=1
retry=3
system=io.popen("uname -s"):read("*l")

--access config
--support mask rules like "allow 10.1.121.138/24"
--NOTE: remove rule can improve performance
--download_rule="allow all;;deny all"
upload_rule="allow 127.0.0.1;deny all"

--cache config
cache=1
mc_ip='127.0.0.1'
Expand Down
20 changes: 19 additions & 1 deletion doc/zimg_guide_book.md → doc/guidebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ http://127.0.0.1:4869/1f08c55a7ca155565f638b5a61e99a3e?w=500&h=300

### 编译
zimg目前支持在Linux和Mac OS下运行,你需要安装一些依赖来保证它的编译和运行。
如果你使用Mac,以下所有依赖都可以通过brew来安装。
如果你使用Mac,以下所有依赖都可以通过brew来安装:

````
brew install openssl libevent cmake imagemagick libmemcached lua
git clone https://github.com/buaazp/zimg
cd zimg
make
````

如果你使用ubuntu,可以使用apt-get来安装所需的依赖:

````
Expand All @@ -27,6 +35,16 @@ git clone https://github.com/buaazp/zimg
cd zimg
make
````

如果你使用CentOS,可以使用yum来安装所需的依赖:

````
sudo yum install openssl libevent-devel cmake ImageMagick libmemcached-devel lua lua-devel
git clone https://github.com/buaazp/zimg
cd zimg
make
````

如果你使用其他的Linux发行版,请依次安装所需的依赖。

#### openssl(可选)
Expand Down
71 changes: 27 additions & 44 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ static void settings_init(void)
strcpy(settings.img_path, "./img");
strcpy(settings.log_name, "./log/zimg.log");
strcpy(settings.version, STR(ZIMG_VERSION));
sprintf(settings.server_name, "zimg/%s", settings.version);
snprintf(settings.server_name, 128, "zimg/%s", settings.version);
settings.port = 4869;
settings.backlog = 1024;
settings.num_threads = get_cpu_cores(); /* N workers */
settings.retry = 3;
settings.up_access = NULL;
settings.down_access = NULL;
settings.log = false;
settings.cache_on = false;
strcpy(settings.cache_ip, "127.0.0.1");
settings.cache_port = 11211;
settings.max_keepalives = 1;
settings.retry = 3;
settings.mode = 1;
strcpy(settings.ssdb_ip, "127.0.0.1");
settings.ssdb_port = 6379;
Expand Down Expand Up @@ -125,7 +127,21 @@ static int load_conf(const char *conf)

lua_getglobal(L, "system");
if(lua_isstring(L, -1))
sprintf(settings.server_name, "%s %s", settings.server_name, lua_tostring(L, -1));
snprintf(settings.server_name, 128, "%s %s", settings.server_name, lua_tostring(L, -1));
lua_pop(L, 1);

lua_getglobal(L, "upload_rule");
if(lua_isstring(L, -1))
{
settings.up_access = conf_get_rules(lua_tostring(L, -1));
}
lua_pop(L, 1);

lua_getglobal(L, "download_rule");
if(lua_isstring(L, -1))
{
settings.down_access = conf_get_rules(lua_tostring(L, -1));
}
lua_pop(L, 1);

lua_getglobal(L, "cache");
Expand Down Expand Up @@ -174,6 +190,7 @@ static int load_conf(const char *conf)
lua_getglobal(L, "img_path");
if(lua_isstring(L, -1))
strcpy(settings.img_path, lua_tostring(L, -1));
LOG_PRINT(LOG_INFO, "settings.img_path: %s", settings.img_path);
lua_pop(L, 1);

lua_getglobal(L, "log_name"); //stack index: -1
Expand Down Expand Up @@ -235,7 +252,7 @@ void init_thread(evhtp_t *htp, evthr_t *thread, void *arg)
if(settings.cache_on == true)
{
memcached_st *memc = memcached_create(NULL);
sprintf(mserver, "%s:%d", settings.cache_ip, settings.cache_port);
snprintf(mserver, 32, "%s:%d", settings.cache_ip, settings.cache_port);
memcached_server_st *servers = memcached_servers_parse(mserver);
memcached_server_push(memc, servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
Expand All @@ -250,7 +267,7 @@ void init_thread(evhtp_t *htp, evthr_t *thread, void *arg)
if(settings.mode == 2)
{
memcached_st *beans = memcached_create(NULL);
sprintf(mserver, "%s:%d", settings.beansdb_ip, settings.beansdb_port);
snprintf(mserver, 32, "%s:%d", settings.beansdb_ip, settings.beansdb_port);
memcached_server_st *servers = memcached_servers_parse(mserver);
servers = memcached_servers_parse(mserver);
memcached_server_push(beans, servers);
Expand Down Expand Up @@ -291,8 +308,6 @@ void init_thread(evhtp_t *htp, evthr_t *thread, void *arg)
int main(int argc, char **argv)
{
int i;
_init_path = getcwd(NULL, 0);
LOG_PRINT(LOG_DEBUG, "Get init-path: %s", _init_path);
retry_sleep.tv_sec = 0;
retry_sleep.tv_nsec = RETRY_TIME_WAIT; //1000 ns = 1 us

Expand Down Expand Up @@ -368,6 +383,7 @@ int main(int argc, char **argv)
if(mk_dir(log_path) != 1)
{
LOG_PRINT(LOG_DEBUG, "log_path[%s] Create Failed!", log_path);
fprintf(stderr, "log_path[%s] Create Failed!\n", log_path);
return -1;
}
}
Expand All @@ -379,53 +395,18 @@ int main(int argc, char **argv)
if(mk_dir(settings.img_path) != 1)
{
LOG_PRINT(LOG_DEBUG, "img_path[%s] Create Failed!", settings.img_path);
fprintf(stderr, "%s Create Failed!\n", settings.img_path);
return -1;
}
}
LOG_PRINT(LOG_DEBUG,"Paths Init Finished.");


//init memcached connection...
/*
if(settings.cache_on == true)
{
LOG_PRINT(LOG_DEBUG, "Begin to Test Memcached Connection...");
memcached_st *memc;
memc= memcached_create(NULL);
char mserver[32];
sprintf(mserver, "%s:%d", settings.cache_ip, settings.cache_port);
memcached_server_st *servers = memcached_servers_parse(mserver);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, 1);
LOG_PRINT(LOG_DEBUG, "Memcached Connection Init Finished.");
if(set_cache(memc, "zimg", "1") == -1)
{
LOG_PRINT(LOG_DEBUG, "Memcached[%s] Connect Failed!", mserver);
settings.cache_on = false;
}
else
{
LOG_PRINT(LOG_DEBUG, "memcached connection to: %s", mserver);
settings.cache_on = true;
}
memcached_free(memc);
}
else
LOG_PRINT(LOG_DEBUG, "Don't use memcached as cache.");
*/

if(settings.mode == 2)
{
LOG_PRINT(LOG_DEBUG, "Begin to Test Memcached Connection...");
memcached_st *beans = memcached_create(NULL);
char mserver[32];
sprintf(mserver, "%s:%d", settings.beansdb_ip, settings.beansdb_port);
snprintf(mserver, 32, "%s:%d", settings.beansdb_ip, settings.beansdb_port);
memcached_server_st *servers = memcached_servers_parse(mserver);
servers = memcached_servers_parse(mserver);
memcached_server_push(beans, servers);
Expand Down Expand Up @@ -488,6 +469,8 @@ int main(int argc, char **argv)
evhtp_free(htp);
event_base_free(evbase);
MagickWandTerminus();
free_access_conf(settings.up_access);
free_access_conf(settings.down_access);

fprintf(stdout, "\nByebye!\n");
return 0;
Expand Down
Loading

0 comments on commit 97059ec

Please sign in to comment.