memcached cache building

memcached cache building
Set up the server and client so that the server can link the client
web client: 192.168.247.161
Server: 192.168.247.160

[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
[root@client ~]# 
[root@nginx ~]# hostnamectl set-hostname server
[root@nginx ~]# su
[root@server ~]# 

Set up server
Deploy libevent event notification Library

[root@server ~]# mkdir /abc
mkdir: cannot create directory '/abc': File exists
[root@server ~]# mount.cifs //192.168.254.10/linuxs /abc
Password for root@//192.168.254.10/linuxs:  
[root@server ~]# cd /abc
[root@server abc]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
[root@server abc]# tar zxvf memcached-1.5.6.tar.gz -C /opt
[root@server abc]# cd /opt
[root@server opt]# ls
data  libevent-2.1.8-stable  memcached-1.5.6  nginx-1.12.2  rh
[root@server opt]# cd libevent-2.1.8-stable/
[root@server libevent-2.1.8-stable]# yum install gcc gcc-c++ make -y
[root@server libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent
[root@server libevent-2.1.8-stable]# make && make install

Once libevent is installed, install memcached

[root@server libevent-2.1.8-stable]# cd /opt/memcached-1.5.6/
[root@server memcached-1.5.6]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[root@server memcached-1.5.6]# make && make install
[root@server memcached-1.5.6]# ln -s /usr/local/memcached/bin/* /usr/local/bin/

Command Notes:

  • -d Specify daemon
  • -m 32m Specified cache 32M
  • -p 11211 Specified port
  • -u root Specifies user management
    [root@server memcached-1.5.6]# memcached -d -m 32m -p 11211 -u root
    [root@server memcached-1.5.6]# netstat -natp | grep memc
    tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      115996/memcached    
    tcp6       0      0 :::11211                :::*                    LISTEN      115996/memcached    
    [root@server memcached-1.5.6]# systemctl stop firewalld
    [root@server memcached-1.5.6]# setenforce 0

    Connect this cached database locally to see if you can connect properly

    [root@server memcached-1.5.6]# yum install telnet -y
    [root@server memcached-1.5.6]# telnet 127.0.0.1 11211
    Trying 127.0.0.1...
    Connected to 127.0.0.1.
    Escape character is '^]'.

    Add add
    Key name username
    0 means no serial number is set
    0 No time requirement, no expiration time set
    7 bytes long. Next, if the byte length you entered does not meet the requirements, you will get an error

    add username 0 0 7
    1234567
    STORED
    add users 0 0 7
    123
    STORED
    ERROR

    View input key values

    get username
    VALUE username 0 7
    1234567
    END

    value is followed by an update factor, which, if updated once, adds one

    gets username
    VALUE username 0 7 1
    1234567
    END
    set username 0 0 8
    12345678
    STORED
    gets username
    VALUE username 0 8 3
    12345678
    END

    replace means update, which fails if the current key name does not exist
    set also means update. If the current key name does not exist, a new key will be created.

    replace school 0 0 2
    NOT_STORED
    get school
    END
    replace username 0 0 9
    123456789
    STORED
    gets username
    VALUE username 0 9 4
    123456789
    END

    cas update, update by update factor, same update

    cas username 0 0 7 4
    1234567
    STORED
    gets username
    VALUE username 0 7 5
    1234567
    END
    cas username 0 0 8 2
    12345678
    EXISTS
    gets username
    VALUE username 0 7 5
    1234567
    END

    Append data after key value

    append username 0 0 4
    appe
    STORED
    get username
    VALUE username 0 11
    1234567appe
    END

    Append data before key value

    prepend username 0 0 5
    prepe
    STORED
    get username
    VALUE username 0 16
    prepe1234567appe
    END

    Delete key value

    delete username
    DELETED
    get username
    END

    stats display status information
    Clear all cached data flush_all

    flush_all
    OK
    get users
    END

    Exit: quit

    quit
    Connection closed by foreign host.
    [root@server memcached-1.5.6]# 

    The next step is to install the client. To install the client, first deploy the LAMP architecture environment. Detailed process of LAMP architecture deployment can be seen in the blog: https://blog.51cto.com/14557905/2458323

Once the LAMP is installed, install the memcahe client

[root@client abc]# yum install autoconf -y
[root@client htdocs]# cd /abc
[root@client abc]# tar zxvf memcache-2.2.7.tgz -C /opt
[root@client abc]# cd /opt
[root@client opt]# ls
httpd-2.4.29  memcache-2.2.7  mysql-5.6.26  package.xml  php-5.6.11  rh
[root@client opt]# cd memcache-2.2.7/
[root@client memcache-2.2.7]# ls
config9.m4  example.php                 memcache.php        memcache_standard_hash.c
config.m4   memcache.c                  memcache_queue.c    php_memcache.h
config.w32  memcache_consistent_hash.c  memcache_queue.h    README
CREDITS     memcache.dsp                memcache_session.c
[root@client memcache-2.2.7]# 
[root@client memcache-2.2.7]# /usr/local/php5/bin/phpize
[root@client memcache-2.2.7]# ls
acinclude.m4    config.sub    Makefile.global             memcache_standard_hash.c
aclocal.m4      configure     memcache.c                  missing
autom4te.cache  configure.in  memcache_consistent_hash.c  mkinstalldirs
build           config.w32    memcache.dsp                php_memcache.h
config9.m4      CREDITS       memcache.php                README
config.guess    example.php   memcache_queue.c            run-tests.php
config.h.in     install-sh    memcache_queue.h
config.m4       ltmain.sh     memcache_session.c
[root@client memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config
[root@client memcache-2.2.7]# make && make install
[root@client memcache-2.2.7]# vim /usr/local/php5/php.ini 
 736 ; extension_dir = "ext"
 737 extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"      #increase
 738 extension = memcache.so    #increase

Detect whether the server can connect on the web client

[root@client memcache-2.2.7]# cd /usr/local/httpd/htdocs/
[root@client htdocs]# ls
index.php
[root@client htdocs]# vim gsy.php
<?php
$memcache = new Memcache();
$memcache->connect('192.168.247.160',11211);
$memcache->set('key','Memcache test Successfull',0,60);
$result = $memcache->get('key');
unset($memcache);
echo $result;
?>
[root@client htdocs]# service httpd restart

Now you can view it on your browser

Keywords: PHP Nginx yum vim

Added by zuessh on Sun, 22 Mar 2020 07:19:16 +0200