开启limits限制

sudo bash -c 'cat >> /etc/security/limits.conf <<-EOF
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072EOF'

reboot重启

安装redis

两台机器都运行

yum install -y wget gcc
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar xzf redis-4.0.9.tar.gz
cd redis-4.0.9
#编译
make MALLOC=libc
#安装并指定安装目录
make install PREFIX=/usr/local/redis

问题
redis直接用make编译报致命错误:jemalloc/jemalloc.h:没有那个文件或目录

分配器allocator,如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。
而且libc 并不是默认的分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。
但是如果你又没有jemalloc而只有 libc 当然 make 出错。 所以加这么一个参数,运行如下命令:
make MALLOC=libc

修改配置

cp redis.conf /usr/local/redis/nodes-9380.conf
vi /usr/local/redis/nodes-9380.conf

修改内容如下

bind 192.168.56.105
port 9380
cluster-enabled yes
cluster-config-file /usr/local/redis/nodes-cluster-9380.conf
cluster-node-timeout 15000
appendonly yes
appendfilename "appendonly-9380.aof"
logfile "log-9380.log"
daemonize yes
cat /usr/local/redis/nodes-9380.conf | sed 's/9380/9381/' > /usr/local/redis/nodes-9381.conf
cat /usr/local/redis/nodes-9380.conf | sed 's/9380/9382/' > /usr/local/redis/nodes-9382.conf#配置拷贝到另外一台机器上
scp /usr/local/redis/nodes-9380.conf 192.168.56.104:/usr/local/redis/

另外一台机器上修改ip
vi /usr/local/redis/nodes-9380.conf
拷贝替换文件

cat /usr/local/redis/nodes-9380.conf | sed 's/9380/9381/' > /usr/local/redis/nodes-9381.conf
cat /usr/local/redis/nodes-9380.conf | sed 's/9380/9382/' > /usr/local/redis/nodes-9382.conf

启动

kill -9 $(ps -ef|grep redis-server|grep -v grep|awk '{print $2}')
/usr/local/redis/bin/redis-server /usr/local/redis/nodes-9380.conf
/usr/local/redis/bin/redis-server /usr/local/redis/nodes-9381.conf
/usr/local/redis/bin/redis-server /usr/local/redis/nodes-9382.conf

安装集群

#yum install ruby -y
#再安装redis插件
#gem install redis
#提示ruby版本过低wget https://github.com/postmodern/ruby-install/archive/v0.8.1.tar.gz
tar xzvf v0.8.1.tar.gz
cd ruby-install-0.8.1/bin/
#看下ruby的最新版本列表
./ruby-install --latest
#安装
./ruby-install ruby 2.7.2
会输出Successfully installed ruby 2.7.2 into /opt/rubies/ruby-2.7.2
ln -s /opt/rubies/ruby-2.7.2/bin/ruby /usr/bin/ruby
ln -s /opt/rubies/ruby-2.7.2/bin/gem /usr/bin/gem
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
#再安装redis插件
gem install redis

切换到redis源码目录

./src/redis-trib.rb  create --replicas 1 192.168.56.104:9380 192.168.56.104:9381 192.168.56.104:9382 192.168.56.105:9380 192.168.56.105:9381 192.168.56.105:9382
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.56.104:9380
192.168.56.105:9380
192.168.56.104:9381
Adding replica 192.168.56.105:9382 to 192.168.56.104:9380
Adding replica 192.168.56.104:9382 to 192.168.56.105:9380
Adding replica 192.168.56.105:9381 to 192.168.56.104:9381
M: e958a652b5d0184b288796121a9b6673534675bf 192.168.56.104:9380slots:0-5460 (5461 slots) master
M: 63292c0bcee1eff0d1f2df4a7678a3795172634d 192.168.56.104:9381slots:10923-16383 (5461 slots) master
S: 420d577f5826ab948f3a6dc13e5d588714159fec 192.168.56.104:9382replicates e579aef656f6bddb578a27b7ca19287d35f9430a
M: e579aef656f6bddb578a27b7ca19287d35f9430a 192.168.56.105:9380slots:5461-10922 (5462 slots) master
S: 92e3a6e4655f0630d8d92161434a7b34a1330495 192.168.56.105:9381replicates 63292c0bcee1eff0d1f2df4a7678a3795172634d
S: 227102968867e9dfd419b5a5729fe15c12323424 192.168.56.105:9382replicates e958a652b5d0184b288796121a9b6673534675bf
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 192.168.56.104:9380)
M: e958a652b5d0184b288796121a9b6673534675bf 192.168.56.104:9380slots:0-5460 (5461 slots) master1 additional replica(s)
S: 92e3a6e4655f0630d8d92161434a7b34a1330495 192.168.56.105:9381slots: (0 slots) slavereplicates 63292c0bcee1eff0d1f2df4a7678a3795172634d
M: 63292c0bcee1eff0d1f2df4a7678a3795172634d 192.168.56.104:9381slots:10923-16383 (5461 slots) master1 additional replica(s)
S: 420d577f5826ab948f3a6dc13e5d588714159fec 192.168.56.104:9382slots: (0 slots) slavereplicates e579aef656f6bddb578a27b7ca19287d35f9430a
M: e579aef656f6bddb578a27b7ca19287d35f9430a 192.168.56.105:9380slots:5461-10922 (5462 slots) master1 additional replica(s)
S: 227102968867e9dfd419b5a5729fe15c12323424 192.168.56.105:9382slots: (0 slots) slavereplicates e958a652b5d0184b288796121a9b6673534675bf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

