{"id":1725,"date":"2017-01-31T05:05:45","date_gmt":"2017-01-30T21:05:45","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=1725"},"modified":"2017-01-31T05:05:45","modified_gmt":"2017-01-30T21:05:45","slug":"centos-7-x%e5%ae%89%e8%a3%85%e9%83%a8%e7%bd%b2memcached%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/centos-7-x%e5%ae%89%e8%a3%85%e9%83%a8%e7%bd%b2memcached%e6%9c%8d%e5%8a%a1%e5%99%a8\/","title":{"rendered":"CentOS 7.x\u5b89\u88c5\u90e8\u7f72Memcached\u670d\u52a1\u5668"},"content":{"rendered":"<p><strong>\u4e00\u3001\u9632\u706b\u5899\u8bbe\u7f6e<\/strong><\/p>\n<p>CentOS 7.x\u9ed8\u8ba4\u4f7f\u7528\u7684\u662ffirewall\u4f5c\u4e3a\u9632\u706b\u5899\uff0c\u8fd9\u91cc\u6539\u4e3aiptables\u9632\u706b\u5899\u3002<\/p>\n<p>1\u3001\u5173\u95edfirewall\uff1a<\/p>\n<p>systemctl stop firewalld.service\u00a0#\u505c\u6b62firewall<\/p>\n<p>systemctl disable firewalld.service\u00a0#\u7981\u6b62firewall\u5f00\u673a\u542f\u52a8<\/p>\n<p>2\u3001\u5b89\u88c5iptables\u9632\u706b\u5899<\/p>\n<p>yum install iptables-services\u00a0#\u5b89\u88c5<\/p>\n<p>vi \/etc\/sysconfig\/iptables\u00a0#\u7f16\u8f91\u9632\u706b\u5899\u914d\u7f6e\u6587\u4ef6<\/p>\n<p># sample configuration for iptables service<\/p>\n<p># you can edit this manually or use system-config-firewall<\/p>\n<p># please do not ask us to add additional ports\/services to this default configuration<\/p>\n<p>*filter<\/p>\n<p>:INPUT ACCEPT [0:0]<\/p>\n<p>:FORWARD ACCEPT [0:0]<\/p>\n<p>:OUTPUT ACCEPT [0:0]<\/p>\n<p>-A INPUT -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<\/p>\n<p>-A INPUT -p icmp -j ACCEPT<\/p>\n<p>-A INPUT -i lo -j ACCEPT<\/p>\n<p>-A INPUT -p tcp -m state &#8211;state NEW -m tcp &#8211;dport 22 -j ACCEPT<\/p>\n<p>-A INPUT -p tcp -m state &#8211;state NEW -m tcp &#8211;dport 11211 -j ACCEPT<\/p>\n<p>-A INPUT -j REJECT &#8211;reject-with icmp-host-prohibited<\/p>\n<p>-A FORWARD -j REJECT &#8211;reject-with icmp-host-prohibited<\/p>\n<p>COMMIT<\/p>\n<p>:wq!\u00a0#\u4fdd\u5b58\u9000\u51fa<\/p>\n<p>systemctl restart iptables.service\u00a0#\u6700\u540e\u91cd\u542f\u9632\u706b\u5899\u4f7f\u914d\u7f6e\u751f\u6548<\/p>\n<p>systemctl enable iptables.service\u00a0#\u8bbe\u7f6e\u9632\u706b\u5899\u5f00\u673a\u542f\u52a8<\/p>\n<p>\/usr\/libexec\/iptables\/iptables.init restart\u00a0#\u91cd\u542f\u9632\u706b\u5899<\/p>\n<p><strong>\u4e8c\u3001\u5173\u95edSELINUX<\/strong><\/p>\n<p>vi \/etc\/selinux\/config<\/p>\n<p>#SELINUX=enforcing\u00a0#\u6ce8\u91ca\u6389<\/p>\n<p>#SELINUXTYPE=targeted\u00a0#\u6ce8\u91ca\u6389<\/p>\n<p>SELINUX=disabled\u00a0#\u589e\u52a0<\/p>\n<p>:wq!\u00a0#\u4fdd\u5b58\u9000\u51fa<\/p>\n<p>setenforce 0\u00a0#\u4f7f\u914d\u7f6e\u7acb\u5373\u751f\u6548<\/p>\n<p><strong>\u4e09 \u3001\u7cfb\u7edf\u7ea6\u5b9a<\/strong><\/p>\n<p>\u8f6f\u4ef6\u6e90\u4ee3\u7801\u5305\u5b58\u653e\u4f4d\u7f6e\uff1a\/usr\/local\/src<\/p>\n<p>\u6e90\u7801\u5305\u7f16\u8bd1\u5b89\u88c5\u4f4d\u7f6e\uff1a\/usr\/local\/\u8f6f\u4ef6\u540d\u5b57<\/p>\n<p><strong>\u56db\u3001\u4e0b\u8f7d\u8f6f\u4ef6\u5305<\/strong><\/p>\n<p>1\u3001\u4e0b\u8f7dlibevent<\/p>\n<p><a href=\"https:\/\/ftp.lfs-matrix.net\/pub\/blfs\/conglomeration\/libevent\/libevent-2.0.22-stable.tar.gz\" target=\"_blank\">https:\/\/ftp.lfs-matrix.net\/pub\/blfs\/conglomeration\/libevent\/libevent-2.0.22-stable.tar.gz<\/a><\/p>\n<p>2\u3001\u4e0b\u8f7dmemcached<\/p>\n<p><a href=\"https:\/\/memcached.org\/files\/memcached-1.4.34.tar.gz\" target=\"_blank\">https:\/\/memcached.org\/files\/memcached-1.4.34.tar.gz<\/a><\/p>\n<p><strong>\u4e94\u3001\u5b89\u88c5\u7f16\u8bd1\u5de5\u5177\u5305<\/strong><\/p>\n<p>yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm*\u00a0libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel<\/p>\n<p><strong>\u516d\u3001\u5b89\u88c5\u914d\u7f6ememcached<\/strong><\/p>\n<p>1\u3001\u5b89\u88c5libevent<\/p>\n<p>cd \/usr\/local\/src<\/p>\n<p>tar zxvf libevent-2.0.22-stable.tar.gz<\/p>\n<p>cd libevent-2.0.22-stable<\/p>\n<p>.\/configure &#8211;prefix=\/usr\/local\/libevent<\/p>\n<p>make<\/p>\n<p>make install<\/p>\n<p>2\u3001\u5b89\u88c5memcached<\/p>\n<p>cd \/usr\/local\/src<\/p>\n<p>tar zxvf memcached-1.4.34.tar.gz<\/p>\n<p>cd memcached-1.4.34<\/p>\n<p>.\/configure &#8211;enable-sasl\u00a0&#8211;prefix=\/usr\/local\/memcached -with-libevent=\/usr\/local\/libevent<\/p>\n<p>make<\/p>\n<p>make install<\/p>\n<p>3\u3001\u6d4b\u8bd5Memcached<\/p>\n<p>groupadd memcached\u00a0#\u521b\u5efa\u7ec4<\/p>\n<p>useradd -g memcached memcached -s \/bin\/false\u00a0#\u521b\u5efa\u8d26\u53f7<\/p>\n<p>ln -s \/usr\/local\/memcached\/bin\/memcached \u00a0 \/usr\/local\/bin\/memcached \u00a0#\u6dfb\u52a0\u8f6f\u8fde\u63a5<\/p>\n<p>\u542f\u52a8Memcache\u7684\u670d\u52a1\u5668\u7aef\u7684\u547d\u4ee4\u4e3a\uff1a<\/p>\n<p>\/usr\/local\/memcached\/bin\/memcached -d -m 4096 -u root -l 192.168.4.6 -p 11211 -c 1024 -P \/usr\/local\/memcached\/memcached.pid<\/p>\n<p>\u6216\u8005<\/p>\n<p>\/usr\/local\/memcached\/bin\/memcached -d -m 4096 -u memcached -l 192.168.4.6 -p 11211 -c 1024<\/p>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<p>-d\u9009\u9879\u662f\u542f\u52a8\u4e00\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff0c<\/p>\n<p>-m\u662f\u5206\u914d\u7ed9Memcache\u4f7f\u7528\u7684\u5185\u5b58\u6570\u91cf\uff0c\u5355\u4f4d\u662fMB\uff0c\u8fd9\u91cc\u662f4096MB<\/p>\n<p>-u\u662f\u8fd0\u884cMemcache\u7684\u7528\u6237\uff0c\u6bd4\u5982root\u6216\u8005memcached<\/p>\n<p>-l\u662f\u76d1\u542c\u7684\u670d\u52a1\u5668IP\u5730\u5740\uff0c\u8fd9\u91cc\u6307\u5b9a\u670d\u52a1\u5668\u7684IP\u5730\u5740192.168.4.6\uff0c\u4e0d\u8bbe\u7f6e\u9ed8\u8ba4\u76d1\u542c\u670d\u52a1\u5668\u6240\u6709IP\u5730\u5740<\/p>\n<p>-p\u662f\u8bbe\u7f6eMemcache\u76d1\u542c\u7684\u7aef\u53e3\uff0c\u9ed8\u8ba4\u4e3a11211<\/p>\n<p>-c\u9009\u9879\u662f\u6700\u5927\u8fd0\u884c\u7684\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u662f1024<\/p>\n<p>-P\u662f\u8bbe\u7f6e\u4fdd\u5b58Memcache\u7684pid\u6587\u4ef6\uff0c\/usr\/local\/memcached\/memcached.pid<\/p>\n<p>\u5f00\u673a\u81ea\u542f\u52a8\uff0c\u5728\/etc\/rc.d\/rc.local\u4e2d\u52a0\u5165\u4e00\u884c<\/p>\n<p>\/usr\/local\/memcached\/bin\/memcached -d -m 4096 -u root -l 192.168.4.6 -p 11211 -c 1024 -P \/usr\/local\/memcached\/memcached.pid<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<p>\/usr\/local\/memcached\/bin\/memcached -d -m 4096 -p 11211 -u memcached<\/p>\n<p>ip\u4e0d\u6307\u5b9a\u65f6\uff0c\u9ed8\u8ba4\u76d1\u542c\u672c\u5730\u6240\u6709ip\u5730\u5740\uff0c\u7528\u6237\u6700\u597d\u9009\u62e9\u662f\u975eroot\u7528\u6237\uff0c\u4f8b\u5982memcached<\/p>\n<p>\u5173\u95edMemcached\u670d\u52a1<\/p>\n<p>cat \/usr\/local\/memcached\/memcached.pid \u00a0#\u67e5\u770b\u8fdb\u7a0b<\/p>\n<p>kill 22856\u00a0#\u7ed3\u675f\u8fdb\u7a0b<\/p>\n<p>\u6216\u8005<\/p>\n<p>killall memcached \u00a0#\u7ed3\u675f\u670d\u52a1<\/p>\n<p>\u7cfb\u7edf\u8fd0\u7ef4 www.osyunwei.com \u6e29\u99a8\u63d0\u9192\uff1aqihang01\u539f\u521b\u5185\u5bb9\u00a9\u7248\u6743\u6240\u6709,\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u53ca\u539f\u6587\u94fe\u63a5<\/p>\n<p>4\u3001\u8bbe\u7f6eMemcached\u5f00\u673a\u542f\u52a8<\/p>\n<p>vi \/etc\/rc.d\/init.d\/memcached<\/p>\n<p>#!\/bin\/sh<\/p>\n<p>#<\/p>\n<p># memcached: MemCached Daemon<\/p>\n<p>#<\/p>\n<p># chkconfig: &#8211; 90 25<\/p>\n<p># description: MemCached Daemon<\/p>\n<p>#<\/p>\n<p># Source function library.<\/p>\n<p>. \/etc\/rc.d\/init.d\/functions<\/p>\n<p>. \/etc\/sysconfig\/network<\/p>\n<p>MEMCACHED=&#8221;\/usr\/local\/memcached\/bin\/memcached&#8221;<\/p>\n<p>start()<\/p>\n<p>{<\/p>\n<p>echo -n $&#8221;Starting memcached: &#8221;<\/p>\n<p>daemon $MEMCACHED -u memcached -d -m 4096 -p 11211\u00a0-c 1024<\/p>\n<p>echo<\/p>\n<p>}<\/p>\n<p>stop()<\/p>\n<p>{<\/p>\n<p>echo -n $&#8221;Shutting down memcached: &#8221;<\/p>\n<p>killproc memcached<\/p>\n<p>echo<\/p>\n<p>}<\/p>\n<p>[ -f $MEMCACHED ] || exit 0<\/p>\n<p># See how we were called.<\/p>\n<p>case &#8220;$1&#8243; in<\/p>\n<p>start)<\/p>\n<p>start<\/p>\n<p>;;<\/p>\n<p>stop)<\/p>\n<p>stop<\/p>\n<p>;;<\/p>\n<p>restart|reload)<\/p>\n<p>stop<\/p>\n<p>start<\/p>\n<p>;;<\/p>\n<p>condrestart)<\/p>\n<p>stop<\/p>\n<p>start<\/p>\n<p>;;<\/p>\n<p>*)<\/p>\n<p>echo $&#8221;Usage: $0 {start|stop|restart|reload|condrestart}&#8221;<\/p>\n<p>exit 1<\/p>\n<p>esac<\/p>\n<p>exit 0<\/p>\n<p>:wq!\u00a0#\u4fdd\u5b58\u9000\u51fa<\/p>\n<p>chmod 775 \/etc\/rc.d\/init.d\/memcached\u00a0#\u8d4b\u4e88\u6587\u4ef6\u6267\u884c\u6743\u9650<\/p>\n<p>chkconfig memcached on\u00a0#\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8<\/p>\n<p>\/etc\/rc.d\/init.d\/memcached start\u00a0#\u542f\u52a8<\/p>\n<p><strong>\u81f3\u6b64\uff0cLinux\u4e0bMemcached\u670d\u52a1\u5668\u90e8\u7f72\u5b8c\u6210\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u9632\u706b\u5899\u8bbe\u7f6e CentOS 7.x\u9ed8\u8ba4\u4f7f\u7528\u7684\u662ffirewall\u4f5c\u4e3a\u9632\u706b\u5899\uff0c\u8fd9\u91cc\u6539\u4e3aiptables\u9632\u706b\u5899\u3002  &#8230; <a title=\"CentOS 7.x\u5b89\u88c5\u90e8\u7f72Memcached\u670d\u52a1\u5668\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/centos-7-x%e5%ae%89%e8%a3%85%e9%83%a8%e7%bd%b2memcached%e6%9c%8d%e5%8a%a1%e5%99%a8\/\" aria-label=\"\u9605\u8bfb CentOS 7.x\u5b89\u88c5\u90e8\u7f72Memcached\u670d\u52a1\u5668\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[82,535],"class_list":["post-1725","post","type-post","status-publish","format-standard","hentry","category-linux","tag-centos","tag-memcached"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=1725"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1725\/revisions"}],"predecessor-version":[{"id":1726,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/1725\/revisions\/1726"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=1725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=1725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=1725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}