Redis学习01介绍与搭建环境
一简介
二yum配置已经配置了的可以跳过
三安装gcc
四安装redis
1 上传Redis到linux中
2 解压到usrlocal下
3 编译redis
4 安装redis
5 拷贝配置文件到redis目录下
6 修改配置文件
五启动redis
1 bin下主要命令说明
2 前端启动
3 后端启动
六测试
Redis学习01——介绍与搭建环境
一、简介
Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。

Redis 与其他 key - value 缓存产品有以下三个特点:

Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。

Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。

Redis支持数据的备份,即master-slave模式的数据备份。

可以查看:

Redis 简介

NoSql

我们可以在 windows 或者linux 下安装 Redis。

Window 下,去这个地址下载安装就行了 https://github.com/MicrosoftArchive/redis/releases

Linux下安装我们需要一个linux。我使用的是 Redhat7。

我们需要去 Redis 的官网下载最新的 redis。 https://redis.io/download。

安装步骤主要分为以下几大步:

下载Redis(可以一边下载,一边进行后面的步骤)

使用yum安装编译器gcc

把下载好的 Redis上传到linux中

解压redis

编译redis

安装redis

配置redis

启动测试

二、yum配置(已经配置了的,可以跳过)
我使用的是 Redhat 7。如果你已经配置了 yum ,就跳过这步。

第1步:把光盘设备中的系统镜像挂载到/media/cdrom目录:

