centos7 搭建redis 集群

栏目: 数据库 · 发布时间: 6年前

内容简介:/usr/local/redis/src/redis-server /usr/local/redis/redis.conf &

1.搭建单个redis

1.1 安装必要插件

yum install gcc-c++ -y

1.2 下载解压

redis_version=5.0.5
wget http://download.redis.io/releases/redis-${redis_version}.tar.gz

tar xzf redis-${redis_version}.tar.gz

mv ./redis-${redis_version} /usr/local/redis

cd /usr/local/redis

make && make install

1.3 运行redis-server

/usr/local/redis/src/redis-server /usr/local/redis/redis.conf &

1.4 检查是否运行

ps -ef | grep redis

1.4 进入客户端

/usr/local/redis/src/redis-cli

1.5 退出redis-server 服务

/usr/local/redis/src/redis-cli shutdown

或者

pkill /usr/local/redis/src/redis-server

或者

kill + 进程号

2 搭建 redis 集群

2.1 准备工作

mkdir -p /usr/local/redis-cluster
mkdir -p {8001,8002,8003,8004,8005,8006}

2.1复制redis.conf

ps:要复制6份

cp /usr/local/redis/redis.conf /usr/local/redis-cluster/8001/

2.2 修改redis.conf

port 8001  #端口
cluster-enabled yes #启用集群模式
cluster-config-file nodes.conf
cluster-node-timeout 15000 #超时时间
appendonly yes
daemonize yes #后台运行
protected-mode no #非保护模式
pidfile  /var/run/redis_8001.pid
bind 127.0.0.1(去掉bind绑定访问ip信息)
cluster-config-file nodes-8001.conf(集群节点信息文件,这里800x最好和port对应上)

ps: 先修改一个 然后用sed命令修改

命令如下:

sed -i s/8001/8002/g /usr/local/redis-cluster/8001/redis.conf

2.3 启动6份redis

/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8001/redis.conf
/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8002/redis.conf
/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8003/redis.conf
/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8004/redis.conf
/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8005/redis.conf
/usr/local/redis/src/redis-server  /usr/local/redis-cluster/8006/redis.conf

2.4 查看是否启动

ps -ef | grep redis
centos7 搭建redis 集群

2.5 用redis-cli创建整个redis集群(redis5以前的版本集群是依靠 ruby 脚本redis-trib.rb实现)

/usr/local/redis/src/redis-cli --cluster create --cluster-replicas 1 172.17.0.5:8001 172.17.0.5:8002 172.17.0.5:8003 172.17.0.5:8004 172.17.0.5:8005 172.17.0.5:8006

ps:期间点击yes

该图为网上图片

centos7 搭建redis 集群

到此集群搭建完毕!!!

2.6 验证集群

./redis-cli -c -a xxx -h 192.168.5.100 -p 8001
提示:-a访问服务端密码,-c表示集群模式,指定ip地址和端口号

进入之后额外命令

进行验证: cluster info(查看集群信息)、cluster nodes(查看节点列表)

2.7关闭集群命令

/usr/local/redis/src/redis-cli -a xxx -c -h 192.168.0.60 -p 8001 shutdown
集群命令需要一个一个关


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Operations

Web Operations

John Allspaw、Jesse Robbins / O'Reilly Media / 2010-6-28 / USD 39.99

A web application involves many specialists, but it takes people in web ops to ensure that everything works together throughout an application's lifetime. It's the expertise you need when your start-u......一起来看看 《Web Operations》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具