{"id":345,"date":"2011-04-20T02:50:40","date_gmt":"2011-04-19T17:50:40","guid":{"rendered":"http:\/\/blog.xcir.net\/?p=345"},"modified":"2011-07-21T00:30:47","modified_gmt":"2011-07-20T15:30:47","slug":"varnish%e3%81%ae%e3%82%a4%e3%83%b3%e3%83%a9%e3%82%a4%e3%83%b3c%e3%81%8b%e3%82%89%e5%85%b1%e6%9c%89%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa","status":"publish","type":"post","link":"http:\/\/blog.xcir.net\/?p=345","title":{"rendered":"varnish\u306e\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5(cc_command)"},"content":{"rendered":"<p>\u304a\u4e45\u3057\u3076\u308a\u3067\u3059\u3002<br \/>\n\u3055\u3059\u304c\u306b\u305f\u307e\u306b\u306f\u66f8\u304b\u306a\u3044\u3068\u5fd8\u308c\u53bb\u3089\u308c\u305d\u3046\u306a\u306e\u3067\u3061\u3087\u3063\u3068\u5c0f\u30cd\u30bf\u3067\u3082<\/p>\n<p>VCL\u4e2d\u306b\u30a4\u30f3\u30e9\u30a4\u30f3C\u3067\u597d\u304d\u306a\u51e6\u7406\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f<a href=\"http:\/\/blog.xcir.net\/index.php\/2010\/04\/varnish%E3%81%AEinline-c%E3%81%A7%E6%A9%9F%E8%83%BD%E6%8B%A1%E5%BC%B5%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\/\">\u4ee5\u524d\u8a18\u4e8b<\/a>\u3067\u3082\u53d6\u308a\u4e0a\u3052\u307e\u3057\u305f\u304c<br \/>\n\u4e16\u306e\u4e2d\u306b\u6ea2\u308c\u3066\u3044\u308b\u69d8\u3005\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u4eca\u56de\u306f\u4f8b\u3068\u3057\u3066libmemcached\u3092\u5229\u7528\u3057\u3066\u6700\u5f8c\u306b\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305fURL(req.url)\u3092memcache\u306b\u30b9\u30c8\u30a2\u3059\u308bVCL\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><!--more--><br \/>\n\u3055\u3066\u3057\u304b\u3057\u3001\u3069\u3046\u3084\u3063\u3066libmemcached\u3092\u547c\u3073\u51fa\u305b\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u3053\u3053\u3067\u4eca\u56de\u306e\u6700\u5927\u306e\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<br \/>\n<strong>cc_command<\/strong>\u3068\u3044\u3046\u8d77\u52d5\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5909\u66f4\u3057\u3066\u3042\u3052\u308b\u3068\u3001\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\ncc_command\u306fvarnish\u304cvcl\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066.so\u306b\u3059\u308b\u969b\u306b\u5229\u7528\u3059\u308b\u30b3\u30de\u30f3\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u306ecc_command\u306f<br \/>\n[code=&#8217;plain&#8217;]<br \/>\nexec cc -fpic -shared -Wl,-x -o %o %s<br \/>\n[\/code]<br \/>\n\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u611f\u306e\u826f\u3044\u65b9\u3067\u3042\u308c\u3070\u3001\u3053\u3053\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3044\u308d\u3044\u308d\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306b\u6c17\u3065\u304f\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u4eca\u56de\u306flibmemcached\u3092\u4f7f\u3046\u306e\u3067<br \/>\n[code=&#8217;plain&#8217;]<br \/>\nexec cc -fpic -shared -Wl,-x -lmemcached -o %o %s<br \/>\n[\/code]<br \/>\n\u3068\u6307\u5b9a\u3059\u308c\u3070libmemcached\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u8d77\u52d5\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u3059\u304c<br \/>\n\u79c1\u306e\u74b0\u5883\u306fCentOS\u306a\u306e\u3067<br \/>\n\/etc\/sysconfig\/varnish<br \/>\n\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<br \/>\n[code=&#8217;plain&#8217;]<br \/>\nDAEMON_OPTS=&#8221;-a :80 \\<br \/>\n             -T localhost:6082 \\<br \/>\n             -f \/etc\/varnish\/default.vcl \\<br \/>\n             -p &#8216;cc_command=exec cc -fpic -shared -Wl,-x -lmemcached -o %o %s&#8217; \\<br \/>\n             -u varnish -g varnish \\<br \/>\n             -s malloc,700M&#8221;<br \/>\n[\/code]<\/p>\n<p>VCL\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059<br \/>\n[code=&#8217;C&#8217;]<br \/>\nC{<br \/>\n#include <stdlib.h><br \/>\n#include <stdio.h><br \/>\n#include <libmemcached\/memcached.h>\n<p>void mctest(char *k ,char *v){<br \/>\n        struct memcached_st             *mmc            = NULL;<br \/>\n        struct memcached_server_st      *servers        = NULL;<br \/>\n        memcached_return                rc;<\/p>\n<p>        mmc     = memcached_create(NULL);<br \/>\n                servers = memcached_server_list_append(servers,<br \/>\n                                &#8220;localhost&#8221;, 11211, &amp;amp;amp; rc);<br \/>\n        rc      = memcached_server_push(mmc, servers);<br \/>\n        memcached_server_list_free(servers);<br \/>\n                rc      = memcached_set(mmc, k, strlen(k),<br \/>\n                        v, strlen(v), 600, 0);<\/p>\n<p>        memcached_free(mmc);<\/p>\n<p>}<\/p>\n<p>}C<br \/>\nbackend xcir{<br \/>\n        .host=&#8221;127.0.0.1&#8243;;<br \/>\n        .host_header=&#8221;xcir.net&#8221;;<br \/>\n        .port=&#8221;81&#8243;;<br \/>\n}<br \/>\nbackend imasu{<br \/>\n        .host=&#8221;127.0.0.1&#8243;;<br \/>\n        .host_header=&#8221;imasu.jp&#8221;;<br \/>\n        .port=&#8221;81&#8243;;<br \/>\n}<br \/>\nsub vcl_recv {<br \/>\n        C{<br \/>\n                char *value=(char*)VRT_r_req_url(sp);<br \/>\n                mctest(&#8220;log&#8221;,value);<br \/>\n                free(value);<br \/>\n        }C<\/p>\n<p>        if (req.http.host ~ &#8220;^xcir.net$&#8221;){set req.backend=xcir;}<br \/>\n        elseif (req.http.host ~ &#8220;^imasu.jp$&#8221;){set req.backend=imasu;}<br \/>\n        return (lookup);<br \/>\n}<br \/>\n[\/CODE]<br \/>\n\u65e9\u901f\u8d77\u52d5\u3057\u3066\u307f\u3066<br \/>\n\u9069\u5f53\u306b\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u898b\u3066\u307f\u308b\u3068memcache\u306b\u30b9\u30c8\u30a2\u3055\u308c\u3066\u3044\u308b\u304b\u898b\u3066\u307f\u307e\u3059\u3002<br \/>\n[code=&#8217;bash&#8217;]<br \/>\n[root@LIP-APP-01 ~]# telnet localhost 11211<br \/>\nTrying 127.0.0.1&#8230;<br \/>\nConnected to localhost.localdomain (127.0.0.1).<br \/>\nEscape character is &#8216;^]&#8217;.<\/p>\n<p>get log<br \/>\nVALUE log 0 92<br \/>\n\/index.php\/2011\/02\/qpstudy05%e8%a1%8c%e3%81%a3%e3%81%a6%e3%81%8d%e3%81%9f%e3%82%88%ef%bc%81\/<br \/>\nEND<br \/>\nget log<br \/>\nVALUE log 0 12<br \/>\n\/favicon.ico<br \/>\nEND<br \/>\nget log<br \/>\nVALUE log 0 12<br \/>\n\/favicon.ico<br \/>\nEND<br \/>\n[\/code]<br \/>\n\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0a\u3067\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3055\u3066\u4eca\u56de\u306f\u4f8b\u3068\u3057\u3066libmemcached\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u304c<br \/>\ncc_command\u306b\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u4ed6\u306e\u69d8\u3005\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u305c\u3072\u7686\u69d8\u3082\u30c1\u30e3\u30ec\u30f3\u30b8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u306a\u304a\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u969b\u306b\u3082\u304d\u3061\u3093\u3068cc_command\u3092\u6307\u5b9a\u3057\u3066\u3042\u3052\u306a\u3044\u3068undefined symbol\u304c\u51fa\u307e\u3059\u306e\u3067\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002<br \/>\n&#8212;<br \/>\n\u53c2\u8003\u30b5\u30a4\u30c8<br \/>\n<a href=\"http:\/\/kaworu.jpn.org\/kaworu\/2009-07-21-2.php\">C\u8a00\u8a9e libmemcached\u3092\u4f7f\u3046<\/a><br \/>\n<a href=\"http:\/\/blogs.yahoo.co.jp\/malmrashede\/60444105.html\">CentOS\u3067libmemcached\u3092\u4f7f\u3046<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u304a\u4e45\u3057\u3076\u308a\u3067\u3059\u3002 \u3055\u3059\u304c\u306b\u305f\u307e\u306b\u306f\u66f8\u304b\u306a\u3044\u3068\u5fd8\u308c\u53bb\u3089\u308c\u305d\u3046\u306a\u306e\u3067\u3061\u3087\u3063\u3068\u5c0f\u30cd\u30bf\u3067\u3082 VCL\u4e2d\u306b\u30a4\u30f3\u30e9\u30a4\u30f3C\u3067\u597d\u304d\u306a\u51e6\u7406\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f\u4ee5\u524d\u8a18\u4e8b\u3067\u3082\u53d6\u308a\u4e0a\u3052\u307e\u3057\u305f\u304c \u4e16\u306e\u4e2d\u306b\u6ea2\u308c\u3066\u3044\u308b\u69d8\u3005\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3069 <a href='http:\/\/blog.xcir.net\/?p=345' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5,16,25],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-3","tag-varnish","tag-vcl","tag-c","category-3-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":11,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":505,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/505"}],"wp:attachment":[{"href":"http:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}