系統環境:c++
[root@DBSERVER ~]# uname -a Linux DBSERVER 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux [root@DBSERVER ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.7 (Tikanga)
所需軟件:web
libevent-2.0.22-stable.tar.gz緩存
memcached-1.4.22.tar.gz 服務器
安裝環境:併發
一、簡歷所需目錄:app
[root@DBSERVER ~]# mkdir -p /usr/local/webserver [root@DBSERVER ~]# mkdir -p /usr/local/webserver/memcached [root@DBSERVER ~]# chmod 775 -R /usr/local/webserver
二、升級所需的庫:dom
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers patch autoconf213.noarch unzip gzip libtool-ltdl libtool-ltdl-devel libaio
三、編輯編譯時使用的動態連接庫的路徑curl
#將/etc/ld.so.conf列出的路徑下的庫文件 緩存到/etc/ld.so.cache 以供使用tcp
#修改ld.so.conf增長新的庫路徑後,須要運行一下/sbin/ldconfigmemcached
#在任何目錄下運行均可以
[root@DBSERVER ~]# cat /etc/ld.so.conf include ld.so.conf.d/*.conf /usr/lib /usr/local/lib /usr/lib64
[root@DBSERVER ~]# /sbin/ldconfig ##使之生效
四、安裝依賴環境:
[root@DBSERVER ~]# tar -xf libevent-2.0.22-stable.tar.gz [root@DBSERVER ~]# cd libevent-2.0.22-stable [root@DBSERVER libevent-2.0.22-stable]# ./configure [root@DBSERVER libevent-2.0.22-stable]# make && make install
五、安裝memcached:
[root@DBSERVER ~]# tar -xf memcached-1.4.22.tar.gz [root@DBSERVER ~]# cd memcached-1.4.22 [root@DBSERVER memcached-1.4.22]# ls aclocal.m4 compile daemon.c items.h memcached_dtrace.d protocol_binary.h slabs.h timedrun.c assoc.c config.guess depcomp jenkins_hash.c memcached.h README.md solaris_priv.c trace.h assoc.h config.h.in doc jenkins_hash.h memcached.spec sasl_defs.c stats.c util.c AUTHORS config.sub hash.c m4 missing sasl_defs.h stats.h util.h cache.c configure hash.h Makefile.am murmur3_hash.c scripts t version.m4 cache.h configure.ac install-sh Makefile.in murmur3_hash.h sizes.c testapp.c ChangeLog COPYING items.c memcached.c NEWS slabs.c thread.c [root@DBSERVER memcached-1.4.22]# ./configure --prefix=/usr/local/webserver/memcached/ --with-libevent=/usr/local
[root@DBSERVER memcached-1.4.22]# make && make install
六、啓動memcached:
[root@DBSERVER bin]# ps aux|grep memcached root 12075 0.0 0.0 61200 756 pts/1 R+ 19:32 0:00 grep memcached [root@DBSERVER bin]# ./memcached -d -m 256 -u root -p 11211 [root@DBSERVER bin]# netstat -tpnl|grep memcached tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 12078/memcached [root@DBSERVER bin]# ps aux|grep memcached root 12078 0.0 0.1 64788 1056 ? Ssl 19:33 0:00 ./memcached -d -m 256 -u root -p 11211 root 12095 0.0 0.0 61200 756 pts/1 R+ 19:33 0:00 grep memcached
指定保存進程文件啓動:
[root@DBSERVER bin]# ./memcached -d -m 256 -u root -p 11211 -P /tmp/memcached.pic
[root@DBSERVER bin]# cat /tmp/memcached.pic
12117
鏈接memcached,而且使用:
[root@DBSERVER bin]# telnet localhost 11211 Trying 172.31.213.231... Connected to localhost.localdomain (172.31.213.231). Escape character is '^]'. set Uid 0 0 5 12345 STORED get Uid VALUE Uid 0 5 12345 END gets Uid VALUE Uid 0 5 1 12345 END
經常使用命令:
啓動/結束
memcached -d -m 10 -u root -l 192.168.0.122 -p 11200 -c 256 -P /tmp/memcached.pid
-d 選項是啓動一個守護進程,
-m 是分配給Memcache使用的內存數量,單位是MB,這裏是10MB
-u 是運行Memcache的用戶,這裏是root
-l 是監聽的服務器IP地址,若是有多個地址的話,這裏指定了服務器的IP地址192.168.0.122
-p 是設置Memcache監聽的端口,這裏設置了12000,最好是1024以上的端口
-c 選項是最大運行的併發鏈接數,默認是1024,這裏設置了256,按照你服務器的負載量來設定
-P 是設置保存Memcache的pid文件
kill `cat /tmp/memcached.pid`
echo stats | nc 192.168.1.123 11200
watch "echo stats | nc 192.168.1.123 11200" (實時狀態)
[root@DBSERVER bin]# echo stats | nc 172.31.213.231 11211 STAT pid 12078 STAT uptime 225 STAT time 1427888213 STAT version 1.4.22 STAT libevent 2.0.22-stable STAT pointer_size 64 STAT rusage_user 0.001999 STAT rusage_system 0.001999 STAT curr_connections 5 STAT total_connections 7 STAT connection_structures 6 STAT reserved_fds 20 STAT cmd_get 2 STAT cmd_set 1 STAT cmd_flush 0 STAT cmd_touch 0 STAT get_hits 2 STAT get_misses 0 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT touch_hits 0 STAT touch_misses 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 53 STAT bytes_written 64 STAT limit_maxbytes 268435456 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 4 STAT conn_yields 0 STAT hash_power_level 16 STAT hash_bytes 524288 STAT hash_is_expanding 0 STAT malloc_fails 0 STAT bytes 73 STAT curr_items 1 STAT total_items 1 STAT expired_unfetched 0 STAT evicted_unfetched 0 STAT evictions 0 STAT reclaimed 0 STAT crawler_reclaimed 0 STAT lrutail_reflocked 0 END