慧9建 发表于 2018-12-24 12:00:34

Memcached服务安装

  简介:
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信。
特点:
memcached作为高速运行的分布式缓存服务器,具有以下的特点。
· 协议简单
· 基于libevent的事件处理
· 内置内存存储方式
· memcached不互相通信的分布式
http://i2.运维网.com/images/blog/201809/21/024f67cb2aa3820f675be25486c31121.jpeg
具体实验:
实验环境:两台CentOS7.3系统完成(一台Memcached服务器,一台基于LAMP架构进行的Memcached API客户端)

Memcached服务器   IP:192.168.120.128
Memcached API客户端IP:192.168.120.135
**实验所需软件包:**
Memcached压缩包链接:https://pan.baidu.com/s/1pekiFGA0rv3XyM7KY58jUA
  提取码:6uff
=========================memcached服务器端========================
# mkdir /abc
# mount.cifs //192.168.100.10/rhel7 /abc
Password for root@//192.168.100.10/rhel7:
# cd /abc/memcached/
# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt/
# tar zxvf memcached-1.5.6.tar.gz -C /opt/
# cd /opt/
# yum install gcc gcc-c++ make -y
# cd libevent-2.1.8-stable/
# ./configure --prefix=/usr/local/libevent
# make && make install
# cd /opt/memcached-1.5.6/
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
# make && make install
# ln -s /usr/local/memcached/bin/ /usr/local/bin/
# memcached -d -m 32m -p 11211 -u root
# netstat -ntap | grep memc
tcp      0      0 0.0.0.0:11211         0.0.0.0:               LISTEN      58189/memcached   
tcp6       0      0 :::11211                :::*                  LISTEN      58189/memcached   
# systemctl stop firewalld.service
# setenforce 0
  ----------------------------数据操作--------------------------------------------------
# yum install telnet -y
# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
  add username 0 0 7            
//不进行压缩和序列化标识 ,数据过期时间为永不过期 ,即将输入的字符串长度(0 0 7含义)
  example               //输入数据
  get username                //获取数据
VALUE username 0 7
example
  gets username
VALUE username 0 7 1            //最后一位时更新因子会自增1
example
  set username 0 0 10         //更新信息,若键名不存在,则自行添加
everything
  replace username 0 0 8          //更新信息,若键名不存在,则报错
12345678
  gets username
VALUE username 0 8 4
12345678
  cas username 0 0 7            //检查更新,更新因子相等则更新否则返回EXISTS(不能更新)
logging
STORED
  append username 0 0 7         //键值后追加数据
example
STORED
  prepend username 0 0 2          //键值前追加数据
un
STORED
  delecte username
  flush_all                   //清除所有缓存数据
OK
  stats                   //显示状态信息
  quit                  //退出
  =====================以下安装客户端--需要LAMP========================
第二台
# mkdir /abc
# mount.cifs //192.168.100.10/rhel7 /abc
# cd /abc/memcached/LAMP-php5.6/
# tar zxvf apr-1.6.2.tar.gz -C /opt/
# tar zxvf apr-util-1.6.0.tar.gz -C /opt/
# tar jxvf httpd-2.4.29.tar.bz2 -C /opt/
# mv apr-1.6.2/ httpd-2.4.29/srclib/apr
# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
# yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
  # cd httpd-2.4.29
# ./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
  # make && make install
# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd
#chkconfig: 35 85 21      //第二行插入
  # chkconfig --add httpd
# vim /usr/local/httpd/conf/httpd.conf
  ServerName www.yun.com:80   //第197行
Listen 192.168.120.135:80       //第51行(注释第52行)
  # ln -s /usr/local/httpd/conf/httpd.conf /etc/
# ln -s /usr/local/httpd/bin/ /usr/local/bin/
# apachectl -t
Syntax OK
# service httpd start
# netstat -ntap | grep 80
tcp      0      0 192.168.120.135:80      0.0.0.0:               LISTEN      71464/httpd
  ------------------------------安装Mysql------------------------------------------
# yum install -y ncurses-devel autoconf cmake
# cd /abc/memcached/LAMP-php5.6/
# tar xzvf mysql-5.6.26.tar.gz -C /opt/
# cd /opt/mysql-5.6.26/
  cmake\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DSYSCONFIDIR=/etc \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
  #make && make install
(等待很长时间)
# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? yes
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld      
# chkconfig --add /etc/init.d/mysqld
# chkconfigmysqld --level 235 on
# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile
# useradd -s /sbin/nologin mysql
# chown -R mysql:mysql /usr/local/mysql/
# /usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
  # ln -s /var/lib/mysql/mysql.sock/home/mysql/mysql.sock
# vim /etc/init.d/mysqld
  basedir=/usr/local/mysql            //第46行
datadir=/home/mysql   //第47行
  # service mysqld start
Starting MySQL. SUCCESS!
# netstat -anpt | grep 3306
tcp6       0      0 :::3306               :::*                  LISTEN      86823/mysqld      
# mysqladmin -u root -p password "abc123"
Enter password:
# mysql -uroot -pabc123
  ------------------------------------------------以下安装PHP----------------------------
  #yum -y install \
gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
  # cd /abc/memcached/LAMP-php5.6/
# tar xjvf php-5.6.11.tar.bz2 -C /opt/
# cd /opt/php-5.6.11/
#./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
  # make && make install
# cp php.ini-development /usr/local/php5/php.ini
# ln -s /usr/local/php5/bin/ /usr/local/bin/
# ln -s /usr/local/php5/sbin/ /usr/local/sbin/
# vim /etc/httpd.conf
  AddType application/x-httpd-php .php            //第394行
AddType application/x-httpd-php-source .phps      //第395行
  DirectoryIndex index.html index.php         //第256行
  #vim /usr/local/httpd/htdocs/index.php

  # mv index.html index.php
mv:是否覆盖"index.php"? yes
# service httpd restart
# systemctl stop firewalld.service
# setenforce 0
  在网页测试“http://192.168.120.135/index.php”
http://i2.运维网.com/images/blog/201809/21/fb52136e1bcfab178006a990207e3d7d.jpg
# vim index.php
  
  # mysql -uroot -p
Enter password:
  mysql> CREATE DATABASE sky;
Query OK, 1 row affected (0.00 sec)
  mysql> GRANT all ON sky.* TO 'skyuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected (0.12 sec)
  mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)
  # service httpd restart
在网页测试“http://192.168.120.135/index.php”
http://i2.运维网.com/images/blog/201809/21/7c0ee9f55492ddbc21351256a8e99eac.jpg
#测试php能否解析连接mysql
  # cd /abc/memcached/
# tar zxvf memcache-2.2.7.tgz -C /opt/
# cd /opt/memcache-2.2.7/
# /usr/local/php5/bin/phpize   //增加为PHP的模块后再对memcache进行配置
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
  # ./configure \
--enable-memcache \
--with-php-config=/usr/local/php5/bin/php-config
  # make && make install
# vim /usr/local/php5/php.ini
  extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"   //第737行
extension=memcache.so                     //第738行
  # cd /usr/local/httpd/htdocs/
# vim index.php
  
  # service httpd restart
在网页测试“http://192.168.120.135/index.php”
http://i2.运维网.com/images/blog/201809/21/8b7868a7b373918860bb7c3898bc01cf.jpg
  基础Memcached服务就搭建完毕了,下一篇将介绍Memcached群集服务。



页: [1]
查看完整版本: Memcached服务安装