準備一台機器,系統版本為centos7。(注意本文描述的是redis-cluster,不是主從複製)
# wget
2、解壓
# tar xvf redis-3.2.8.tar.gz -c /usr/local/
# cd /usr/local/
# ln -sv redis-3.2.8/ redis
3、編譯
# yum groupinstall -y "development tools"
# cd redis
# make
4、為多例項redis配置啟動環境
# mkdir -pv /home/redis-cluster/
# cp src/ /home/redis-cluster/9000/
# cp src/ /home/redis-cluster/9001/
# cp src/ /home/redis-cluster/9002/
# cp redis.conf sentinel.conf /home/redis-cluster/9000/
# cp redis.conf sentinel.conf /home/redis-cluster/9001/
# cp redis.conf sentinel.conf /home/redis-cluster/9002/
5、修改配置檔案
# vim /home/redis-cluster/9000/redis.conf
bind 192.168.135.170
port 9000
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
# \cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9001/redis.conf
# \cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9002/redis.conf
# vim /home/redis-cluster/9001/redis.conf
port 9001
# vim /home/redis-cluster/9002/redis.conf
port 9002
6、啟動三個redis例項
# cd /home/redis-cluster/9000/
# ./redis-server redis.conf
# cd ../9001/
# ./redis-server redis.conf
# cd ../9002/
# ./redis-server redis.conf
# ps -ef | grep redis
root 15583 1 0 00:32 ? 00:00:00 ./redis-server 192.168.135.170:9000 [cluster]
root 15592 1 0 00:33 ? 00:00:00 ./redis-server 192.168.135.170:9001 [cluster]
root 15597 1 0 00:33 ? 00:00:00 ./redis-server 192.168.135.170:9002 [cluster]
7、安裝ruby環境
# yum install -y ruby
# gem install redis
8、啟動redis集群
9、檢視集群狀態
# /usr/local/redis/src/redis-cli -c -h 192.168.135.170 -p 9000
9000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:3
cluster_size:3
cluster_current_epoch:3
cluster_my_epoch:1
cluster_stats_messages_sent:364
cluster_stats_messages_received:364
centos7 安裝單節點redis
由於是在vmware中安裝,所以首先要配置虛擬機器相關環境,網路介面使用nat。虛擬機器環境配置 靜態ip,可參考centos7 靜態ip 主機名 hostnamectl set hostname redis singlegcc環境 yum y install gcc tcl y redis編譯及安...
Centos 7 搭建 Redis 單節點集群
yum y install gcc automake autoconf libtool maketar zxvf redis 5.0.0.tar.gz cd redis 5.0.0 make make install mkdir redis cluster cd redis cluster mkdi...
Redis學習 Centos7下安裝Redis
root cd opt root zxk opt ll root zxk opt wget root zxk opt tar xzf redis 5.0.4.tar.gz root zxk opt cd redis 5.0.4 root zxk redis 5.0.4 make2 make完後 re...