Centos7下安装Redis-简单记录

文章目录

    • 单节点搭建
    • 集群搭建

之前在Centos7下安装过,后来删除了,然后改为Docker下安装,然后发现在Docker下操作还是不太方便,所以还是再回到Centos7下安装一个。

单节点搭建

一看官网,哇,Redis6都出了,还是先用熟悉的5。
安装方式,一种自己编译,另一种直接yum。都很简单。

参考文章:https://www.cnblogs.com/heqiuyong/p/10463334.html
yum instal wget
yum install -y gcc
wget http://download.redis.io/releases/redis-5.0.8.tar.gz

最后安装的目录:
三、cd切换到redis解压目录下,执行编译

[root@localhost local]# cd redis-5.0.3

[root@localhost redis-5.0.3]# make

四、安装并指定安装目录

[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis

这里在记录一下帮助如何用。

127.0.0.1:6379> help
redis-cli 5.0.8
To get help about Redis commands type:
      "help @" to get a list of commands in <group>
      "help " for help on <command>
      "help " to get a list of possible help topics
      "quit" to exit

To set redis-cli preferences:
      ":set hints" enable online hints
      ":set nohints" disable online hints
Set your preferences in ~/.redisclirc

学的技术太多,help必须记住,其他的可以查。

127.0.0.1:6379> help @list

  BLPOP key [key ...] timeout
  summary: Remove and get the first element in a list, or block until one is available
  since: 2.0.0

开放端口:
redis.conf
注释:
#bind 127.0.0.1
修改 保护模式修改
protected-mode no

启动
./redis-server redis.conf
关闭:./redis-cli shutdown

集群搭建

复制bin和配置文件,修改端口。建立三主,三从。
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis01 -r
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis02 -r
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis03 -r
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis04 -r
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis05 -r
[root@localhost local]# cp ./redis/bin/ redis-cluster/redis06 -r
修改端口,集群支持。
打开redis.conf配置文件
修改端口号为7001,并把cluster-enabled yes前的注释去掉。

命令:不再使用redis-trib.rb,直接使用redis-cli 方便多了。

/usr/local/redis-cluster/redis01/redis-cli --cluster create    --cluster-replicas 1 192.168.172.150:7001 192.168.172.150:7002 192.168.172.150:7003 192.168.172.150:7004 192.168.172.150:7005 192.168.172.150:7006 

Centos7下安装Redis-简单记录_第1张图片
客户端连接测试:

[root@localhost bin]# redis-cli -c -p 7001
127.0.0.1:7001> set 1 1
-> Redirected to slot [9842] located at 192.168.172.150:7002
OK
192.168.172.150:7002> set  2 2
OK
192.168.172.150:7002> set  3 3
-> Redirected to slot [1584] located at 192.168.172.150:7001
OK
192.168.172.150:7001> set  4 4
-> Redirected to slot [14039] located at 192.168.172.150:7003
OK
192.168.172.150:7003> 

启停脚本:
start.sh
stop.sh

可以参考文章:https://www.jianshu.com/p/8045b92fafb2

你可能感兴趣的:(Redis)