在CentOS 7下安装Redis和MongoDB

树叶云

前一篇记录了Node.js,这一次说说在CentOS 7下安装Redis和MongoDB,这样基本就安装好nodejs的整套开发环境了。

Redis

在CentOS下安装Redis也比较简单,按照步骤一步一步的操作,基本不会出错。

1、切换到/usr/src 目录(如果你安装在别的目录,注意后面要一些路径也要修改),下载Redis,目前最新的是2.8.13版本

  1. cd /usr/src
  2. wget http://download.redis.io/releases/redis-2.8.13.tar.gz

2、解压,切换目录

  1. tar xzf redis2.8.13.tar.gz
  2. cd redis2.8.13

3、编译

  1. make
  2. make install
  1. daemonize yes
  2. loglevel notice
  3. logfile /var/log/redis.log
  4. dir ./

5、设置系统的overcommit_memory,执行

  1. vi /etc/sysctl.conf

在文件中添加一行,保存:

  1. vm.overcommit_memory =1

执行:

  1. sysctl vm.overcommit_memory=1

6、添加启动脚本,执行:

  1. vi /etc/init.d/redis

写入下面的代码,保存:

  1. #!/bin/sh
  2. #
  3. # redis Startup script for Redis Server
  4. #
  5. # chkconfig: – 90 10
  6. # description: Redis is an open source, advanced key-value store.
  7. #
  8. # processname: redis-server
  9. # config: /etc/redis.conf
  10. # pidfile: /var/run/redis.pid
  11.  
  12. REDISPORT=6379
  13. EXEC=/usr/local/bin/redisserver
  14. REDIS_CLI=/usr/local/bin/rediscli
  15. PIDFILE=/var/run/redis.pid
  16. CONF=“/usr/src/redis-2.8.13/redis.conf”
  17. case“$1”in
  18. start)
  19. if[f $PIDFILE ]
  20. then
  21. echo “$PIDFILE exists, process is already running or crashed”
  22. else
  23. echo “Starting Redis server…”
  24. $EXEC $CONF
  25. fi
  26. if[“$?”=“0”]
  27. then
  28. echo “Redis is running…”
  29. fi
  30. ;;
  31. stop)
  32. if[!f $PIDFILE ]
  33. then
  34. echo “$PIDFILE does not exist, process is not running”
  35. else
  36. PID=$(cat $PIDFILE)
  37. echo “Stopping …”
  38. $REDIS_CLI p $REDISPORT SHUTDOWN
  39. while[x ${PIDFILE}]
  40. do
  41. echo “Waiting for Redis to shutdown …”
  42. sleep 1
  43. done
  44. echo “Redis stopped”
  45. fi
  46. ;;
  47. restart|forcereload)
  48. ${0} stop
  49. ${0} start
  50. ;;
  51. *)
  52. echo “Usage: /etc/init.d/redis {start|stop|restart|force-reload}”>&2
  53. exit 1
  54. esac

设置权限和开机启动:

  1. chmod +x /etc/init.d/redis
  2. chkconfig add redis
  3. chkconfig redis on

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/221002.html<

(0)
运维的头像运维
上一篇2025-04-14 20:12
下一篇 2025-04-14 20:13

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注