博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
memcached 01-安装
阅读量:6932 次
发布时间:2019-06-27

本文共 5855 字,大约阅读时间需要 19 分钟。

转自:

1、  安装文件准备

1)、Memcache的服务器端程序:当前最新版本号为

  下载地址:

2)、Memcache的安装先决条件:先安装libevent,当前最新版本号为

  Libevent介绍:libevent是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部使用select、epoll、kqueue等系统调用管理事件机制。著名的用于apache的php缓存库据说也是libevent based,而且libevent在使用上可以做到跨平台,而且根据libevent官方网站上公布的数据统计,似乎也有着非凡的性能。

  下载地址:

2、  要求

鉴于我们线上环境和线下的要保持一致,我们都将采用linux。具体的版本号为:

Redhat advance server4 v4,可以使用更高版本(更高版本未经测试

如果是redhat advance server4 v2 ,请保证gcc编译器可以使用,或者升级到v4然后安装gcc编译器。一般升级的方式都是从光盘启动升级过程,升级后安装gcc编译器。默认的v2版本没有安装gcc编译器。

3、  编译器要求

Memcache的安装文件是要求我们安装gcc编译器的。否则我们的libevent和memcache都无法安装。

检查是否有gcc编译器的命令:gcc –v

如果系统的gcc编译器可以用,将会有一段描述,否则提示找不到类库。

成功的例如:

Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux

Thread model: posix

gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)

4、  安装

 先安装libevent,然后才能安装memcache

 1)、libevent安装

//先解压缩

[root@localhost]#tar -zxvf  libevent-1.4.8-stable.tar.gz

//切换到libevent的目录中

[root@localhost]#cd  libevent-1.4.8-stable

//指定安装路径到/usr/目录下

[root@localhost]#./configure --prefix=/usr/

//编译

[root@localhost]#make

//安装

[root@localhost]#.make install

 

 

 2)、memcache服务器安装

//先解压缩memcached-1.2.6.tar.gz

[root@localhost]#tar -zxvf  memcached-1.2.6.tar.gz

//切换到memcache的目录中

[root@localhost]#cd  memcached-1.2.6

//指定安装路径到/usr/local/server/memcache目录下,同时指定libevent的安装位置

[root@localhost]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/

//编译

[root@localhost]#make

//安装

[root@localhost]#.make install

 测试每步是否安装成功:

   测试libevent:

   [root@localhost]# ls /usr/lib |grep libevent

libevent-1.4.so.2

libevent-1.4.so.2.1.1

libevent.a

libevent.la

libevent.so

libevent_core-1.4.so.2

libevent_core-1.4.so.2.1.1

libevent_core.a

libevent_core.la

libevent_core.so

libevent_extra-1.4.so.2

libevent_extra-1.4.so.2.1.1

libevent_extra.a

libevent_extra.la

libevent_extra.so

  测试memcache:

[root@localhost]# ls -al /usr/local/memcached/bin

total 264

drwxr-xr-x  2 root root   4096 Sep 19 15:31 .

drwxr-xr-x  4 root root   4096 Sep 19 15:31 ..

-rwxr-xr-x  1 root root 120949 Sep 19 15:31 memcached

-rwxr-xr-x  1 root root 129947 Sep 19 15:31 memcached-debug

5、  启动memcache

1)、启动Memcache的服务器端:

[root@localhost]# /usr/local/bin/memcached -d -m 100 -u root -l 192.168.36.200 -p 11211 -c 256 -P /tmp/memcached.pid 

# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

    -d选项是启动一个守护进程,
    -m是分配给Memcache使用的内存数量,单位是MB,我这里是100MB,
    -u是运行Memcache的用户,我这里是root,
    -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.36.200,
    -p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,我们这里统一使用11211
    -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定。
    -P是设置保存Memcache的pid文件,我这里是保存在/tmp/memcached.pid,

2)、如果要结束Memcache进程,执行:

[root@localhost]# kill cat /tmp/memcached.pid

6、  监测是否启动成功方式

我们可以使用telnet来对我们的memcache服务器进行访问

例如:telnet 192.168.36.199 11211 (访问的是192.168.36.199这个ip的11211端口)

连接上后,直接敲击stats命令看当前缓存服务器状态

7、  设定memcache的telnet访问限制

请限定telnet的访问,使之只能在中转机上访问

8、  memcache的常见概念

memcached会预先分配内存,memcached分配内存方式称之为allocator,首先,这里有3个概念:

