Redis installation and basic operations (1)

Source: Internet
Author: User

0. Environment
linux:centos6.5

redis:3.0.5

1. Download

Mode one: Download the war package, through XFTP Copy to the Linux server, unzip;

Mode two: Linux server, execute command wget http://download.redis.io/releases/redis-3.0.5.tar.gz

2. Compiling

2.1 Decompression

TAR-ZXVF redis-3.0.5.tar.gz

2.1 Compiling

CD redis-3.0. 5/ make

2.3 The test is successful

CD src.

Open a new terminal window, execute the command:./REDIS-3.0.5/SRC/REDIS-CLI

Set Foo bar

Get foo

=============================================================

REDIS.CONF Configuration Item Description:

1, Daemonize No

Whether to start the redis-server in the background, the default is "No", change to Yes, will generate a PID file

2, Pidfile

/var/run/redis.pid,redis-server's PID file.

3. Port

Port number of the Redis-server

4, Dbfilename Dump.rdb

The location of the database files, it is best to add absolute path, if not added in the start user's home directory

5, Slaveof

Set the address and port of the master server for the primary server

6, LogLevel verbose

Log level, debug,verbose,notice,warning

7, LogFile stdout

The output file of the log, which is standard output by default. Example: Logfile/tmp/redis.log

=============================================================

Master-Slave configuration

Working principle:

After the slave is started and connected to master, it will actively send a sync command. Master will then start the background disk process and collect all the received commands to modify the dataset, and master will transfer the entire database file to slave to complete a full synchronization once the background process has finished executing. The slave server then disks and loads the database file data into memory after it receives it. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization.

If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but once the connection is successful, a full synchronization will be performed automatically.

Master-slave configuration of the same machine * * *

Master-slave configuration for different machines * * *

(1) Master-slave configuration of the same machine

1. Start two Redis servers on the same machine and listen to different ports separately

2. Environmental description

Master 6379,slave 6380

3. Modify the configuration file

Copy an REDIS.CONF,CP redis.conf redis_slave.conf

Modify the redis_slave.conf, change the port to 6380, change the slaveof to slaveof 127.0.0.1 6379

4. Testing

#启动master服务器, which is a 6379-port server./src/redis.server redis.conf# starts the slave server, which is a 6380-port server./src/Redis.server redis_slave.conf# starts the master client./src/redis.cli-h127.0.0.1-P6379#启动slave客户端./src/redis.cli-h127.0.0.1-P6380#清空master当前数据库中的所有Keys127.0.0.1:6379>Create key in Flushdb#master127.0.0.1:6379>set Foo aaaok127.0.0.1:6379>set Foo2 bbbok# see which keys exist in master127.0.0.1:6379> Keys *1)"Foo"2)"Foo2"#在slave中查看keys127.0.0.1:6380> Keys *1)"Foo2"2)"Foo"#在master中删除其中一个测试Key and view the results after the deletion. 127.0.0.1:6379>del foo (integer)1127.0.0.1:6379> Keys *1)"Foo2"#在slave中查看是否foo也已经在slave中被删除. 127.0.0.1:6380> Keys *1)"Foo2"

#查看同步状态主从关系
127.0.0.1:6379> Info
More content, only focus on what is needed: Replication items

(2) Master-slave configuration of different machines

Configuration and configuration of the same machine is basically the same way, but IP is not the same machine.

Redis installation and basic operations (1)

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.