Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Memcache cache server

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

A brief introduction to MemCache

MemCache is a free, open source, high-performance, distributed distributed memory object caching system, which is used for dynamic Web applications to reduce the load of the database. It reduces the number of times to read the database by caching data and objects in memory, thus improving the speed of website access. MemCaChe is a HashMap that stores key-value pairs. Key-value storage is used in memory for any data (such as strings, objects, etc.). The data can come from database calls, API calls, or the results of page rendering. The design concept of MemCache is small and powerful, and its simple design promotes rapid deployment, easy development and solving many problems facing large-scale data cache. the open API enables MemCache to be used in most popular programming languages such as Java, C/C++/C#, Perl, Python, PHP, Ruby and so on.

Second, centos7.2+nginx+php+memcache+mysql

1. Install nginx (operate on 192.168.1.10 host)

(1) install the dependency package yum-y install pcre-devel openssl-devel (2) extract zlib and pcre tar xzf pcre-8.39.tar.gz tar zxf zlib-1.2.8.tar.gz (3) compile and install nginx

Make & & make install

(4) create the required users

Useradd nginx-s / sbin/nologin-M

(4) Link command file

Ln-s / usr/local/nginx1.14/sbin/nginx / usr/local/sbin/

(5) Open nginx and check the port

2. Install php (operate on 192.168.1.20 host)

(1) install dependency packages

Install libmcrypt

Yum-y install libxml2-devel libcurl-devel openssl-devel bzip2-devel

(2) compile and install php

Make & & make install

(3) copy the php.ini configuration file and modify

Modify the / etc/php.ini file, and change short_open_tag to on. The modified content is as follows:

Short_open_tag = On / / support php short tags

Vim / etc/php.ini

(3) create a php-fpm service script

Cp sapi/fpm/init.d.php-fpm / etc/init.d/php-fpmchmod + x / etc/init.d/php-fpm

(4) provide php-fpm configuration file and edit:

Modify 164listen = 0.0.0.0Vl9000optimize pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35

(4) Open php and check the port

3. Make a test page

Nginx

(1) modify nginx configuration file 65

(2) restart nginx

Nginx-s reload

Php (1) create required folder mkdir-p / var/www/bdqn (2) create required web page vim / var/www/bdqn/index.php

Browser testing

Install the memcached server (operate on 192.168.1.30 host)

Memcached is event handling based on libevent. Libevent is a library that encapsulates event handling functions such as epoll of Linux and kqueue of BSD operating system into a unified interface. Even if the number of connections to the server increases, it can still play the performance of Iripple O. Memcached uses this libevent library, so it can perform its high performance on Linux, BSD, Solaris, and other operating systems. First install the memcached dependency library libevent

(1) install the dependency package libevent

(2) compile and install memcached

(3) Link command file

Ln-s / usr/local/memcached/bin/memcached / usr/local/bin/

(4) Open memcached and check the port

5. Install the mecache client on php

(1) create. / configure

(3) compile and install memcache

. / configure-- enable-memcache-- with-php-config=/usr/local/php1.10/bin/php-config & & make & & make install

Configure environment variables:

Go to the user host directory and edit .bash _ profile to add a new directory to the system environment variable LD_LIBRARY_PATH

What needs to be added is as follows:

Extension=/usr/local/php1.10/lib/php/extensions/no-debug-zts-20131226/memcache.so

(4) restart php

/ etc/init.d/php-fpm restart

(5) browser testing

(6) add a test page to php

(7) memcached installs telnet

Yum-y install telnet

(8) browser testing

(9) telnet test on memcached

Using memcache to realize session sharing

Php

(1) configure Session in php.ini to memcache mode. Add session.save_handler = memcachesession.save_path= "tcp://192.168.31.250:11211?persistent=1&weight=1&timeout=1&retry_interval=15" at the end of vim / etc/php.ini

(2) Test the availability of memcache

Create a new / var/www/bdqn/test1.php file on the web server

Vim / var/www/bdqn/test1.php add

(3) restart php

/ etc/init.d/php-fpm restart

(5) browser testing

7. Test memcache cache database data

(1) create a test table on the Mysql server

(2) make test page on php

Vim / var/www/bdqn/test3.php add

(3) browser testing

(4) telnet test on memcached

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report