1 slab
2 page
3 chunk
解释一下,一般来说一个memcahced进程会预先将自己划分为若干个slab,每个slab下又有若干个page,每个page下又有多个chunk,如果我们把这3个咚咚看作是object得话,这是两个一对多得关系。再一般来说,slab得数量是有限得,几个,十几个,或者几十个,这个跟进程配置得内存有关。而每个slab下得page默认情况是1m,也就是说如果一个slab占用100m得内存得话,那么默认情况下这个slab所拥有得page得个数就是100,而chunk就是我们得数据存放得最终地方。

9、  Memcache的常用命令

 Memcache常见的命令都在协议文件上:安装文件的的doc目录下的protocol.txt文件中有详细说明

 1)、查询状态命令:stats:

    Name              Type     Meaning

----------------------------------

pid               32u      Process id of this server process

uptime            32u      Number of seconds this server has been running

time              32u      current UNIX time according to the server

version           string   Version string of this server

pointer_size      32       Default size of pointers on the host OS

                           (generally 32 or 64)

rusage_user       32u:32u  Accumulated user time for this process

                           (seconds:microseconds)

rusage_system     32u:32u  Accumulated system time for this process

                           (seconds:microseconds)

curr_items        32u      Current number of items stored by the server

total_items       32u      Total number of items stored by this server

                           ever since it started

bytes             64u      Current number of bytes used by this server

                           to store items

curr_connections  32u      Number of open connections

total_connections 32u      Total number of connections opened since

                           the server started running

connection_structures 32u  Number of connection structures allocated

                           by the server

cmd_get           64u      Cumulative number of retrieval requests

cmd_set           64u      Cumulative number of storage requests

get_hits          64u      Number of keys that have been requested and

                           found present

get_misses        64u      Number of items that have been requested

                           and not found

evictions         64u      Number of valid items removed from cache                                                                          

                           to free memory for new items                                                                                      

bytes_read        64u      Total number of bytes read by this server

                           from network

bytes_written     64u      Total number of bytes sent by this server to

                           network

limit_maxbytes    32u      Number of bytes this server is allowed to

                           use for storage.

threads           32u      Number of worker threads requested.

                           (see doc/threads.txt)

2)、查询版本号 version

3)、退出命令 quit

4)、显示各个slab的信息,包括chunk的大小、数目、使用情况等:stats slabs5)、显示各个slab中item的数目和最老item的年龄(最后一次访问距离现在的秒数):stats items

6)、显示内存分配:stats malloc

7)、清空缓存数据(其实是将所有缓存数据标记为过期):flush_all

memcached状态查看:

pid memcache服务器的进程ID
uptime 服务器已经运行的秒数
time 服务器当前的unix时间戳
version memcache版本
pointer_size 当前操作系统的指针大小(32位系统一般是32bit)
rusage_user 进程的累计用户时间
rusage_system 进程的累计系统时间
curr_items 服务器当前存储的items数量
total_items 从服务器启动以后存储的items总数量
bytes 当前服务器存储items占用的字节数
curr_connections 当前打开着的连接数
total_connections 从服务器启动以后曾经打开过的连接数
connection_structures 服务器分配的连接构造数
cmd_get get命令(获取)总请求次数
cmd_set set命令(保存)总请求次数
get_hits 总命中次数
get_misses 总未命中次数
evictions 为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)
bytes_read 总读取字节数(请求字节数)
bytes_written 总发送字节数(结果字节数)
limit_maxbytes 分配给memcache的内存大小(字节)
threads 当前线程数

 

 

转载地址:http://lnljl.baihongyu.com/

你可能感兴趣的文章
【iOS开发】---- UIView动画
查看>>
Java 编程的动态性,第 7 部分: 用 BCEL 设计字节码--转载
查看>>
15 Tricks to Appear Smart in Emails(转)
查看>>
ubuntu14.04如何卸载qq
查看>>
单链表逆转
查看>>
Myeclipse7.5 下载 安装 注冊 注冊码 100%成功
查看>>
按键驱动的恩恩怨怨之查询方式
查看>>
SOCKet 编程 简介
查看>>
C/C++产生随机数
查看>>
java集合经常出现空指针问题的解决方案
查看>>
Scala Trait
查看>>
[原]Android打包之Eclipse打多渠道包
查看>>
表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
查看>>
bat启动/停止oracle服务
查看>>
一、UITableView的属性
查看>>
python setuptools工具打包
查看>>
UVa 101 The Blocks Problem
查看>>
指针二次释放(_BLOCK_TYPE_IS_VALID)
查看>>
【转】每天一个linux命令(51):lsof命令
查看>>
copy_to_user 和 copy_from_user
查看>>