Installation and Use of Redis in Linux, linuxredis

Source: Internet
Author: User

Installation and Use of Redis in Linux, linuxredis
1. install and use Redis in Linux

Official download: http://redis.io/download can download different versions as needed

Download, decompress, and install:

$ Wgethttp: // download. redis. io/releases/redis-2.6.17.tar.gz

$ Tar xzf redis-2.6.17.tar.gz

$ Redis-2.6.17 cd

$ Make

The compiled executable file is in the src directory. Run Redis with the following command:

$ Src/redis-server

You can use the built-in client to connect to Redis:

$ Src/redis-cli

Redis> set foo bar

OK

Redis> get foo

"Bar"

 

Problems encountered during installation:

1. If "Youneed 'tclsh8. 5' appears in order to run the Redis test ". Run sudo apt-get install tcl8.5 to install tcl.
Then, make test to test whether it is in the redis directory.
\ O/All tests passed without errors!

Centos can be installed using yum install tcl.

You can also download tclfrom http://sourceforge.net/projects/tcl/files/tcl/and click Next to install it:

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.

Install the rpm package from the installation disc or download the compressed package from the official website (provided that gcc of earlier versions is installed ).

3. jemalloc/jemalloc. h: the file or directory does not exist.
Add the MALLOC = libc parameter to make.

 

2. Redis master-slave Replication

Configuration

Configuration replication is very simple, just add content similar to the following line in the slave configuration file:

slaveof 192.168.1.1 6379

You can change the master's IP address or address, or you can use the slaveof command to start synchronization with slave.

Set slave to master Authentication

If the master needs to log on with a password, you need to configure slave to use the password for all synchronization operations.

Try to useredis-cli:

config set masterauth <password>

Toset it permanently, add this to your config file:

masterauth <password>

 

3. Redis persistence

Snapshots

By default, Redis saves the database snapshot indump.rdb. You can set apsaradb for Redis to automatically save a dataset when the condition "at least M changes to the dataset in N seconds" is met. You can also manually ask Redis to SAVE the dataset by calling SAVE or BGSAVE.

For example, the following settings enable Redis to automatically save the dataset once the condition "at least 1000 keys have been modified in 60 seconds" is met:

save 60 1000

This persistence method is called a snapshot.Snapshotting.

Append-only file (AOF)

The Snapshot feature is not durable: If Redis is down due to a fault for some reason, the server will lose the data that has been recently written and has not been saved to the snapshot.

Starting from Version 1.1, Redis has added a completely durable persistence method: AOF persistence.

You can open the AOF method in the configuration file:

appendonly yes

From now on, every time Redis executes a command to change the dataset (such as SET), this command will be appended to the end of the AOF file. In this way, when Redis is restarted, the program can re-execute the commands in the AOF file to recreate the dataset.

How durable is AOF?

How long can you configure Redis to collect data?fsyncTo the disk once. There are three methods:

· Execute fsync every time a new command is appended to the AOF file: very slow and secure

· Fsync once per second: fast enough (similar to RDB persistence), and only one second of data will be lost in the event of a fault.

· Never fsync: Hand over data to the operating system for processing. Faster and less secure options.

The recommended (and also the default) method is fsync once per second. This fsync policy can take both speed and security into account.

 

1. Test Results

Test master-slave replication:

Run the "info" command on the host to view the machine status. Run the "keys *" command to check that the database data is empty. Run the "set" command to set the key k1 with the value v1. Run the "get" command to obtain the value v1:

 

Run the info command on the machine to view the machine status. Run the keys * command to check whether the database data is empty. Run the get command to obtain the value of k1 v1 for master-slave replication:

 


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.