redis了解及安装.docx

上传人:b****8 文档编号:28293196 上传时间:2023-07-10 格式:DOCX 页数:11 大小:395.50KB
下载 相关 举报
redis了解及安装.docx_第1页
第1页 / 共11页
redis了解及安装.docx_第2页
第2页 / 共11页
redis了解及安装.docx_第3页
第3页 / 共11页
redis了解及安装.docx_第4页
第4页 / 共11页
redis了解及安装.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

redis了解及安装.docx

《redis了解及安装.docx》由会员分享,可在线阅读,更多相关《redis了解及安装.docx(11页珍藏版)》请在冰豆网上搜索。

redis了解及安装.docx

redis了解及安装

前言

概述

本文档详细的描述了Redis3.0.4的安装配置,包括单实例安装的搭建和简单的管理使用方法。

 

1初步认识Redis

1.1Redis的介绍

Redis是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件.它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sortedsets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询.Redis内置了 复制(replication), LUA脚本(Luascripting), LRU驱动事件(LRUeviction), 事务(transactions) 和不同级别的 磁盘持久化(persistence),并通过 Redis哨兵(Sentinel) 和自动分区(Cluster)提供高可用性(highavailability).

你可以对这些类型执行 原子操作 ,列如:

字符串(strings)的append命令; 散列(hashes)的hincrby命令; 列表(lists)的lpush命令; 集合(sets)计算交集sinter命令, 计算并集union命令 和 计算差集sdiff命令;或者在有序集合(sortedsets)里面获取成员的最高排名zrangebyscore命令.

为了实现其卓越的性能,Redis采用运行在 内存中的数据集工作方式.根据您的使用情况,您可以每隔一定时间将 数据集导出到磁盘 ,或者追加到命令日志中.您也可以关闭持久化功能,将Redis作为一个高效的网络的缓存数据功能使用.

Redis同样支持 主从复制(能自动重连和网络断开时自动重新同步),并且第一次同步是快速的非阻塞式的同步.

其他功能包括:

l 事务(Transactions)

l 订阅分发(Pub/Sub)

l LUA脚本(Luascripting)

l 过期自动删除key

l 内存回收

l 自动故障转移

 

您可以使用大多数的编程语言来使用Redis.

Redis使用 ANSIC 编写并且能在绝大Linux系统上运行,基于BSD协议,对OSX没有外部依赖.我们支持Linux和OSX两种系统的开发和测试,我们推荐使用Linux部署.Redis可以像SmartOS一样运行在Solaris系统中,但是我们会最大力度的支持它.官方不支持Windos版本的Redis,但微软开发和维护着支持win-64的Redis版本.

 

1.2Redis的官方网址

官方网址:

https:

//redis.io/

中文翻译网址:

 

1.3Redis部署环境选择

官方资料如下:

TheRedisprojectdoesnotofficiallysupportWindows.However,theMicrosoftOpenTechgroupdevelopsandmaintainsthisWindowsporttargetingWin64.

WesuggestdeployingRedisusingthe Linuxoperatingsystem.RedisisalsotestedheavilyonOSX,andtestedfromtimetotimeonFreeBSDandOpenBSDsystems.HoweverLinuxiswherewedoallthemajorstresstesting,andwheremostproductiondeploymentsareworking.

Ø Redis没有官方的Windows版本;

Ø Redis在linux系统上进行过所有主要的压力测试;

Ø 目前实际使用中的产品项目绝大多数是把Redis部署在linux系统上;

 

1.4Redis的安装提示

Ø MakesuretosettheLinuxkernel overcommitmemorysettingto1. 

Ø MakesuretodisableLinuxkernelfeature transparenthugepages,itwillaffectgreatlybothmemoryusageandlatencyinanegativeway.

Ø Makesureto setupsomeswap inyoursystem(wesuggestasmuchasswapasmemory).

Ø Setanexplicit maxmemory optionlimitinyourinstanceinordertomakesurethattheinstancewillreporterrorsinsteadoffailingwhenthesystemmemorylimitisneartobereached.

