High performance Memory object cache memcached installation and database operation and management

Source: Internet
Author: User
Tags bz2 install php memcached pack zts

Meet memcached

Memcached is an open-source, high-performance distributed memory object caching system that stores all of the data in memory because a huge hash table is maintained in memory, so data from any storage type is supported. Many websites use memcached to increase the speed of access to a website, especially for large sites that require frequent access to data. Memcached is a typical C/s architecture, so you need to install Memcached server and MEMCACHEDAPI client. The memcached server is written in C, and the Memcached API client can be written in any language, such as PHP, Python, Perl, etc., and communicate with the memcached server through the memcached protocol.

When a Web client sends a request to the Web server's application, the application queries the data by calling the Memcached API client library interface to connect to the memcached server. If the data requested by the Web client is already cached in the memcached server, the memcached server returns the data to the Web client, and if the data does not exist, the Web client request is sent to the MySQL database. The data that is requested is returned by the database to memcached and to the Web client, while the memcached server also saves the data to facilitate the user's next request.

memcached caching mechanism

The cache is a memory-resident data that can be read quickly. And memcached is such a very good cache software, when the program writes the cache data request, the Memcached API interface routes the key input routing algorithm module to one server in the cluster, then communicates with the server by the API interface and completes a distributed cache write.

Installing the memcached case

This case is done using two CentOS 7 systems and one Windows 7, two CentOS 7 in one is the memcached server and the other is Memcached API client based on the memcached extension of the lamp architecture.

Memcached服务器IP: 192.168.10.172主要软件包:libevent-2.1.8-stable.tar.gz memcached-1.5.6.tar.gzMemcached API客户端IP:192.168.10.154主要软件包:httpd-2.4.29.tar.gz mysql-5.6.26.tar.gz php-5.6.11.tar.bz2 libevent-2.1.8-stable.tar.gz memcached-1.5.6.tar.gz 测试主机IP:192.168.10.145
Install Memcached server 1, unzip the relevant package
tar xzvf memcached-1.5.6.tar.gz -C /opt/tar xzvf libevent-2.1.8-stable.tar.gz -C /opt/
2, memcached server-side operation
cd /opt/libevent-2.1.8-stable  ./configure --prefix=/usr/local/libevent      //指明安装路径make && make installcd /opt/memcached-1.5.6./configure --prefix=/usr/local/memcached \     //指明安装路径--with-libevent=/usr/local/libevent/      //指明libevent安装路径make && make installln -s /usr/local/memcached/bin/* /usr/local/bin/    memcached -d -m 32m -p 11211 -u root     //开启服务,-d守护进程 -m缓存大小32M -p端口11211netstat -anpt | grep memc   //查看端口,确认开启systemctl stop firewalld.servicesetenforce 0      //关闭防火墙和安全功能

memcached Data manipulation
#登录yum install telnet -y   //安装telnet进行连接登录telnet 127.0.0.1 11211      //本机所以是127.0.0.1#输入数据add username 0 0 7 //不进行压缩和序列化标识 数据过期时间为永不过期  标识号是7就需要输入7位数。example //输入数据#获取数据get username   //获取数据VALUE username 0 7examplegets usernameVALUE username 0 7 1     //最后一位是更新因子会自增1example#更新数据set username 0 0 10    //更新信息,若键名不存在,则自行添加everythingreplace username 0 0 8    //更新信息,若键名不存在,则报错12345678#检查更新gets usernameVALUE username 0 8 412345678cas username 0 0 7 4     //检查更新,更新因子相等则更新否则返回EXISTSlodgingSTORED#追加数据append username 0 0 7    //键值后追加数据exampleSTOREDprepend username 0 0 2   //键值前追加数据unSTORED#清楚数据delete usernameflush_all      //清除所有缓存数据OK#显示状态信息stats //显示状态信息#退出quit //退出
3, the client build lamp architecture 1, install Apache

The following two Apr plugins are required for future versions of httpd2.4

tar xzvf apr-1.6.2.tar.gz -C /opttar xzvf apr-util-1.6.0.tar.gz -C /opttar xzvf httpd-2.4.29.tar.gz -C /optcd /optmv apr-1.6.2 httpd-2.4.29/srclib/aprmv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Install the Environment pack

yum -y install gcc gcc-c++ make pcre-devel expat-devel perl

Configuring and compiling the installation

cd /opt/httpd-2.4.29./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgimake && make install