有防火墙会无法连接

systemctl stop firewalld
systemctl disable firewalld

连接集群测试

./redis-cli -c -h 192.168.56.104 -p 9380
192.168.56.104:9380> set a 1
-> Redirected to slot [15495] located at 192.168.56.104:9381
OK
192.168.56.104:9381> get a
"1"
192.168.56.104:9381> get b
-> Redirected to slot [3300] located at 192.168.56.104:9380
(nil)

redis集群密码设置
1、密码设置(推荐)方式一:修改所有Redis集群中的redis.conf文件加入:

masterauth passwd123
requirepass passwd123

说明:这种方式需要重新启动各节点
方式二:进入各个实例进行设置:

./redis-cli -c -p 7000
config set masterauth passwd123
config set requirepass passwd123
config rewrite

之后分别使用./redis-cli -c -p 7001,./redis-cli -c -p 7002……命令给各节点设置上密码。
注意:各个节点密码都必须一致,否则Redirected就会失败, 推荐这种方式,这种方式会把密码写入到redis.conf里面去,且不用重启。

带密码访问集群

./redis-cli -c -p 7000 -a passwd123

redis 4.0.9 centos7 双机集群安装相关推荐

  1. Centos7 ceph集群安装 cephfs客户端挂载 java代码调用

    Centos7 ceph集群安装 cephfs客户端挂载 java代码调用 ceph简介(http://docs.ceph.org.cn/ 官方文档) ceph分为ceph monitor,ceph ...

  2. linux下,redis 3.2.1双节点集群安装部署

    为什么80%的码农都做不了架构师?>>>    一.环境准备 1.JDK环境准备,需卸载掉自带JDK (1)检查服务器是否自带jdk环境 [root@redis1 /]# rpm - ...

  3. redis5.0.5版本搭建集群

                                         redis5.0.5版本搭建集群 安装redis5.0.5版本 将redis5.0.5解压 sudo tar -zxcf re ...

  4. redis-4.0.10集群安装(3台机器,6个node),以及在Spring项目中的集成,redis操作工具类

    1 Redis安装 redis高可用的三种常见的集群方式:redis sentinel .redis cluster(多主机+分布式).redis sharding.接下来主要介绍redis sent ...

  5. 记一次 Centos7.x Hadoop3.x集群安装部署 Pig 0.17.0

    基本信息 官网 http://pig.apache.org/ 下载地址 http://www.apache.org/dyn/closer.cgi/pig https://mirror.bit.edu. ...

  6. Redis进阶-5.x 单节点 及Redis Cluster 3主3从集群部署

    文章目录 Redis 下载地址 Redis 5.x 单节点 编译安装 Redis 启停 Redis Cluster 4.x VS Redis Cluster 5.x 演进之路 ( Master/Sla ...

  7. redis3.0.0 集群安装详细步骤

    2019独角兽企业重金招聘Python工程师标准>>> redis3.0.0 集群安装详细步骤 博客分类: 缓存 Redis集群部署文档(centos6系统) (要让集群正常工作至少 ...

  8. redis3.0.2 分布式集群安装详细步骤

    redis3.0.2 分布式集群安装详细步骤 --(centos5.8 X64系统) 版本历史 时间 版本 说明 编写者 2015-06-5 1.0 redis3.0.2 分布式集群安装详细步骤 cs ...

  9. redis伪集群安装linux,redis伪集群搭建(亲测无坑)

    一.单机版安装部署,伪集群只需要操作前1-8步即可,再往下浏览找到:二.单机版-伪集群  安装部署继续搭建,如需设置密码参照第10步 1.安装基本工具 yum install -y gcc-c++ v ...

最新文章

  1. 1242 Rescue BFS
  2. 弱电工程计算机网络系统基础知识
  3. Qt Creator和VS2010中添加槽信号_差异与详解
  4. Alibaba-AndFix Bug热修复框架的使用
  5. springboot中配置文件使用2
  6. poj 1734 (最小环)
  7. HTML textarea控件
  8. windows下用XShell远程ubuntu时连接失败
  9. 光标的覆盖模式与插入模式
  10. 利用Netica训练简易贝叶斯网络模型【教程】
  11. 中期答辩记录与总结反思
  12. easyrecovery2023免费版电脑数据恢复软件下载功能介绍
  13. CheckBox复选框全选以及获取值(转)
  14. 工具教程第十五讲:如何查询大户持仓地址情况
  15. C#委托和事件的概念
  16. pythonrpg游戏_python实现的简单RPG游戏流程实例
  17. 模运算性质-mod (ACM学习笔记)
  18. 复睿智行CC++开发实习面试
  19. 设计模式 行为型模式 -- 备忘录模式 具体实例:游戏挑战BOSS
  20. 九方智投是正规公司吗?一起聊聊九方智投

热门文章

  1. “约见”面试官系列之常见面试题之第九十七篇之怎么定义vue-router的动态路由(建议收藏)
  2. 前端学习(2161):vuecli项目得目录结构解析
  3. 前端学习(2155):htmlwebpackplugin的使用
  4. 前端学习(688):断点调试
  5. 前端学习(14):相对路径和绝对路径
  6. java面试题43要使某个类能被同一个包中的其他类访问,但不能被这个包以外的类访问,可以( )
  7. spring学习(4):spring管理对象之间的关联关系
  8. 第五十六期:百度CTO王海峰CNCC2019演讲:深度学习平台支撑产业智能化
  9. 线性系统的基本理论与运算
  10. centos7网卡识别不到,无法远程工具连接