Memcached源码安装配置

Memcached源码安装配置

官方网站:
memcached - a distributed memory object caching system
Free & open source, high-performance, distributed memory object caching system


环境:
CentOS 7.1/6.5
memcached-1.4.25


一.安装编译依赖库
yum -y install gcc gcc-c++ unzip gzip bzip2 libevent-devel cyrus-sasl-devel systemtap-sdt-devel


二.编译安装
tar -xvf memcached-1.4.25.tar.gz -C /usr/local/src
cd /usr/local/src/memcached-1.4.25
./configure --prefix=/opt/memcached \
--enable-sasl \
--enable-sasl-pwdb \
--enable-dtrace \
--enable-64bit
make -j4 && make -j4 install

cp -a /opt/memcached/share/man/* /usr/share/man
cp -a /usr/local/src/memcached-1.4.25/scripts /opt/memcached/


三.init sysv脚本
useradd -r -s /sbin/nologin memcached
mkdir -p /var/run/memcached/

cp -f /usr/local/src/memcached-1.4.25/scripts/memcached.sysv /etc/init.d/memcached

sed -i 's#daemon memcached#daemon /opt/memcached/bin/memcached#' /etc/init.d/memcached

sed -i "/^USER=/c USER=memcached" /etc/init.d/memcached

sed -i "/^CACHESIZE=/c CACHESIZE=2048" /etc/init.d/memcached


chmod +x /etc/init.d/memcached
chkconfig memcached on


四.配置并启动
init脚本启动
service memcached start
Memcached源码安装配置

命令行启动
/opt/memcached/bin/memcached -d -u memcached -m 2048 -t 4 -p 11211 -P /tmp/memcached.pid
命令行停止
kill -9 $(cat /tmp/memcached.pid)或killall memcached
提示:命令行更为灵活,memcached -h可以查看所有可定制选项参数


测试

root@jlive:~#telnet localhost 11211

Trying ::1...

Connected to localhost.

Escape character is '^]'.

stats

STAT pid 16350

STAT uptime 735

STAT time 1463576183

STAT version 1.4.25

STAT libevent 2.0.21-stable

STAT pointer_size 64

STAT rusage_user 0.019445

STAT rusage_system 0.026345

STAT curr_connections 2

STAT total_connections 5

STAT connection_structures 3

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 101

STAT bytes_written 2389

STAT limit_maxbytes 2147483648

STAT accepting_conns 1

STAT listen_disabled_num 0

STAT time_in_listen_disabled_us 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

STAT crawler_items_checked 0

STAT lrutail_reflocked 0

END

quit

Connection closed by foreign host.



自带小工具--memcached-tool

       memcached-tool 10.0.0.5:11211 display    # shows slabs

       memcached-tool 10.0.0.5:11211            # same.  (default is display)

       memcached-tool 10.0.0.5:11211 stats      # shows general stats

       memcached-tool 10.0.0.5:11211 settings   # shows settings stats

       memcached-tool 10.0.0.5:11211 sizes      # shows sizes stats

 

       memcached-tool 10.0.0.5:11211 dump       # dumps keys and values

[root@master ~]# /opt/memcached/scripts/memcached-tool 192.168.8.10:11211 settings

#192.168.8.10:11211 Field       Value

       auth_enabled_sasl          no

        binding_protocol auto-negotiate

             cas_enabled         yes

              chunk_size          48

          detail_enabled          no

           domain_socket        NULL

               evictions          on

expirezero_does_not_evict          no

           flush_enabled         yes

           growth_factor        1.25

          hash_algorithm     jenkins

          hashpower_init           0

             hot_lru_pct          32

                   inter        NULL

           item_size_max     1048576

             lru_crawler          no

       lru_crawler_sleep         100

     lru_crawler_tocrawl           0

   lru_maintainer_thread          no

                maxbytes  2147483648

                maxconns        1024

           maxconns_fast          no

             num_threads           4

     num_threads_per_udp           4

                  oldest           0

          reqs_per_event          20

           slab_automove           0

           slab_reassign          no

         stat_key_prefix           :

        tail_repair_time           0

             tcp_backlog        1024

                 tcpport       11211

                 udpport           0

                   umask         700

               verbosity           0

 

            warm_lru_pct          32


自带小工具--mc_slab_mover

/opt/memcached/scripts/mc_slab_mover --host='127.0.0.1:11211'




GUI管理工具

php扩展(memcached & memcache)

http://libmemcached.org/libMemcached.html

http://php.net/manual/zh/book.memcached.php

http://pecl.php.net/package/memcached

注意:php的memcached扩展,功能和特性比memcache扩展都要优秀

1.安装libmemcached

wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz

tar -xvf libmemcached-1.0.18.tar.gz -C /usr/local/src/

cd /usr/local/src/libmemcached-1.0.18

./configure && make && make install

2.安装php memcached扩展库

wget http://pecl.php.net/get/memcached-2.2.0.tgz

tar -xvf memcached-2.2.0.tgz -C /usr/local/src/

cd /usr/local/src/memcached-2.2.0

phpize

./configure --enable-memcached-json && make -j4 && make -j4 install

3.php.ini加载memcached.so

echo extension=memcached.so >>/usr/local/php/etc/php.ini

service php-fpm restart

memcached

memcached support enabled
Version  2.2.0 
libmemcached version  1.0.18 
SASL support  yes 
Session support  yes 
igbinary support  no 
json support  yes 
msgpack support  no


但有些php GUI是基于php memcache的扩展库,所以这里也一并安装

http://php.net/manual/zh/memcache.installation.php

http://pecl.php.net/package/memcache

wget http://pecl.php.net/get/memcache-2.2.7.tgz

tar -xvf memcache-2.2.7.tgz /usr/local/src/

cd /usr/local/src/memcache-2.2.7

phpize

./configure && make -j4 && make -j4 install

echo extension=memcache.so >>/usr/local/php/etc/php.ini

 

 

service php-fpm restart

root@jlive:memcache-2.2.7#ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

ldap.so memcached.so memcache.so*  opcache.a opcache.so*

memcache

memcache support enabled
Active persistent connections 
Version  2.2.7 
Revision  $Revision: 327750 $




php memcache GUI工具--MemAdmin

基于 PHP5 & JQuery 的 Memcached 管理监控工具,界面非常清爽

wget http://www.junopen.com/memadmin/memadmin-1.0.12.tar.gz

tar -xvf memadmin-1.0.12.tar.gz -C /usr/local/nginx/html

Memcached源码安装配置
默认用户名和密码为admin/admin, memadmin/config.php可以修改

Memcached源码安装配置



posted @ 2016-05-18 19:16  李庆喜  阅读(315)  评论(0编辑  收藏  举报