Copy the startup script into the/etc/init.d/directory to facilitate service management, modify the script

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpdvi /etc/init.d/httpd# chkconfig: 35 85 21  //35级别自动运行  第85个启动 第21个关闭# description: Apache is a World Wide Web serverchkconfig --add httpd //将httpd加入到SERVICE管理器

Modify master configuration file, specify domain name and listening port

vi /usr/local/httpd/conf/httpd.confServerName www.yun.com:80Listen 192.168.175.130:80

Create soft links for ease of administration, turn off firewalls and start services

ln -s /usr/local/httpd/conf/httpd.conf /etc/ln -s /usr/local/httpd/bin/* /usr/local/bin/systemctl stop firewalld.servicesetenforce 0    //关闭防火墙及安全功能httpd -t apachectl -t       //检查是否有误systemctl start httpd.service    //开启服务netstat -anpt | grep 80           //检查端口

2. Install MySQL

Install the relevant Environment pack

yum install -y ncurses-devel autoconf cmake

Unpack packages, configure, compile and install

tar xzvf mysql-5.6.26.tar.gz -C /optcd /opt/mysql-5.6.26cmake  -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.sockmake && make install

Copy the startup script to the/etc/init.d/directory for easy service management

cp support-files/my-default.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqldchmod 755 /etc/init.d/mysqld    //给启动脚本加权限   chkconfig --add /etc/init.d/mysqld     //添加到service管理器中chkconfig  mysqld --level 35 on     //35级别开机自启动

Setting environment variables

echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile    //环境变量source /etc/profile   //刷新环境变量echo $PATH     //查看

Create a database administrative user, initialize the database

useradd -s /sbin/nologin mysqlchown -R mysql:mysql /usr/local/mysql/cd /opt/mysql-5.6.26/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   //方便管理创建软链接

Modify the master configuration file and turn on the service

vi  /etc/init.d/mysqldbasedir=/usr/local/mysql        //指明安装目录datadir=/home/mysql       //指明数据存放目录

systemctl start mysqld.service //开启服务netstat -anpt | grep 3306      //检查端口是否开启mysqladmin -u root -p password "abc123" //给root账号设置密码

3. Install PHP

Install GD Library and related environment package

yum -y install gd libpng libpng-devel pcre pcre-devel libxml2-devel libjpeg-devel

Unzip the package, configure, and compile the installation

tar xjvf php-5.6.11.tar.bz2 -C /optcd /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

Easy to manage create soft links

cp php.ini-development /usr/local/php5/php.iniln -s /usr/local/php5/bin/* /usr/local/bin/ln -s /usr/local/php5/sbin/* /usr/local/sbin/

Edit the Apache master configuration file to support PHP

vim /etc/httpd.conf #插入下两行内容AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps#添加PHP类型的首页DirectoryIndex index.php index.html



Home directory to add PHP type home page, you can use the browser test

vi /usr/local/httpd/htdocs/index.php<?phpphpinfo();?>浏览器测试“http://192.168.10.154/index.php”


The following test database is working properly

mysql -u root -p      //进入数据库CREATE DATABASE sky;      //创建sky库GRANT all ON sky.* TO ‘skyuser‘@‘%‘ IDENTIFIED BY ‘admin123‘;      //允许任何网段用skyuser用户,admin123密码访问flush privileges;        //刷新#修改PHP类型的首页文件内容为如下内容<?php$link=mysql_connect(‘192.168.175.130‘,‘skyuser‘,‘admin123‘);if($link) echo "


4, Memcached API Client 1, installation Memcache
yum install autoconf -ytar xzvf memcache-2.2.7.tgz -C /opt/cd /opt/memcache-2.2.7/usr/local/php5/bin/phpize //增加为PHP的模块后再对memcache进行配置编译./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config     //配置make && make install/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/ //记录编译安装完的最后一行此内容,下面用到vim /usr/local/php5/php.ini //搜索并修改下面一行,再新增一行内容如下extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"    

The following is the client to detect whether the server can connect
vim /usr/local/httpd/htdocs/index.php //编写测试页面,测试memcached工作是否正常#重新插入如下内容<?php$memcache = new Memcache();$memcache->connect(‘192.168.175.128‘,11211);$memcache->set(‘key‘,‘Memcache test Successfull!‘,0,60);$result = $memcache->get(‘key‘);unset($memcache);echo $result;?>systemctl restart httpd.service     //重启Apachehttp://192.168.10.154/index.php  //输入客户端地址测试是否成功


High performance Memory object cache memcached installation and database operation and management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.