Mencached的基本架构搭建
Mencached基本部署
Mamcached概述
memcached是一套分布式的高速缓存系统,运行在内存中。memcached缺乏认证以及安全管制,这代表应该将memcached服务器放置在防火墙后。
实验准备
实验步骤
memcached服务端
1、安装环境包
[ libevent-2.1.8-stable]# yum install gcc gcc-c++ make -y
2、安装Libevent软件本体
挂载软件包,并到挂载目录下解压 [ memcached]# tar zxf libevent-2.1.8-stable.tar.gz -C /opt/ [ memcached]# cd /opt/libevent-2.1.8-stable/ //配置并编译安装 [ libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent [ libevent-2.1.8-stable]# make && make install
3、配置、安装Memcached
[ memcached]# tar zxf memcached-1.5.6.tar.gz -C /opt/ [ memcached]# cd /opt/memcached-1.5.6/ [ memcached-1.5.6]# ./configure --prefix=/usr/local/memached --with-libevent=/usr/local/libevent/ [ memcached-1.5.6]# make && make install //建立软链接 [ memcached-1.5.6]# ln -s /usr/local/memached/bin/* /usr/local/bin/ 启动服务 [ memcached-1.5.6]# memcached -d -m 32m -p 11211 -u root //“-d”:以守护进程的方式运行(后台运行) //“-m”:指定最大使用内存大小 //“-p”:指定端口 //“-u”:指定用户 [ memcached-1.5.6]# netstat -atnp | grep 11211 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 12591/memcached tcp6 0 0 :::11211 :::* LISTEN 12591/memcached #关闭防火墙和安全功能 [ memcached-1.5.6]# systemctl stop firewalld.service [ memcached-1.5.6]# setenforce 0
4、安装Telent用于连接Memcached
[ memcached-1.5.6]# yum install telnet -y //连接memcached [ memcached-1.5.6]# telnet 192.168.142.66 11211 Trying 192.168.142.66... Connected to 192.168.142.66. Escape character is ‘^]‘.
客户端
安装LAMP架构
详情见本人博客 LAMP架构之Discuz论坛(实操部分)https://blog.51cto.com/14449528/2447886
论坛搭建部分可不做
1、数据库中进行提权
[ ~]# mysql -uroot -p mysql> create database sky; mysql> grant all on sky.* to ‘skyuser‘@‘%‘ identified by ‘123123‘; mysql> flush privileges;
2、测试PHP工具能否连接数据库
[ htdocs]# vim /usr/local/httpd/htdocs/index.php <?php $link=mysql_connect(‘192.168.142.132‘,‘skyuser‘,‘123123‘); if($link) echo "<h1>Success!!!</h1>"; else echo "Fail!!"; mysql_close(); ?>
3、安装、配置memcache客户端
[ memcached]# tar zxf memcache-2.2.7.tgz -C /opt/ [ memcached]# cd /opt/memcache-2.2.7/ [ memcache-2.2.7]# /usr/local/php5/bin/phpize //为memcache生成启动脚本 [ memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config //编译&安装 [ memcache-2.2.7]# make && make install 修改PHP的配置文件 [ memcache-2.2.7]# vim /usr/local/php5/php.ini //736行后添加 extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/" extension = memcache.so
4、建立测试页面
[ memcache-2.2.7]# vim /usr/local/httpd/htdocs/index.php <?php $memcache = new Memcache(); $memcache->connect(‘192.168.142.136‘,11211); //memached服务端地址 $memcache->set(‘key‘,Memcache test Successfull!!!‘,0,60); $result = $memcache->get(‘key‘); unset($memcache); echo $result; ?>