memcached安装运行

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=/usr
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for icc in use... no
checking for clang in use... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether __SUNPRO_C is declared... no
checking for gcc option to accept ISO C99... -std=gnu99
checking whether gcc -std=gnu99 and cc understand -c and -o together... yes
checking sasl/sasl.h usability... no
checking sasl/sasl.h presence... no
checking for sasl/sasl.h... no
checking for gcov... /usr/bin/gcov
checking for main in -lgcov... yes
checking for library containing clock_gettime... -lrt
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for libevent directory... /usr
checking for library containing umem_cache_create... no
checking for library containing gethugepagesizes... no
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for inttypes.h... (cached) yes
checking for sasl_callback_ft... no
checking for print macros for integers (C99 section 7.8.1)... yes
checking for an ANSI C-conforming const... yes
checking for socklen_t... yes
checking for endianness... little
checking for htonll... no
checking for library containing pthread_create... none required
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
checking for sigignore... yes
checking for clock_gettime... yes
checking for accept4... yes
checking for alignment... need
checking for GCC atomics... yes
checking for setppriv... no
checking umem.h usability... no
checking umem.h presence... no
checking for umem.h... no
checking for xml2rfc... no
checking for xsltproc... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.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.5
ln: 创建符号链接 "/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 ~]# exit
logout

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 11211
STAT pid 14279
STAT uptime 79957
STAT time 1407767792
STAT version 1.4.20
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 1.392788
STAT rusage_system 0.910861
STAT curr_connections 5
STAT total_connections 7
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 2
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 2
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 22
STAT bytes_written 10
STAT limit_maxbytes 1073741824
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 0
STAT curr_items 0
STAT total_items 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
STAT crawler_reclaimed 0
END


你可能感兴趣的:(memcached安装运行)