Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis cluster actual combat

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Practical Notes from Redis Foundation to Cluster

Persistent storage

Redis introduction

Redis is a persistent database storage system based on key-value. Redis and memcached services would like to, but the data storage types supported by redis

Richer services

Memcached supports value

Redis supports string (character) list (linked list) set (collection) push, pop

Redis performs better than memcached services, but is relatively worse than relative relational databases such as mysql

Redis supports sorting in a variety of ways. Like memcached, data is cached in memory for efficiency, but redis periodically sets the

Data is stored on disk, and redis supports master-slave (master-slave) synchronization, which is very similar to MYSQL

Advantages of redis

Data can be stored persistently

High performance: redis supports a read and write frequency of more than 100k + seconds.

Rich data types: strings lists,hashes,Sets data type operations

Redis supports master-slave replication

Redis application scenario

Problems encountered in traditional MYSQL+MEMCACHED architecture

MYSQL database is suitable for massive data storage, coupled with the hot spot data through Memcached placed in memory cache, as the number of visits increases, it will appear.

problem.

1 the MYSQL library needs to be disassembled constantly, and the Memcached also needs to be constantly expanded to take up a lot of operation and maintenance time.

Data consistency between 2Memcached and MYSQL

3Memcached database hit rate is low or crash, resulting in a large number of access to directly penetrate the database, resulting in mysql can not support access

4 synchronization consistency problem of cross-level party cache

The best application scenario of redis

All data in the best use scenario of 1Redis is in-memory (memory)

More scenes of 2Redis as an alternative to Memcached

3 when more data type support other than key/value is needed, Redis is more appropriate

4 support persistence

5 scenarios where load balancing is required (redis master-slave synchronization)

Redis deployment build

MASTER 192.168.2.1

SLAVE 192.168.2.4

MASTER:

[root@localhost ~] # ls

Anaconda-ks.cfg bbs boke install.log install.log.syslog mysql-5.5.32-linux2.6-x86_64.tar.gz redis-3.0.2.tar.gz test.sh www

[root@localhost ~] # tar zxf redis-3.0.2.tar.gz

[root@localhost ~] # cd redis-3.0.2

[root@localhost redis-3.0.2] # make MALLOC=jemalloc

[root@localhost redis-3.0.2] # make PREFIX=/application/redis install specifies the installation path

SLAVE

[root@localhost ~] # ls

Anaconda-ks.cfg bbs boke install.log install.log.syslog mysql-5.5.32-linux2.6-x86_64.tar.gz redis-3.0.2.tar.gz test.sh www

[root@localhost ~] # tar zxf redis-3.0.2.tar.gz

[root@localhost ~] # cd redis-3.0.2

[root@localhost redis-3.0.2] # make MALLOC=jemalloc

[root@localhost redis-3.0.2] # make PREFIX=/application/redis install specifies the installation path

After loading, bin has five commands.

[root@localhost bin] # ls

Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server

Redis-benchmark redis performance testing tool

Redis-check-aof update log check

Redis-check-dump

Redis-cli Redis command operation tool

Redis-sentinel is used for local database check

Initiator for redis-server Redis service

To start Redis, you need to do the environment variable.

[root@localhost redis] # export PATH=/application/redis/bin/:$PATH

[root@localhost redis] # which redis-server

/ application/redis/bin/redis-server

Modification file in permanent effect

[root@localhost redis] # vim / etc/profile

Export PATH=/application/redis/bin/:$PATH

[root@localhost redis] #. / etc/profile

Redis configuration

[root@localhost redis-3.0.2] # mkdir / application/redis/conf

[root@localhost redis-3.0.2] # cp redis.conf / application/redis/conf/

Start Redis

[root@localhost redis-3.0.2] # redis-server / application/redis/conf/redis.conf

5522 Feb M 18 Feb 05 it was originally set to 02 Feb 08.448 * Increased maximum number of open files to 10032.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.2 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 5522 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

