1, 安装依赖包
确保服务器中已经安装了Memcached的依赖包。
<code>[root@localhost~]</code><code>#yum-y install </code>
<code>--skip-broken gcc gcc-c++autoconf automake zlib zlib-devel </code>
<code> </code><code>pcre-developenssl-devel libevent libevent-devel.x86_64</code>
2, 创建Memcached的安装用户
<code>[root@localhost~]</code><code># groupadd dfhapp</code>
<code>[root@localhost~]</code><code># useradd -d /home/dfhapp -g dfhappdfhapp</code>
<code>[root@localhost~]</code><code># passwd dfhapp</code>
<code>更改用户 nginx 的密码。</code>
<code>新的密码:</code>
<code>无效的密码:过于简单化/系统化</code>
<code>无效的密码:过于简单</code>
<code>重新输入新的密码:</code>
<code>passwd</code><code>:所有的身份验证令牌已经成功更新。</code>
3, 下载源码包
<code>#不可把源码包放在/root目录下</code>
<code>[root@localhost/]</code><code># mkdir -p /soft</code>
<code>[root@localhost/]</code><code># cd soft/</code>
<code>[root@localhostsoft]</code><code>#wget http://www.memcached.org/files/memcached-1.4.10.tar.gz</code>
<code>[root@localhostsoft]</code><code># ll</code>
<code>总用量 308</code>
<code>-rw-r--r--.1 root root 311926 5月 20 01:21 memcached-1.4.10.</code><code>tar</code><code>.gz</code>
<code>#解压</code>
<code>[root@localhostsoft]</code><code># tar -zxvf memcached-1.4.10.tar.gz </code>
<code>#赋权</code>
<code>[root@localhostsoft]</code><code># mkdir -p /usr/local/memcached</code>
<code>[root@localhostsoft]</code><code># chown -R dfhapp:dfhapp /usr/local/memcached</code>
<code>[root@localhostsoft]</code><code># chown -R dfhapp:dfhapp /soft/memcached-1.4.10</code>
4, 切换dfhapp用户进行安装
<code>#切换用户</code>
<code>[root@localhost~]</code><code># su dfhapp</code>
<code>#安装</code>
<code>[[email protected]]$ .</code><code>/configure</code> <code>--prefix=</code><code>/usr/local/memcached</code>
<code>[[email protected]]$ </code><code>make</code> <code>&& </code><code>make</code> <code>test</code>
<code>[[email protected]]$ </code><code>make</code> <code>install</code>
5, dfhapp用户启动Memcached
<code>[[email protected]]$ </code><code>cd</code> <code>/usr/local/memcached/</code>
<code>[dfhapp@localhostmemcached]$ ll</code>
<code>总用量 12</code>
<code>drwxr-xr-x.2 dfhapp dfhapp 4096 6月 15 22:58 bin</code>
<code>drwxr-xr-x.3 dfhapp dfhapp 4096 1月 6 09:30 include</code>
<code>drwxr-xr-x.3 dfhapp dfhapp 4096 1月 6 09:30 share</code>
<code>[dfhapp@localhostmemcached]$ </code><code>cd</code> <code>bin/</code>
<code>[dfhapp@localhostbin]$ ll</code>
<code>总用量 280</code>
<code>-rwxr-xr-x.1 dfhapp dfhapp 286459 6月 15 22:58 memcached</code>
<code>#启动</code>
<code>[dfhapp@localhostbin]$ .</code><code>/memcached</code> <code>-d -m 512 -p 11211 -c 256 -P </code><code>/var/run/memcached</code><code>.pid</code>
6, 测试Memcached是否安装成功
<code>[dfhapp@localhostbin]$ telnet 127.0.0.1 11211</code>
<code>Trying127.0.0.1...</code>
<code>Connectedto 127.0.0.1.</code>
<code>Escapecharacter is </code><code>'^]'</code><code>.</code>
<code> </code>
<code>ERROR</code>
<code>settest 8 8 8</code>
<code>12345678</code>
<code>STORED</code>
<code>stats</code>
<code>STATpid 8751</code>
<code>STATuptime 54</code>
<code>STATtime 1402844424</code>
<code>STATversion 1.4.10</code>
<code>STATlibevent 1.4.13-stable</code>
<code>STATpointer_size 64</code>
<code>STATrusage_user 0.000000</code>
<code>STATrusage_system 0.044993</code>
<code>STATcurr_connections 10</code>
<code>STATtotal_connections 11</code>
<code>STATconnection_structures 11</code>
<code>STATreserved_fds 20</code>
<code>STATcmd_get 1</code>
<code>STATcmd_set 1</code>
<code>STATcmd_flush 0</code>
<code>STATcmd_touch 0</code>
<code>STATget_hits 0</code>
<code>STATget_misses 1</code>
<code>STATdelete_misses 0</code>
<code>STATdelete_hits 0</code>
<code>STATincr_misses 0</code>
<code>STATincr_hits 0</code>
<code>STATdecr_misses 0</code>
<code>STATdecr_hits 0</code>
<code>STATcas_misses 0</code>
<code>STATcas_hits 0</code>
<code>STATcas_badval 0</code>
<code>STATtouch_hits 0</code>
<code>STATtouch_misses 0</code>
<code>STATauth_cmds 0</code>
<code>STATauth_errors 0</code>
<code>STATbytes_read 68</code>
<code>STATbytes_written 83</code>
<code>STATlimit_maxbytes 536870912</code>
<code>STATaccepting_conns 1</code>
<code>STATlisten_disabled_num 0</code>
<code>STATthreads 4</code>
<code>STATconn_yields 0</code>
<code>STAThash_power_level 16</code>
<code>STAThash_bytes 524288</code>
<code>STAThash_is_expanding 0</code>
<code>STATexpired_unfetched 0</code>
<code>STATevicted_unfetched 0</code>
<code>STATbytes 0</code>
<code>STATcurr_items 0</code>
<code>STATtotal_items 1</code>
<code>STATevictions 0</code>
<code>STATreclaimed 0</code>
<code>END</code>
7, 制作Memcached启动脚本
<code>[dfhapp@localhost root]$ </code><code>cd</code> <code>/home/dfhserver/</code>
<code>[dfhapp@localhost ~]$ vim memcached.sh </code>
<code>/usr/local/memcached/bin/memcached</code> <code>-d -m 512 -p11211 -c 256 -P </code><code>/var/run/memcached</code><code>.pid</code>
<code>[dfhapp@localhost ~]$ </code><code>chmod</code> <code>+x memcached.sh</code>
8, dfhapp开机启动Memcached
<code>[root@localhost~]</code><code># vim /etc/rc.d/rc.local</code>
<code>#!/bin/sh</code>
<code>#</code>
<code>#This script will be executed *after* all the other init scripts.</code>
<code>#You can put your own initialization stuff in here if you don't</code>
<code>#want to do the full Sys V style init stuff.</code>
<code>touch</code><code>/var/lock/subsys/local</code>
<code> </code>
<code>su</code> <code>– dfhapp -c </code><code>/home/dfhserver/memcached</code><code>.sh</code>
9, 测试是否成功
如果条件允许,最好重启服务器验证一下。
<code>[root@localhost~]</code><code># shutdown -r now</code>
重启后。
<code>[root@localhost~]</code><code># ps -ef |grep memcached</code>
<code>501 1832 1 017:27 ? 00:00:00</code><code>/usr/local/memcached/bin/memcached</code> <code>-d -m 512 -p 11211 -c 256 -P</code><code>/var/run/memcached</code><code>.pid</code>
<code>root 2522 2499 0 17:29 pts</code><code>/1</code> <code>00:00:00 </code><code>grep</code> <code>memcached</code>
<code>[root@localhost~]</code><code># cat /etc/passwd</code>
<code>root:x:0:0:root:</code><code>/root</code><code>:</code><code>/bin/bash</code>
<code>bin:x:1:1:bin:</code><code>/bin</code><code>:</code><code>/sbin/nologin</code>
<code>daemon:x:2:2:daemon:</code><code>/sbin</code><code>:</code><code>/sbin/nologin</code>
<code>adm:x:3:4:adm:</code><code>/var/adm</code><code>:</code><code>/sbin/nologin</code>
<code>lp:x:4:7:lp:</code><code>/var/spool/lpd</code><code>:</code><code>/sbin/nologin</code>
<code>sync</code><code>:x:5:0:</code><code>sync</code><code>:</code><code>/sbin</code><code>:</code><code>/bin/sync</code>
<code>shutdown</code><code>:x:6:0:</code><code>shutdown</code><code>:</code><code>/sbin</code><code>:</code><code>/sbin/shutdown</code>
<code>halt:x:7:0:halt:</code><code>/sbin</code><code>:</code><code>/sbin/halt</code>
<code>mail:x:8:12:mail:</code><code>/var/spool/mail</code><code>:</code><code>/sbin/nologin</code>
<code>uucp:x:10:14:uucp:</code><code>/var/spool/uucp</code><code>:</code><code>/sbin/nologin</code>
<code>operator:x:11:0:operator:</code><code>/root</code><code>:</code><code>/sbin/nologin</code>
<code>games:x:12:100:games:</code><code>/usr/games</code><code>:</code><code>/sbin/nologin</code>
<code>gopher:x:13:30:gopher:</code><code>/var/gopher</code><code>:</code><code>/sbin/nologin</code>
<code>ftp</code><code>:x:14:50:FTPUser:</code><code>/var/ftp</code><code>:</code><code>/sbin/nologin</code>
<code>nobody:x:99:99:Nobody:/:</code><code>/sbin/nologin</code>
<code>dbus:x:81:81:Systemmessage bus:/:</code><code>/sbin/nologin</code>
<code>usbmuxd:x:113:113:usbmuxduser:/:</code><code>/sbin/nologin</code>
<code>vcsa:x:69:69:virtualconsole memory owner:</code><code>/dev</code><code>:</code><code>/sbin/nologin</code>
<code>rpc:x:32:32:RpcbindDaemon:</code><code>/var/cache/rpcbind</code><code>:</code><code>/sbin/nologin</code>
<code>rtkit:x:499:497:RealtimeKit:</code><code>/proc</code><code>:</code><code>/sbin/nologin</code>
<code>avahi-autoipd:x:170:170:AvahiIPv4LL Stack:</code><code>/var/lib/avahi-autoipd</code><code>:</code><code>/sbin/nologin</code>
<code>abrt:x:173:173::</code><code>/etc/abrt</code><code>:</code><code>/sbin/nologin</code>
<code>rpcuser:x:29:29:RPCService User:</code><code>/var/lib/nfs</code><code>:</code><code>/sbin/nologin</code>
<code>nfsnobody:x:65534:65534:AnonymousNFS User:</code><code>/var/lib/nfs</code><code>:</code><code>/sbin/nologin</code>
<code>haldaemon:x:68:68:HALdaemon:/:</code><code>/sbin/nologin</code>
<code>gdm:x:42:42::</code><code>/var/lib/gdm</code><code>:</code><code>/sbin/nologin</code>
<code>ntp:x:38:38::</code><code>/etc/ntp</code><code>:</code><code>/sbin/nologin</code>
<code>apache:x:48:48:Apache:</code><code>/var/www</code><code>:</code><code>/sbin/nologin</code>
<code>saslauth:x:498:76:</code><code>"Saslauthduser"</code><code>:</code><code>/var/empty/saslauth</code><code>:</code><code>/sbin/nologin</code>
<code>postfix:x:89:89::</code><code>/var/spool/postfix</code><code>:</code><code>/sbin/nologin</code>
<code>pulse:x:497:496:PulseAudioSystem Daemon:</code><code>/var/run/pulse</code><code>:</code><code>/sbin/nologin</code>
<code>sshd:x:74:74:Privilege-separatedSSH:</code><code>/var/empty/sshd</code><code>:</code><code>/sbin/nologin</code>
<code>tcpdump:x:72:72::/:</code><code>/sbin/nologin</code>
<code>mzsx:x:500:500:mzsx:</code><code>/home/mzsx</code><code>:</code><code>/bin/bash</code>
<code>dfhapp:x:501:501::</code><code>/home/</code> <code>dfhapp:</code><code>/bin/bash</code>
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任
本文转自 梦朝思夕 51CTO博客,原文链接:http://blog.51cto.com/qiangmzsx/1413984