A detailed explanation of Linux Redis installation and persistence configuration method

Source: Internet
Author: User
Tags download redis memcached redis

Redis is an open source, using ANSI C language to write, support network, can be based on memory can also be persistent log-type, Key-value database

Redis use of NoSQL database, the biggest feature is no fixed mode, that is, the format of the table is not fixed,

Generally abandon the transaction processing function and pay attention to the mass storage of read and write performance.

Redis is a key-value storage system. Like memcached, it supports a relatively larger number of stored value types, including string (string), list (linked list), set (set), Zset (sorted set– ordered set), and hash (hash type). These data types support Push/pop, Add/remove and intersection-set and differential sets and richer operations, and these operations are atomic. On this basis, Redis supports a variety of different ways of ordering. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to the disk or writes the modification operation to the appended record file, and on this basis, it realizes the Master-slave (master-slave) synchronization.

If you simply compare the differences between Redis and memcached, most will get the following view:

1, Redis not only support the simple k/v type of data, but also provide list,set,zset,hash and other data structure storage.

2, Redis support data backup, that is, Master-slave mode of master-slave replication

3, Redis support data persistence, you can keep the data in memory in the disk, restart can be loaded again to use

First download Redis and PHP extensions

Redis wget http://download.redis.io/releases/redis-2.8.13.tar.gz

PHP extension wget https://codeload.github.com/owlient/phpredis/zip/master


1 Decompression Redis
2 Copy one to/usr/local/redis
3 Make installation if you encounter an error and then add a parameter

Cflags= "-march=i686"

4 Copy redis configuration file to/etc directory

5 VI Modify Redis. conf file simple configuration a bit

One daemon Running

Daemonize=yes Modify. Dir is the path to install

Open AppendOnly Log

Appendonly=yes

And then open the REDSI service.

Redis-server/etc/redis.conf

Access to services

REDIS-CLI test can be less than read Test OK add PHP extension

First unpack the master.tar.gz package

/usr/local/php/bin/phpize

The Phpize command is prepared for compiling the PHP extension file.

./configure--with-php-config=/usr/local/php/bin/php-configmake && make install
Then modify the php.ini to find the Extension_dir, fix it instead

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
Extension = redis.so

Restart the environment

<?php
Header ("Content-type:text/html;charset=utf-8");
$redis =new Redis ();
Connect Redis
$result = $redis->connect (' 127.0.0.1 ', 6379);
echo $redis->set (' Test ', ' 12345 ');
echo $redis->get (' Test ');

?>

If you want to upgrade you can decide from the configuration

M/s Master cluster configuration

1 Master and one Slave
Master ip:127.0.0.1 port:6379
Slave1 ip:127.0.0.1 port:63791
2. Copy slave directory for easy Management

Cp-r/usr/local/webserver/redis/usr/local/webserver/redis-slave1
3. Modify slave configuration files and service scripts
--vi/usr/local/webserver/redis-slave1/conf/redis.conf--
Port 63791
Pidfile/usr/local/webserver/redis-slave1/run/redis.pid
dir/usr/local/webserver/redis-slave1/db
slaveof 127.0.0.1 6379
----------------------------------------------------------

--vi/usr/local/webserver/redis-slave1/start.sh--
#!/bin/bash
/usr/local/webserver/redis-slave1/redis-server/usr/local/webserver/redis-slave1/conf/redis.conf
---------------------------------------------------

-------vi/usr/local/webserver/redis-slave1/stop.sh---------
#!/bin/bash
Kill ' Cat/usr/local/webserver/redis-slave1/run/redis.pid '
--------------------------------------------------------
4. Start m/s service
/usr/local/webserver/redis/start.sh
/usr/local/webserver/redis-slave1/start.sh
Verify that the service is normal
Netstat-nlpt | grep redis-server
5. Verify that the Redis is valid
/USR/LOCAL/WEBSERVER/REDIS/REDIS-CLI [Default connection port: 6379 Master Service]
>set Key1 Val1
>quit

/usr/local/webserver/redis/redis-cli-p 63791 [connect Slave1 service]
>get Key1
"Val1″ (data has been successfully synchronized)
Multiple slave empathy configuration

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.