5522:M 18 Feb 05:02:08.463 # Server started, Redis version 3.0.2

5522:M 18 Feb 05:02:08.464 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory=1' to / etc/sysctl.conf and then reboot or run the command' sysctl vm.overcommit_memory=1' for this to take effect.

5522:M 18 Feb 05:02:08.470 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

5522 M 18 Feb 05VR 02lo 08.470 * The server is now ready to accept connections on port 6379

Vm.overcommit_memory = 1 prompts for this error

Solve

[root@localhost redis-3.0.2] # sysctl vm.overcommit_memory=1

Vm.overcommit_memory = 1

[root@localhost redis-3.0.2] # redis-server / application/redis/conf/redis.conf

5560 it was originally set to M 18 Feb 05 Feb 05 it was originally set to 23.085 * Increased maximum number of open files to 10032.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.2 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 5560 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

5560:M 18 Feb 05:05:23.087 # Server started, Redis version 3.0.2

5560:M 18 Feb 05:05:23.088 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

5560 seconds M 18 Feb 05 seconds 05V 23.088 * seconds

5560VR M 18 Feb 05VR 05R 23.088 * The server is now ready to accept connections on port 6379

Success!

Test redis

[root@localhost ~] # redis-cli

127.0.0.1purl 6379 >

Create a library to view the library

127.0.0.1 purl 6379 > set no002 xiaohu

OK

127.0.0.1 purl 6379 > get no002

"xiaohu"

Do not create a library on the command line

[root@localhost] # redis-cli-h 192.168.2.1-p 6379 set no001 qi

OK

[root@localhost] # redis-cli-h 192.168.2.1-p 6379 get no001

"qi"

Delete database

[root@localhost ~] # redis-cli del no001

(integer) 1

[root@localhost ~] # redis-cli get no001

(nil)

Redis Typ

String type

List type list is an array correspondence

[root@localhost ~] # redis-cli rpush messages "hello"

(integer) 1

[root@localhost ~] # redis-cli rpush messages "hell"

(integer) 2

Display

[root@localhost ~] # redis-cli lrange messages 0 2

1) "hello"

2) "hell"

The function of redis set that sets three values on a variable value corresponding to the label.

127.0.0.1 purl 6379 > sadd myset a

(integer) 1

127.0.0.1 purl 6379 > sadd myset b

(integer) 1

127.0.0.1 purl 6379 > sadd myset c

(integer) 1

127.0.0.1 purl 6379 > smembers myset

1) "c"

2) "b"

3) "a"

Redis master-slave synchronization

MASTER 192.168.2.1

SLAVE 192.168.2.4

Edit the redis.conf of slave

Vim / application/redis/conf/redis.conf

Add under slaveof:

Slaveof 192.168.2.1 6379 main library address and port number

Slave View

[root@localhost redis-3.0.2] # redis-server / application/redis/conf/redis.conf

6631 it was originally set to S 24 Mar 06 21 it was originally set to 26.599 * Increased maximum number of open files to 10032.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.2 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 6631 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

6631:S 24 Mar 06:21:26.611 # Server started, Redis version 3.0.2

6631:S 24 Mar 06:21:26.613 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

6631 seconds S 24 Mar 06 21 seconds 26. 613 * seconds

6631 S 24 Mar 06 21 Swiss 26.613 * The server is now ready to accept connections on port 6379

6631 Mar S 24 Vol 06 21 V 27.602 * Connecting to MASTER 192.168.2.1 V 6379

6631 S24 Mar 0621RV 27.602 * MASTER SLAVE sync started has been successful

6631 S 24 Mar 06 21 V 27.603 * Non blocking connect for SYNC fired the event.

6631 replication can continue... S 24 Mar 06 21 Swiss 27.604 * Master replied to PING, replication can continue...

6631 Mar S 24 no cached master 06 21 Fringe 27.606 * Partial resynchronization not possible (no cached master)

