redis 6.2.6 cluster 集群部署

redis 6.2.6 cluster 集群部署,第1张

redis 6.2.6 cluster 集群部署

hadoop用户下,安装redis:

[hadoop@node01 soft]$ wget https://download.redis.io/releases/redis-6.2.6.tar.gz
[hadoop@node01 soft]$ tar xzf redis-6.2.6.tar.gz -C /kkb/install/
[hadoop@node01 soft]$ sudo yum -y install gcc gcc-c++ libstdc++-devel
[hadoop@node01 soft]$ cd /kkb/install/redis-6.2.6
[hadoop@node01 redis-6.2.6]$ make distclean  && make
[hadoop@node01 redis-6.2.6]$ make PREFIX=/kkb/install/redis-6.2.6/ install
[hadoop@node03 redis-6.2.6]$ sudo vim /etc/profile
export REDIS_HOME=/kkb/install/redis-6.2.6
export PATH=$PATH:$REDIS_HOME/bin
[hadoop@node01 redis-6.2.6]$ source /etc/profile

cluster部署:

[hadoop@node01 redis-6.2.6]$ mkdir redis_cluster
[hadoop@node01 redis-6.2.6]$ cd redis_cluster/
[hadoop@node01 redis_cluster]$ mkdir 7001 7002
[hadoop@node01 redis_cluster]$ vim 7001/redis_7001.conf

vim添加内容:

#端口号
port 7001
#本机ip
bind 192.168.51.100
#守护进程
daemonize yes
#pidfile文件对应7001,7002,
pidfile "/var/run/redis_7001.pid"
#日志文件
logfile "/kkb/install/redis-6.2.6/redis_cluster/7001/redis_7001.log"
#数据存放目录
dir "/kkb/install/redis-6.2.6/redis_cluster/7001"
#开启集群
cluster-enabled yes
#集群的配置,配置文件首次启动自动生成7001,7002…
cluster-config-file nodes_7001.conf
#请求超时,默认15秒,可自行设置
cluster-node-timeout 15000
#aof日志开启,有需要就开启,它会每次写 *** 作都记录一条日志
appendonly yes
#master密码
masterauth 123456
#密码
requirepass 123456
[hadoop@node01 redis_cluster]$ cp 7001/redis_7001.conf 7002/redis_7002.conf
[hadoop@node01 redis_cluster]$ vim 7002/redis_7002.conf 
改端口

拷贝到其他节点:

[hadoop@node01 redis_cluster]$ cd /kkb/install/redis-6.2.6/
[hadoop@node01 redis-6.2.6]$ scp -r /kkb/install/redis-6.2.6/ node02:$PWD
[hadoop@node01 redis-6.2.6]$ scp -r /kkb/install/redis-6.2.6/ node03:$PWD
改端口:
[hadoop@node02 redis_cluster]$ mv 7001 7003
[hadoop@node02 redis_cluster]$ mv 7002 7004
[hadoop@node02 redis_cluster]$ mv 7003/redis_7001.conf 7003/redis_7003.conf 
[hadoop@node02 redis_cluster]$ mv 7004/redis_7002.conf 7004/redis_7004.conf
[hadoop@node02 redis_cluster]$ vim 7003/redis_7003.conf 
[hadoop@node02 redis_cluster]$ vim 7004/redis_7004.conf

编写脚本:

start_7001_7002.sh:
redis-server /kkb/install/redis-6.2.6/redis_cluster/redis_7001.conf
redis-server /kkb/install/redis-6.2.6/redis_cluster/redis_7002.conf
shut_down.sh:
redis-cli -h 192.168.51.100 -p 7001 -a 123456 shutdown
redis-cli -h 192.168.51.100 -p 7002 -a 123456 shutdown
look.sh:
ps -ef | grep redis

启动服务:

[hadoop@node01 redis-6.2.6]$ bash start_7001_7002.sh
[hadoop@node01 redis-6.2.6]$ bash look.sh
输出:
hadoop    10573      1  0 20:12 ?        00:00:00 redis-server 192.168.51.120:7005 [cluster]
hadoop    10579      1  1 20:12 ?        00:00:00 redis-server 192.168.51.120:7006 [cluster]
hadoop    10586  10584  0 20:12 pts/1    00:00:00 grep redis

启动集群:

[hadoop@node01 redis-6.2.6]$ redis-cli -a 123456 --cluster create 192.168.51.100:7001 192.168.51.100:7002 192.168.51.110:7003 192.168.51.110:7004 192.168.51.120:7005 192.168.51.120:7006 --cluster-replicas 1


登录集群:

[hadoop@node01 redis-6.2.6]$ redis-cli -c -h 192.168.51.100 -p 7001 -a 123456

注:

  1. 公网不要开放端口
  2. 密码要强
  3. 不要用root用户搭建redis

参考:
https://redis.io/download
https://blog.csdn.net/miss1181248983/article/details/90056960
https://www.cnblogs.com/wps54213/p/12571226.html
https://blog.csdn.net/Jocker_C/article/details/121749128
https://blog.csdn.net/qingbo_2920249511/article/details/121948972

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5690185.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存