1.下载redis
可以在线安装或者下载redis
①在线安装前需要检测是否存在rpm包不存在的话查看yum在线是否存在rpm包不存在的话就只能手动下载或者用别的方式下载
[root@localhost~]#rpm-qa|grepredis [root@localhost~]#yumlist|grepredis
说明不存在。
②去官网下载或者在线下载
wgethttp://redis.googlecode.com/files/redis-2.2.13.tar.gz
官网下载好的redis已经存在博客中了点击下载 redis。
2.安装
由于是tar.gz格式的所以需要解压安装
下载好之后查找下载文件所在路径
[root@localhost~]#whereisredis redis:/etc/redis [root@localhost~]#
解压编译redis的软件包需要有gcc环境
总之缺少什么安装什么。
tar-zxvfreids-2.8.13.tar.gz cdredis-2.8.13 make sudomakeinstall #配置开始--- 编译完成后在Src目录下有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf。然后拷贝到一个目录下。 mkdir/usr/redis cpredis-server/usr/redis cpredis-benchmark/usr/redis cpredis-cli/usr/redis cpredis.conf/usr/redis cd/usr/redis #配置结束--
或者可以这样配置
mkdir/etc/redis cpredis.conf/etc/redis/redis.conf mkdir/var/lib/redis
可从此处下载修改好的 redis.conf
启动redis redis-server/etc/redis/redis.conf #即可在后台启动redis服务确认运行了之后可以用redis-benchmark命令测试看看还可以通过redis-cli命令实际操作一下比如 #install的时候redis的命令会被拷贝到/usr/local/bin下面
3.测试
客户端测试一下是否启动成功
[root@localhostsrc]#ps-aux|grepredis Warning:badSyntax,perhapsabogus'-'?See/usr/share/doc/procps-3.2.8/FAQ root232660.00.71373567768?Sl00:230:04redis-server*:6379 root239820.00.5194045100pts/0S+01:090:00redis-cli root243980.00.0103244876pts/2S+01:440:00grepredis [root@localhostsrc]#redis-cli 127.0.0.1:6379>setwwang OK 127.0.0.1:6379>getw "wang" 127.0.0.1:6379>
4.关闭服务
redis-clishutdown 如果端口变化可以指定端口: redis-cli-p6379shutdown
127.0.0.1:6379>i+j CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused notconnected>setw3 CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused notconnected>
5.启动服务
[root@localhostsrc]#redis-server [24502]28Oct01:54:35.784#Warning:noconfigfilespecified,usingthedefaultconfig.Inordertospecifyaconfigfileuseredis-server/path/to/redis.conf [24502]28Oct01:54:35.784*Increasedmaximumnumberofopenfilesto10032(itwasoriginallysetto1024). _._ _.-``__''-._ _.-```.`_.''-._Redis2.8.13(00000000/0)64bit .-``.-```.```\/_.,_''-._ (',.-`|`,)Runninginstandalonemode |`-._`-...-`__...-.``-._|'`_.-'|Port:6379 |`-._`._/_.-'|PID:24502 `-._`-._`-./_.-'_.-' |`-._`-._`-.__.-'_.-'_.-'| |`-._`-.__.-'_.-'|http://redis.io `-._`-._`-.__.-'_.-'_.-' |`-._`-._`-.__.-'_.-'_.-'| |`-._`-.__.-'_.-'| `-._`-._`-.__.-'_.-'_.-' `-._`-.__.-'_.-' `-.__.-' `-.__.-' [24502]28Oct01:54:35.786#Serverstarted,Redisversion2.8.13 [24502]28Oct01:54:35.786#WARNINGovercommit_memoryissetto0!Backgroundsavemayfailunderlowmemorycondition.Tofixthisissueadd'vm.overcommit_memory=1'to/etc/sysctl.confandthenrebootorrunthecommand'sysctlvm.overcommit_memory=1'forthistotakeeffect. [24502]28Oct01:54:35.786*DBloadedfromdisk:0.000seconds [24502]28Oct01:54:35.786*Theserverisnowreadytoacceptconnectionsonport6379
启动之后最好重新打开个窗口运行redsi-cli进入控制台
否则可能出现连接错误。和windows下cmd运行tomcat类似。
[root@localhostredis]#redis-cli CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused notconnected>redis-cli CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused notconnected> [root@localhostredis]#redis-cli 127.0.0.1:6379>setname=wangxin (error)ERRSyntaxerror 127.0.0.1:6379>setnamewangxin OK 127.0.0.1:6379>setage26 OK 127.0.0.1:6379>getnameage (error)ERRwrongnumberofargumentsfor'get'command 127.0.0.1:6379>getname "wangxin" 127.0.0.1:6379>getage "26" 127.0.0.1:6379>