preface

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

To review the basic architecture:

In this article, we will deploy the Memcached server on machine 9.

Memcached is a high-performance distributed memory object caching system, a memory-based key-value storage. Memory can be used to cache some frequently accessed data. The general purpose is to cache database query results, reduce the number of database access, and improve the speed and scalability of dynamic Web applications.

In recent years, however, it has been overtaken by Redis, which has been called “enhanced Memcached,” which trumps memcached in terms of versatility and is more powerful and flexible, but also more complex than memcached. But there are two special scenarios that memcached still rules the world. The first is caching small static data, most typically HTML snippets. In addition, memcached has an advantage over Redis when it comes to scaling horizontally. Unless you need to consider a particular reliance on memcached for certain qualifications (such as dealing with traditional applications), or if your actual use cases fall into one of the two scenarios mentioned earlier, go straight to Redis and apply them. — Memcached Redis Comparative Analysis

The deployment of

Install Memcached (machine 9)

Yum -y install GCC libevent - devel wget tar ZXVF - http://www.memcached.org/files/memcached-1.4.39.tar.gz Memcached - 1.4.39. Tar. Gzcd/configure && make && make installcd scripts
cp memcached-init /etc/init.d/memcached
chkconfig --add memcached
The # Memcached service script calls the start-memcached script and also needs to be copied to the specified path
mkdir -p /usr/share/memcached/scripts
cp start-memcached /usr/share/memcached/scripts/
cd ~
Create a connection for the path specified in the start-memcached script
ln -s /usr/local/bin/memcached /usr/bin/memcached
The scripts in # Memcached rely on Perl and start-stop-daemon, which is provided in Debain and is installed separately in CentOS
yum -y install gcc-c++ wget patch perl-core xz ncurses-devel You can install perl as well as perl-core:
#yum install perl-version perl-data-dumper # centOS minimal install requires several packages to run. "Minimal" is really small, and there is no Perl at all. I recommend installing Perl-core
# The installation of the above answers please see https://community.opmantek.com/display/OA/questions/17760323/how-to-resolve-openaudit-install-error-cant-locate -version.pm-in-inc-on-centos-7Wget https://mirrors.tuna.tsinghua.edu.cn/debian/pool/main/d/dpkg/dpkg_1.18.25.tar.xz tar - XVF dpkg_1. 18.25. Tar. Xzcd/configure --without-libselinux && make# withoutlibselinux: libselinux-devel: libselinux-devel: libselinux-devel: libselinux-devel: libselinux-devel
Copy the compiled version to /usr/local/sbin/
cp utils/start-stop-daemon /usr/local/sbin/
Start the Memcached service
vi /etc/memcached.conf
-m 512  Allocate memory size
-p 11211  TCP port to listen on
-u nobody  Configure the working user
-c 1024  # configure the maximum number of concurrent connections
-t 16  # configure the number of threads used

/usr/local/bin/memcached -h
service memcached start
iptables -I INPUT -p tcp --dport 11211 -j ACCEPT
service iptables save
Copy the code

Install Memcached extension (machines 3, 4, 5)

# Memcached for PHP (PECL: PHP Community extension library)Wget HTTP: / / http://pecl.php.net/get/memcached-2.2.0.tgz# This extension depends on libmemcachedYum, wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz y install Cyrus sasl - devel m4 autoconf# prevent phpize from running: Cannot find autoconfThe tar - ZXVF libmemcached - 1.0.18. Tar. GzcdLibmemcached-1.0.18./configure && make && make install &&cd. The tar ZXVF memcached - 2.2.0. TGZcdMemcached - 2.2.0 / usr /local/php/bin/phpize
./configure \
--with-php-config=/usr/local/php/bin/php-config
make && make install && cd. vi /usr/local/php/lib/php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcached.so

service php-fpm reload
Copy the code

Test Memcached

vi /data/www/test.php

      
Connect to the Memcached server
$mem = new Memcached();
$mem->addServer('192.168.177.19'.11211);
Key=UserName, Value=James
$mem->set('UserName'.'James');
Select * from Key where UserName = 'UserName'
echo $mem->get('UserName');
Copy the code

Now we have all the virtual machines:

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

dffaceCopyright notice: All articles are valid unless otherwise statedCC BY – NC – SA 4.0License agreement. Reproduced please indicate the source, commercial use is strictly prohibited!