首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

redis安装(单机/集群)

  • 25-04-19 00:41
  • 3390
  • 6617
juejin.cn

参考 Linux 安装 Redis 6.0.6

1.获取资源路径

redis官网

2.准备

bash
代码解读
复制代码
yum install wget yum install gcc #***gcc默认安装的gcc是4.8.5,版本过低,需要升级*** yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile #查看版本号 gcc -v

2.编译

bash
代码解读
复制代码
cd redis-6.0.6 make make install PREFIX=/usr/local/redis/ # 配置环境变量 #从源码中把可执行文件迁出 make install PREFIX=/usr/local/redis/ vi /etc/profile #增加以下内容: export REDIS_HOME=/usr/local/redis/ export PATH=$REDIS_HOME/bin:$PATH #使配置生效 source /etc/profile #验证 echo $PATH

3. 创建redis实例

bash
代码解读
复制代码
cd /usr/local/redis-6.0.6/utils ./install_server.sh
css
代码解读
复制代码
这步有可能会报错:` `This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install t hem. Sorry!

解决方案:

bash
代码解读
复制代码
vi ./install_server.sh 1

注释下面的代码即可

shell
代码解读
复制代码
#bail if this system is managed by systemd #_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即可。 按几下回车

makefile
代码解读
复制代码
如果出现错误: # Please select the redis executable path [] Mmmmm... it seems like you don't have a redis executable.. 需要在path || 后手动输入路径
perl
代码解读
复制代码
#查看该实例的运行状态 service redis_6379 status #停止 service redis_6379 stop #启动 service redis_6379 start [root@localhost utils]# ps -ef|grep redis root 3831 1 0 10:03 ? 00:00:01 /usr/local/redis//bin/redis-server 127.0.0.1:6379 root 12076 1434 0 10:26 pts/0 00:00:00 grep --color=auto redis #需要开启外部访问 1.找到redis中的redis.cof文件并打开 2.找到bind 127.0.0.1并注释掉 3.修改 protected-mode 属性值为no #启动 redis-server /usr/local/redis-6.0.6/redis.conf #注:redis默认是只能本地访问,注释掉并叫保护模式禁用以后可以IP访问

2.集群搭建

参考  CSDN 博客园

准备

复制源目录根目录下的redis.conf文件到生成的/usr/local/redis目录下

使用vi编辑配置redis.conf

yaml
代码解读
复制代码
bind 0.0.0.0  设置绑定的主机ip,0.0.0.0表示监听所有地址 protected-mode no  关闭安全模式,允许外网访问 daemonize yes  后台启动 port 7001  修改端口号,各节点不重复 cluster-enabled yes  开启集群支持

复制redis实例

bash
代码解读
复制代码
# 创建文件夹 mkdir redis-cluster # 可以使用一台机器,我使用三台,每台两个 cp -r redis redis-cluster/redis01 cp -r redis redis-cluster/redis02 ...

启动所有节点

bash
代码解读
复制代码
[root@redis121 redis02] ./redis-server redis.conf [root@redis121 redis01] ./redis-server redis.conf ...

创建集群

vbnet
代码解读
复制代码
# 进入到集群中某个实例下的bin目录执行 [root@redis121 redis01] /usr/local/redis-cluster/redis01/redis-cli --cluster create 192.168.25.104:7001 192.168.25.104:7004 1 92.168.25.121:7002 192.168.25.121:7005 192.168.25.122:7003 192.168.25.122:7006 --cluster-replicas 1 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 192.168.25.121:7005 to 192.168.25.104:7001 Adding replica 192.168.25.122:7006 to 192.168.25.121:7002 Adding replica 192.168.25.104:7004 to 192.168.25.122:7003 M: 81e6d7cb24891849940d73f9e9c10ac0545cd65d 192.168.25.104:7001 slots:[0-5460] (5461 slots) master S: c2bbaeb68c172aa1fed55e519b86347f6bd2b9b7 192.168.25.104:7004 replicates 63e280dae17aa3d980f6c4fe2c0532a11b83616f M: f957b6e222f6a3c996a4ba0fa2a77dec01524266 192.168.25.121:7002 slots:[5461-10922] (5462 slots) master S: b80c9fcea4f6d2a9d1db68954848075311542598 192.168.25.121:7005 replicates 81e6d7cb24891849940d73f9e9c10ac0545cd65d M: 63e280dae17aa3d980f6c4fe2c0532a11b83616f 192.168.25.122:7003 slots:[10923-16383] (5461 slots) master S: 2e55f80db5784568a26b3ae2b3418e9700bfe811 192.168.25.122:7006 replicates f957b6e222f6a3c996a4ba0fa2a77dec01524266 Can I set the above configuration? (type 'yes' to accept): yes # 输入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 192.168.25.104:7001) M: 81e6d7cb24891849940d73f9e9c10ac0545cd65d 192.168.25.104:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 2e55f80db5784568a26b3ae2b3418e9700bfe811 192.168.25.122:7006 slots: (0 slots) slave replicates f957b6e222f6a3c996a4ba0fa2a77dec01524266 M: f957b6e222f6a3c996a4ba0fa2a77dec01524266 192.168.25.121:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: c2bbaeb68c172aa1fed55e519b86347f6bd2b9b7 192.168.25.104:7004 slots: (0 slots) slave replicates 63e280dae17aa3d980f6c4fe2c0532a11b83616f M: 63e280dae17aa3d980f6c4fe2c0532a11b83616f 192.168.25.122:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: b80c9fcea4f6d2a9d1db68954848075311542598 192.168.25.121:7005 slots: (0 slots) slave replicates 81e6d7cb24891849940d73f9e9c10ac0545cd65d [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. # 如果一直在 Waiting for the cluster to join..................... # 停掉所有节点,删除文件夹底下的nodes.conf,dump.rdb # 修改 pidfile /var/run/redis_7001.pid 为端口 # 重启,重新执行

连接

bash
代码解读
复制代码
# 使用redis-cli连接 -c 表示集群模式,不带的话无法执行操作 在本机的节点不用输入ip [root@redis104 redis01] ./redis-cli -c -p 7002 # 如果节点在其他服务器 需要加 -h [root@redis104 redis01] ./redis-cli -c -h 192.168.25.122 -p 7006
注:本文转载自juejin.cn的刘量包的文章"https://juejin.cn/post/7489720690884640777"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

143
阅读
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top