安装Redis 4.0单实例
一、Redis简单介绍
转载于网络
Redis是一个开源(BSD许可)的内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。由于Redis采用运行在内存中的数据集工作方式,其性能卓越,能支持超过100K+每秒的读写频率。它支持多种类型的数据结构,如字符串(strings), 散列(hashes),列表(lists),集合(sets),有序集合(sorted sets)与范围查询和地理空间(geospatial)索引半径查询。Redis内置了复制(replication), LUA脚本(Lua scripting),LRU淘汰机制,事务实现(transactions),发布订阅(publish/subscribe)和不同级别的磁盘持久化(persistence)等能力, 并通过Redis哨兵(Sentinel)和自动分区(Cluster)提供高可用性(high availability)。
Redis的主要功能都是基于单线程网络模型实现,也就是说Redis使用一个线程来服务所有的客户端请求,同时Redis采用了非阻塞式IO,并精细地优化各种命令的算法和时间复杂度,大部分命令的算法都是O(1)的,详细的命令具体可以看 Redis命令参考。
另外Redis的大部分操作都是原子性的(简单的单线程模型),同时Redis还支持对几个操作全并后的原子性执行。列如:字符串(strings)的append命令;散列(hashes)的hincrby命令;列表(lists)的lpush命令;集合(sets)计算交集sinter命令,计算并集union命令和计算差集sdiff命令;或者在有序集合(sorted sets)里面获取成员的最高排名zrangebyscore命令等。
官方站点:http://redis.io
二、安装Redis 4.0单实例
1、安装依赖包
- [root@VM_2_13_centos redis]# yum install gcc*
2、获取安装文件
- [root@VM_2_13_centos redis]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz
3、解压文件
- [root@VM_2_13_centos redis]# tar zxvf redis-4.0.9.tar.gz
- [root@VM_2_13_centos redis]# ll
- total 1708
- drwxrwxr-x 6 root root 4096 Mar 27 00:04 redis-4.0.9
- -rw-r--r-- 1 root root 1737022 Mar 27 00:04 redis-4.0.9.tar.gz
4、编译安装
- [root@VM_2_13_centos redis-4.0.9]# make
- [root@VM_2_13_centos redis-4.0.9]# make PREFIX=/usr/local/redis install
- cd src && make install
- make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'
- CC Makefile.dep
- make[1]: Leaving directory `/usr/local/redis/redis-4.0.9/src'
- make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'
- Hint: It's a good idea to run 'make test'
- INSTALL install
- INSTALL install
- INSTALL install
- INSTALL install
- INSTALL install
5、查看redis的版本
- [root@VM_2_13_centos ~]# redis-server --version
- Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=c97ec2b5e9b86914
6、启动redis服务
- [root@VM_2_13_centos redis]# /usr/local/redis/bin/redis-server /etc/redis/redis.conf
- [root@VM_2_13_centos redis]# netstat -tuplan | grep 6379
- tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5305/redis-server
- [root@VM_2_13_centos redis]# ps -ef | grep redis
- root 5305 1 0 21:38 ? 00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
- root 5356 30807 0 21:39 pts/1 00:00:00 grep --color=auto redis
7、通过客户端登录
- [root@VM_2_13_centos ~]# redis-cli
- 127.0.0.1:6379>
备注:如果要卸载redis,把/usr/local/redis/bin/目录下的redis删除即可。为了卸载干净,你还可以把解压和编译的redis包及配置的redis.conf也删除。
三、安全配置
1、设置密码
redis的默认安装是不设置密码的,可以在redis.conf中进行配置
- [root@VM_2_13_centos ~]# vim /etc/redis/redis.conf
- requirepass qcloud@2018
或者通过命令配置
- 127.0.0.1:6379>CONFIG set requirepass qcloud@2018
由于Redis的性能极高,并且输入错误密码后Redis并不会进行主动延迟(考虑到Redis的单线程模型),所以攻击者可以通过穷举法破解Redis的密码(1秒内能够尝试十几万个密码),因此在设置时一定要选择复杂的密码,可以用随机密码生成器生成。
注意:配置Redis复制的时候如果主数据库设置了密码,需要在从数据库的配置文件中通过masterauth参数设置主数据库的密码,以使从数据库连接主数据库时自动使用AUTH命令认证。
验证密码是否有效,是否需要认证
- [root@VM_2_13_centos ~]# redis-cli
- 127.0.0.1:6379>
- 127.0.0.1:6379> keys *
- (error) NOAUTH Authentication required.
- 127.0.0.1:6379> auth qcloud@2018
- OK
- 127.0.0.1:6379> keys *
- (empty list or set)
2、禁用高危命令
目前该命令可以正常使用
- 127.0.0.1:6379> flushall
- OK
关闭redis,但是由于上面设置了密码,必须要认证成功后才能关闭
- [root@VM_2_13_centos ~]# redis-cli shutdown
- (error) NOAUTH Authentication required.
- [root@VM_2_13_centos ~]# redis-cli -a qcloud@2018 shutdown
- [root@VM_2_13_centos ~]#
- [root@VM_2_13_centos ~]# ps -ef | grep redis
- root 6144 5406 0 21:54 pts/0 00:00:00 grep --color=auto redis
修改配置文件redis.conf,增加如下行:
- [root@VM_2_13_centos ~]# vim /etc/redis/redis.conf
- rename-command FLUSHALL ""
- rename-command CONFIG ""
- rename-command EVAL ""
重新启动redis
- [root@VM_2_13_centos ~]# redis-server /etc/redis/redis.conf
- [root@VM_2_13_centos ~]#
- [root@VM_2_13_centos ~]# redis-cli
- 127.0.0.1:6379>
- 127.0.0.1:6379> keys *
- (error) NOAUTH Authentication required.
- 127.0.0.1:6379>
- 127.0.0.1:6379> auth qcloud@2018
- OK
- 127.0.0.1:6379>
- 127.0.0.1:6379> flushall
- (error) ERR unknown command 'flushall'
- 127.0.0.1:6379>
- 127.0.0.1:6379> config
- (error) ERR unknown command 'config'
- 127.0.0.1:6379>
- 127.0.0.1:6379> eval
- (error) ERR unknown command 'eval'
通过上面的报错可以发现,在配置文件禁用的三个命令无法使用
3、绑定只能本机访问
- [root@VM_2_13_centos ~]# vim /etc/redis/redis.conf
- bind 127.0.0.1
4、设置redis开启自启动
- [root@VM_2_13_centos ~]# vim /etc/rc.d/rc.local
- /usr/local/redis/bin/redis-server /etc/redis/redis.conf &
安装Redis 4.0单实例的更多相关文章
- liunx 安装redis 4.0
liunx 上安装redis 4.0.1 第一步:将 redis-4.0.1.tar.gz 压缩问上传至/home目录下 第二步: 解压文件 tar -zxvf redis-4.0.1.tar.g ...
- CentOS7.2 安装redis 3.0.6集群
1.环境确认 a.系统版本查看 [hadoop@p168 ~]$ cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) b.安装依 ...
- centos / Linux 服务环境下安装 Redis 5.0.3
原文:centos / Linux 服务环境下安装 Redis 5.0.3 1.首先进入你要安装的目录 cd /usr/local 2.下载目前最新稳定版本 Redis 5.0.3 wget http ...
- linux安装 redis(redis-3.0.2.tar.gz) 和 mongodb(mongodb-linux-x86_64-rhel62-4.0.0)
1:首先 要下载 这两个 压缩包 注意:liunx是否已经安装过 gcc没安装的话 先安装:yum install gcc-c++ 2:安装 redis:redis-3.0.2.tar.gz (1): ...
- CentOS 7.3 安装redis 4.0.2服务
CentOS 7.3 安装redis 4.0.2服务 1.下载解压 下载地址:/home/xiaoming/ wget http://download.redis.io/releases/redis- ...
- Linux安装Redis 6.0.5 ./install_server.sh报错
Linux安装Redis 6.0.5 ./install_server.sh报错 linux 安装Redis6.0.5时 进行到./install_server.sh时报错, This systems ...
- Linux 安装Redis 5.0
结构如下: Redis 官方不建议Redis安装在WINDOWS 服务器上(尤其是生产中分布式事物缓存). linux 下Redis 5.0主从复制(一主二从)哨兵模式的搭建:https://www. ...
- RHEL5.6静默安装oracle11.2.0数据库实例脚本
脚本:单实例静默安装echo '[GENERAL] RESPONSEFILE_VERSION = "11.2.0" //查看虚拟机的版本,不能更改 OPERATION_TYPE = ...
- Linux下安装redis 3.0及C语言中客户端实现demo
1.获取安装文件 wget http://download.redis.io/redis-stable.tar.gz 2.解压文件 tar xzvf redis-stable.tar.gz 3.进入目 ...
随机推荐
- MongoDB学习目录
前面的话 为了能够使用NodeJS实现后端,MongoDB——这个NodeJS标配的数据库就不得不学.小火柴将MongoDB数据库的学习记录整理如下 基础 基础操作 数据类型 文档操作 索引 索引构建 ...
- name设置id的方式 解决多个单选域冲突现象 同时有利于从动态网页取值
- Centos安装python3
安装环境 系统:阿里云服务器centos7.5系统 看见好多博客对centos安装python3的方式各不相同且都不完整,今天我来完整的演示安装python3 1.下载python3源码包 命令 wg ...
- 洛谷P2918 [USACO08NOV]买干草(一道完全背包模板题)
题目链接 很明显的一道完全背包板子题,做法也很简单,就是要注意 这里你可以买比所需多的干草,只要达到数量就行了 状态转移方程:dp[j]=min(dp[j],dp[j-m[i]]+c[i]) 代码如下 ...
- POJ 1125-Stockbroker Grapevine-最短路
裸最短路 /*--------------------------------------------------------------------------------------*/ // H ...
- 【AGC002E】Candy Piles 博弈论
题目大意 有\(n\)堆糖果,第\(i\)堆有\(a_i\)个. 两个人轮流决策,决策分为两种: 1.选择糖果数最多的一堆糖果,并把这堆糖全吃了. 2.在每堆非空的糖果堆里拿一颗糖吃掉. 吃掉最后一颗 ...
- git 提交报错 : The file will have its original line endings in your working directory.
报错现象 git add . 的时候发现此报错 报错分析 看情况应该是不同系统对换行的识别不到位导致的 就常识来说文件是在windows下生成的所以换行和 linux 确实不同可能是因为这个导致的 ...
- Codeforces Bubble Cup 11 J. Moonwalk challenge加强版
题意 有一棵 \(n\) 个节点的树,每条边上有一个字符,有 \(m\) 次询问. 每次会选定两个点 \(u, v\) , \(u\) 到 \(v\) 的路径上的字符形成了一个字符串 \(T\) ,再 ...
- 「ZJOI2016」旅行者 解题报告
「ZJOI2016」旅行者 对网格图进行分治. 每次从中间选一列,然后枚举每个这一列的格子作为起点跑最短路,进入子矩形时把询问划分一下,有点类似整体二分 至于复杂度么,我不会阿 Code: #incl ...
- CF285E Positions in Permutations(dp+容斥)
题意,给定n,k,求有多少排列是的 | p[i]-i |=1 的数量为k. Solution 直接dp会有很大的后效性. 所以我们考虑固定k个数字使得它们是合法的,所以我们设dp[i][j][0/1] ...