前言:
三大传统数据库:mysql,sqlserver,oracle 【sql数据库-存硬盘-慢】
新兴数据库:mogodb,memcached,redis 【nosql-缓存数据库-快】
构建memcached服务
1)使用yum安装软件包memcached
# yum -y install memcached
# rpm -qa memcached
2)启动服务并查看网络连接状态验证是否开启成功:
# systemctl start memcached
# systemctl status memcached
# netstat -anptu | grep memcached
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 2839/memcachedtcp 0 0 :::11211 :::* LISTEN 2839/memcachedudp 0 0 0.0.0.0:11211 0.0.0.0:* 2839/memcachedudp 0 0 :::11211 :::* 2839/memcached
验证:使用telnet访问memcached服务器
# yum –y install telnet
使用telnet连接服务器测试memcached服务器功能,包括增、删、改、查等操作。
高级应用:LNMP+memcached
部署LNMP环境
1)使用yum安装基础依赖包
# yum -y install gcc openssl-devel pcre-devel zlib-devel
2)源码安装Nginx
# useradd -s /sbin/nologin www
# tar -zxvf nginx-1.8.0.tar.gz
# cd nginx-1.8.0
# ./configure \
# make && make install
3)安装MariaDB数据库
# yum –y install mariadb mariadb-server mariadb-devel
4)安装PHP
# yum –y install php php-mysql
# yum –y localinstall php-fpm-5.4.16-36.el7_1.x86_64.rpm
5)为PHP添加memcache扩展
# yum –y install php-pecl-memcache
6)修改Nginx配置文件
# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
启动服务
1)启动Nginx服务
# systemctl stop httpd //如果该服务存在,则关闭该服务
# /usr/local/nginx/sbin/nginx
# netstat -utnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 32428/nginx
2)启动MySQL服务
# systemctl start mariadb
# systemctl status mariadb
3)启动PHP-FPM服务
# systemctl start php-fpm
# systemctl status php-fpm
创建PHP页面,使用PHP语言测试memcached服务
# vim /usr/local/nginx/html/test.php
<?php
$memcache=new Memcache; //创建memcache对象
$memcache->connect(‘localhost’,11211) or die (‘could not connect!!’);
$memcache->set(‘key’,‘test’); //定义变量
$get_values=$memcache->get(‘key’); //获取变量值
echo $get_values;
?>
客户端测试
客户端使用浏览器访问服务器PHP首页文档,检验对memcached的操作是否成功:
# firefox http://192.168.4.5/test.php