目录
1、安装memcached的准备工作
2、安装、配置 Memcached
3、Memcached常用管理命令
4、Memcached测试
1、安装memcached的准备工作
1.1、系统环境
root@com:~# cat /etc/issue
Debian GNU/Linux 8 n l
root@com:~# uname -r
3.16.0-4-amd64
1.2、更改软件源,安装常用软件包
root@com:~# vim /etc/apt/sources.list #把此文件中原有的内容全部删除,并增加如下内容
deb http://mirrors.163.com/debian/ jessie main
deb http://mirrors.163.com/debian/ jessie-updates main
deb http://mirrors.163.com/debian/ jessie-backports main
deb-src http://mirrors.163.com/debian/ jessie main
deb-src http://mirrors.163.com/debian/ jessie-updates main
deb-src http://mirrors.163.com/debian/ jessie-backports main
deb http://mirrors.163.com/debian-security/ jessie/updates main
deb-src http://mirrors.163.com/debian-security/ jessie/updates main
root@com:~# apt-get update #更改软件源后用此命令更新包列表
再安装如下三个软件,这不是必要的步骤,可选。
123 root@com:~# apt-get install vim
root@com:~# apt-get install sudo
root@com:~# apt-get install chkconfig
2、安装、配置 Memcached
root@com:~# apt-cache show memcached #查看源中的memcached包的信息
Package: memcached
Version: 1.4.21-1.1 #这里是版本号
Installed-Size: 206
Maintainer: David Martínez Moreno <ender@debian.org>
Architecture: amd64
Depends: libc6 (>= 2.17), libevent-2.0-5 (>= 2.0.10-stable), libsasl2-2, perl, init-system-helpers (>= 1.18~), lsb-base (>= 3.2-13), adduser
Suggests: libcache-memcached-perl, libmemcached, libanyevent-perl, libyaml-perl, libterm-readkey-perl
Description-en: high-performance memory object caching system
Danga Interactive developed memcached to enhance the speed of LiveJournal.com,
a site which was already doing 20 million+ dynamic page views per day for 1
million users with a bunch of webservers and a bunch of database servers.
memcached dropped the database load to almost nothing, yielding faster page
load times for users, better resource utilization, and faster access to the
databases on a memcache miss.
.
memcached optimizes specific high-load serving applications that are designed
to take advantage of its versatile no-locking memory access system. Clients
are available in several different programming languages, to suit the needs
of the specific application. Traditionally this has been used in mod_perl
apps to avoid storing large chunks of data in Apache memory, and to share
this burden across several machines.
Description-md5: f7b1936bf072e208b59db960aca4de8a
Homepage: http://www.memcached.org/
Tag: devel::profiler, implemented-in::c, interface::daemon, network::server,
role::program, secteam::squeeze-limited-support,
secteam::wheezy-limited-support
Section: web
Priority: optional
Filename: pool/main/m/memcached/memcached_1.4.21-1.1_amd64.deb
Size: 97362
MD5sum: db1f2159c2a7086d85b9839577490239
SHA1: a2139100c90351e25f232da7415caa0ff3dae052
SHA256: 8efbb75ed1c65343cc72d0e50058b25a671b386eaafe41e456ca4ad29c4630b8
123456789101112131415161718192021222324252627282930313233343536373839404142 root@com:~# apt-get install memcached #这里是安装memcached软件
root@com:~# dpkg -L memcached #这里是查看memcached这个包安装后产生的了哪些文件,但没有显示出“/etc/memcached.conf”这个文件,很奇怪
/.
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/memcached.service
/usr
/usr/include
/usr/include/memcached
/usr/include/memcached/protocol_binary.h
/usr/bin
/usr/bin/memcached
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/memcached.1.gz
/usr/share/memcached
/usr/share/memcached/memcached.conf.default
/usr/share/memcached/scripts
/usr/share/memcached/scripts/mc_slab_mover
/usr/share/memcached/scripts/README.damemtop
/usr/share/memcached/scripts/damemtop.yaml
/usr/share/memcached/scripts/damemtop
/usr/share/memcached/scripts/memcached-tool
/usr/share/memcached/scripts/systemd-memcached-wrapper
/usr/share/memcached/scripts/start-memcached
/usr/share/doc
/usr/share/doc/memcached
/usr/share/doc/memcached/NEWS.gz
/usr/share/doc/memcached/protocol.txt.gz
/usr/share/doc/memcached/changelog.Debian.gz
/usr/share/doc/memcached/NEWS.Debian.gz
/usr/share/doc/memcached/changelog.gz
/usr/share/doc/memcached/copyright
/usr/share/doc/memcached/README.Debian
/usr/share/doc/memcached/README.md
/etc
/etc/init.d
/etc/init.d/memcached
/etc/default
/etc/default/memcached
root@com:~# vim /etc/memcached.conf
这里只需修改两个参数,一是指定memcached所能使用的内存大小,如下:
-m 1024 #默认是64M,请修改成实际所需要的大小
二是修改监听的IP地址,默认时memcached只监听在127.0.0.1这个本地回环地址上,如下修改成本地网卡接口上的实际IP:
-l 172.31.11.96
3、Memcached常用管理命令
root@com:~# service memcached start #启动memcached
root@com:~# ss -tnl | grep 11211
LISTEN 0 128 172.31.11.96:11211 *:*
root@com:~# service memcached status #查看memcached的是否已启动
● memcached.service - memcached daemon
Loaded: loaded (/lib/systemd/system/memcached.service; enabled)
Active: active (running) since Thu 2015-08-13 14:06:44 CST; 2min 47s ago
Main PID: 17416 (memcached)
CGroup: /system.slice/memcached.service
└─17416 /usr/bin/memcached -m 1024 -p 11211 -u memcache -l 172.31.11.96
root@com:~# service memcached stop #停止memcached
root@com:~# chkconfig --list | grep memcached #查看在哪些启动级别memcached是自启动
memcached 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4、Memcached测试
Xshell:> telnet 172.31.11.96 11211 #我这里直接用xshell工具进行测试
Connecting to 172.31.11.96:11211...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
stats #输入stats命令获取到memcached的状态信息
STAT pid 17416
STAT uptime 1637
STAT time 1439447639
STAT version 1.4.21
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.036000
STAT rusage_system 0.052000
STAT curr_connections 5
STAT total_connections 7
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
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 22
STAT bytes_written 1103
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
STAT lrutail_reflocked 0
END
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。