Redis for Nosql database service


A picture to explain the branch products of DB


image

Nosql database introduction

It is a non-relational database service that can solve the concurrency capabilities of conventional databases, such as the IO and performance bottlenecks of traditional databases. It is also a supplement to relational databases with relatively good high efficiency and high performance.

Focus on redis, memcached, ttserver for key-value queries

Solve the following problems:

1) High concurrent read and write requirements for the database

2) High-efficiency storage and access requirements for big data

3) High scalability and high availability requirements

Application environment of Nosql database

1) The data model is relatively simple

2) Need more flexible IT system

3) Higher performance requirements for the database

4) No need for high data consistency

5) For a given KEY, it is easier to map an environment with complex values

Classification and characteristics of Nosql software

1) Key-value key-value storage database (redis, memcached)

  1. Used for content caching, suitable for load and expansion of large data sets

  2. The data type is a series of key-value pairs

  3. Has a quick query function, but the stored data is less structured

  4. The support for transactions is not good, and the rollback cannot be performed when a database failure occurs

image

2) Column storage database (HBase)

  1. For distributed file system

  2. Column cluster storage, storing the same column data together

  3. Fast search speed, strong scalability, and easier distributed expansion

  4. Relatively limited functions

image

3) File-oriented database (mongoDB)

  1. More used for WEB applications

  2. The data type is a series of key-value pairs

  3. The query performance is not high, there is no unified query syntax

image

4) Graph

  1. More social network applications

  2. It is not easy to make a distributed cluster solution

image

Introduction to commonly used Nosql databases

1)memcached

Is an open source high-performance cache system with distributed memory objects

Features:

1. Simple installation and deployment

2. Support high concurrency and high performance

3. Distributed can be realized through program or load balancing

4. Only memory cache, restart service data loss

Official website: http://memcached.org

2)memcacheDB

It is an open source project developed by Sina based on memcached, with transaction recovery function

Features:

1. High concurrent reading and writing

2. Efficient storage

3. Highly available data storage

Official website: http://memcachedb.org/benchmark.html

生产环境如何选择Nosql数据库

1、最常规的缓存应用,memcached最合适

2、持久化存储方案memcacheDB

3、2000万以内数据量的小数据用memcached

4、大数据量可以用redis

redis持久化数据服务

REmote DIctionary server(redis)是一个基于key-value键值对的持久化数据库存储系统,对支持数据存储类型更多,包括字符串、列表、集合等

是一种持久化缓存服务,会周期的把更新的数据写入磁盘以及把修改操作记录追加到文件里记录下来,还支持主从同步模式,是一个开源的基于C语言编写的,支持网络、内存可持久化的日志型、key-value数据库


image

redis持久服务的特点
  1. key-value键值类型存储系统

  2. 支持数据可靠存储

  3. 单进程单线程高性能服务器

  4. 恢复比较慢

  5. 单机qps(秒并发)可以达到10W

  6. 适合小数据高速读写访问

redis存储系统优、缺点:

  1. 可以持久化存储数据

  2. 支持每秒10W的读写频率

  3. 支持丰富的数据类型

  4. 所有操作都是原子性的

  5. 支持异机主从复制

  6. 内存管理开销大(低于物理内存的3/5)

  7. 不同命令延迟差别大

官方网站:http://www.redis.io

redis持久化介绍

redis将数据存储于内存中,通过快照、日志两种方式实现持久化存储,前者性能高,会有数据丢失的情况,后者相反。

image


redis应用场景

MYSQL+memcached网站架构的问题:数据量大就需要拆表,需要扩容,数据一致性是个问题

1)最佳应用场景就是内存服务

2)作为memcached替代方案

3)对数据一致性有一定要求但不高的业务

4)需要更多数据类型支持的业务

5)需要主从同步及负载均衡的业务


redis的安装

要进行主从同步配置,可以实现故障切换,主上禁用数据持久化,从上配置,内存要够大

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

