CentOS 7 Deployment memcached cache server

Source: Internet
Author: User
Tags memcached zend

1. Introduction


1.1Memcached

Memcached is an open-source, high-performance, pure memory caching service software.

MySQL database belongs to the database on disk, the data read and write is slow, and the memcached database belongs to the in-memory database, the reading speed is fast, but the data is easy to lose. Memcached does not natively support distributed clusters, and can only support distributed storage through programs. Use memcached database, improve the speed of users to visit the website, reduce the pressure of MySQL database server, improve the site's concurrent access, so work, mysql+memcached collocation.


1.2Memcached Working process



2. System Environment Preparation

[Email protected] ~]# Cat/etc/re

Redhat-release resolv.conf

[Email protected] ~]# Cat/etc/re

Redhat-release resolv.conf

[Email protected] ~]# cat/etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

[Email protected] ~]# uname-r

3.10.0-327.el7.x86_64

[Email protected] ~]# Getenforce

Disabled

[Email protected] ~]# systemctl status Firewalld.service

firewalld.service-firewalld-dynamic Firewall daemon

loaded:loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset:enabled)

Active:inactive (Dead)

[Email protected] ~]# ifconfig

Eth0:flags=4163<up,broadcast,running,multicast> MTU 1500

inet 10.0.0.21 netmask 255.255.255.0 broadcast 10.0.0.255

Inet6 Fe80::20c:29ff:fee1:ad7 Prefixlen ScopeID 0x20<link>

Ether 00:0c:29:e1:0a:d7 Txqueuelen (Ethernet)

RX packets 3228 Bytes 815585 (796.4 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX Packets 419 Bytes 52728 (51.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


Eth1:flags=4163<up,broadcast,running,multicast> MTU 1500

inet 172.16.1.21 netmask 255.255.255.0 broadcast 172.16.1.255

Inet6 fe80::20c:29ff:fee1:ae1 Prefixlen ScopeID 0x20<link>

Ether 00:0c:29:e1:0a:e1 Txqueuelen (Ethernet)

RX Packets 0 Bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX Packets Bytes 1698 (1.6 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


Lo:flags=73<up,loopback,running> MTU 65536

inet 127.0.0.1 netmask 255.0.0.0

Inet6:: 1 prefixlen ScopeID 0x10

Loop Txqueuelen 0 (Local Loopback)

RX Packets 0 Bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX Packets 0 Bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


3. Server-side Deployment memcached Services


3.1 Installing memcached

[email protected] ~]# Yum install-y memcached


3.2 Starting the memcached service

[Email protected] ~]# systemctl start Memcached.service


3.3 Testing

[[email protected] ~]# printf "set fengfyu 0 0 5\r\n12345\r\n" |nc 10.0.0.21 11211 ---write Data

STORED

[[email protected] ~]# printf "Get fengfyu 0 0 5\r\n12345\r\n" |nc 10.0.0.21 11211 ---read data

VALUE Fengfyu 0 5

12345

END

ERROR


4.web Server Client Deployment memcached


4.1 Compiling and installing memcached

[Email protected] tools]# Tar XF memcache-2.2.5.tgz

[Email protected] tools]# CD memcache-2.2.5/

[Email protected] memcache-2.2.5]#/application/php/bin/ph

[Email protected] memcache-2.2.5]#/application/php/bin/phpize

Configuring for:

PHP Api version:20121113

Zend Module Api no:20121212

Zend Extension Api no:220121212

[Email protected] memcache-2.2.5]#/configure--enable-memcache--with-php-config=/application/php/bin/php-config --with-zlib-dir && make && make install


4.2 Associating PHP with the memcached

Sed-i ' $a extension=memcache.so '/application/php/lib/php.ini


4.3 Starting PHP

/application/php/sbin/php-fpm


4.4 Client Testing

[Email protected] www]# cat/application/nginx/html/www/mc.php

<?php

$memcache = new Memcache;

$memcache->connect (' 10.0.0.21 ', 11211) or Die ("Could not Connect");

$memcache->set (' Fengyu ', ' Hello,world ');

$get _value = $memcache->get (' Fengyu ');

echo $get _value;

?>

[[email protected] www]# printf "Get fengyu\r\n" |nc 10.0.0.21 11211

VALUE Fengyu 0 11

Hello,world

END


5.web Interface Management maceched


5.1 Unzip the Memadmin package to the/application/nginx/html/www/directory

[Email protected] tools]# tar XF memadmin-1.0.12.tar.gz-c/application/nginx/html/www/


5.2 Browser Access

Http://10.0.0.7/memadmin

6.Memcached Session Sharing


6.1 Through the program implementation, WEB01 only need to write to Memcahce SESSION,WEB02 from MEMCAHCE read session, as normal data read and write (more versatile)


6.1 PHP configuration file, PHP by default, the session is stored in the file, modified to be stored in the memcached

Sed-i ' S#session.save_handler = Files#session.save_handler = memcache#; $a session.save_path = "tcp://10.0.0.21:11211" /application/php/lib/php.ini

CentOS 7 Deployment memcached cache server

Related Article

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.