L:Linux(centos 7.6)
R: Redis(5.0.7)http://download.redis.io/releases/node
172.24.77.241(sr1.dj.com):運行Redis-Master&Slaveredis
172.24.77.242(sr2.dj.com):運行Redis--Master&Slavevim
172.24.77.243(sr3.dj.com):運行Redis--Master&Slavecentos
cd /usr/local/src/服務器
tar xvf redis-5.0.7.tar.gzide
cd redis-5.0.7測試
make PREFIX=/usr/local/redis installui
ll /usr/local/redis/spa
mkdir /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc/rest
vim /etc/sysctl.conf
net.core.somaxconn=512
vm.overcommit_memory = 1
sysctl -p
1:表示內核容許分配全部的物理內存,而無論當前的內存狀態如何。
2:表示內核容許分配超過全部物理內存和交換空間總和的內存
vim /etc/rc.d/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
chmod a+x /etc/rc.d/rc.local
init 6
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=root
Group=root
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
groupadd -g 1000 redis && useradd -u 1000 -g 1000 redis -s /sbin/nologin
mkdir -pv /usr/local/redis/{etc,logs,data,run}
chown redis.redis /usr/local/redis/ -R
systemctl start redis
/usr/local/redis/bin/redis-cli
/usr/local/redis/bin/redis-cli -h 172.24.77.241 -p 6379 -a PASSWORD
ln -sv /usr/local/redis/bin/redis-* /usr/bin/
vim /usr/local/redis/etc/redis.conf
bind 0.0.0.0
daemonize yes
master 若是密碼須要設置 293行
masterauth 123456
設置啓用密碼507行
requirepass 123456
cluster-enabled yes
systemctl start redis
/usr/local/redis/bin/redis-cli
get key*
info replication
systemctl stop redis
cp -r /usr/local/redis /usr/local/redis2
vim /usr/local/redis2/etc/redis.conf
port 6380
/usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf
redis-cli -a 123456 --cluster create 172.24.77.241:6379 172.24.77.241:6380 172.24.77.242:6379 172.24.77.242:6380 172.24.77.243:6379 172.24.77.243:6380 --cluster-replicas 1
yes #輸入 yes 自動建立集羣
[OK] All nodes agree about slots configuration.
Check for open slots...#全部節點槽位分配完成
Check slots coverage...#檢查打開的槽位
[OK] All 16384 slots covered.#檢查插槽覆蓋範圍
redis-cli -h 172.24.77.241 -p 6380 -a 123456
CONFIG SET masterauth 123456
info replication
redis-cli -h 172.24.77.242 -p 6380 -a 123456
CONFIG SET masterauth 123456
redis-cli -h 172.24.77.243 -p 6380 -a 123456
CONFIG SET masterauth 123456
redis-cli -h 172.24.77.241 -p 6379 -a 123456
info replication
cluster info
cluster nodes
172.24.77.242:6379> set key1 test1
172.24.77.243:6380> keys *
redis-trib.rb check 172.24.77.241:6379 ##redis4版本
redis-cli -a 123456 --cluster check 172.24.77.241:6379 ##redis5版本
新節點244安裝redis(略)
配置雙redis
cp -r /usr/local/redis /usr/local/redis2
cd /usr/local/redis/etc/
在如今節點上執行
scp redis.conf root@172.24.77.244:/usr/local/redis/etc/
cd /usr/local/redis2/etc
scp redis.conf root@172.24.77.244:/usr/local/redis/etc/
systemctl daemon-reload
systemctl restart redis
/usr/local/redis/bin/redis-server /usr/local/redis2/etc/redis.conf
redis-cli -a 123456 --cluster add-node 172.24.77.244:6379 172.24.77.241:6379
要添加的新redis節點IP和端口添加到的集羣中的 master IP:端口, 加到集羣以後默認是 master 節點可是沒有slots 數據,須要從新分配
redis-trib.rb check 172.24.77.241:6379
redis-cli -a 123456 --cluster reshard 172.24.77.244:6379
4096 #分配多少個槽位
新redis ID ##接收 slot 的服務器 ID, 手動輸入172.24.77.244的 node ID
Source node all #1: all #將哪些源主機的槽位分配給 192.168.7.104:6379, all 是自動在全部的 redis node 選
擇劃分,若是是從 redis cluster 刪除主機能夠使用此方式將主機上的槽位所有移動到別的 redis 主機
yes #確認分配
redis-cli -a 123456 --cluster check 172.24.77.242:6379
redis-cli -a 123456 --cluster add-node 172.24.77.244:6380 172.24.77.244:6379
redis-cli -h 172.24.77.244 -p 6380 -a 123456
CLUSTER REPLICATE master id
cluster replicate 9d63a881bf0e7f8d8b29a786448e7c22de30ba6a
CLUSTER NODES #再次查看集羣節點狀態, 驗證節點是否已經更改成指定 master 的 slave
redis-cli -a 123456 --cluster check 172.24.77.244:6379