NoSQL篇 | Redis 安装配置

Posted 5ithink

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NoSQL篇 | Redis 安装配置相关的知识,希望对你有一定的参考价值。

        开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API 。

概览

  • 简介

  • 安装

  • 单节点

  • 主从

  • 集群

  • Q&A

  • 参考连接

简介


       Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

  • 支持数据持久化

  • 支持多种数据结构类型:list set zset hash等数据结构存储

  • 数据备份:Master-Slave模式

  • 性能高

  • 操作原子性特征

  • 支持publish/subscribe  通知 key过期特性

安装配置


1.下载Redis

wget http://download.redis.io/releases/redis-3.2.11.tar.gz

2.安装

tar xzf redis-redis-3.2.11.tar.gz

cd redis-redis-3.2.11

make

3.创建目录

mkdir -p /home/redis/single

cp home/redis/redis-3.2.11/src/redis-server /home/redis/single

cp home/redis/redis-3.2.11/redis.conf /home/redis/single

4.修改配置文件redis.conf [其他使用默认配置]

bind 192.168.1.202

port 6379

daemonize yes

pidfile /home/redis/single/redis.pid

logfile /home/redis/single/redis.log

dbfilename dump.rdb

dir /home/redis/single/

5.启动  /home/redis/single/redis-server /home/redis/single/redis.conf

6.验证

a.日志:tail -f /home/redis/single/redis.log

b.进程:ps -ef |grep redis

c.监听:netstat -nltp

NoSQL篇 | Redis 安装配置

7.连接 /home/redis/redis-3.2.11/src/redis-cli -h 192.168.1.202 -p 6379

NoSQL篇 | Redis 安装配置

8.测试

NoSQL篇 | Redis 安装配置

主从Master-Slave配置


1.一主三从:

master:

192.168.1.202:6379

slaver:

slave_1:192.168.1.202:63791

slave_2:192.168.1.202:63792

slave_3:192.168.1.202:63793

2.创建目录

mkdir -p /home/redis/master-slaver/

cd /home/redis/master-slaver/

mkdir s1 s2 s3

3.配置从节点s1:

a.拷贝redis-server redis.conf文件

cp home/redis/redis-3.2.11/src/redis-server /home/redis/master-slaver/s1

cp home/redis/redis-3.2.11/redis.conf /home/redis/master-slaver/s1

b.修改配置redis.conf

bind 192.168.1.202

port 63791

daemonize yes

pidfile /home/redis/master-slaver/s1/redis.pid

logfile /home/redis/master-slaver/s1/redis.log

dbfilename dump.rdb

dir /home/redis/master-slaver/s1

slaveof 192.168.1.202 6379

4.配置从节点s2:

a.拷贝redis-server redis.conf文件

cp home/redis/redis-3.2.11/src/redis-server /home/redis/master-slaver/s2

cp home/redis/redis-3.2.11/redis.conf /home/redis/master-slaver/s2

b.修改配置redis.conf

bind 192.168.1.202

port 63792

daemonize yes

pidfile /home/redis/master-slaver/s2/redis.pid

logfile /home/redis/master-slaver/s2/redis.log

dbfilename dump.rdb

dir /home/redis/master-slaver/s2

slaveof 192.168.1.202 6379

5.配置从节点s3

a.拷贝redis-server redis.conf文件

cp home/redis/redis-3.2.11/src/redis-server /home/redis/master-slaver/s3

cp home/redis/redis-3.2.11/redis.conf /home/redis/master-slaver/s3

b.修改配置redis.conf

bind 192.168.1.202

port 63793

daemonize yes

pidfile /home/redis/master-slaver/s3/redis.pid

logfile /home/redis/master-slaver/s3/redis.log

dbfilename dump.rdb

dir /home/redis/master-slaver/s3

slaveof 192.168.1.202 6379

6.目录结构

NoSQL篇 | Redis 安装配置

7.启动Redis 服务

从节点s1: /home/redis/master-slaver/s1/redis-server /home/redis/master-slaver/s1/redis.conf

从节点s2: /home/redis/master-slaver/s2/redis-server  /home/redis/master-slaver/s2/redis.conf

