1. Installation and use of Redis under Linux
Official Download: Http://redis.io/download You can download different versions as needed
Download, unzip and install:
$ wgethttp://download.redis.io/releases/redis-2.6.17.tar.gz
$ tar xzf redis-2.6.17.tar.gz
$ CD redis-2.6.17
$ make
The compiled executable file is src directory, you can use the following command to run Redis:
$ src/redis-server
You can use the built-in client connection Redis:
$ src/redis-cli
Redis> set Foo Bar
Ok
Redis> get foo
"Bar"
Problems encountered during installation:
1.  if "Youneed ' tclsh8.5 ' in order to run the Redis test" can run sudo apt-get install tcl8.5 tcl
make test testing Note that the redis
\o/all tests passed without errors!
CentOS can be Yum install Tcl so installed.
You can also download tclfrom the official website http://sourceforge.net/projects/tcl/files/Tcl/, and then follow these steps to install:
1. wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
2. sudo tar xzvf tcl8.6.1-src.tar.gz-c/usr/local/
3. cd/usr/local/tcl8.6.1/unix/
4. sudo./configure
5. sudo make
6. sudo make install
2. gcc: command not found
sudo yum install gcc.
mounting from the installation CD rpm package or download a compressed package from the official website (provided that the lower version is installed ) GCC ).
3. jemalloc/jemalloc.h: no file or directory
Add the malloc=libc parameter when make.
2. Redis Master-slave replication
Configuration
Configuring replication is simple, just slave add something similar to the following line in the configuration file :
slaveof 192.168.1.1 6379
You can change Master of the IP address or address, or you can use the slaveof command, Master it will start and slave the synchronization.
Set the slave to master certification
if Master need to login via password, it needs to be configured slave The password is also used for all synchronization operations.
try on a running instance, using the redis-cli
:
config set masterauth <password>
Toset It permanently, add this to your config file:
masterauth <password>
3. Redis Persistence
Snapshot
in the default case,RedisSave the DB snapshot in the name dump.rdb
Binary files. You can tellRedisto set up,Let it in"NThe data set in seconds has at leastMa Change"when this condition is met,Save the data set automatically once. You can also do this by calling SAVEor BGSAVE ,manually LetRedisSave the data set operation.
For example, The following settings will let Redis in meeting " in seconds there are at least + A key has been changed " this condition, automatically save data set once :
save 60 1000
This persistence method is called a snapshot snapshotting.
Append action-only files (append-only file,aof)
The snapshot feature is not very durable ( Durable ): if Redis failure to stop for some reason, then the server loses the data that was recently written and is still not saved to the snapshot.
from 1.1 version started, Redis adds a completely durable way of persistence: AOF persistent.
you can open it in the configuration file AOF Way :
appendonly yes
from now on, whenever Redis when executing a command that changes the data set (for example, SET ), This command will be appended to the AOF the end of the file. That way, when Redis restarts, the program can rebuild the dataset by re-executing the commands in the AOF file.
How durable is the AOF?
You can configure Redis how long before the data to disk fsync
at once. There are three ways of doing this:
· executes fsync every time a new command is appended to the AOF file : Very slow and very secure
· fsync per second : Fast enough (almost as long as the RDB is persisted), and only 1 seconds of data are lost in the case of a failure.
· never fsync: Give the data to the operating system for processing. Faster and less secure choice.
recommended (and also default) measures for each second Fsync once, this Fsync strategies can take into account speed and security.
1. Test results
To test master-slave replication:
On the host through the info command to view the machine status, through the keys* command to view the data in the database is empty, set the key K1 with the set command, the value v1, with the get command to get K1 value v1:
Check the machine status through the info command on the machine, view the data in the database with the keys* command, and get the K1 value for V1 to achieve master-slave replication with the Get command:
Installation and use of Redis under Linux