CentOs 6.3 下安装启动memcache
2014-01-07 00:24
323 查看
CentOs 6.3 下安装memcache:
1.安装memcached时,memcached需要libevent支持,所以首先安装libevent.编译的时候提示需要指定libevent库,可以看看系统是否安装了libevent库:rpm -qa|grep libevent (libevent-1.4.13-4.el6.i686)如果是系统自带安装的,此时可以再自动安装一下 yum -y install libevent(自动选择y)
2.因为libevent 这个包是系统默认安装的,没有安装相应的开发所用的头文件。所以,还要使用如下命令来安装:yum install libevent-devel。
3.whereis libevent 或者 #ls -al /usr/lib | grep libevent 就可以看到多个libevent列表文件
4. #wget https://memcached.googlecode.com/files/memcached-1.4.15.tar.gz 从网上下载tar.gz的memcache的安装包 ,也可以自己手动离线下载。
5.安装:
# tar -zxvf memcached-1.4.8.tar.gz
# cd memcached-1.4.8
# ./configure –help (看看帮助文件)
# ./configure –prefix=/usr/memcache(源码安装:指定安装路径)
# make
# make install
(此时如果出现checking for libevent directory… configure: error: libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
If it’s already installed, specify its path using –with-libevent=/dir/,因为libevent 这个包是系统默认安装的,没有安装相应的开发所用的头文件。用上边的yum install libevent-devel后,编译安装)
6.启动:/usr/local/memcache/bin/memcached -d -m 128 -l 192.168.1.1 -p 11211 -u root (如果报:启动报error while loading shared libraries: libevent-1.4.s解决办法:原因是找不到libevent-1.4.so.2类库,解决办法如下:使用LD_DEBUG=help ./memcached -v来确定 加载的类库路径,方法如下:
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2)
----------------------------------------------------
启动关闭memcache:
1.进入默认安装目录(上面安装的时候,改路径了),启动:/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -u root
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,这里是1024MB,默认是64MB
-u 是运行Memcache的用户,这里是root
-l 是监听的服务器IP地址,默认应该是本机
-p 是设置Memcache监听的端口,默认是11211,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024,这里设置了10240,按照你服务器的负载量来设定
-P 是设置保存Memcache的pid文件位置
-h 打印帮助信息
-v 输出警告和错误信息
-vv 打印客户端的请求和返回信息
2.获取运行状态:使用ps -ef|grep memcached (ps:process status 功能说明:报告程序状况。)或者使用echo stats | nc localhost 11211(可以查看出pid,nc命令在发行版带)
3.停止:kill -9 pid (-9表示强制杀死,pid 为进程的进程标识符)
------------
另外一个启动关闭例子:
1.启动:memcached -d -m 10 -u root -l 192.168.0.122 -p 11200 -c 256 -P /tmp/memcached.pid
2.获取运行状态 watch "echo stats | nc 192.168.1.123 11200" (实时状态)或者 echo stats | nc 192.168.1.123 11200
3.关闭:kill `cat /tmp/memcached.pid`
----------------------------------------------------
连接到 memcached:
1.telnet ip 端口,如telnet 192.168.100.11 11211 ,注:如果没有telnet ,安装:yum install telnet 即可,telnet 127.0.0.1 11211 可以进入:
[root@CentOs63hp 桌面]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats 输入stats 可以看到 查看memcached状态信息
此时如果要跳出telnet使用ctrl+] 即可,再输入quit
2.stats查看状态,
3.flush_all:清楚缓存
查看memcached状态信息:
STAT pid 22459 进程ID
STAT uptime 1027046 服务器运行秒数
STAT time 1273043062 服务器当前unix时间戳
STAT version 1.4.4 服务器版本
STAT pointer_size 64 操作系统字大小(这台服务器是64位的)
STAT rusage_user 0.040000 进程累计用户时间
STAT rusage_system 0.260000 进程累计系统时间
STAT curr_connections 10 当前打开连接数
STAT total_connections 82 曾打开的连接总数
STAT connection_structures 13 服务器分配的连接结构数
STAT cmd_get 54 执行get命令总数
STAT cmd_set 34 执行set命令总数
STAT cmd_flush 3 指向flush_all命令总数
STAT get_hits 9 get命中次数
STAT get_misses 45 get未命中次数
STAT delete_misses 5 delete未命中次数
STAT delete_hits 1 delete命中次数
STAT incr_misses 0 incr未命中次数
STAT incr_hits 0 incr命中次数
STAT decr_misses 0 decr未命中次数
STAT decr_hits 0 decr命中次数
STAT cas_misses 0 cas未命中次数
STAT cas_hits 0 cas命中次数
STAT cas_badval 0 使用擦拭次数
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 15785 读取字节总数
STAT bytes_written 15222 写入字节总数
STAT limit_maxbytes 1048576 分配的内存数(字节)
STAT accepting_conns 1 目前接受的链接数
STAT listen_disabled_num 0
STAT threads 4 线程数
STAT conn_yields 0
STAT bytes 0 存储item字节数
STAT curr_items 0 item个数
STAT total_items 34 item总数
STAT evictions 0 为获取空间删除item的总数
-----------------------
网上帖子:Memcached的代理服务器软件:magent使用小记(http://blog.s135.com/post/393)
magent是一款开源的Memcached代理服务器软件,其项目网址为:http://code.google.com/p/memagent/
一、安装步骤:
1、编译安装libevent:
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable/
./configure --prefix=/usr
make && make install
cd ../
2、编译安装Memcached:
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6/
./configure --with-libevent=/usr
make && make install
cd ../
3、编译安装magent:
mkdir magent
cd magent/
wget http://memagent.googlecode.com/files/magent-0.5.tar.gz
tar zxvf magent-0.5.tar.gz
/sbin/ldconfig
sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
make
cp magent /usr/bin/magent
cd ../
二、使用实例:
memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
magent -u root -n 51200 -l 127.0.0.1 -p 12000 -s 127.0.0.1:11211 -s 127.0.0.1:11212 -b 127.0.0.1:11213
1、分别在11211、11212、11213端口启动3个Memcached进程,在12000端口开启magent代理程序;
2、11211、11212端口为主Memcached,11213端口为备份Memcached;
3、连接上12000的magent,set key1和set key2,根据哈希算法,key1被写入11212和11213端口的Memcached,key2被写入11212和11213端口的Memcached;
4、当11211、11212端口的Memcached死掉,连接到12000端口的magent取数据,数据会从11213端口的Memcached取出;
5、当11211、11212端口的Memcached重启复活,连接到12000端口,magent会从11211或11212端口的Memcached取数据,由于这两台Memcached重启后无数据,因此magent取得的将是空值,尽管11213端口的Memcached还有数据(此问题尚待改进)。
三、整个测试流程:
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
memcached agent v0.4
matrix 1 -> 127.0.0.1:11211, pool size 0
matrix 2 -> 127.0.0.1:11212, pool size 0
END
set key1 0 0 8
zhangyan
STORED
set key2 0 0 8
zhangyan
STORED
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11212
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
END
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
模拟11211、11212端口的Memcached死掉
[root@centos52 ~]# ps -ef | grep memcached
root 6589 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
root 6591 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
root 6593 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
root 6609 6509 0 01:44 pts/0 00:00:00 grep memcached
[root@centos52 ~]# kill -9 6589
[root@centos52 ~]# kill -9 6591
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
模拟11211、11212端口的Memcached重启复活
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
END
quit
Connection closed by foreign host.
1.安装memcached时,memcached需要libevent支持,所以首先安装libevent.编译的时候提示需要指定libevent库,可以看看系统是否安装了libevent库:rpm -qa|grep libevent (libevent-1.4.13-4.el6.i686)如果是系统自带安装的,此时可以再自动安装一下 yum -y install libevent(自动选择y)
2.因为libevent 这个包是系统默认安装的,没有安装相应的开发所用的头文件。所以,还要使用如下命令来安装:yum install libevent-devel。
3.whereis libevent 或者 #ls -al /usr/lib | grep libevent 就可以看到多个libevent列表文件
4. #wget https://memcached.googlecode.com/files/memcached-1.4.15.tar.gz 从网上下载tar.gz的memcache的安装包 ,也可以自己手动离线下载。
5.安装:
# tar -zxvf memcached-1.4.8.tar.gz
# cd memcached-1.4.8
# ./configure –help (看看帮助文件)
# ./configure –prefix=/usr/memcache(源码安装:指定安装路径)
# make
# make install
(此时如果出现checking for libevent directory… configure: error: libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
If it’s already installed, specify its path using –with-libevent=/dir/,因为libevent 这个包是系统默认安装的,没有安装相应的开发所用的头文件。用上边的yum install libevent-devel后,编译安装)
6.启动:/usr/local/memcache/bin/memcached -d -m 128 -l 192.168.1.1 -p 11211 -u root (如果报:启动报error while loading shared libraries: libevent-1.4.s解决办法:原因是找不到libevent-1.4.so.2类库,解决办法如下:使用LD_DEBUG=help ./memcached -v来确定 加载的类库路径,方法如下:
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2)
----------------------------------------------------
启动关闭memcache:
1.进入默认安装目录(上面安装的时候,改路径了),启动:/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -u root
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,这里是1024MB,默认是64MB
-u 是运行Memcache的用户,这里是root
-l 是监听的服务器IP地址,默认应该是本机
-p 是设置Memcache监听的端口,默认是11211,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024,这里设置了10240,按照你服务器的负载量来设定
-P 是设置保存Memcache的pid文件位置
-h 打印帮助信息
-v 输出警告和错误信息
-vv 打印客户端的请求和返回信息
2.获取运行状态:使用ps -ef|grep memcached (ps:process status 功能说明:报告程序状况。)或者使用echo stats | nc localhost 11211(可以查看出pid,nc命令在发行版带)
3.停止:kill -9 pid (-9表示强制杀死,pid 为进程的进程标识符)
------------
另外一个启动关闭例子:
1.启动:memcached -d -m 10 -u root -l 192.168.0.122 -p 11200 -c 256 -P /tmp/memcached.pid
2.获取运行状态 watch "echo stats | nc 192.168.1.123 11200" (实时状态)或者 echo stats | nc 192.168.1.123 11200
3.关闭:kill `cat /tmp/memcached.pid`
----------------------------------------------------
连接到 memcached:
1.telnet ip 端口,如telnet 192.168.100.11 11211 ,注:如果没有telnet ,安装:yum install telnet 即可,telnet 127.0.0.1 11211 可以进入:
[root@CentOs63hp 桌面]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats 输入stats 可以看到 查看memcached状态信息
此时如果要跳出telnet使用ctrl+] 即可,再输入quit
2.stats查看状态,
3.flush_all:清楚缓存
查看memcached状态信息:
STAT pid 22459 进程ID
STAT uptime 1027046 服务器运行秒数
STAT time 1273043062 服务器当前unix时间戳
STAT version 1.4.4 服务器版本
STAT pointer_size 64 操作系统字大小(这台服务器是64位的)
STAT rusage_user 0.040000 进程累计用户时间
STAT rusage_system 0.260000 进程累计系统时间
STAT curr_connections 10 当前打开连接数
STAT total_connections 82 曾打开的连接总数
STAT connection_structures 13 服务器分配的连接结构数
STAT cmd_get 54 执行get命令总数
STAT cmd_set 34 执行set命令总数
STAT cmd_flush 3 指向flush_all命令总数
STAT get_hits 9 get命中次数
STAT get_misses 45 get未命中次数
STAT delete_misses 5 delete未命中次数
STAT delete_hits 1 delete命中次数
STAT incr_misses 0 incr未命中次数
STAT incr_hits 0 incr命中次数
STAT decr_misses 0 decr未命中次数
STAT decr_hits 0 decr命中次数
STAT cas_misses 0 cas未命中次数
STAT cas_hits 0 cas命中次数
STAT cas_badval 0 使用擦拭次数
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 15785 读取字节总数
STAT bytes_written 15222 写入字节总数
STAT limit_maxbytes 1048576 分配的内存数(字节)
STAT accepting_conns 1 目前接受的链接数
STAT listen_disabled_num 0
STAT threads 4 线程数
STAT conn_yields 0
STAT bytes 0 存储item字节数
STAT curr_items 0 item个数
STAT total_items 34 item总数
STAT evictions 0 为获取空间删除item的总数
-----------------------
网上帖子:Memcached的代理服务器软件:magent使用小记(http://blog.s135.com/post/393)
magent是一款开源的Memcached代理服务器软件,其项目网址为:http://code.google.com/p/memagent/
一、安装步骤:
1、编译安装libevent:
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable/
./configure --prefix=/usr
make && make install
cd ../
2、编译安装Memcached:
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6/
./configure --with-libevent=/usr
make && make install
cd ../
3、编译安装magent:
mkdir magent
cd magent/
wget http://memagent.googlecode.com/files/magent-0.5.tar.gz
tar zxvf magent-0.5.tar.gz
/sbin/ldconfig
sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
make
cp magent /usr/bin/magent
cd ../
二、使用实例:
memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
magent -u root -n 51200 -l 127.0.0.1 -p 12000 -s 127.0.0.1:11211 -s 127.0.0.1:11212 -b 127.0.0.1:11213
1、分别在11211、11212、11213端口启动3个Memcached进程,在12000端口开启magent代理程序;
2、11211、11212端口为主Memcached,11213端口为备份Memcached;
3、连接上12000的magent,set key1和set key2,根据哈希算法,key1被写入11212和11213端口的Memcached,key2被写入11212和11213端口的Memcached;
4、当11211、11212端口的Memcached死掉,连接到12000端口的magent取数据,数据会从11213端口的Memcached取出;
5、当11211、11212端口的Memcached重启复活,连接到12000端口,magent会从11211或11212端口的Memcached取数据,由于这两台Memcached重启后无数据,因此magent取得的将是空值,尽管11213端口的Memcached还有数据(此问题尚待改进)。
三、整个测试流程:
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
memcached agent v0.4
matrix 1 -> 127.0.0.1:11211, pool size 0
matrix 2 -> 127.0.0.1:11212, pool size 0
END
set key1 0 0 8
zhangyan
STORED
set key2 0 0 8
zhangyan
STORED
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11212
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
END
quit
Connection closed by foreign host.
[root@centos52 ~]# telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
模拟11211、11212端口的Memcached死掉
[root@centos52 ~]# ps -ef | grep memcached
root 6589 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
root 6591 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
root 6593 1 0 01:25 ? 00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
root 6609 6509 0 01:44 pts/0 00:00:00 grep memcached
[root@centos52 ~]# kill -9 6589
[root@centos52 ~]# kill -9 6591
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.
模拟11211、11212端口的Memcached重启复活
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
END
quit
Connection closed by foreign host.
相关文章推荐
- 无光驱U盘启动安装CentOS 6.3
- CentOS 6.3 NFS的安装配置、启动及mount挂载方法
- CentOS 6.3 NFS的安装配置、启动及mount挂载方法
- CentOS6.3采用server方式安装后网卡不能加载或启动时不能连接网卡的问题
- CentOS6.3编译安装Memcached的PHP客户端memcache
- CentOS 6.3 安装php 5.4.13 phpredis ,phpmemcache
- CentOS 6.3 NFS的安装配置、启动及mount挂载方法
- [转载]centos6.3安装启动使用PostgreSQL 9.2
- 无光驱U盘启动安装CentOS 6.3
- centos6.3安装启动使用PostgreSQL 9.2
- 联想 V480c grub 启动硬盘安装 CentOS-6.3
- U盘启动安装CentOS 6.3
- U盘启动安装centos5.5+centos6.3+PXE网络安装CentOS
- CentOS 6.3安装Memcache 1.4.15步骤(Linux+Nginx+PHP+Memcached)
- 测试U盘启动安装系统之安装CentOS6.3及PXE网络安装Centos 6.3
- CentOS 6.3 NFS的安装配置、启动及mount挂载方法
- Centos6.3 安装tomcat及开机启动
- CentOS 6.4源码编译安装httpd并启动测试(转自linux公社)
- linux下memcache的安装和启动
- 在CentOS 6.3上安装gcc 4.7.0