redis安装,配置

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介:

一)下载源码,编译安装

 
  1. # wget http://redis.googlecode.com/files/redis-2.2.8.tar.gz 
  2. # tar xf redis-2.2.8.tar.gz 
  3. # cd redis 
  4. # make  
  5. # 网上说不能make install,可我这就是可以,奇怪,省去了手动copy redis命令的步骤
  6. # make install  

make install后显示

 
  1. cd src && make install 
  2. make[1]: Entering directory `/usr/local/src/redis-2.2.8/src' 
  3. cd ../deps/hiredis && make static ARCH="" 
  4. make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  5. make[2]: Nothing to be done for `static'. 
  6. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  7. cd ../deps/linenoise && make ARCH="" 
  8. make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/linenoise' 
  9. make[2]: `linenoise_example' is up to date. 
  10. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/linenoise' 
  11. cd ../deps/hiredis && make static 
  12. make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  13. make[2]: Nothing to be done for `static'. 
  14. make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis' 
  15. cc -o redis-benchmark -std=c99 -pedantic -O2 -Wall -W   -lm -pthread   -g -rdynamic -ggdb  ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o ../deps/hiredis/libhiredis.a 
  16. cc -o redis-cli -std=c99 -pedantic -O2 -Wall -W   -lm -pthread   -g -rdynamic -ggdb  anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o 
  17.  
  18. Hint: To run 'make test' is a good idea ;) 
  19.  
  20. mkdir -p /usr/local/bin 
  21. cp -p redis-server /usr/local/bin 
  22. cp -p redis-benchmark /usr/local/bin 
  23. cp -p redis-cli /usr/local/bin 
  24. cp -p redis-check-dump /usr/local/bin 
  25. cp -p redis-check-aof /usr/local/bin 
  26. make[1]: Leaving directory `/usr/local/src/redis-2.2.8/src' 

二)修改配置

修改配置之前,请将redis.conf copy一份到/etc/目录下

 
  1. daemonize no 

改成

 
  1. daemonize yes 

这两个参数

 
  1. loglevel warning  
  2. logfile /var/log/redis.log  

取消注释

 
  1. syslog-enabled no #这个改成syslog-enabled yes
  2. syslog-facility local0

数据文件目录

 
  1. # The working directory. 
  2. # The DB will be written inside this directory, with the filename specified 
  3. # above using the 'dbfilename' configuration directive. 
  4. # Also the Append Only File will be created inside this directory. 
  5. # Note that you must specify a directory here, not a file name. 
  6. dir /var/db/redis 

内存,连接数设置

 
  1. maxmemory 256000000
  2. maxclients 500

三)启动脚本

 
  1. #!/bin/bash 
  2. # Init file for redis 
  3. # chkconfig: - 80 12 
  4. # description: redis daemon 
  5. # processname: redis 
  6. # config: /etc/redis.conf 
  7. # pidfile: /var/run/redis.pid 
  8.  
  9. . /etc/init.d/functions 
  10.  
  11. BIN="/usr/local/bin" 
  12. CONFIG="/etc/redis.conf" 
  13. PIDFILE="/var/run/redis.pid" 
  14.  
  15. ### Read configuration 
  16. [ -r "$SYSCONFIG" ] && source "$SYSCONFIG" 
  17.  
  18. RETVAL=0 
  19. prog="redis-server" 
  20. desc="Redis Server" 
  21.  
  22. start() { 
  23.  
  24.         if [ -e $PIDFILE ];then 
  25.              echo "$desc already running...." 
  26.              exit 1 
  27.         fi 
  28.  
  29.         echo -n $"Starting $desc: " 
  30.         daemon $BIN/$prog $CONFIG 
  31.  
  32.         RETVAL=$? 
  33.         echo 
  34.         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
  35.         return $RETVAL 
  36.  
  37. stop() { 
  38.         echo -n $"Stop $desc: " 
  39.         killproc $prog 
  40.         RETVAL=$? 
  41.         echo 
  42.         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
  43.         return $RETVAL 
  44.  
  45. restart() { 
  46.         stop 
  47.         start 
  48.  
  49.  
  50. case "$1" in 
  51.   start) 
  52.         start 
  53.         ;; 
  54.   stop) 
  55.         stop 
  56.         ;; 
  57.   restart) 
  58.         restart 
  59.         ;; 
  60.   condrestart) 
  61.         [ -e /var/lock/subsys/$prog ] && restart 
  62.         RETVAL=$? 
  63.         ;; 
  64.   status) 
  65.         status $prog 
  66.         RETVAL=$? 
  67.         ;; 
  68.    *) 
  69. echo $"Usage: $0 {start|stop|restart|condrestart|status}" 
  70.         RETVAL=1 
  71. esac 
  72.  
  73. exit $RETVAL 

配置启动脚本

 
  1. #chmod 755 /etc/init.d/redis 
  2. # chkconfig --add redis 
  3. # chkconfig redis on 

四)启动

在正式启动redis之前,先创建数据目录

 
  1. # mkdir /var/db/redis 

否则会出现下面的错误

 
  1. [3030] 27 May 16:50:38 # Can't chdir to '/var/db/redis': No such file or directory 

同时配置内核参数

 
  1. sysctl vm.overcommit_memory=1 

否则提示错误

 
  1. # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 
  2. #To fix this issue 
  3. #add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 
  4. #'sysctl vm.overcommit_memory=1' for this to take effect. 

最后,启动

 
  1. [root@web ~]# /etc/init.d/redis start 
  2. Starting Redis Server:                                     [  OK  ]

PS:不利用脚本启动,关闭redis的命令

 
  1. 启动 
  2. # redis-server /etc/redis.conf 
  3.  
  4. 关闭 
  5. # redis-cli shutdown 
  6.  
  7. 关闭某个端口上的redis 
  8. # redis-cli -p port shutdown

本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/579825,如需转载请自行联系原作者
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
11天前
|
NoSQL 数据可视化 Linux
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
本文介绍了Redis的两个可视化管理工具:付费的Redis Desktop Manager和免费的Another Redis DeskTop Manager,包括它们的下载、安装和使用方法,以及在使用Another Redis DeskTop Manager连接Redis时可能遇到的问题和解决方案。
36 1
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
|
3天前
|
存储 NoSQL Redis
Redis 配置
10月更文挑战第14天
8 1
|
3天前
|
NoSQL Ubuntu Linux
Redis 安装
10月更文挑战第14天
18 1
|
8天前
|
NoSQL Linux Redis
Docker学习二(Centos):Docker安装并运行redis(成功运行)
这篇文章介绍了在CentOS系统上使用Docker安装并运行Redis数据库的详细步骤,包括拉取Redis镜像、创建挂载目录、下载配置文件、修改配置以及使用Docker命令运行Redis容器,并检查运行状态和使用Navicat连接Redis。
63 3
|
15天前
|
NoSQL Linux Shell
Redis 的安装与部署(图文)
Redis 的安装与部署(图文)
|
17天前
|
NoSQL Ubuntu Redis
Ubuntu安装redis
本文介绍了在Ubuntu系统上安装Redis的两种方法:一种是通过编译安装本地Redis包,包括下载、解压、编译安装、配置启动和测试连接的步骤;另一种是通过apt安装在线的Redis包,并提供了更新系统软件包列表、安装Redis服务器、检查Redis服务器状态和测试连接的命令。
20 0
Ubuntu安装redis
|
1月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
1月前
|
NoSQL Linux Redis
linux安装单机版redis详细步骤,及python连接redis案例
这篇文章提供了在Linux系统中安装单机版Redis的详细步骤,并展示了如何配置Redis为systemctl启动,以及使用Python连接Redis进行数据操作的案例。
45 2
|
1月前
|
NoSQL Linux Redis
linux之centos安装redis
linux之centos安装redis
|
13天前
|
消息中间件 NoSQL Kafka
大数据-116 - Flink DataStream Sink 原理、概念、常见Sink类型 配置与使用 附带案例1:消费Kafka写到Redis
大数据-116 - Flink DataStream Sink 原理、概念、常见Sink类型 配置与使用 附带案例1:消费Kafka写到Redis
59 0