redis 4.0.9 centos7 双机集群安装

开启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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416605.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

关于毕业的一些事情

这篇日志&#xff0c;算是日记吧。就当做日记。 今天上午8点開始在8-302举行答辩&#xff0c;关于毕业论文&#xff0c;就是用的原先的智能问答机器人。也还算顺利。无论咋样&#xff0c;过是没问题。 晚上在校园食代举行班级谢师宴&#xff0c;老师来了15位左右&#xff0c;跟…

递归树思路总结思考

递归思路 传入数组 传入单个对象 传入数组 内部先遍历进行单个对象处理&#xff0c; 再递归单个对象的children 传入对象 内部先处理当前对象&#xff0c;再遍历对象children&#xff0c;对每个children进行递归调用。 需要处理返回值的情况 一种是传入对象指针&#xff…

前端学习(2441):删除处理完成

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…

5、用枚举值表示状态、选项、状态码

一、C语言中1、C语言中的枚举类型enum。在以一系列常量来表示错误状态码或可组合的选项时&#xff0c;极宜使用枚举为其命名。2、定义一个enumenum personAgeState { personAgeStateLitter,personAgeStateBigger};property (nonatomic, assign) enum personAgeState personAge;…

openjdk17体验

jdk17是继jdk8和jdk11之后的LTS版本&#xff0c;该版本支持到2029年12月&#xff0c;下载地址 https://jdk.java.net/17/ 我是ubuntu64位环境&#xff0c;下载linux/x64版本&#xff0c;解压 打开idea创建一个新项目&#xff0c;添加jdk17并设置为jdk17 写个helloworld packa…

linux zip分卷压缩解压命令

linux下有时因为文件过大&#xff0c;传输过程中需要将源文件压缩为多个zip文件&#xff0c;以下是具体方法 压缩 zip -r -s 1g split.zip fold/ -s 1g代表分卷大小 split.zip为压缩包名 fold/为待压缩的目录 解压 zip -s 0 split.zip --out unsplit.zip unzip unslit.zip…

不确定屏幕大小的弹窗垂直居中(用了box方法)

对于父元素高度不确定&#xff0c;又要实现上下左右对齐&#xff0c;只需要在弹窗的父元素上使用box布局&#xff0c;控制弹窗上下左右居中 <div class"pop_wrap"><div class"pop"></div> </div> .pop_wrap{display:-webkit-box;-…

npm i依赖版本兼容问题处理

npm i报错提示 whqwhq-Z270P-D3:/data/code/builder_git/xx$ npm i npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: webbq-cmm1.1.0 npm ERR! Found: webpack3.12.0 npm ERR! node_modules/webpack npm ER…

前端学习(2449):发布文章组件

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…

centos7 geenplum5.x postgis开源版本编译

下载5.1 https://codeload.github.com/greenplum-db/gpdb/tar.gz/5.1.0 基础环境 tar xzvf gpdb-5.1.0.tar.gz cd gpdb-5.1.0 参照README.md、README.amazon_linux准备依赖 yum install -y epel-release yum install -y python-pip sudo yum -y install git gcc readline-dev…

linux查看基础硬件信息

#CPU核数 cat /proc/cpuinfo | grep "cpu cores" | uniq #CPU线程数 cat /proc/cpuinfo| grep "processor"| wc -l #内存大小 cat /proc/meminfo | grep MemTotal #硬盘信息 fdisk -l

前端学习(2450):页面布局制作

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…

前端学习(2451):表单数据的绑定

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…

mysql string types ---- mysql 字符类型详解

一、mysql 中包涵的字符类型&#xff1a; [national] char [(m)] [character set charset_name] [collate collation_name] [national] varchar [(m)] [character set charset_name] [collate collation_name]binary(m) -- 和char 只不过它用来保存二进制字节串…

前端学习(2452):封装数据接口

request.js <template> <div class"artical-container"><!--卡片--><el-card class"filter-card"><div slot"header" class"clearfix"><!--面包屑导航--><el-breadcrumb separator-class&quo…

【NOIP2016】换教室

题目描述 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程。 在可以选择的课程中,有2n节课程安排在n个时间段上。在第 i ( 1≤ i≤n)个时同段上, 两节内容相同的课程同时在不同的地点进行, 其中, 牛牛预先被安排在教室 ci上课, 而另一节课程在教室…

react和react develop tools编译

下载 https://github.com/facebook/react/tags 我这里下载的18.0.0 下载react&#xff0c;里面的packages/react-devtools-extensions目录就是chrome等的扩展插件&#xff0c;需要编译下 需要yarn环境编译&#xff0c;如果需要安装yarn&#xff0c;使用命令 npm install --…