{"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":"https:\/\/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<\/p>\n<pre class=\"brush: plain; \">\n\r\nexec cc -fpic -shared -Wl,-x -o %o %s\r\n\n<\/pre>\n<p>\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<\/p>\n<pre class=\"brush: plain; \">\n\r\nexec cc -fpic -shared -Wl,-x -lmemcached -o %o %s\r\n\n<\/pre>\n<p>\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<\/p>\n<pre class=\"brush: plain; \">\n\r\nDAEMON_OPTS=&quot;-a :80 \\\r\n             -T localhost:6082 \\\r\n             -f \/etc\/varnish\/default.vcl \\\r\n             -p &#039;cc_command=exec cc -fpic -shared -Wl,-x -lmemcached -o %o %s&#039; \\\r\n             -u varnish -g varnish \\\r\n             -s malloc,700M&quot;\r\n\n<\/pre>\n<p>VCL\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059<\/p>\n<pre class=\"brush: c; \">\n\r\nC{\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;stdio.h&gt;\r\n#include &lt;libmemcached\/memcached.h&gt;\r\n\r\nvoid mctest(char *k ,char *v){\r\n        struct memcached_st             *mmc            = NULL;\r\n        struct memcached_server_st      *servers        = NULL;\r\n        memcached_return                rc;\r\n\r\n        mmc     = memcached_create(NULL);\r\n                servers = memcached_server_list_append(servers,\r\n                                &quot;localhost&quot;, 11211, &amp;amp;amp;amp; rc);\r\n        rc      = memcached_server_push(mmc, servers);\r\n        memcached_server_list_free(servers);\r\n                rc      = memcached_set(mmc, k, strlen(k),\r\n                        v, strlen(v), 600, 0);\r\n\r\n        memcached_free(mmc);\r\n\r\n}\r\n\r\n}C\r\nbackend xcir{\r\n        .host=&quot;127.0.0.1&quot;;\r\n        .host_header=&quot;xcir.net&quot;;\r\n        .port=&quot;81&quot;;\r\n}\r\nbackend imasu{\r\n        .host=&quot;127.0.0.1&quot;;\r\n        .host_header=&quot;imasu.jp&quot;;\r\n        .port=&quot;81&quot;;\r\n}\r\nsub vcl_recv {\r\n        C{\r\n                char *value=(char*)VRT_r_req_url(sp);\r\n                mctest(&quot;log&quot;,value);\r\n                free(value);\r\n        }C\r\n\r\n        if (req.http.host ~ &quot;^xcir.net$&quot;){set req.backend=xcir;}\r\n        elseif (req.http.host ~ &quot;^imasu.jp$&quot;){set req.backend=imasu;}\r\n        return (lookup);\r\n}\r\n\n<\/pre>\n<p>\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<\/p>\n<pre class=\"brush: bash; \">\n\r\n[root@LIP-APP-01 ~]# telnet localhost 11211\r\nTrying 127.0.0.1...\r\nConnected to localhost.localdomain (127.0.0.1).\r\nEscape character is &#039;^]&#039;.\r\n\r\nget log\r\nVALUE log 0 92\r\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\/\r\nEND\r\nget log\r\nVALUE log 0 12\r\n\/favicon.ico\r\nEND\r\nget log\r\nVALUE log 0 12\r\n\/favicon.ico\r\nEND\r\n\n<\/pre>\n<p>\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<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D345&title=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%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95%28cc_command%29' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_hatena_users\"><a href='\/\/b.hatena.ne.jp\/entry\/https:\/\/blog.xcir.net\/?p=345' title='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - varnish\u306e\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5(cc_command)' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='\/\/b.hatena.ne.jp\/entry\/image\/https:\/\/blog.xcir.net\/?p=345' alt='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - varnish\u306e\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5(cc_command)' title='\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af - varnish\u306e\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5(cc_command)'   class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D345&t=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%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95%28cc_command%29' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_linkedin\"><a href='\/\/www.linkedin.com\/shareArticle?mini=true&url=https%3A%2F%2Fblog.xcir.net%2F%3Fp%3D345&title=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%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95%28cc_command%29' title='LinkedIn \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/blog.xcir.net\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/linkedin.png' alt='LinkedIn \u306b\u30b7\u30a7\u30a2' title='LinkedIn \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/blog.xcir.net\/?p=345\" data-text=\"varnish\u306e\u30a4\u30f3\u30e9\u30a4\u30f3C\u304b\u3089\u5171\u6709\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u65b9\u6cd5(cc_command)\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\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='https:\/\/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":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":11,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":505,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/505"}],"wp:attachment":[{"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xcir.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}