设为首页 收藏本站
查看: 1728|回复: 0

[经验分享] redis安装,配置

[复制链接]

尚未签到

发表于 2018-11-7 13:24:20 | 显示全部楼层 |阅读模式
  一)下载源码,编译安装
  


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

  make install后显示
  


  • cd src && make install
  • make[1]: Entering directory `/usr/local/src/redis-2.2.8/src'
  • cd ../deps/hiredis && make static ARCH=""
  • make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis'
  • make[2]: Nothing to be done for `static'.
  • make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis'
  • cd ../deps/linenoise && make ARCH=""
  • make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/linenoise'
  • make[2]: `linenoise_example' is up to date.
  • make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/linenoise'
  • cd ../deps/hiredis && make static
  • make[2]: Entering directory `/usr/local/src/redis-2.2.8/deps/hiredis'
  • make[2]: Nothing to be done for `static'.
  • make[2]: Leaving directory `/usr/local/src/redis-2.2.8/deps/hiredis'
  • 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
  • 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

  • Hint: To run 'make test' is a good idea ;)

  • mkdir -p /usr/local/bin
  • cp -p redis-server /usr/local/bin
  • cp -p redis-benchmark /usr/local/bin
  • cp -p redis-cli /usr/local/bin
  • cp -p redis-check-dump /usr/local/bin
  • cp -p redis-check-aof /usr/local/bin
  • make[1]: Leaving directory `/usr/local/src/redis-2.2.8/src'
  

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


  • daemonize no
  

  改成
  


  • daemonize yes
  

  这两个参数
  


  • loglevel warning
  • logfile /var/log/redis.log
  

  取消注释
  


  • syslog-enabled no #这个改成syslog-enabled yes
  • syslog-facility local0
  

  数据文件目录
  


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

  内存,连接数设置
  


  • maxmemory 256000000
  • maxclients 500
  

  三)启动脚本
  


  • #!/bin/bash
  • #
  • # Init file for redis
  • #
  • # chkconfig: - 80 12
  • # description: redis daemon
  • #
  • # processname: redis
  • # config: /etc/redis.conf
  • # pidfile: /var/run/redis.pid

  • . /etc/init.d/functions

  • BIN="/usr/local/bin"
  • CONFIG="/etc/redis.conf"
  • PIDFILE="/var/run/redis.pid"

  • ### Read configuration
  • [ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

  • RETVAL=0
  • prog="redis-server"
  • desc="Redis Server"

  • start() {

  •         if [ -e $PIDFILE ];then
  •              echo "$desc already running...."
  •              exit 1
  •         fi

  •         echo -n $"Starting $desc: "
  •         daemon $BIN/$prog $CONFIG

  •         RETVAL=$?
  •         echo
  •         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
  •         return $RETVAL
  • }

  • stop() {
  •         echo -n $"Stop $desc: "
  •         killproc $prog
  •         RETVAL=$?
  •         echo
  •         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
  •         return $RETVAL
  • }

  • restart() {
  •         stop
  •         start
  • }


  • case "$1" in
  •   start)
  •         start
  •         ;;
  •   stop)
  •         stop
  •         ;;
  •   restart)
  •         restart
  •         ;;
  •   condrestart)
  •         [ -e /var/lock/subsys/$prog ] && restart
  •         RETVAL=$?
  •         ;;
  •   status)
  •         status $prog
  •         RETVAL=$?
  •         ;;
  •    *)
  • echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  •         RETVAL=1
  • esac

  • exit $RETVAL
  

  配置启动脚本
  


  • #chmod 755 /etc/init.d/redis
  • # chkconfig --add redis
  • # chkconfig redis on
  

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


  • # mkdir /var/db/redis
  

  否则会出现下面的错误
  


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

  同时配置内核参数
  


  • sysctl vm.overcommit_memory=1
  

  否则提示错误
  


  • # 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.
  

  最后,启动
  


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

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


  • 启动
  • # redis-server /etc/redis.conf

  • 关闭
  • # redis-cli shutdown

  • 关闭某个端口上的redis
  • # redis-cli -p port shutdown



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-631998-1-1.html 上篇帖子: redis 指令集(适用于telnet) 下篇帖子: Installing Redis on Mac Snow Leopard(苹果机上安装Redis)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表