从节点s3: /home/redis/master-slaver/s3/redis-server  /home/redis/master-slaver/s3/redis.conf

8.验证

a.进程 ps -ef |grep redis

NoSQL篇 | Redis 安装配置

b.日志 tail -f /home/redis/master-slaver/s[1,2,3]/redis.log

NoSQL篇 | Redis 安装配置

NoSQL篇 | Redis 安装配置

NoSQL篇 | Redis 安装配置

9.连接从节点:

/home/redis/redis-3.2.11/src/redis-cli -h 192.168.1.202 -p 63791

/home/redis/redis-3.2.11/src/redis-cli -h 192.168.1.202 -p 63792

/home/redis/redis-3.2.11/src/redis-cli -h 192.168.1.202 -p 63793

NoSQL篇 | Redis 安装配置

集群Cluster配置


1.ruby环境支持:

a.下载安装包 wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.7.tar.gz

b.解压 tar xf ruby-2.2.7.tar.gz cd ruby-2.2.7 

c.配置 ./configure --prefix=/home/app/ruby2.2.7 

d.编译&安装

make && make install

yum install rubygems

gem install redis

2.创建目录

mkdir -p /home/redis/cluster

cd /home/redis/cluster

mkdir -p m1 m2 m3

cp home/redis/redis-3.2.11/src/redis-server /home/redis/cluster/m1

cp home/redis/redis-3.2.11/redis.conf /home/redis/cluster/m1

同理,将redis-server redis.conf分别拷贝到m2 m3目录

NoSQL篇 | Redis 安装配置3.修改m1配置文件 vi /home/redis/cluster/m1/redis.conf [其他默认]

bind 192.168.1.202

port 6381

daemonize yes

dir /home/redis/cluster/m1/

dbfilename dump.rdb

appendonly yes

appendfilename "appendonly.aof"

appendfsync everysec

cluster-enabled yes

cluster-config-file nodes.conf

4.修改m2配置文件 vi /home/redis/cluster/m2/redis.conf [其他默认]

bind 192.168.1.202

port 6382

daemonize yes

dir /home/redis/cluster/m2/

dbfilename dump.rdb

appendonly yes

appendfilename "appendonly.aof"

appendfsync everysec

cluster-enabled yes

cluster-config-file nodes.conf

5.修改m3配置文件 vi /home/redis/cluster/m3/redis.conf [其他默认]

bind 192.168.1.202

port 6383

daemonize yes

dir /home/redis/cluster/m3/

dbfilename dump.rdb

appendonly yes

appendfilename "appendonly.aof"

appendfsync everysec

cluster-enabled yes

cluster-config-file nodes.conf

6.启动cluster 

m1 :/home/redis/cluster/m1/redis-server /home/redis/cluster/m1/redis.conf

m2 :/home/redis/cluster/m2/redis-server /home/redis/cluster/m2/redis.conf

m3 :/home/redis/cluster/m3/redis-server /home/redis/cluster/m3/redis.conf

7.验证

a.进程

NoSQL篇 | Redis 安装配置

b.日志 [m1] tail -f /home/redis/cluster/m1/redis.log

NoSQL篇 | Redis 安装配置

c.日志 [m2] tail -f /home/redis/cluster/m2/redis.log

NoSQL篇 | Redis 安装配置

d.日志 [m3] tail -f /home/redis/cluster/m3/redis.log

NoSQL篇 | Redis 安装配置

e.nodes.conf

NoSQL篇 | Redis 安装配置

8.连接 /home/redis/redis-3.2.11/src/redis-cli -h 192.168.1.202 -p 6381 -c

9.RedisDesktopManager

Redis Mac客户端  https://github.com/uglide/RedisDesktopManager/releases/

Q&A

参考链接:

  • https://redis.io/

  • https://github.com/uglide/RedisDesktopManager/releases/

以上是关于NoSQL篇 | Redis 安装配置的主要内容,如果未能解决你的问题,请参考以下文章

NoSQL篇 | NoSQL从小白到码神 之 Redis篇

redis安装配置

NoSQL -- redis 安装 主从 配置详解 常用命令

NoSQL篇 | Memcached 安装配置

NoSQL之 Redis配置与优化

Redis在Linux下的安装与配置