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

Principle and deployment of Memcached

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Memcached Overview An open-source, high-performance, distributed in-memory object caching system where all data is stored in memory. Supports arbitrary storage types of data. Speeds up website access. Memcached Common Architecture

Memcached routing algorithm ● Find the remainder hash algorithm first hash with the key to get an integer, and then hash algorithm, according to the remainder of the routing, this algorithm is suitable for most data requirements, but not suitable for use in dynamically changing environments ● Consistency hash algorithm according to hash algorithm The corresponding key through a certain hash algorithm after processing mapping to form a closed loop, and then through the use of the same hash algorithm as the object storage machine will also be mapped to the ring, Clockwise Compute Store all objects in your nearest machine Suitable for use in dynamically changing environments Deploy server roles IP addresses Packages to install Memcached Server 192.168.142.139memcached-1.5.6.tar.gz, libevent-2.1.8-stable.tar.gzMemcache Client 192.168.142.130memcache-2.2.7.tgz, LAMP (httpd, mysql, php) Step 1: Configure Memcached Server

1. Install build environment

[root@server ~]# yum install gcc gcc-c++ make -y

2. Remote mount gets resource package

[root@server ~]# mount.cifs //192.168.142.1/memcached /mnt

3. Decompress the resource pack

[root@server memcached]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt[root@server memcached]# tar zxvf memcached-1.5.6.tar.gz -C /opt[root@server memcached]# tar zxvf magent-0.5.tar.gz -C /opt

4. Configure and compile installation libevent

[root@server memcached]# cd /opt/libevent-2.1.8-stable[root@server libevent-2.1.8-stable]# ./ configure --prefix=/usr/local/libevent[root@server libevent-2.1.8-stable]# make && make install

5. Build and 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

6. Establish soft links of service commands to the system for easy operation

[root@server memcached-1.5.6]# ln -s /usr/local/memcached/bin/* /usr/local/bin

7. Start service,-d daemon;-m cache size 32M ;-p port 11211; -u user

[root@server memcached-1.5.6]# memcached -d -m 32m -p 11211 -u root

8. View service port status

[root@server memcached-1.5.6]# netstat -ntap | grep memcachedtcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 129587/memcached tcp6 0 0 :::11211 :::* LISTEN 129587/memcached

9. Install memcached with telnet connection

[root@server memcached-1.5.6]# yum install telnet -y#connect using telnet [root@server memcached-1.5.6]# telnet 127.0.0.1 11211#add key name, do not set serial number, do not set expiration time, the byte length to be entered add username 0 0 #view gets username #last digit is with new factor VALUE username 0 7 1 #update, if the key name does not exist, error replace username 0 0 9#update, add to the non-existent set username 0 0 10#check update, Update if update factors are equal Otherwise return EXISTScas username 0 0 7 4 #append data after key Last digit is number of bytes appended apppend username 0 0 4 #append data before key prepend username 0 0 2 #delete key delete username #clear all cached data flush_all #display status stats #returns statistics for all key pairs stats items#returns key pairs for specified storage spaces stats cachedump 1 0 #displays information for individual slabs stats slabs#outputs the size and number of all items stats sizes#quits Step 2: Configure the LAMP architecture of the client

1. Install schema using scripts

[root@client ~]# vim lamp.sh#!/ bin/bash#Please use source to execute this script #Database default password is 123123#Remote mount df -hT| grep -o "cifs"if [ $? -ne 0 ];thenecho "Start mount"yum install expect -yread -p "Please enter the host IP providing the resource: " gongip/usr/bin/expect /etc/profileresource/etc/profileecho $PATH| grep -o "mysql"if [ $? -eq 0 ];then echo "Add successfully"else echo "Failure" exit 1fiuseradd -s /sbin/nologin mysqlchown -R mysql:mysql /usr/local/mysql//usr/local/mysql/scripts/mysql_install_db \--user=mysql \--ldata=/var/lib/mysql \--basedir=/usr/local/mysql \--datadir=/home/mysqlsed -i -e '47d' -e '46d' -e '45abasedir=/usr/local/mysql\ndatadir=/home/mysql' /etc/init.d/mysqldservice mysqld startnetstat -ntuap | grep mysqldif [ $? -eq 0 ];then echo Mysql database startup else echo failed to start exit 1 fi#read -p "Please enter the database password (custom):" mima/usr/bin/expect

5. Use your browser to visit http://192.168.142.130/index.php to test success

Step 3: Install Memcache on the client side

1. Installation environment package

[root@client ~]# yum install autoconf -y

2. Remote mount gets resource package

[root@client ~]# mount.cifs //192.168.142.1/memcached /mnt

3. Decompress the resource pack

[root@client memcached]# tar zvxf memcache-2.2.7.tgz -C /opt/

4. Go to memcache-2.2.7 directory

[root@client memcached]# cd /opt/memcache-2.2.7/

5. Add PHP modules before configuring memcache

[root@client memcache-2.2.7]# /usr/local/php5/bin/phpize

6. Configure memcache

[root@client memcache-2.2.7]# ./ configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config

7. compile and install

[root@client memcache-2.2.7]# make && make install

8. Modify PHP master configuration file

[root@client memcache-2.2.7]# vim /usr/local/php5/php.ini#Replace the quotation marks on line 736 extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"#Add the following entry extension = memcache.so

9. Write test pages, test memcache

[root@client memcache-2.2.7]# vim /usr/local/httpd/htdocs/index.php

10. Restart httpd service

[root@client memcache-2.2.7]# service httpd restart

11. Use your browser to visit http://192.168.142.130/index.php to test success

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