Redis部署管理持久化遷移

來源:互聯網
上載者:User

標籤:

Redis主從部署

Master:192.168.30.131Slave01:192.168.30.132Slave02:192.168.30.134

1) 下載軟體包

這裡使用:redis-3.0.3.tar.gz

2) Redis安裝

tarzxf redis-3.0.3.tar.gzmv redis-3.0.3  /data/rediscd  /data/redismake&& make installmkdir  /data/redis_6379

3) Redis配置

找到設定檔/data/redis/redis.conf

修改如下內容:

daemonize  no 改為 yes #啟動後台運行dir ./ 改為 /data/redis_6379  #資料目錄slaveof   192.168.30.131  6379   #同步master,只在從上設定此參數

4) Redis啟動

cp /data/redis/util/redis_init_scriptetc/init.d/redis

且修改如下:

CONF=/data/redis/redis.conf

PIDFILE=/var/run/redis.pid

serviceredis start

5) Redis主從測試

redis-cli

127.0.0.1:6379>set name yang

OK

127.0.0.1:6379>get name

“yang”

總結:缺點為單點故障

 

Redis哨兵部署

架構圖:

修改檔案/data/redis/sentinel.conf如下:

Sentialmontinelmymastar  192.168.30.131  2

格式如下:

Sentialmontinel監控主機名稱字(隨意定義)  主要資料IP  連接埠號碼quorum值

quorum值計演算法:哨兵節點數量/2+1 

總結:解決了單點故障,缺點是每個資料庫依然存有叢集中的所有資料,導致叢集的總資料存放區受限於可用儲存記憶體最小的資料庫節點,形成木桶效應。

/data/redis/src/redis-sentinel /data/redis/sentinel.conf

 

Redis持久化

兩種持久化:RDB和AOF

RDB:指定的規則“定時”將記憶體中的資料存放區在硬碟上;

AOF:在每次執行命令後將命令本身記錄下來。

 

RDB設定(預設開啟):

根據配置規則進行自動快照

使用者執行save或bgsave命令

執行flushall命令

執行複製(主從)時

AOF設定:

開啟appendonly參數

指定儲存檔案appendfilename參數

 

Redis資料移轉

利用持久化遷移資料##########查看配置資訊及當前儲存的key值###########127.0.0.1:6379> INFO# Serverredis_version:3.0.3redis_git_sha1:00000000redis_git_dirty:0redis_build_id:b12f89c1e0186f28…..# Keyspacedb0:keys=7,expires=0,avg_ttl=0#########儲存最新的key值################127.0.0.1:6379> BGSAVEBackground saving started##########查看是否儲存成功##############127.0.0.1:6379> LASTSAVE(integer) 1444357287##########關閉redis伺服器##############[[email protected] ~]# killall -9 redis-server##########壓縮redis檔案並拷入另一台機器#########[[email protected] data]# tar zcf redis.gz redis_6379[[email protected] data]# scp [email protected]192.168.30.134:/data/#########登陸192.168.30.134機器並做相應配置#######修改redis.conf檔案dir /data/redis_6379#########解壓縮RDB檔案########################[[email protected] data]# tarzxf redis.gz#########重啟Redis伺服器########################[[email protected] redis_6379]# serviceredis start

 

Redis管理

以下都是在修改redis.conf設定檔

1)  指定登入伺服器

bing 127.0.0.1

註:bing參數只能綁定一個地址

2)  資料庫密碼認證

requrepass密碼

登入用戶端認證格式:

AUTH  密碼

註:從伺服器設定masterauth參數為主的密碼

3)       命令重新命名設定

rename-command  FLUSHELLdfsad

格式:

rename-command  原命令名新命令名

Redis desktop manager工具

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.