[root@wiming ~]# mkdir -p /media/cdrom
[root@wiming ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
1
2
3
4
第2步:使用Vim文本编辑器创建Yum仓库的配置文件

name=rhel7 yum仓库的名称描述,易于识别仓库用处。。

baseurl=file:///media/cdrom 提供方式包括FTP(ftp://..)、HTTP(http://..)、本地(file:///..)

enabled=1 设置此源是否可用,1为可用,0为禁用。

gpgcheck=1 设置此源是否校验文件,1为校验,0为不校验。

[root@wiming ~]# vim /etc/yum.repos.d/rhel7.repo
[rhel7]
name=rhel7
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
1
2
3
4
5
6
7
三、安装gcc
[root@wiming ~]# yum install gcc-c++
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7 | 4.1 kB 00:00:00 
(1/2): rhel7/group_gz | 134 kB 00:00:00 
(2/2): rhel7/primary_db | 3.4 MB 00:00:01 
....省略了输出.... 
Total download size: 34 M
Installed size: 83 M
Is this ok [y/d/N]: y(这里选择y)
Downloading packages:
-------------------------------------------

....省略了输出....

Dependency Installed:
cpp.x86_64 0:4.8.2-16.el7 gcc.x86_64 0:4.8.2-16.el7 glibc-devel.x86_64 0:2.17-55.el7 glibc-headers.x86_64 0:2.17-55.el7 
kernel-headers.x86_64 0:3.10.0-123.el7 libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.2-16.el7 mpfr.x86_64 0:3.1.1-4.el7

Complete!(完成)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
四、安装redis
我下载的版本是 redis-4.0.2

4.1 上传Redis到linux中
这一个步骤就是把下载好的redis上传到linux中。我使用的是Xshell,可以看着文章操作

linux学习(八) XShell上传、下载本地文件到linux服务器

4.2 解压到/usr/local下
[root@wiming ~]# tar -xvf redis-4.0.2.tar.gz -C /usr/local
redis-4.0.2/
redis-4.0.2/.gitignore
redis-4.0.2/00-RELEASENOTES
redis-4.0.2/BUGS
redis-4.0.2/CONTRIBUTING
redis-4.0.2/COPYING
redis-4.0.2/INSTALL
......
1
2
3
4
5
6
7
8
9
4.3 编译redis
进入 redis-4.0.2 目录 使用 make 命令编译redis

[root@wiming ~]# cd /usr/local/
[root@wiming local]# ls
bin etc games include lib lib64 libexec redis-4.0.2 sbin share src
[root@wiming local]# cd redis-4.0.2/
[root@wiming redis-4.0.2]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis-4.0.2/src'
...........省略输出........
1
2
3
4
5
6
7
8
9
4.4 安装redis
在 redis-4.0.2 目录中 使用 make PREFIX=/usr/local/redis install 命令安装 redis到/usr/local/redis 中

[root@wiming redis-4.0.2]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: Entering directory `/usr/local/redis-4.0.2/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis-4.0.2/src'
make[1]: Entering directory `/usr/local/redis-4.0.2/src'

Hint: It's a good idea to run 'make test' ;)

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis-4.0.2/src'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
4.5 拷贝配置文件到redis目录下
拷贝 redis-4.0.2 中的 redis.conf 到安装目录 redis\bin 中

[root@wiming bin]# cp /usr/local/redis-4.0.2/redis.conf /usr/local/redis/bin/redis.conf
1
2
4.6 修改配置文件
使用vim打开 redis.conf,修改136行 daemonize为yes 
这个配置文件是 bin 下的配置文件

....
132 ################################# GENERAL #####################################
133 
134 # By default Redis does not run as a daemon. Use 'yes' if you need it.
135 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
136 daemonize yes

....
1
2
3
4
5
6
7
8
9
五、启动redis
5.1 bin下主要命令说明
redis-benchmark 性能测试工具

redis-check-aof 检查修复aof文件

redis-cli 命令行客户端

redis.conf Redis配置文件

redis-server redis服务启动命令

5.2 前端启动
直接使用 /redis-server 就会前端启动,缺点就是其中完成后,不能再进行操作(除非重新打开一个终端),停止使用 ctrl+c 。

[root@wiming bin]# ./redis-server
7341:C 24 Sep 05:01:19.756 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7341:C 24 Sep 05:01:19.757 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=7341, just started
7341:C 24 Sep 05:01:19.757 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
7341:M 24 Sep 05:01:19.759 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._ 
_.-``__ ''-._ 
_.-`` `. `_. ''-._ Redis 4.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._ 
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7341
`-._ `-._ `-./ _.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | http://redis.io 
`-._ `-._`-.__.-'_.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | 
`-._ `-._`-.__.-'_.-' _.-' 
`-._ `-.__.-' _.-' 
`-._ _.-' 
`-.__.-'

7341:M 24 Sep 05:01:19.764 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7341:M 24 Sep 05:01:19.764 # Server initialized
7341:M 24 Sep 05:01:19.765 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7341:M 24 Sep 05:01:19.765 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
7341:M 24 Sep 05:01:19.765 * DB loaded from disk: 0.000 seconds
7341:M 24 Sep 05:01:19.765 * Ready to accept connections
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
5.3 后端启动
后端启动就是启动的同时,带上配置文件,使用的命令是

./redis-server redis.conf
1
例如:

[root@wiming bin]# ./redis-server redis.conf 
7374:C 24 Sep 05:04:13.424 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7374:C 24 Sep 05:04:13.424 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=7374, just started
7374:C 24 Sep 05:04:13.424 # Configuration loaded
[root@wiming bin]# 
1
2
3
4
5
6
关闭服务器使用

[root@wiming bin]# ./redis-cli shutdown
1
六、测试
测试之前,必须打开redis服务。

测试使用 ./redis-cli 来打开一个客户端

然后使用 set 和 get 来存入和取出数据

退出客户端使用 exit

[root@wiming bin]# ./redis-server redis.conf
7422:C 24 Sep 05:09:07.642 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7422:C 24 Sep 05:09:07.642 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=7422, just started
7422:C 24 Sep 05:09:07.642 # Configuration loaded
[root@wiming bin]# ./redis-cli
127.0.0.1:6379> set username wiming
OK
127.0.0.1:6379> get username
"wiming"
127.0.0.1:6379> exit
[root@wiming bin]# ./redis-cli shutdown
1
2
3
4
5
6
7
8
9
10
11
12

--------------------- 
作者:愤怒的小明 
来源:CSDN 
原文:https://blog.csdn.net/qiwenmingshiwo/article/details/78074795 
版权声明:本文为博主原创文章,转载请附上博文链接!

Redis学习01——介绍与搭建环境的更多相关文章

  1. Android Testing学习01 介绍 测试测什么 测试的类型

    Android Testing学习01 介绍 测试测什么 测试的类型 Android 测试 测什么 1.Activity的生命周期事件 应该测试Activity的生命周期事件处理. 如果你的Activ ...

  2. java学习第01天(搭建环境配置)

    搭建环境配置分为3个步骤 1.下载并安装 jdk使用1.8.0_151版本,下载地址(包含32位和64位):链接:https://pan.baidu.com/s/1qZau8oO 密码:0t5o 2. ...

  3. 阶段3 3.SpringMVC·_06.异常处理及拦截器_4 SpringMVC拦截器之介绍和搭建环境

    拦截器可以有多个 搭建环境 不用改,直接finish 复制原来项目的 依赖的包也复制过来 web.xml配置前端控制器 springmvc的配置文件 先创建对应的文件夹 分别创建java和resour ...

  4. Redis学习_01 windows下的环境搭建

    一.Redis 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset( ...

  5. ES6学习(一)搭建环境

    作为一名后端小开发,业务工作需要将后台系统重构一番,许多同事都已经使用前后分离搭建项目,为了不拖后腿自己在家摸索ES6的新特性,真心不知道什么ES3,ES5,一上来就开始搞ES6,在此留下学习笔记,方 ...

  6. Redis学习——数据结构介绍(四)

    一.简介 作为一款key-value 的NoSQL数据库,Redis支持的数据结构比较丰富,有:String(字符串) .List(列表) .Set(集合) .Hash(哈希) .Zset(有序集合) ...

  7. 【Java学习01】:win7环境安装JDK

    最近开始学习java,从第一步做起吧.win7中安装jdk非常简单,大牛勿喷. 1.下载JDK并执行安装. 访问网站www.java.com,选择win7版本的JDK下载.下载后双击安装(比较慢,耐心 ...

  8. redis 学习 01(下载 学习资源)

    1. windows 版 redis 下载地址 https://github.com/MSOpenTech/redis/releases 2. redis 实战源码 http://redisinact ...

  9. spring.net学习(一) 搭建环境,实例化spring.net容器。

    1,使用nuget安装SPring.Core.安装这个的同时,会把Common.Logging,Common.Logging.Core也装上. 2,建立对象配置xml文件.如图Objects.xml. ...

随机推荐

  1. Eclipse_断点设置不起作用

    在使用Ecplise进行代码调试的时候,发现打了断点,却一直不进入断点,也不会进取断点调试模式,找了很久答案,之前就发现断点的样子有些奇怪,现在看来,还真是这个原因造成的. 只要不跳过断点快捷键(Ct ...

  2. spring boot过滤器FilterRegistrationBean

    有2种方式可以实现过滤器 1:通过FilterRegistrationBean实例注册 2:通过@WebFilter注解生效 这里选择第一种,因为第二种不能设置过滤器之间的优先级 为了演示优先级,这里 ...

  3. ">/dev/null 2>&1 "是什么意思

    在Linux中: 0:表示键盘输入(stdin) 1:表示标准输出(stdout),系统默认是1 2:表示错误输出(stderr) shell命令:command >/dev/null  2&g ...

  4. 把类完善了一下,播放器也完善了一下,纯MFC与WinMM的产物

  5. iOS开发系列-JSON解析

    概述 JOSN是一种轻量级的数据格式,一般用于数据交互.服务器返回给客户端,一般都是JSON格式或者XML格式. JSON的格式: {"name" : "CoderHon ...

  6. java char <-> int

    int = char - '0' or Character.getNumericValue(char ch) char = (char)int

  7. Linux命令查看文件内容

    cat:一次性顺序显示文件所有内容和 cat filename tac:一次性倒序显示文件所有内容和 tac filename head:显示文件开头的若干行内容 head -n filename t ...

  8. flask请求上下文源码分析

    一.什么是上下文 每一段程序都有很多外部变量,只有像add这种简单的函数才是没有外部变量的,一旦你的一段程序有了外部变量,这段程序就不完整了,不能独立运行,你为了使他们能运行,就要给所有的外部变量一个 ...

  9. 解析Request和Response

    简介: Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. request和response对象即然代表请求和响应 ...

  10. C++嵌套类(内部类与外部类)

    在一个类中定义的类被称为嵌套类,定义嵌套类的类被称为外部类.; //不能访问 mytest::i = 10;//不能访问 } private: class mytest { int i; int j; ...