码迷,mamicode.com
首页 > 系统相关 > 详细

memcache

时间:2018-04-13 16:20:06      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:memcache

192.168.4.5
yum -y install memcached telnet

NoSQL数据库、KV数据库、缓存数据库(快)

CPU > 内存 > 硬盘 > 数据库 (SQL:增,删,改,查)

#systemctl start memcached
#netstat -nutlp |grep memcache

#telnet 127.0.0.1 11211

set name 0 100 3
tom
get name
存储一个key,名称name,值是tom
set key 0 100 3
xxx
get key

set key 0 100 3
存储的数据不压缩
数据存储100秒
存储的数据为3个字符

add name 0 180 10 //仅可以新建
set name 0 180 10 //可以新建或替换覆盖
replace name 0 180 10 //仅可以替换覆盖
get name //查询
append name 0 180 10 //追加
delete name //删除
stats //查看状态
flush_all //清空所有

memcached的端口?
memcached缓存的大小?

#systemctl start memcached
#cat /usr/lib/systemd/system/memcached.service
#cat /etc/sysconfig/memcached

确认下自己LNMP环境:
如果没有LNMP环境,可以在lnmp_soft目录下找到install_lnmp.sh,运行脚本根据提示安装即可
安装后,修改nginx配置文件/usr/local/nginx/conf/nginx.conf,将配置文件中的如下内容注释去除,并修改为如下的内容:
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

        include        fastcgi.conf;
    }

#nginx -s reload //重新加载配置文件即可

生成一个测试页面测试一下
vim /usr/local/nginx/html/test.php
<?php
phpinfo();
?>

#firefox http://192.168.4.5/test.php
nginx,php,php-fpm,
nginx配置,实现动静分离location / {}
location .php$ {}

案例:使用PHP连接memcached

yum -y install php-pecl-memcache

systemctl restart php-fpm

#cd /root/lnmp_soft/php_scripts
#cat mem.php
<?php
$memcache=new Memcache;
$memcache->connect(‘localhost‘,11211) or die (‘could not connect!! ‘);
$memcache->set(‘key‘, ‘test‘);
$get_values=$memcache->get(‘key‘);
echo $get_values;
?>
#cp mem.php /usr/local/nginx/html
#firefox http://192.168.4.5/mem.php //验证

检查:1.LNMP是否正确
2.是否给PHP安装了memcache扩展包
3.是否重启了php-fpm
4.是否启动了memcahced服务
5.是否关闭了SELinux,防火墙
6.netstat 检查80 , 9000 , 11211端口


client: eth0 192.168.4.100

proxy: eth0 192.168.4.5
eth1 192.168.2.5

web1: eth1 192.168.2.100

web2: eth1 192.168.2.200

                                                web1:tomcat
    proxy(nginx)        
    调度器                                 web2:tomcat

    upstream  toms {
        server 192.168.2.100:8080;
        server 192.168.2.200:8080;
    }    

测试集群:firefox http://192.168.4.5

两台tomcat做相同操作:
#cd /root/lnmp_soft/session
#cp test.jsp /usr/local/tomcat/webapps/ROOT/
适当修改test.jsp

再次测试:firefox http://192.168.4.5/test.jsp

实验:使用memcached缓存session会话信息

两台tomcat做相同操作:
tocmat-----将会话信息存在memcached
1.给tomcat添加扩展
#cd /root/lnmp_soft/session
#ls .jar
#cp
.jar /usr/local/tomcat/lib/

2.修改配置文件让tomcat连接特定的memcached服务器
#cd /root/lnmp_soft/session
#cp context.xml /usr/local/tomcat/conf
#vim /usr/local/tomcat/conf/context.xml
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="mem1:192.168.2.5:11211"
... ...
#/usr/local/tomcat/bin/shutdown.sh
#/usr/local/tomcat/bin/startup.sh

memcache

标签:memcache

原文地址:http://blog.51cto.com/2168836/2102935

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!