memcached安装运行

来源:互联网 发布:数控滚齿机编程 编辑:程序博客网 时间:2024/05/10 12:16
1. 安装libevent 

tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure  
make
make install --用root用户,否则没权限

2:安装memcached
tar zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5.tar.gz
./configure  --with-libevent=/usr
说明:configure 需要加 libevent的安装路径


make
make install --用root用户,否则没权限
安装完成后会把memcached放到 /usr/local/bin/memcached

[jifeng@jifeng04 ~]$ tar zxf memcached-1.4.20.tar.gz [jifeng@jifeng04 ~]$ cd memcached-1.4.20[jifeng@jifeng04 memcached-1.4.20]$ ./configure --with-libevent=/usrchecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuchecking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... gawkchecking whether make sets $(MAKE)... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for style of include used by make... GNUchecking dependency style of gcc... gcc3checking how to run the C preprocessor... gcc -Echecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking for icc in use... nochecking for clang in use... nochecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking whether __SUNPRO_C is declared... nochecking for gcc option to accept ISO C99... -std=gnu99checking whether gcc -std=gnu99 and cc understand -c and -o together... yeschecking sasl/sasl.h usability... nochecking sasl/sasl.h presence... nochecking for sasl/sasl.h... nochecking for gcov... /usr/bin/gcovchecking for main in -lgcov... yeschecking for library containing clock_gettime... -lrtchecking for library containing socket... none requiredchecking for library containing gethostbyname... none requiredchecking for libevent directory... /usrchecking for library containing umem_cache_create... nochecking for library containing gethugepagesizes... nochecking for stdbool.h that conforms to C99... yeschecking for _Bool... yeschecking for inttypes.h... (cached) yeschecking for sasl_callback_ft... nochecking for print macros for integers (C99 section 7.8.1)... yeschecking for an ANSI C-conforming const... yeschecking for socklen_t... yeschecking for endianness... littlechecking for htonll... nochecking for library containing pthread_create... none requiredchecking for mlockall... yeschecking for getpagesizes... nochecking for memcntl... nochecking for sigignore... yeschecking for clock_gettime... yeschecking for accept4... yeschecking for alignment... needchecking for GCC atomics... yeschecking for setppriv... nochecking umem.h usability... nochecking umem.h presence... nochecking for umem.h... nochecking for xml2rfc... nochecking for xsltproc... noconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating doc/Makefileconfig.status: creating config.hconfig.status: executing depfiles commands[jifeng@jifeng04 memcached-1.4.20]$make [root@jifeng04 memcached-1.4.20]$make install 


启动时出现“memcached: error while loading shared libraries:libevent-2.0.so.5: cannot

open shared object file: No such file or directory”之类的信息,表示memcached 找不到
libevent 的位置所以,请先使用whereis libevent 得到位置,然后连接到memcached 所寻找的路径
# whereis libevent
libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a
然后,再看memcached 从哪里找它
# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less
可以看到:是/usr/lib/libevent-2.0.so.5,所以,创建软链
 ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5

[jifeng@jifeng04 memcached-1.4.20]$ ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5ln: 创建符号链接 "/usr/lib/libevent-2.0.so.5": 权限不够[jifeng@jifeng04 memcached-1.4.20]$ su -密码:[root@jifeng04 ~]# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5[root@jifeng04 ~]# exitlogout

3:启动memcached

[jifeng@jifeng04 memcached-1.4.20]$ /usr/local/bin/memcached -d -m 1024 -l 10.3.7.215 -p 11211[jifeng@jifeng04 memcached-1.4.20]$ 

memcached基本选项
memcached -d -m 1024 -u root -l 10.3.7.215 -p 11211 -c 256 -P /tmp/memcached.pid
-d 选项是启动一个守护进程, 
-m 是分配给Memcache使用的内存数量,单位是MB,这里是1024MB
-u 是运行Memcache的用户,这里是root
-l 是监听的服务器IP地址,如果有多个地址的话,这里指定了服务器的IP地址10.3.7.215 
-p 是设置Memcache监听的端口,这里设置了11211,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024,这里设置了256,按照你服务器的负载量来设定
-P 是设置保存Memcache的pid文件
kill `cat /tmp/memcached.pid`
检查memcached是否正常运行
#ps aux | grep memcached
#telnet localhost 11211
....
echo stats | nc 10.3.7.215 11211
会显示memcached的基本信息
[jifeng@jifeng03 ~]$ echo stats | nc 10.3.7.215 11211STAT pid 14279STAT uptime 79957STAT time 1407767792STAT version 1.4.20STAT libevent 2.0.21-stableSTAT pointer_size 64STAT rusage_user 1.392788STAT rusage_system 0.910861STAT curr_connections 5STAT total_connections 7STAT connection_structures 6STAT reserved_fds 20STAT cmd_get 2STAT cmd_set 0STAT cmd_flush 0STAT cmd_touch 0STAT get_hits 0STAT get_misses 2STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 22STAT bytes_written 10STAT limit_maxbytes 1073741824STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT malloc_fails 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT expired_unfetched 0STAT evicted_unfetched 0STAT evictions 0STAT reclaimed 0STAT crawler_reclaimed 0END


0 0