6631 Mar S 24 7a09e0f69c3888561658ec8a480d250d219c2444:1 06 21 Fringe 27.611 * 7a09e0f69c3888561658ec8a480d250d219c2444:1

6631 receiving S 24 Mar 06 21 receiving 27.671 * receiving 83 bytes from master

6631 Mar S 24 Flushing old data 06 21 Fringe 27.671 * Flushing old data

6631 Mar S 24 Loading DB in memory 06 21 Fringe 27.671 * Loading DB in memory

6631 Mar S 24 Finished with success 06 21 Fringe 27.672 * Finished with success

MASTER View

[root@localhost ~] # redis-server / application/redis/conf/redis.conf

2178 it was originally set to M 19 Feb 03 it was originally set to 22 it was originally set to 56.204 * Increased maximum number of open files to 10032.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.2 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 2178 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

2178:M 19 Feb 03:22:56.224 # Server started, Redis version 3.0.2

2178:M 19 Feb 03:22:56.224 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory=1' to / etc/sysctl.conf and then reboot or run the command' sysctl vm.overcommit_memory=1' for this to take effect.

2178:M 19 Feb 03:22:56.224 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

2178 seconds M 19 Feb 03 22 seconds 56.224 * seconds

2178 M 19 Feb 03 22 Swiss 56.224 The server is now ready to accept connections on port 6379

2178 seconds M 19 Feb 03 seconds 37 seconds. Saving...

2178 M 19 Feb 03 37 57.014 * Background saving started by pid 2374

2374V C 19 Feb 03RV 37RV 57.046 * DB saved on disk

2374 MB of memory used by copy-on-write C 19 Feb 03 37 MB of memory used by copy-on-write 57.046 * MB of memory used by copy-on-write

2178VR M 19 Feb 03RV 37RV 57.120 * Background saving terminated with success

2178 seconds M 19 Feb 03 seconds 52V 58.020 * 1. Saving...

2178VR M 19 Feb 03Rose 52R 58.031 * Background saving started by pid 2546

2546 C 19 Feb 03 VR 52R 58.049 * DB saved on disk

2546 MB of memory used by copy-on-write C 19 Feb 03 MB of memory used by copy-on-write 52purl 58.049 * MB of memory used by copy-on-write

2178VR M 19 Feb 03UR 52RV 58.138 * Background saving terminated with success

2178 asks for synchronization M 19 Feb 04 asks for synchronization 09 asks for synchronization 04.556 * 192.168.2.4 asks for synchronization

2178VR M 19 Feb 04V 09R 04.556 * Full resync requested by slave 192.168.2.4V 6379

2178VR M 19 Feb 04V 09R 04.556 * Starting BGSAVE for SYNC with target: disk

2178VR M 19 Feb 04VR 09R 04.557 * Background saving started by pid 2773

2773 VR C 19 Feb 04VR 09R 04.580 * DB saved on disk

2773 MB of memory used by copy-on-write C 19 Feb 04V 09V 04.581 * RDB: 6 main MB of memory used by copy-on-write library also accepted

2178VR M 19 Feb 04R 09R 04.620 * Background saving terminated with success

2178 succeeded M 19 Feb 04 succeeded 09 succeeded 04.620 * 192.168.2.4 succeeded

Do a monitoring in the slave database, and the master database writes data verification.

[root@localhost ~] # redis-cli main library to create database

127.0.0.1 6379 > set T1 xiaohu01

OK

127.0.0.1 6379 > get T1

"xiaohu01"

View synchronization from the library

[root@localhost] # redis-cli-h 192.168.2.4 get T1

"xiaohu01"

Remotely connect to view data synchronization from the library

[root@localhost ~] # redis-cli-h localhost-p 6379 monitor starts monitoring database writing from the library

OK

1458772016.182626 [0 192.168.2.1 6379] "PING"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report