在CentOS 7下安裝Redis和MongoDB

來源:互聯網
上載者:User

在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 redis-2.8.13.tar.gz
  2. cd redis-2.8.13

3、編譯

  1. make
  2. make install

4、開啟redis.conf 修改設定檔,最關鍵是下面幾行,其他的設定參考官方文檔:

  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/redis-server
  14. REDIS_CLI=/usr/local/bin/redis-cli
  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|force-reload)
  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

ok,現在就安裝好了。啟動redis使用service redis start 或者/etc/init.d/redis start ,停止redis的命令service redis stop 或者/etc/init.d/redis stop ,在windows系統下使用redis可以參考這篇文章。

下面關於Redis的文章您也可能喜歡,不妨參考下:

Ubuntu 14.04下Redis安裝及簡單測試

Redis主從複製基本配置

Redis叢集明細文檔

Ubuntu 12.10下安裝Redis(圖文詳解)+ Jedis串連Redis

Redis系列-安裝部署維護篇

CentOS 6.3安裝Redis

Redis安裝部署學習筆記

Redis設定檔redis.conf 詳解

Redis 的詳細介紹:請點這裡
Redis 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.