Ø IfyouareusingRedisinaverywrite-heavyapplication,whilesavinganRDBfileondiskorrewritingtheAOFlog Redismayuseupto2timesthememorynormallyused.

Ø Evenifyouhavepersistencedisabled,RediswillneedtoperformRDBsavesifyouusereplication,unlessyouusethenewdisklessreplicationfeature,whichiscurrentlyexperimental.

Ø Ifyouareusingreplication,makesurethateitheryourmasterhaspersistenceenabled,orthatitdoesnotautomaticallyrestartsoncrashes:

slaveswilltrytobeanexactcopyofthemaster,soifamasterrestartswithanemptydataset,slaveswillbewipedaswell.

Ø BydefaultRedisdoesnotrequire anyauthenticationandlistenstoallthenetworkinterfaces.ThisisabigsecurityissueifyouleaveRedisexposedontheinternetorotherplaceswhereattackerscanreachit.

 

1.5Redis安装软件下载

登录官方网站下载最新版本的Redis软件(https:

//redis.io/)

 

 

1.6环境依赖包检查

[root@Redis~]#rpm-qmake

make-3.81-20.el6.x86_64

 

 

2配置环境

2.1修改linux系统限制

编辑/etc/security/limits.conf,添加以下内容:

#usebyRedis

*softnproc65536

*hardnproc65536

*softnofile65536

*hardnofile65536

*softstack10240

 

编辑/etc/pam.d/login,添加以下内容:

sessionrequired/lib/security/pam_limits.so

2.2内核参数:

overcommit_memory

overcommit_memory:

内存分配策略

可选值:

0、1、2。

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程;

1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何;

2, 表示内核允许分配超过所有物理内存和交换空间总和的内存;

OOM(out-of-memory):

Linux对大部分申请内存的请求都回复"yes",以便能跑更多更大的程序。

因为申请内存后,并不会马上使用内存。

这种技术叫做Overcommit。

当linux发现内存不足时,会发生OOMkiller(OOM=out-of-memory)。

它会选择杀死一些进程(用户态进程,不是内核线程),以便释放内存。

当oom-killer发生时,linux会选择杀死哪些进程?

选择进程的函数是oom_badness函数(在mm/oom_kill.c中),该函数会计算每个进程的点数(0~1000)。

点数越高,这个进程越有可能被杀死。

每个进程的点数跟oom_score_adj有关,而且oom_score_adj可以被设置(-1000最低,1000最高)。

处理方法:

编辑/etc/sysctl.conf,添加vm.overcommit_memory=1,然后sysctl-p使配置文件生效;

 

2.3内核参数:

somaxconn

net.core.somaxconn是linux中的一个kernel参数,表示socket监听(listen)的backlog上限。

backlog是socket的监听队列,当一个请求(request)尚未被处理或建立时,他会进入backlog。

而socketserver可以一次性处理backlog中的所有请求,处理后的请求不再位于监听队列中。

当server处理请求较慢,以至于监听队列被填满后,新来的请求会被拒绝。

所以说net.core.somaxconn限制了接收新TCP连接侦听队列的大小。

对于一个经常处理新连接的高负载web服务环境来说,默认的128太小了。

大多数环境这个值建议增加到1024或者更多。

处理方法:

编辑/etc/sysctl.conf,添加net.core.somaxconn=65536,然后sysctl-p使配置文件生效;

 

2.4内核参数:

netdev_max_backlog

在每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目。

处理方法:

编辑/etc/sysctl.conf,添加dev_max_backlog=65536, 然后sysctl-p使配置文件生效;

 

2.5关闭TransparentHugePages

TodisableTHPatboottime:

Appendthefollowingtothekernelcommandline in grub.conf:

transparent_hugepage=never

 

example:

#grub.confgeneratedbyanaconda

#

#Notethatyoudonothavetorerungrubaftermakingchangestothisfile

#NOTICE:

 Youdonothavea/bootpartition. Thismeansthat

#         allkernelandinitrdpathsarerelativeto/,eg.

#         root(hd0,0)

#         kernel/boot/vmlinuz-versionroroot=/dev/sda1

#         initrd/boot/initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

titleRedHatEnterpriseLinux(2.6.32-431.el6.x86_64)

        root(hd0,0)

        kernel/boot/vmlinuz-2.6.32-431.el6.x86_64roroot=UUID=f09a9d3b-1b6d-4845-b413-12c8ae2893ddrd_NO_LUKSrd_NO_LVMLANG=en_US.UTF-8rd_NO_MDSYSFONT=latarcyrheb-sun16crashkernel=128M KEYBOARDTYPE=pcKEYTABLE=usrd_NO_DMrhgbquiettransparent_hugepage=never

        initrd/boot/initramfs-2.6.32-431.el6.x86_64.img

 

OR

Addthefollowinglinesin/etc/rc.localandreboottheserver (thisstillcanbedoneonRedhat7althoughrc.localisbeingdeprecated):

iftest-f/sys/kernel/mm/transparent_hugepage/enabled;then

   echonever>/sys/kernel/mm/transparent_hugepage/enabled

fi

iftest-f/sys/kernel/mm/transparent_hugepage/defrag;then

   echonever>/sys/kernel/mm/transparent_hugepage/defrag

fi

 

NOTE:

 PleasechangethefilepathforRHELkernelto

/sys/kernel/mm/redhat_transparent_hugepage/accordingly.

 

2.6禁用防火墙和Selinux

编辑/etc/selinux/config  Selinux=enable 修改为 selinux=disabled

 serviceiptablesstop

 chkconfigiptablesoff

 serviceiptablesstatus

 

3安装Redis软件

3.1上传并解压Redis软件包

[root@Redisredis]#cd/u01/software/

[root@Redissoftware]#tar-zxvfredis-4.0.1.tar.gz

[root@Redissoftware]#ln-s/u01/software/redis-4.0.1/usr/local/redis

[root@Redissoftware]#cd/usr/local/redis/

[root@Redisredis]#moreREADME.md

注:

README.md文件中包含了Redis的介绍、安装、使用和文件说明等信息,阅读能够进一步加深对Redis软件的理解。

 3.2编译Redis

[root@Redisredis]#pwd

/usr/local/redis

[root@Redisredis]#make

3.3配置全局环境(可选)

[root@Redis~]#vi/etc/profile

加入如下内容:

exportPATH

PATH=$PATH:

/usr/local/redis/src

 

重新加载全局配置文件:

[root@Redis~]#source/etc/profile

 

4配置Redis实例

4.1创建Redis数据库所属目录

[root@Redis~]#mkdir-p/u01/redis_27000/---DB目录

[root@Redis~]#mkdir-p/u01/redis_config/--配置文件目录

 

4.2创建Redis配置文件

[root@Redisredis]#vi/u01/redis_config/redis_27000.conf

 

5使用Redis

5.1启动Redis数据库

命令:

#redis-server配置文件绝对路径

范例:

[root@Redis~]#redis-server/u01/redis_config/redis_27000.conf

 

5.2登录Redis数据库

命令:

#redis-cli[-h-a-p-n......]

范例:

[root@Redis~]#redis-cli-p27000--raw

 

5.3关闭Redis数据库

命令:

#redis-clishutdown

范例:

[root@Redis~]#redis-cli-p27000shutdown

[root@Redis~]#redis-cli-p27000

127.0.0.1:

27000>shutdown

 

5.4KEY(键)的使用

命令:

setkeyvalue[EXseconds][PXmilliseconds][NX|XX]

范例:

127.0.0.1:

27000>setnamejack

127.0.0.1:

27000>getname

 

5.5其它命令的使用和详解

更多命令的使用方法和解析,请登录官方网址进行学习和了解:

https:

//redis.io/commands

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1