Linux installation Redis Php-redis extended redis Restart shell Script Super detailed!

Source: Internet
Author: User
Tags download redis

The preface has just written a comparison of three popular products in NoSQL, this time writing about some things about Redis, the introduction of Redis, installation and extension (Php-redis, because I am phper) installation and so on. It is also written to my friends (CCCJJJZ) as well as to my own later installation use.


Table of Contents 1. Redis Introduction 2.Redis installation 3.php-redis Extension Install 4.Redis restart script 5. End


about Redis1. Introduction Redis is completely open source free, comply with BSD protocol, is a high-performance Key-value database. Redis and other Key-value cache products have the following three features:
1.Redis supports the persistence of data, can save in-memory data on disk, restart can be loaded again for use.
2.Redis not only supports simple key-value types of data, but also provides storage of data structures such as List,set,zset,hash.
3.Redis backup of supporting data, i.e. Master-slave mode data backup. 2. Advantage 1. Very high performance –redis can read the speed is 110,000 times/s, the speed of writing is 81,000 times/s.
2. Rich data types –redis supports binary case Strings, Lists, hashes, sets and Ordered sets data type operations, and is transparent to programmers without abstraction.
3. All operations of atomic –redis are atomic, meaning either successful execution or failure to execute at all. A single operation is atomic. Multiple operations also support transactions, namely atomicity, wrapped by multi and EXEC commands.
4. Rich features –redis also supports publish/subscribe, notifications, key expiration, and more.


Redis InstallationFirst, the last officer network Download Redis compressed package, Address: http://redis.io/download. There are two ways to download: 1. Download the compressed package 2.wget mode download, this need to configure the DNS address or cannot be resolved

Commandwget http://download.redis.io/releases/redis-4.0.2.tar.gz

Here is the latest version of the download 4.02, you can download the version according to your needs. If the small partner who downloaded the package needs to upload the package to the installation directory via the Remote tool (I am in usr/local because the installation is installed to this directory according to the FHS recommended self-installing software)


Second, decompression command: tar -xzvf redis-4.0.2.tar.gz


Third, enter the redis-4.0.2 directory and make to compile and install

Commandcd redis-4.0.2/



Commandmake

Four, start Redis


Commandsrc/redis-server

Five, start mode the above command Src/redis-server will start Redis but after booting the current interface can not perform any action, press CTRL + C after you exit Redis, can only be used to determine whether Redis installed successfully and successfully started. We need to have redis boot up as a daemon, as in the following way:

1. Edit the redis.conf file and change the Daemonize property to Yes (indicating that you need to run in the background).

Commandvi redis.conf
Go to the redis.conf file and save the exit after modifying the configuration. If you can't find this configuration or do not know how to edit the save, please look at the previous several blogs.


2. Specify the configuration file and start Redis

Commandsrc/redis-server redis.conf
After successful startup, you will find that the Redis interface is not there. This time we use the command: REDIS-CLI test the Redis Link:

The instructions have been successfully connected!
You can also use this command:ps -ef | grep redis

It means Redis is already running!


Php-redis Extended InstallationOne, download the extension of the compressed package, the address is: Http://pecl.php.net/package/redis. I'm down here in 2.2.8.

Second, upload to the server


I was using RZ to upload to the server's usr/local directory.

Three, decompression installation

1. Unzip the expansion pack

Commandtar zxf redis-2.2.8.tgz

2. Enter the directory and generate the Configure configuration file with Phpize

Note here is the need to use the Phpize module, if there is no installation required to install Php-dev, if installed can use the command: Whereis phpize to find his location.
Command:.[/usr/local/php/bin/phpize]
[] It represents the position of phpize.

3. Configuration

When configured here, be sure to find the correct php-config position, and also use Whereis to get the location.
Command:./configure --with-php-config=[/usr/local/php/bin/php-config]
[] It represents the position of php-config.

4. Compiling the installation

Commandmake&make install

5. Configure PHP Support

Editing a configuration file

Add the Redis extension on the last line, and then save it. Added: extension= "redis.so"

6. Restart the service

Re-launch Apache

Instructions to install successfully!


Redis Restart Script


The red circle is circled by the absolute path of the Redis restart mode, executed once every three seconds

 #! /bin/bash
while true; do
/bin/sleep 3
a=netstat -tlunp|grep redis|awk ‘{print $1}‘
if [ -z $a ];then
/redis-2.8.13/src/redis-server /redis-2.8.13/redis.conf
fi
done


 #! /bin/bash
a=ps aux|grep redis |awk ‘{print $1}‘|grep redis
if [ -z $a ];then
/redis-2.8.13/src/redis-server /redis-2.8.13/redis.conf
fi

This script is suitable for timed script crontab startup, once per minute

These two scripts are intended to monitor whether the Redis service is hung, and then restart immediately after it has been hung out


EndThere may be some aspects of the written not detailed or bad, welcome to correct me!

Linux installation Redis Php-redis extended redis Restart shell Script Super detailed!

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.