Memcached and Redis Installation

Source: Internet
Author: User
Tags delete key fpm install php memcached zts

Memcached

1. Build up the LNMP

2. Installing dependent Packages
Yum Install-y libevent-devel

3. Installing memcached
$ cd/usr/local/src
$ wget http://memcached.org/files/memcached-1.4.33.tar.gz
$ TAR-ZXVF memcached-1.4.33.tar.gz
$ CD memcached-1.4.33
$./configure--prefix=/usr/local/memcached && make && make install

Open service
Cd/usr/local/memcached/bin
./memcached-u www-d
-p TCP port, default is 11211, can not be set
-m maximum memory, in megabytes.
-u specifies that the user, if currently root, needs to use this parameter to specify the user
-D Daemon (daemon)

4. Installing libmemcached
$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
$ tar xvzf libmemcached-1.0.18.tar.gz
$ CD lmemcached-1.0.18
$./configure--prefix=/usr/local/libmemcached--with-memcached
$ make && make install

5. Installing PHP-MEMCACHED-PHP7
wget http://www.memcached.org/files/memcached-1.4.33.tar.gz
Phpize
./configure--with-php-config=/usr/local/php7/bin/php-config
--with-libmemcached-dir=/usr/local/libmemcached/
Make && make install
Add the path from the previous step to the PHP configuration file:/usr/local/php7/etc/php.ini
extension= "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/memcached.so"
Restart Php:service php-fpm Restart

6. Using memcached
Create new object: Memcached
Add Server: Addserver
To add a key-value pair: Set
Get values based on key values: get
Delete a key-value pair: Delete
Increment specified value: increment
Minus the specified value: Decrement
Clear all caches: flush

7. Set session to save with memcached
Vi/usr/local/php7/etc/php/ini
Session.save_handler=memcached
Session.save_path= "127.0.0.1:11211"

Redis installation Uses

1.redis Installation:
Description
1) also a storage service similar to memcached's key-value mechanism
2) A non-relational database NoSQL
3) Www.redis.io www.redis.cn
Characteristics:
1) Ability to persist data storage memcache cannot
2) value supports more data types

Installation: Redis
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
1) Unzip
TAR-ZXVF redis-3.2.8.tar.gz
2) move
Cp-r Redis-3.2.8/usr/local/redis
3) Installation
Make install

Service:
After the installation is complete, there are two service programs in the/USR/LOCAL/REDIS/SRC directory
Client: REDIS-CLI
Service side: Redis-server
Service test:./redis-server
1) You need to specify the boot configuration file
2) Default configuration/usr/local/redis/redis.conf
To add an environment variable:
Vi/etc/profile
Export path= $PATH:/USR/LOCAL/REDIS/SRC
Source/etc/profile

Boot up:
1) copy config file
Cd/usr/local/redis
CP redis.conf redis_6379.conf
2) Edit Profile
Daemonize Yes # Run as daemon (background run)
3) Copy startup script file
CD utils
CP redis_init_script redis_init_script_6379
4) Edit the startup script file Redis_init_ script_6379
Exec=/usr/local/redis/src/redis-server #服务端路径
Cliexec=/usr/local/redis/src/redis-cli #客户端路径
conf=/usr/local/redis/redis_6379.conf #配置文件路径
5) test the startup script (can be viewed via PS and connected with REDIS-CLI)
./redis_init_script_ 6379 Start
6) Modify boot file/etc/rc.local
Add/usr/local/redis/utils/redis_init_script_6379 start
7) The Redis service will start automatically the next time you turn on

Service test:
1) View process
PS aux | grep Redis
2) using a client connection
Cd/usr/local/redis/src
Connection parameters
-H: Specify host
-P: Specify port number
-A: Specify password
./redis-cli
127.0.0.1:6379>ping
PONG
3) default is no password using password two ways
1. Single entry effective via command configuration
Set Password: config requirepass 123456
Get password: config get requirepass
Authorized use: Auth 123456
2. Permanent entry into force
1.VI redis_6379.conf
2. Cancel the ' Requirepass ' line comment after the password is written
Requirepass 123456
Description: Password is enabled without password and can be connected without permission action

Client actions

Common commands:
Ping to see if the server allows
Quit to close the current connection
Auth
Select: Choose Library 0-15 A total of 16 default use 0
FLUSHDB: Delete the current library
Flushall: Delete all databases
DEL: Delete key
EXISTS: Check if key exists

Data type:
String: The most basic data type is the same as the memcached Key-value
Setting: Set key value
Get: Get key
Hash (hash): is a set of key-value pairs suitable for storing objects
Settings: Hmset user:1 name xiaoming password 123456 Level 2
Get all information: Hgetall user:1
Get a single message: Hget user:1 name
List: Sort by Insertion order to add an element to the head of the list (to the left) or to the tail (to the right)
Left-hand Press: Lpush key value1 [value2 ...]
Range Display: Lrange Key strat stop
Number of displays: Llen key
Left popup: Lpop
Right Press in: Rpush
Right popup: Rpop
Collection (SET): Data in a string type without a consolidated collection is unique
Add data: Sadd key value1 [value2 ...]
Display data: Smembers key
Total displayed: SCard key
Random removal: Spop key [count] randomly removes a
Ordered set (zset:sorted set)
Unlike set, each element is associated with a double-type fraction.
Redis is a small-to-large ordering of members in a collection by fractions
Add data: Zadd key score Value
Display data: Zrange key start stop
Total displayed: Zcard key
Display range: Zcount key start stop
Display Number: Zrank key member
Show score: Zscore Key member

PHP Operation Redis:

(Error: Can ' t find PHP headers in/usr/include/php
Yum install php-devel)
1. Installing PHP Extensions
$ wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz
$ CD phpredis-2.2.7
$/usr/bin/phpize #phpize路径, available which phpize commands to view
$./configure--with-php-config=/usr/bin/php-config #/usr/bin/php as php path, Ibid. phpize
$ make && make install

2. Modify the PHP configuration file php.ini
Vi/usr/local/php7/etc/php.ini
Add the path to the previous step
Extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/redis.so

3. Restart PHP-FPM
Service PHP-FPM Restart

4. Test the expansion library for Success (Phpinfo ())

/usr/lib64/php/modules/redis.so

Memcached and Redis Installation

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.