一篇文章詳解NOsql資料庫Redis

來源:互聯網
上載者:User

標籤:.gz   force   --   cep   sage   補充   變數   緩衝   test   

一圖詳解DB的分支產品

osql資料庫介紹

是一種非關係型資料庫服務,它能解決常規資料庫的並發能力,比如傳統的資料庫的IO與效能的瓶頸,同樣它是關係型資料庫的一個補充,有著比較好的高效率與高效能。

專註於key-value查詢的redis、memcached、ttserver

解決以下問題:

1)對資料庫的高並發讀寫需求
2)大資料的高效儲存和訪問需求
3)高可擴充性和高可用性的需求
Nosql資料庫的應用環境

1)資料模型比較簡單
2)需要靈活性更強的IT系統
3)對資料庫的效能要求較高
4)不需要高度資料一致性
5)對於給定KEY,比較容易映射複雜值的環境
Nosql軟體的分類與特點

1)key-valueKVStore for Redis資料庫(redis、memcached)

1.用於內容緩衝,適合負載並擴充大的資料集

2.資料類型是一系列的索引值對

3.有快速查詢功能,但儲存資料少結構化

4.對事務的支援不好,資料庫故障產生時不可進行復原

2)列儲存資料庫(HBase)

1.用於分布式的檔案系統

2.以列簇式儲存,將同一列資料存在一起

3.尋找速度快,可擴充強,更容易進行分布式擴充

4.功能相對局限

3)面向檔案的資料庫(mongoDB)

1.用於WEB應用較多

2.資料類型是一系列索引值對

3.查詢效能不高,沒有統一的查詢文法

4)圖形資料庫(Graph)

1.社交網路應用較多

2.不容易做分布式的叢集方案

常用的Nosql資料庫介紹

1)memcached

是一個開源高效能的,具有分布式記憶體對象的緩衝系統

特點:

1、安裝布署簡單
2、支援高並發、高效能
3、通過程式或負載平衡可以實現分布式
4、僅為記憶體緩衝,重啟服務資料丟失

2)memcacheDB

是新浪基於memcached開發的一個開源項目,具備了事務恢複功能

特點:

1、高並發讀寫
2、高效儲存
3、高可用資料存放區

生產環境如何選擇Nosql資料庫

1、最常規的緩衝應用,memcached最合適
2、持久化儲存方案memcacheDB
3、2000萬以內資料量的小資料用memcached
4、大資料量可以用redis
redis持久化資料服務

REmote DIctionary server(redis)是一個 基於key-value索引值對的持久化資料庫 儲存系統,對支援資料存放區類型更多,包括字串、列表、集合等

是一種 持久化快取服務 ,會周期的把更新的資料寫入磁碟以及把修改操作記錄追加到檔案裡記錄下來,還 支援主從同步模式 ,是一個開源的基於C語言編寫的,支援網路、記憶體可持久化的日誌型、key-value資料庫

redis持久服務的特點

key-value索引值類型儲存系統

支援資料可靠儲存

單進程單線程高效能伺服器

恢複比較慢

單機qps(秒並發)可以達到10W

適合小資料高速讀寫訪問

redis儲存系統優、缺點:

可以持久化儲存資料

支援每秒10W的讀寫頻率

支援豐富的資料類型

所有操作都是原子性的

支援異機主從複製

記憶體管理開銷大(低於實體記憶體的3/5)

不同命令延遲差別大

redis持久化介紹

redis將 資料存放區於記憶體中 ,通過 快照、日誌 兩種方式實現持久化儲存,前者效能高,會有資料丟失的情況,後者相反。

redis應用情境

MYSQL+memcached網站架構的問題:資料量大就需要拆表,需要擴容,資料一致性是個問題

1)最佳應用情境就是記憶體服務
2)作為memcached替代方案
3)對資料一致性有一定要求但不高的業務
4)需要更多資料類型支援的業務
5)需要主從同步及負載平衡的業務
redis的安裝

要進行主從同步配置,可以實現故障切換,主上禁用資料持久化,從上配置,記憶體要夠大

wget http://download.redis.io/releases/redis-2.8.24.tar.gz
[[email protected] tools]#tar zxf redis-2.8.24.tar.gz
[[email protected] tools]#cd redis-2.8.24
[[email protected] redis-2.8.24]#make
[[email protected] redis-2.8.24]#make PREFIX=/application/redis-2.8.24 install
[[email protected] redis-2.8.24]#ln -s /application/redis-2.8.24 /application/redis
[[email protected] tools]# tree /application/redis
/application/redis
-- bin<br/>|-- redis-benchmark #效能測試工具<br/>|-- redis-check-aof #檢測更新日誌<br/>|-- redis-check-dump #檢查本機資料庫rdb檔案<br/>|-- redis-cli #命令列用戶端操作工具<br/>|-- redis-sentinel -&gt; redis-server<br/>-- redis-server #服務的啟動程式

配置環境變數

[[email protected] tools]# echo "PATH=/application/redis/bin:$PATH">>/etc/profile
[[email protected] tools]# source /etc/profile
[[email protected] tools]# which redis-server
/application/redis/bin/redis-server

查看協助文檔

[[email protected] 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

啟動服務

[[email protected] ~]# cd /application/redis/
[[email protected] redis]# ll
total 4
drwxr-xr-x 2 root root 4096 Mar 22 04:50 bin
[[email protected] redis]# mkdir conf
[[email protected] redis]# cp /download/tools/redis-2.8.24/redis.conf ./conf/
[[email protected] 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
[[email protected] 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表示使用者空間請求更多記憶體時,核心嘗試估算出餘下可用記憶體
1表示核心允許最大限度的的使用記憶體

關閉服務命令

[[email protected] 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

Redis叢集生產環境高可用方案實戰過程

一篇文章詳解NOsql資料庫Redis

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.