Redis学习01——介绍与搭建环境
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——介绍与搭建环境的更多相关文章
- Android Testing学习01 介绍 测试测什么 测试的类型
Android Testing学习01 介绍 测试测什么 测试的类型 Android 测试 测什么 1.Activity的生命周期事件 应该测试Activity的生命周期事件处理. 如果你的Activ ...
- java学习第01天(搭建环境配置)
搭建环境配置分为3个步骤 1.下载并安装 jdk使用1.8.0_151版本,下载地址(包含32位和64位):链接:https://pan.baidu.com/s/1qZau8oO 密码:0t5o 2. ...
- 阶段3 3.SpringMVC·_06.异常处理及拦截器_4 SpringMVC拦截器之介绍和搭建环境
拦截器可以有多个 搭建环境 不用改,直接finish 复制原来项目的 依赖的包也复制过来 web.xml配置前端控制器 springmvc的配置文件 先创建对应的文件夹 分别创建java和resour ...
- Redis学习_01 windows下的环境搭建
一.Redis 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset( ...
- ES6学习(一)搭建环境
作为一名后端小开发,业务工作需要将后台系统重构一番,许多同事都已经使用前后分离搭建项目,为了不拖后腿自己在家摸索ES6的新特性,真心不知道什么ES3,ES5,一上来就开始搞ES6,在此留下学习笔记,方 ...
- Redis学习——数据结构介绍(四)
一.简介 作为一款key-value 的NoSQL数据库,Redis支持的数据结构比较丰富,有:String(字符串) .List(列表) .Set(集合) .Hash(哈希) .Zset(有序集合) ...
- 【Java学习01】:win7环境安装JDK
最近开始学习java,从第一步做起吧.win7中安装jdk非常简单,大牛勿喷. 1.下载JDK并执行安装. 访问网站www.java.com,选择win7版本的JDK下载.下载后双击安装(比较慢,耐心 ...
- redis 学习 01(下载 学习资源)
1. windows 版 redis 下载地址 https://github.com/MSOpenTech/redis/releases 2. redis 实战源码 http://redisinact ...
- spring.net学习(一) 搭建环境,实例化spring.net容器。
1,使用nuget安装SPring.Core.安装这个的同时,会把Common.Logging,Common.Logging.Core也装上. 2,建立对象配置xml文件.如图Objects.xml. ...
随机推荐
- Java 11 发布计划来了,已确定 3个 新特性!!
Oracle 已经发布了 Java Development Kit 10,下一个版本 JDK 11 也在准备之中了.按照 Java 新的版本发布标准,Java 11 将在 6 个月后到来,现在它还只有 ...
- java读取字符串,生成txt文件
/** * 读取字符串,生成txt 文件 已解决未设置编码时,在项目中直接打开文件,中文乱码问题 * WriteText.writeToText(musicInfo,fileName)直接调用 * * ...
- python函数基础(函数的定义和调用)
函数的定义 python定义函数使用def关键字 return[表达式]语句用于退出函数,选择性的向调用方返回一个表达式,不带参数值的return语句返回none def 函数名(参数列表): 函数体 ...
- nginx源码分析-源码结构
本文主要简单介绍nginx源码目录结构.程序编译流程.如何构建学习nginx的环境等.本文以及后续nginx源码分析文章是基于nginx当前(2009-02-27)的稳定版本0.6.35进行的分析,该 ...
- node vue 微信公众号(三)启用本地服务器
1.下载nginx http://nginx.org/en/download.html 2.启动服务 3.配置natapp服务,并启动
- csps模拟测试707172部分题解myc
题面:https://www.cnblogs.com/Juve/articles/11678524.html 骆驼:构造题,留坑 根据5×5的矩形构造成大矩形 毛一琛: mid in the midd ...
- 「题解」:07.18NOIP模拟赛T1:星际旅行
问题 A: 星际旅行 时间限制: 1 Sec 内存限制: 256 MB 题面 题面谢绝公开. 考试心路历程 拿到这道题感觉很懵逼,所以先搞的T2和T3,最后码了个暴力,结果还不如直接输出‘0’得分高 ...
- Clion IDE的安装
/下载压缩包 wget https://download.jetbrains.8686c.com/cpp/CLion-2016.2.2.tar.gz //解压 tar -zxvf CLion-2016 ...
- vue之vant组件下拉加载更多
vant地址:https://youzan.github.io/vant/#/zh-CN/intro 基础用法 List 组件通过loading和finished两个变量控制加载状态,当组件滚动到底部 ...
- css---switch开关
html: <label><input class="mui-switch" type="checkbox"> 默认未选中</la ...