redis6.0.6单机部署、主从复制、集群部署(rockylinux8.6)

一、单机部署

1、安装系统-最小化安装  rockylinux8.6  设置地址192.168.3.181

2、关闭selinux,并设置防火墙

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
firewall-cmd  --permanent --add-port=6379/tcp
firewall-cmd --reload

3、更改yum源

rm -rf /etc/yum.repos.d/*
vi /etc/yum.repos.d/base.repo

[rocky-base]
name=rocky-base
baseurl=http://mirrors.163.com/rocky/8.6/BaseOS/x86_64/os/
enable=1
gpgcheck=0

[rocky-appstream]
name=rocky-appstream
baseurl=http://mirrors.163.com/rocky/8.6/AppStream/x86_64/os/
gpgcheck=0
enable=1

[rocky-extras]
name=rocky-extras
baseurl=http://mirrors.163.com/rocky/8.6/extras/x86_64/os/
gpgcheck=0
enable=1

4、安装软件包

dnf install -y net-tools gcc gcc-c++ bash-completion make vim
reboot

5、下载软件包redis6.0.6,并上传至/root

CRUG网站 (redis.cn)http://www.redis.cn/6、解压并安装

cd
tar -xvf  redis-6.0.6.tar.gz
cd redis-6.0.6/

vim redis.conf

改
bind  127.0.0.1 192.168.3.181

make

make install

 前台运行

redis-server

另开终端

redis-cli

ctrl+c关闭前台运行

后台运行

vim redis-6.0.6/redis.conf

改  daemonize   no   为  daemonize   yes

redis-server    redis-6.0.6/redis.conf

7、安装服务 

cd /root/redis-6.0.6/utils/
vim install_server.sh

注释以下几行
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
# fi
./install_server.sh

systemctl start redis_6379.service

 运行状态查看

redis-cli
info

 二、主从复制

安装部署同单机部署192.168.3.182

在192.168.1.181上修改配置文件

vim   /etc/redis/6379.conf

增加

requirepass  password

systemctl restart redis_6379.service

在192.168.3.182上修改配置文件

vim /etc/redis/6379.conf

增加

slaveof     192.168.3.181     6379

replicaof   192.168.3.181      6379

systemctl restart redis_6379.service
redis-cli info

 在192.168.3.181上查看

redis-cli  -a password info

测试

redis-cli
set testname mytest
get testname

从节点192.168.3.182上查看

redis-cli
get testname

三、集群部署

192.168.3.181    192.168.3.182   192.168.3.183三台服务器部署redis

三台服务器关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

1、初始化redis(192.168.3.181)

cd redis-6.0.6/utils/
./install_server.sh

./install_server.sh

systemctl start redis_6381.service
systemctl start redis_6391.service

vim /etc/redis/6381.conf
修改如下
bind 192.168.3.181
cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 15000

vim /etc/redis/6391.conf
修改如下
bind 192.168.3.181
cluster-enabled yes
cluster-config-file nodes-6391.conf
cluster-node-timeout 15000

systemctl restart redis_6381.service
systemctl restart redis_6391.service
netstat -antup | grep redis

2、初始化redis(192.168.3.182)

cd redis-6.0.6/utils/
./install_server.sh

./install_server.sh

systemctl start redis_6382.service
systemctl start redis_6392.service

vim /etc/redis/6382.conf
修改如下
bind 192.168.3.182
cluster-enabled yes
cluster-config-file nodes-6382.conf
cluster-node-timeout 15000

vim /etc/redis/6392.conf
修改如下
bind 192.168.3.182
cluster-enabled yes
cluster-config-file nodes-6392.conf
cluster-node-timeout 15000

systemctl restart redis_6382.service
systemctl restart redis_6392.service
netstat -antup | grep redis

3、初始化redis(192.168.3.183)

cd redis-6.0.6/utils/
./install_server.sh

./install_server.sh

systemctl start redis_6383.service
systemctl start redis_6393.service

vim /etc/redis/6383.conf
修改如下
bind 192.168.3.183
cluster-enabled yes
cluster-config-file nodes-6383.conf
cluster-node-timeout 15000

vim /etc/redis/6393.conf
修改如下
bind 192.168.3.183
cluster-enabled yes
cluster-config-file nodes-6393.conf
cluster-node-timeout 15000

systemctl restart redis_6383.service
systemctl restart redis_6393.service
netstat -antup | grep redis

 4、集群配置(192.168.3.181)

redis-cli --cluster create --cluster-replicas 1 192.168.3.181:6381 192.168.3.182:6382 192.168.3.183:6383 192.168.3.182:6392 192.168.3.183:6393 192.168.3.181:6391

(type 'yes' to accept):  yes

5、检查

redis-cli -h 192.168.3.181 -p 6381 info replication
redis-cli -h 192.168.3.182 -p 6382 info replication
redis-cli -h 192.168.3.183 -p 6383 info replication
redis-cli -h 192.168.3.181 -p 6391 info replication
redis-cli -h 192.168.3.182 -p 6392 info replication
redis-cli -h 192.168.3.183 -p 6393 info replication

redis-cli -h 192.168.3.181 -p 6381 cluster info

redis-cli -h 192.168.3.181 -c -p 6381
set test mytest
exit
redis-cli -h 192.168.3.183 -c -p 6383 
get test

查看集群自动转至 192.168.3.182  

192.168.3.182上执行

systemctl stop redis_6382.service

192.168.3.181上执行

redis-cli -h 192.168.3.181 -c -p 6381
get test

 

查看集群节点信息

 redis-cli -h 192.168.3.181 -c -p 6381 cluster nodes

redis-cli -h 192.168.3.181 -c -p 6381 cluster slots

redis-cli -h 192.168.3.181 -c -p 6381 role

redis-cli --cluster check 192.168.3.181:6381

节点1    槽   [0-5460]

节点2    槽   [5461-10922]

节点3    槽   [10923-16383]

删除节点

redis-cli del-node 192.168.3.182:6392 b70322fb68209b2d62235ab3c2d224a3368c3e7e
redis-cli --cluster check 192.168.3.181:6381

b70322fb68209b2d62235ab3c2d224a3368c3e7e  为节点ID

 填加节点

192.168.3.181

cd redis-6.0.6/utils/
./install_server.sh

systemctl start redis_6371.service

vim /etc/redis/6371.conf
修改如下
bind 192.168.3.181
cluster-enabled yes
cluster-config-file nodes-6371.conf
cluster-node-timeout 15000

systemctl restart redis_6371.service
netstat -antup | grep redis

192.168.3.182

cd redis-6.0.6/utils/
./install_server.sh

systemctl start redis_6372.service

vim /etc/redis/6372.conf
修改如下
bind 192.168.3.182
cluster-enabled yes
cluster-config-file nodes-6372.conf
cluster-node-timeout 15000

systemctl restart redis_6372.service
netstat -antup | grep redis
redis-cli --cluster add-node 192.168.3.182:6372  192.168.3.182:6382
redis-cli --cluster check 192.168.3.181:6381

默认填加为主节点

填加从节点

redis-cli --cluster add-node  192.168.3.181:6371 192.168.3.182:6382 --cluster-slave 192.168.3.181:6371
redis-cli --cluster check 192.168.3.182:6382

 填加刚删除节点为从节点

redis-cli --cluster add-node  192.168.3.182:6392 192.168.3.182:6382 --cluster-slave 192.168.3.182:6392

负载均衡

刚填加节点后,新节点无槽

redis-cli --cluster rebalance 192.168.3.182:6382

 移动槽

redis-cli -h 192.168.3.181 -p 6381  cluster setslot 2 migrating ed417799db755e4a2bb12402e2fa201af9899c99
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值