memcacched的安装

memcached的安装过程:

安装软件:

#yum install memcached -y

修改配置文件:
# vim /etc/sysconfig/memcached
# cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="1500"
OPTIONS=""

[root@server 1802]# systemctl start memcached.service
[root@server 1802]# ps aux | grep memca
memcach+ 20212 0.0 0.0 325564 1180 ? Ssl 10:15 0:00 /usr/bin/memcached -u memcached -p 11211 -m 1500 -c 1024

编译安装的memcached启动方法:
# /usr/local/memcached/bin/memcached -u memcached -p 11211 -m 1500 -c 1024

编译安装的memcached开启启动方案:
1.把启动命令写到rc.local里面
# chmod a+x /etc/rc.d/rc.local
# echo '/usr/local/memcached/bin/memcached -u memcached -p 11211 -m 1500 -c 1024' >> /etc/rc.d/rc.local
# systemctl enable rc-local


2.编写shell启动脚本

--------------------
如何部署分布式缓存服务器
1.使用什么软件
2.用多少台机器,每台机器多大内存
3.如果是redis对硬盘要求也很高
4.安装软件


--------------------扩展--------------------
前端的网站可能使用php,使用memcached
使用php且和memcached在不同机器上就需要安装php的memcache扩展

测试memcached:
1.使用memcached的原始命令
# yum install telnet
# telnet 10.18.44.126 11211
Trying 10.18.44.126...
Connected to 10.18.44.126.
Escape character is '^]'.
set name 0 900 5 //设置名称为name的key
wing //给name的值
get name //查询key为name的值

set 设置key
name key的名字 自己定义
0 key的id号,需要和其他的key不一样
900 缓存过期时间
5 字符串最大长度

2.使用各个编程语言的API接口


php+php的memcache(redis)扩展
lamp
lnmp

PHP Memcache 扩展安装:(问题)
PHP Memcache 扩展包下载地址: http://pecl.php.net/package/memcache,你可以下载最新稳定包(stable)。
wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar -zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install


php测试memcached代码:
<?php
$memcache = new Memcache();
$memcache->connect('10.18.44.126',11211) or die ("could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$memcache->set('key','hello everybody',false,1000) or die("Failed to save data at the server"); //1000为过期时间
echo "Store data in the cache(data will expire in 1000 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Date from the cache:<br/>\n";
var_dump($get_result);
?>

lamp

client
|
linux+代理
|
---------------------------------------------
| | | |
apache apache php-fpm php-fpm(php fastcgi)
apache+php
|
memcached memcached

mysql


rpm包的安装测试需要安装:
yum -y install memcached
yum -y install php
yum -y php*memcac*

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值