Linux下部署redis、启动redis、创建redis节点集群
目录
- 1. 准备工作
- 2. 启动redis
- 3. 查看redis是否启动成功
- 4. 创建redis集群
- 5. 连接redis
- 6. 查看集群状态
- 7. 通过set和get方法插入和查询
- 总结:
1. 准备工作
a.集群redis包
下载
b.下载的包中有6个redis节点,端口7001、7002、7003、7004、7005、7006,使用时请注意端口是否占用,密码为123455
c.如果需要修改端口和密码,可以在/data/redis-cluster/7001/etc/redis.conf配置文件中修改
[root@wanwan redis-cluster]# cat /data/redis-cluster/7001/etc/redis.conf
#redis密码
requirepass 123456
#redis端口
port 7001
2. 启动redis
通过start_all.sh脚本批量启动所有redis,通过stop_all.sh脚本批量关闭redis
[root@wanwan redis-cluster]# pwd
/data/redis-cluster
[root@wanwan redis-cluster]# ll
总用量 8
drwxr-xr-x. 5 root root 100 4月 13 05:26 7001
drwxr-xr-x. 5 root root 88 4月 13 05:26 7002
drwxr-xr-x. 5 root root 88 4月 13 05:26 7003
drwxr-xr-x. 5 root root 88 4月 13 05:26 7004
drwxr-xr-x. 5 root root 88 4月 13 05:25 7005
drwxr-xr-x. 5 root root 88 4月 13 05:25 7006
-rwxrwxrwx. 1 root root 545 7月 24 2019 start_all.sh
-rwxrwxr-x. 1 root root 974 4月 12 12:53 stop_all.sh
[root@wanwan redis-cluster]# sh start_all.sh
321746:C 13 Apr 2022 05:26:34.211 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321746:C 13 Apr 2022 05:26:34.211 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321746, just started
321746:C 13 Apr 2022 05:26:34.211 # Configuration loaded
321755:C 13 Apr 2022 05:26:39.234 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321755:C 13 Apr 2022 05:26:39.234 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321755, just started
321755:C 13 Apr 2022 05:26:39.234 # Configuration loaded
321772:C 13 Apr 2022 05:26:44.256 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321772:C 13 Apr 2022 05:26:44.256 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321772, just started
321772:C 13 Apr 2022 05:26:44.256 # Configuration loaded
321781:C 13 Apr 2022 05:26:49.279 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321781:C 13 Apr 2022 05:26:49.279 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321781, just started
321781:C 13 Apr 2022 05:26:49.279 # Configuration loaded
321790:C 13 Apr 2022 05:26:54.302 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321790:C 13 Apr 2022 05:26:54.302 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321790, just started
321790:C 13 Apr 2022 05:26:54.302 # Configuration loaded
321799:C 13 Apr 2022 05:26:59.325 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
321799:C 13 Apr 2022 05:26:59.325 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=321799, just started
321799:C 13 Apr 2022 05:26:59.325 # Configuration loaded
[root@wanwan redis-cluster]#
3. 查看redis是否启动成功
[root@wanwan redis-cluster]# ps -ef|grep redis
root 321747 1 0 05:26 ? 00:00:00 /data/redis-cluster/7001/bin/redis-server *:7001 [cluster]
root 321756 1 0 05:26 ? 00:00:00 /data/redis-cluster/7002/bin/redis-server *:7002 [cluster]
root 321773 1 0 05:26 ? 00:00:00 /data/redis-cluster/7003/bin/redis-server *:7003 [cluster]
root 321782 1 0 05:26 ? 00:00:00 /data/redis-cluster/7004/bin/redis-server *:7004 [cluster]
root 321791 1 0 05:26 ? 00:00:00 /data/redis-cluster/7005/bin/redis-server *:7005 [cluster]
root 321800 1 0 05:26 ? 00:00:00 /data/redis-cluster/7006/bin/redis-server *:7006 [cluster]
root 321912 320809 0 05:35 pts/0 00:00:00 grep --color=auto redis
[root@wanwan redis-cluster]# [root@wanwan redis-cluster]# netstat -nltp|grep redis
tcp 0 0 0.0.0.0:17001 0.0.0.0:* LISTEN 321747/redis-server
tcp 0 0 0.0.0.0:17002 0.0.0.0:* LISTEN 321756/redis-server
tcp 0 0 0.0.0.0:17003 0.0.0.0:* LISTEN 321773/redis-server
tcp 0 0 0.0.0.0:17004 0.0.0.0:* LISTEN 321782/redis-server
tcp 0 0 0.0.0.0:17005 0.0.0.0:* LISTEN 321791/redis-server
tcp 0 0 0.0.0.0:17006 0.0.0.0:* LISTEN 321800/redis-server
tcp 0 0 0.0.0.0:7001 0.0.0.0:* LISTEN 321747/redis-server
tcp 0 0 0.0.0.0:7002 0.0.0.0:* LISTEN 321756/redis-server
tcp 0 0 0.0.0.0:7003 0.0.0.0:* LISTEN 321773/redis-server
tcp 0 0 0.0.0.0:7004 0.0.0.0:* LISTEN 321782/redis-server
tcp 0 0 0.0.0.0:7005 0.0.0.0:* LISTEN 321791/redis-server
tcp 0 0 0.0.0.0:7006 0.0.0.0:* LISTEN 321800/redis-server
tcp6 0 0 :::17001 :::* LISTEN 321747/redis-server
tcp6 0 0 :::17002 :::* LISTEN 321756/redis-server
tcp6 0 0 :::17003 :::* LISTEN 321773/redis-server
tcp6 0 0 :::17004 :::* LISTEN 321782/redis-server
tcp6 0 0 :::17005 :::* LISTEN 321791/redis-server
tcp6 0 0 :::17006 :::* LISTEN 321800/redis-server
tcp6 0 0 :::7001 :::* LISTEN 321747/redis-server
tcp6 0 0 :::7002 :::* LISTEN 321756/redis-server
tcp6 0 0 :::7003 :::* LISTEN 321773/redis-server
tcp6 0 0 :::7004 :::* LISTEN 321782/redis-server
tcp6 0 0 :::7005 :::* LISTEN 321791/redis-server
tcp6 0 0 :::7006 :::* LISTEN 321800/redis-server
[root@wanwan redis-cluster]#
4. 创建redis集群
执行命令后会弹出确认,一定要记得输入yes
[root@wanwan redis-cluster]# cd 7001/bin
[root@wanwan bin]# ll
总用量 40668
drwxr-xr-x. 3 root root 75 5月 26 2021 agent_tmp
-rwxr-xr-x. 1 root root 734 7月 23 2019 mkreleasehdr.sh
-rwxr-xr-x. 1 root root 4366592 7月 23 2019 redis-benchmark
-rwxr-xr-x. 1 root root 8111800 7月 23 2019 redis-check-aof
-rwxr-xr-x. 1 root root 8111800 7月 23 2019 redis-check-rdb
-rwxr-xr-x. 1 root root 4806824 7月 23 2019 redis-cli
-rwxr-xr-x. 1 root root 8111800 7月 23 2019 redis-sentinel
-rwxr-xr-x. 1 root root 8111800 7月 23 2019 redis-server
-rwxr-xr-x. 1 root root 3600 7月 23 2019 redis-trib.rb
[root@wanwan bin]# ./redis-cli -a 123456 --cluster create 172.16.17.208:7001 172.16.17.208:7002 172.16.17.208:7003 172.16.17.208:7004 172.16.17.208:7005 172.16.17.208:7006
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 2730
Master[1] -> Slots 2731 - 5460
Master[2] -> Slots 5461 - 8191
Master[3] -> Slots 8192 - 10922
Master[4] -> Slots 10923 - 13652
Master[5] -> Slots 13653 - 16383
M: 1e45ed256292db35537cebd81bfaf115114bd7c0 172.16.17.208:7001slots:[0-2730] (2731 slots) master
M: b40f67d276487608a1e67f2653743bd2a7ce3c37 172.16.17.208:7002slots:[2731-5460] (2730 slots) master
M: 96e3f0c09c027da8a2d54d4a26fc6db214ee1a17 172.16.17.208:7003slots:[5461-8191] (2731 slots) master
M: 7d7444d171d2e8792bf672f6fc4ff20ba8339bb7 172.16.17.208:7004slots:[8192-10922] (2731 slots) master
M: bcad065c97331730be619a7b54c7c6a51ef3dbfc 172.16.17.208:7005slots:[10923-13652] (2730 slots) master
M: f7a02c5330b5836ce78280224f40796fcbd92ae1 172.16.17.208:7006slots:[13653-16383] (2731 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
>>> 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 172.16.17.208:7001)
M: 1e45ed256292db35537cebd81bfaf115114bd7c0 172.16.17.208:7001slots:[0-2730] (2731 slots) master
M: bcad065c97331730be619a7b54c7c6a51ef3dbfc 172.16.17.208:7005slots:[10923-13652] (2730 slots) master
M: 96e3f0c09c027da8a2d54d4a26fc6db214ee1a17 172.16.17.208:7003slots:[5461-8191] (2731 slots) master
M: 7d7444d171d2e8792bf672f6fc4ff20ba8339bb7 172.16.17.208:7004slots:[8192-10922] (2731 slots) master
M: f7a02c5330b5836ce78280224f40796fcbd92ae1 172.16.17.208:7006slots:[13653-16383] (2731 slots) master
M: b40f67d276487608a1e67f2653743bd2a7ce3c37 172.16.17.208:7002slots:[2731-5460] (2730 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@wanwan bin]#
5. 连接redis
本机连接不需要输入ip地址,如果是远程连接需要加-h ip
[root@wanwan bin]# ./redis-cli -a 123456 -p 7001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:7001>
6. 查看集群状态
集群创建成功==》cluster_state:ok
集群未创建==》cluster_state:fail
127.0.0.1:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:6
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:99
cluster_stats_messages_pong_sent:89
cluster_stats_messages_sent:188
cluster_stats_messages_ping_received:84
cluster_stats_messages_pong_received:99
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:188
127.0.0.1:7001>
7. 通过set和get方法插入和查询
尝试redis是否能否正常使用,通过set插入缓存数据,通过get获取缓存数据
127.0.0.1:7001> set key12345 value12345
OK
127.0.0.1:7001> get key12345
"value12345"
127.0.0.1:7001>
总结:
可视化工具
博主留言:如果没有积分下载的朋友可以在评论区留言,我看到了可以私下发出来,csdn上传资源现在默认就是5分;
Linux下部署redis、启动redis、创建redis节点集群相关推荐
- Linux下安装、启动、关闭 Redis服务详解
1. Redis简介 Redis全名:Remote Dictionary Service Redis是广泛应用的NoSQL数据库,基于C开发的键值对存储数据库 Redis是一个使用ANSI C编写的开 ...
- linux里创建表空间和用户名,linux下oracle的启动和创建表空间用户
1.进入到sqlplus启动实例 [oracle@redhat ~]$ su - oracle --"切换到oracle用户& ...
- linux下部署tomcat没起成功,linux下部署tomcat 上线jpress博客系统
tomcat Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器. tomcat有三个端口 开始部署 安装tomcat 第一步:下载tomcat 安装包 tomcat官网 ...
- Linux下部署多个Tomcat
Linux下部署多个Tomcat 1.环境: 1.1.Centos 5.0 1.2.apache-tomcat-6.0.18 2.需要解决一下几个问题 2.1.不同的tomcat启动和关闭监听不同的端 ...
- Linux下通用线程池的创建与使用
Linux下通用线程池的创建与使用 本文给出了一个通用的线程池框架,该框架将与线程执行相关的任务进行了高层次的抽象,使之与具体的执行任务无关.另外该线程池具有动态伸缩性,它能根据执行任务的轻重自动调整 ...
- Linux 下部署 TFTP 服务
1. TFTP服务简介 TFTP是 Trivial File Transfer Protocol 的缩写,即简单文件传输协议,是一个基于 UDP 协议实现的用于在客户机和服务器之间进行简单文件传输的协 ...
- 大数据互联网架构阶段 Linux下安装mysql启动的常见问题
Linux下安装mysql启动的常见问题 1.PID file could not be found mysql无法启动ERROR! MySQL is running but PID file cou ...
- linux下的Tomcat启动
linux下的Tomcat启动 一直在eclipse中启动Tomcat,只有第一次安装Tomcat时亲自启动过一次,那时用的还是Win10,看书看到了Tomcat的配置,于是想实践一下,打开tomca ...
- Linux下browser-sync无法启动Chrome的解决方法
Linux下browser-sync无法启动Chrome的解决方法 参考文章: (1)Linux下browser-sync无法启动Chrome的解决方法 (2)https://www.cnblogs. ...
- Linux下Tomcat项目启动报错
Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...
最新文章
- Debian 6.0 安装过程 及中文乱码
- Vmware下Centos7安装预览
- Linux 中的各种栈:进程栈 线程栈 内核栈 中断栈
- Java加密与解密的艺术~数字签名~DSA实现
- 发动机压缩比怎么计算公式_怎么判断发动机有积碳,发动机积碳多的症状有哪些...
- jQuery基础资料(三)
- [中文翻译] ASP.NET 5 简介(Introducing ASP.NET 5,原作ScottGu 2015/2/23)
- SQLyog下载与安装
- Excel的规划求解【详细步骤】
- Toshiba Folio + CWM +CM
- CAN FD 总线协议深度解析-简单易懂协议详解
- html风琴图片展示,基于jquery的手风琴图片展示效果实现方法
- HDU - 1546 Idiomatic Phrases Game
- 七段数码显示管—设计报告,visio图,Multisim仿真
- 国企的面试我们应该怎么准备?
- Arduino压电震动传感器(二)
- Java是剑客,.NET是刀客
- 多属性决策的权重确定方法及matlab 程序
- 数学建模 微分方程实战:利用SEIR模型对新冠病毒预测
- c++ windows网络编程底层涉及库