[root@redis-m tools]#tar zxf redis-2.8.24.tar.gz

[root@redis-m tools]#cd redis-2.8.24

[root@redis-m redis-2.8.24]#make

[root@redis-m redis-2.8.24]#make PREFIX=/application/redis-2.8.24 install

[root@redis-m redis-2.8.24]#ln -s /application/redis-2.8.24 /application/redis

[root@redis-m tools]# tree /application/redis

/application/redis

`-- bin

    |-- redis-benchmark #性能测试工具

    |-- redis-check-aof #检测更新日志

    |-- redis-check-dump #检查本地数据库rdb文件

    |-- redis-cli #命令行客户端操作工具

    |-- redis-sentinel -> redis-server

    `-- redis-server #服务的启动程序

配置环境变量

[root@redis-m tools]# echo "PATH=/application/redis/bin:$PATH">>/etc/profile

[root@redis-m tools]# source /etc/profile

[root@redis-m tools]# which redis-server

/application/redis/bin/redis-server

查看帮助文档

[root@redis-m tools]# redis-server --help

Usage: ./redis-server [/path/to/redis.conf] [options]

       ./redis-server - (read config from stdin)

       ./redis-server -v or --version

       ./redis-server -h or --help

       ./redis-server --test-memory <megabytes>

Examples:

       ./redis-server (run the server with default conf)

       ./redis-server /etc/redis/6379.conf

       ./redis-server --port 7777

       ./redis-server --port 7777 --slaveof 127.0.0.1 8888

       ./redis-server /etc/myredis.conf --loglevel verbose

启动服务

[root@redis-m ~]# cd /application/redis/   

[root@redis-m redis]# ll

total 4

drwxr-xr-x 2 root root 4096 Mar 22 04:50 bin

[root@redis-m redis]# mkdir conf

[root@redis-m redis]# cp /download/tools/redis-2.8.24/redis.conf ./conf/

[root@redis-m redis]# redis-server /application/redis/conf/redis.conf &

[6072] 22 Mar 05:00:51.373 # Server started, Redis version 2.8.24

[6072] 22 Mar 05:00:51.374 # 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. 

#内存不足的时候,数据加载到磁盘可能失效,可以使用命令解决或修改配置文件

[6072] 22 Mar 05:00:51.375 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

[6072] 22 Mar 05:00:51.375 * The server is now ready to accept connections on port 6379

[root@redis-m redis]# lsof -i :6379

COMMAND PID USER FD  TYPE DEVICE SIZE/OFF NODE NAME

redis-ser 6072 root 4u IPv6  24271 0t0  TCP *:6379 (LISTEN)

redis-ser 6072 root 5u IPv4 24273 0t0  TCP *:6379 (LISTEN)

vm.overcommit_memory

0 means that when user space requests more memory, the kernel tries to estimate the remaining available memory

1 means that the kernel allows the maximum use of memory

Close service command

[root@redis-m redis]# redis-cli shutdown

[6072] 22 Mar 05:09:32.699 # User requested shutdown...

[6072] 22 Mar 05:09:32.699 * Saving the final RDB snapshot before exiting.

[6072] 22 Mar 05:09:32.710 * DB saved on disk

[6072] 22 Mar 05:09:32.711 # Redis is now ready to exit, bye bye...

[1]+  Done  redis-server /application/redis/conf/redis.conf

If you need to understand the knowledge of redis cluster, please refer to the previous article

The actual combat process of the high-availability solution for the Redis cluster production environment

Recommended reading

Elaborately Organized|Public Account Article Directory

Resource Sharing|Embrace open source, share open source, love open source

How to win an interview Get a high-paying offer (2)

Zookeeper technology introduction | python book benefits

Four basic principles for operation and maintenance of standardized documents

Introduction to Docker container technology (2)

·end·



Guess you like

Origin blog.51cto.com/15127557/2668485