這是以前在csdn上的博客, 遷移到掘金html
今天記錄下redis的安裝過程node
根據Redis官方介紹, Redis是一種開源(BSD許可)、內存中的數據結構存儲,用做數據庫、緩存和消息代理,它支持數據結構,如字符串、散列、列表、集合、帶範圍查詢的排序集、位圖、超loglogs、帶半徑查詢的地理空間索引和流。Redis具備內置的複製、Lua腳本、LRU退出、事務和不一樣級別的磁盤持久性,並經過Redis Sentinel和使用Redis集羣的自動分區提供高可用性。redis
Redis一共支持5種數據類型的存儲數據庫
string類型是最基礎的存儲類型,一個key對應一個value。 最大能夠存儲512M緩存
hash 是一個鍵值(key=>value)對集合。bash
list是簡單的字符串列表數據結構
set是string類型的無序集合。 且集合是經過哈希表實現的,因此添加,刪除,查找的複雜度都是O(1)。app
zset 和 set 同樣也是string類型元素的集合,且不容許重複的成員。ui
此次經過wget直接下載而後安裝spa
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
複製代碼
tar -zxvf redis-5.0.3.tar.gz
複製代碼
mkdir -p /opt/redis
複製代碼
make PREFIX=/opt/redis install
複製代碼
若是make出錯, 執行
yum install gcc
cp redis.conf /opt/redis/
複製代碼
# 進入/opt/redis下
cd /opt/redis/
# 啓動
./bin/redis-server ./redis.conf
# 查看是否啓動
ps -ef | grep redis
複製代碼
上面的啓動是在前臺啓動, 在後臺啓動有一下兩種方式
方式一 & 表明 運行到後臺
./bin/redis-server ./redis.conf &
複製代碼
方式二 修改redis.conf文件 找到daemonize 把no改爲yes
daemonize yes
# 啓動
./bin/redis-server ./redis.conf
複製代碼
關於Redis集羣的安裝, 這裏有Redis集羣規範,你們能夠參考下 針對Ruby方式的集羣, 能夠參考文檔Redis集羣指南
Redis 5.0以後放棄使用Ruby方式的集羣, 改用C語言方式的redis-cli 集羣, 簡化了集羣方式
CentOs 7 Redis 5.x
要讓 Redis3.0 集羣正常工做至少須要 3 個 Master 節點,要想實現高可用,每一個 Master 節點要配備 至少 1 個 Slave 節點。根據以上特色和要求,進行以下的集羣實施規劃:
下面進行安裝 (下載, 解壓同單機安裝)192.168.87.129
mkdir -p /opt/redis/redis-7111
mkdir -p /opt/redis/redis-7112
複製代碼
192.168.87.130
mkdir -p /opt/redis/redis-7113
mkdir -p /opt/redis/redis-7114
複製代碼
192.168.87.131
mkdir -p /opt/redis/redis-7115
mkdir -p /opt/redis/redis-7116
複製代碼
192.168.87.129
make PREFIX=/opt/redis/redis-7111 install
make PREFIX=/opt/redis/redis-7112 install
複製代碼
192.168.87.130
make PREFIX=/opt/redis/redis-7113 install
make PREFIX=/opt/redis/redis-7114 install
複製代碼
192.168.87.131
make PREFIX=/opt/redis/redis-7115 install
make PREFIX=/opt/redis/redis-7116 install
複製代碼
192.168.87.129
mkdir -p /opt/redis/redis-7111/cluster/7111
mkdir -p /opt/redis/redis-7112/cluster/7112
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7111/cluster/7111
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7112/cluster/7112
複製代碼
192.168.87.130
mkdir -p /opt/redis/redis-7113/cluster/7113
mkdir -p /opt/redis/redis-7114/cluster/7114
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7113/cluster/7113
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7114/cluster/7114
複製代碼
192.168.87.131
mkdir -p /opt/redis/redis-7115/cluster/7115
mkdir -p /opt/redis/redis-7116/cluster/7116
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7115/cluster/7115
cp /usr/local/opt/redis-5.0.3/redis.conf /opt/redis/redis-7116/cluster/7116
複製代碼
port 7111 #端口 一一對應修改
cluster-enabled yes #啓用集羣模式
cluster-config-file /opt/redis/redis-7111/cluster/7111/nodes.conf # 一一對應修改
cluster-node-timeout 5000 #超時時間
appendonly yes
daemonize yes #後臺運行
protected-mode no #非保護模式
pidfile /var/run/redis_7111.pid # 一一對應修改
dir /opt/redis/redis-7111/cluster/7111 # 一一對應修改(非必須, 建議配置)
databases 1
複製代碼
192.168.87.129
./opt/redis/redis-7111/bin/redis-server /opt/redis/redis-7111/cluster/7111/redis-7111.conf
./opt/redis/redis-7112/bin/redis-server /opt/redis/redis-7112/cluster/7112/redis-7112.conf
複製代碼
192.168.87.130
./opt/redis/redis-7113/bin/redis-server /opt/redis/redis-7113/cluster/7113/redis-7113.conf
./opt/redis/redis-7114/bin/redis-server /opt/redis/redis-7114/cluster/7114/redis-7114.conf
複製代碼
192.168.87.131
./opt/redis/redis-7115/bin/redis-server /opt/redis/redis-7115/cluster/7115/redis-7115.conf
./opt/redis/redis-7116/bin/redis-server /opt/redis/redis-7116/cluster/7116/redis-7116.conf
複製代碼
啓動以後經過ps -ef | grep redis
查看啓動結果
啓動成功後接下來準備建立集羣 隨便在那一臺機器上操做均可以,
/usr/local/opt/redis-5.0.3/src/redis-cli --cluster create 192.168.87.129:7111 192.168.87.130:7113 192.168.87.131:7115 192.168.87.129:7112 192.168.87.130:7114 192.168.87.131:7116 --cluster-replicas 1
複製代碼
須要設置那些爲master就將地址寫在前面
稍等片刻會出現確認信息, 仔細查看節點配置是否正確。 正確輸入yes便可
Creating cluster
Connecting to node 192.168.87.129:7111: OK
Connecting to node 192.168.87.130:7113: OK
Connecting to node 192.168.87.131:7115: OK
Connecting to node 192.168.87.129:7112: OK
Connecting to node 192.168.87.130:7114: OK
Connecting to node 192.168.87.131:7116: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.87.129:7111
192.168.87.130:7113
192.168.87.131:7115
Adding replica 192.168.87.129:7112 to 192.168.87.129:7111
Adding replica 192.168.87.130:7114 to 192.168.87.130:7113
Adding replica 192.168.87.131:7116 to 192.168.87.131:7115
M: 007a3fe8d7451d3d0a78fffd2653c8641809499c 192.168.87.129:7111
replicates 94e140b9ca0735040ae3428983835f1d93327aeb
M: ea69b6b6e2e7723eed50b1dabea9d244ccf3f098 192.168.87.130:7113
replicates c642b3071c4b2b073707ed3c3a2c16d53a549eff
M: 5f09dc0671732cf06a09f28631c90e0c68408520 192.168.87.131:7115
replicates 896a3c99da4fcf680de1f42406fccb551d8c40c3
S: 94e140b9ca0735040ae3428983835f1d93327aeb 192.168.87.129:7112
slots:10923-16383 (5461 slots) master
S: c642b3071c4b2b073707ed3c3a2c16d53a549eff 192.168.87.130:7114
slots:5461-10922 (5462 slots) master
S: 896a3c99da4fcf680de1f42406fccb551d8c40c3 192.168.87.131:7116
slots:0-5460 (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
(輸入 yes 並按下回車確認以後,集羣就會將配置應用到各個節點,並鏈接起(join)各個節點,也就是
讓各個節點開始互相通信)
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join....
>>> Performing Cluster Check (using node 192.168.87.129)
M: 007a3fe8d7451d3d0a78fffd2653c8641809499c 192.168.87.129:7111
slots: (0 slots) master
replicates 94e140b9ca0735040ae3428983835f1d93327aeb
M: ea69b6b6e2e7723eed50b1dabea9d244ccf3f098 192.168.87.130:7113
slots: (0 slots) master
replicates c642b3071c4b2b073707ed3c3a2c16d53a549eff
M: 5f09dc0671732cf06a09f28631c90e0c68408520 192.168.87.131:7115
slots: (0 slots) master
replicates 896a3c99da4fcf680de1f42406fccb551d8c40c3
M: 94e140b9ca0735040ae3428983835f1d93327aeb 192.168.87.129:7112
slots:10923-16383 (5461 slots) master
M: c642b3071c4b2b073707ed3c3a2c16d53a549eff 192.168.87.130:7114
slots:5461-10922 (5462 slots) master
M: 896a3c99da4fcf680de1f42406fccb551d8c40c3 192.168.87.131:7116
slots:0-5460 (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
複製代碼
到此Redis5.x集羣正式結束
./redis-cli -c -p 7111
複製代碼