{"id":215,"date":"2016-10-26T16:19:28","date_gmt":"2016-10-26T07:19:28","guid":{"rendered":"http:\/\/jook.pe.kr\/?p=215"},"modified":"2016-10-26T16:19:28","modified_gmt":"2016-10-26T07:19:28","slug":"memcached-%ec%84%9c%eb%b2%84-%ea%b5%ac%ec%84%b1","status":"publish","type":"post","link":"http:\/\/jook.pe.kr\/?p=215","title":{"rendered":"Memcached \uc11c\ubc84 \uad6c\uc131"},"content":{"rendered":"<p><strong>memcached \uc11c\ubc84\uad6c\uc131<\/strong><\/p>\n<p><a href=\"http:\/\/memcached.org\/\">http:\/\/memcached.org\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\ud544\uc694 \ud328\ud0a4\uc9c0 \uc124\uce58<br \/>\n[root@localhost ~]# yum install libevent-devel<\/p>\n<p>[root@localhost ~]# tar -zxvf memcached-1.x.x.tar.gz<\/p>\n<p>[root@localhost ~]# cd memcached-1.x.x<br \/>\n[root@localhost ~]# .\/configure &#8211;with-libevent=\/usr\/lib64\/<br \/>\n[root@localhost ~]# make &amp;&amp; make test &amp;&amp; make install<br \/>\n[root@localhost ~]# vi \/etc\/memcached.conf<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# run as a daemon<br \/>\n-d<br \/>\n# user to run daemon nobody\/apache\/www-data<br \/>\n-u nobody<br \/>\n#Memory a usar<br \/>\n-m 512<br \/>\n# default port<br \/>\n-p 11211<br \/>\n#max simultaneous connections<br \/>\n-c 9216<\/p>\n<p># only listen locally<br \/>\n#-l 127.0.0.1<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\uc2e4\ud589\uc2a4\ud06c\ub9bd\ud2b8 \ubc0f \ub370\ubaac\uc2a4\ud06c\ub9bd\ud2b8<\/p>\n<p>[root@localhost ~]# touch \/etc\/init.d\/memcached<br \/>\n[root@localhost ~]# chmod +x \/etc\/init.d\/memcached<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#!\/bin\/bash<br \/>\n#<br \/>\n# memcached\u00a0\u00a0\u00a0 This shell script takes care of starting and stopping<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 standalone memcached.<br \/>\n#<br \/>\n# chkconfig: &#8211; 80 12<br \/>\n# description: memcached is a high-performance, distributed memory<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 object caching system, generic in nature, but<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 intended for use in speeding up dynamic web<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 applications by alleviating database load.<br \/>\n# processname: memcached<br \/>\n# config: \/etc\/memcached.conf<br \/>\n# Source function library.<br \/>\n. \/etc\/rc.d\/init.d\/functions<br \/>\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin<br \/>\nDAEMON=\/usr\/local\/bin\/memcached<br \/>\nDAEMONBOOTSTRAP=\/usr\/local\/bin\/start-memcached<br \/>\nDAEMONCONF=\/etc\/memcached.conf<br \/>\nNAME=memcached<br \/>\nDESC=memcached<br \/>\nPIDFILE=\/var\/run\/$NAME.pid<br \/>\n[ -x $DAEMON ] || exit 0<br \/>\n[ -x $DAEMONBOOTSTRAP ] || exit 0<br \/>\nRETVAL=0<br \/>\nstart() {<br \/>\necho -n $&#8221;Starting $DESC: &#8221;<br \/>\ndaemon $DAEMONBOOTSTRAP $DAEMONCONF<br \/>\nRETVAL=$?<br \/>\n[ $RETVAL -eq 0 ] &amp;&amp; touch $PIDFILE<br \/>\necho<br \/>\nreturn $RETVAL<br \/>\n}<br \/>\nstop() {<br \/>\necho -n $&#8221;Shutting down $DESC: &#8221;<br \/>\nkillproc $NAME<br \/>\nRETVAL=$?<br \/>\necho<br \/>\n[ $RETVAL -eq 0 ] &amp;&amp; rm -f $PIDFILE<br \/>\nreturn $RETVAL<br \/>\n}<\/p>\n<p># See how we were called.<br \/>\ncase &#8220;$1&#8243; in<br \/>\nstart)<br \/>\nstart<br \/>\n;;<br \/>\nstop)<br \/>\nstop<br \/>\n;;<br \/>\nrestart|reload)<br \/>\nstop<br \/>\nstart<br \/>\nRETVAL=$?<br \/>\n;;<br \/>\nstatus)<br \/>\nstatus $prog<br \/>\nRETVAL=$?<br \/>\n;;<br \/>\n*)<br \/>\necho $&#8221;Usage: $0 {start|stop|restart|status}&#8221;<br \/>\nexit 1<br \/>\nesac<br \/>\nexit $RETVAL<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>&nbsp;<\/p>\n<p>[root@localhost ~]# touch \/usr\/local\/bin\/start-memcached<br \/>\n[root@localhost ~]# chmod +x\u00a0 \/usr\/local\/bin\/start-memcached<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#!\/usr\/bin\/perl -w<br \/>\n# start-memcached<br \/>\n# 2003\/2004 &#8211; Jay Bonci &lt;<a href=\"mailto:jaybonci@debian.org\">jaybonci@debian.org<\/a>&gt;<br \/>\n# This script handles the parsing of the \/etc\/memcached.conf file<br \/>\n# and was originally created for the Debian distribution.<br \/>\n# Anyone may use this little script under the same terms as<br \/>\n# memcached itself.<br \/>\nuse strict;<br \/>\nif ($&gt; != 0 and $&lt; != 0) {<br \/>\nprint STDERR &#8220;Only root wants to run start-memcached.\\n&#8221;;<br \/>\nexit;<br \/>\n}<br \/>\nmy $etcfile = shift || &#8220;\/etc\/memcached.conf&#8221;;<br \/>\nmy $params = [];<br \/>\nmy $etchandle;<br \/>\n# This script assumes that memcached is located at \/usr\/bin\/memcached, and<br \/>\n# that the pidfile is writable at \/var\/run\/memcached.pid<br \/>\nmy $memcached = &#8220;\/usr\/local\/bin\/memcached&#8221;;<br \/>\nmy $pidfile = &#8220;\/var\/run\/memcached.pid&#8221;;<br \/>\n# If we don&#8217;t get a valid logfile parameter in the \/etc\/memcached.conf file,<br \/>\n# we&#8217;ll just throw away all of our in-daemon output. We need to re-tie it so<br \/>\n# that non-bash shells will not hang on logout. Thanks to Michael Renner for<br \/>\n# the tip<br \/>\nmy $fd_reopened = &#8220;\/dev\/null&#8221;;<br \/>\nsub handle_logfile {<br \/>\nmy ($logfile) = @_;<br \/>\n$fd_reopened = $logfile;<br \/>\n}<br \/>\nsub reopen_logfile {<br \/>\nmy ($logfile) = @_;<br \/>\nopen *STDERR, &#8220;&gt;&gt;$logfile&#8221;;<br \/>\nopen *STDOUT, &#8220;&gt;&gt;$logfile&#8221;;<br \/>\nopen *STDIN, &#8220;&gt;&gt;\/dev\/null&#8221;;<br \/>\n$fd_reopened = $logfile;<br \/>\n}<br \/>\n# This is set up in place here to support other non -[a-z] directives<br \/>\nmy $conf_directives = {<br \/>\n&#8220;logfile&#8221; =&gt; \\&amp;handle_logfile<br \/>\n};<br \/>\nif (open $etchandle, $etcfile) {<br \/>\nforeach my $line (&lt;$etchandle&gt;) {<br \/>\n$line =~ s\/\\#.*\/\/go;<br \/>\n$line = join &#8216; &#8216;, split &#8216; &#8216;, $line;<br \/>\nnext unless $line;<br \/>\nnext if $line =~ \/^\\-[dh]\/o;<br \/>\nif ($line =~ \/^[^\\-]\/o) {<br \/>\nmy ($directive, $arg) = $line =~ \/^(.*?)\\s+(.*)\/;<br \/>\n$conf_directives-&gt;{$directive}-&gt;($arg);<br \/>\nnext;<br \/>\n}<br \/>\npush @$params, $line;<br \/>\n}<br \/>\n}<br \/>\nunshift @$params, &#8220;-u root&#8221; unless (grep $_ eq &#8216;-u&#8217;, @$params);<br \/>\n$params = join &#8221; &#8220;, @$params;<br \/>\nif (-e $pidfile) {<br \/>\nopen PIDHANDLE, &#8220;$pidfile&#8221;;<br \/>\nmy $localpid = &lt;PIDHANDLE&gt;;<br \/>\nclose PIDHANDLE;<br \/>\nchomp $localpid;<br \/>\nif (-d &#8220;\/proc\/$localpid&#8221;) {<br \/>\nprint STDERR &#8220;memcached is already running.\\n&#8221;;<br \/>\nexit;<br \/>\n} else {<br \/>\n`rm -f $localpid`;<br \/>\n}<br \/>\n}<br \/>\nmy $pid = fork();<br \/>\nif ($pid == 0) {<br \/>\nreopen_logfile($fd_reopened);<br \/>\nexec &#8220;$memcached $params&#8221;;<br \/>\nexit(0);<br \/>\n} elsif (open PIDHANDLE,&#8221;&gt;$pidfile&#8221;) {<br \/>\nprint PIDHANDLE $pid;<br \/>\nclose PIDHANDLE;<br \/>\n} else {<br \/>\nprint STDERR &#8220;Can&#8217;t write pidfile to $pidfile.\\n&#8221;;<br \/>\n}<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p># \/etc\/init.d\/memcached restart<\/p>\n<p>Shutting down memcached:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [\u00a0 OK\u00a0 ]<br \/>\nStarting memcached:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [\u00a0 OK\u00a0 ]<\/p>\n<p>\ub370\ubaac \ud655\uc778<br \/>\n[root@localhost ~]# ps ax | grep memcach<br \/>\n14688 pts\/0\u00a0\u00a0\u00a0 Sl\u00a0\u00a0\u00a0\u00a0 0:00 \/usr\/local\/bin\/memcached -u root -u nobody -m 512 -p 11211 -c 9216<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>client (web\uc11c\ubc84)<\/p>\n<p>memcache \ubaa8\ub4c8 \uc124\uce58<\/p>\n<p># wget <a href=\"http:\/\/pecl.php.net\/get\/memcache-2.2.4.tgz\">http:\/\/pecl.php.net\/get\/memcache-2.2.4.tgz<\/a><br \/>\n# tar xzfv memcache-2.2.4.tgz<br \/>\n# cd memcache-2.2.4<br \/>\n# phpize<br \/>\n# .\/configure &#8211;enable-memcache<br \/>\n# make<br \/>\n# make install<br \/>\n# vi \/usr\/local\/apache\/conf\/php.ini<\/p>\n<p>extension_dir = &#8220;\/usr\/local\/lib\/php\/extensions\/no-debug-non-zts-20060613\/&#8221;<br \/>\nextension=memcache.so<\/p>\n<p>[Session]<br \/>\n; Handler used to store\/retrieve data.<br \/>\n;session.save_handler = files<br \/>\nsession.save_handler = memcache<br \/>\nsession.save_path = &#8220;tcp:\/\/192.168.0.101:11211&#8221;\u00a0\u00a0 &lt;&#8212; memcached \uc11c\ubc84 IP<\/p>\n<p>&nbsp;<\/p>\n<p>\uc800\uc7a5 \ud6c4 apache\u00a0restart<\/p>\n","protected":false},"excerpt":{"rendered":"<p>memcached \uc11c\ubc84\uad6c\uc131 http:\/\/memcached.org\/ &nbsp; \ud544\uc694 \ud328\ud0a4\uc9c0 \uc124\uce58 [root@localhost ~]# yum install libevent-devel [root@localhost ~]# tar -zxvf memcached-1.x.x.tar.gz [root@localhost ~]# cd<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7],"tags":[],"_links":{"self":[{"href":"http:\/\/jook.pe.kr\/index.php?rest_route=\/wp\/v2\/posts\/215"}],"collection":[{"href":"http:\/\/jook.pe.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jook.pe.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jook.pe.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jook.pe.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215"}],"version-history":[{"count":0,"href":"http:\/\/jook.pe.kr\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"wp:attachment":[{"href":"http:\/\/jook.pe.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jook.pe.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jook.pe.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}