1. 下载并安装 redis 2.6.16版

sudo mkdir /usr/local/src/Redis

cd /usr/local/src/Redis

sudo wget http://download.redis.io/releases/redis-2.6.16.tar.gz

tar -zxf redis-2.6.16.tar.gz
cd redis-2.6.16

sudo make

2. 检验编译是否 正确

sudo make test

  1. <span style="font-size:14px;">sounion@ubuntu:/usr/local/src/redis-2.6.16$ make test
  2. cd src && make test
  3. make[1]: Entering directory `/usr/local/src/redis-2.6.16/src'
  4. You need tcl 8.5 or newer in order to run the Redis test
  5. make[1]: *** [test] Error 1
  6. make[1]: Leaving directory `/usr/local/src/redis-2.6.16/src'
  7. make: *** [test] Error 2
  8. </span>

安装 tcl 8.5 后可以解决上述编译错误。

  1. <span style="font-size:14px;">sounion@ubuntu:/usr/local/src/redis-2.6.16$ sudo apt-get install tcl
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following package was automatically installed and is no longer required:
  6. tdb-tools
  7. Use 'apt-get autoremove' to remove them.
  8. The following extra packages will be installed:
  9. tcl8.5
  10. Suggested packages:
  11. tclreadline
  12. The following NEW packages will be installed:
  13. tcl tcl8.5
  14. 0 upgraded, 2 newly installed, 0 to remove and 565 not upgraded.
  15. Need to get 1,102 kB of archives.
  16. After this operation, 3,862 kB of additional disk space will be used.
  17. Do you want to continue [Y/n]? y
  18. Get:1 http://mirrors.sohu.com/ubuntu/ precise/main tcl8.5 amd64 8.5.11-1ubuntu1 [1,098 kB]
  19. Get:2 http://mirrors.sohu.com/ubuntu/ precise/main tcl all 8.5.0-2 [4,690 B]
  20. Fetched 1,102 kB in 3s (303 kB/s)
  21. Selecting previously unselected package tcl8.5.
  22. (Reading database ... 199470 files and directories currently installed.)
  23. Unpacking tcl8.5 (from .../tcl8.5_8.5.11-1ubuntu1_amd64.deb) ...
  24. Selecting previously unselected package tcl.
  25. Unpacking tcl (from .../archives/tcl_8.5.0-2_all.deb) ...
  26. Processing triggers for man-db ...
  27. Setting up tcl8.5 (8.5.11-1ubuntu1) ...
  28. update-alternatives: using /usr/bin/tclsh8.5 to provide /usr/bin/tclsh (tclsh) in auto mode.
  29. Setting up tcl (8.5.0-2) ...
  30. update-alternatives: using /usr/bin/tclsh-default to provide /usr/bin/tclsh (tclsh) in auto mode.
  31. Processing triggers for libc-bin ...
  32. ldconfig deferred processing now taking place
  33. </span>

3. 手工启动redis,测试redis是否运行正常

a)执行命令手工启动redis server:     该命令将使用缺省参数

./src/redis-server

b)检查进程是否有Redis了:ps aux | grep redis,可以看见进程列表中有一个叫“src/redis-server”的进程了

  1. <span style="font-size:14px;">sounion@ubuntu:~/Desktop$ ps aux | grep redis
  2. sounion  65350  0.0  0.0  35024  1960 pts/1    Sl+  07:28   0:00 ./src/redis-server
  3. sounion  65441  0.0  0.0  13584   916 pts/4    S+   07:31   0:00 grep --color=auto redis
  4. </span>

c) 启动redis自带的客户端,进行测试:
        # src/redis-cli -- 启动客户端并连接本地Redis
        # set foo bar -- 提示 “ok”说明设置键值正常。
        # get foo -- 能够提示返回正确的“bar”,说明运行正常。
        # quit -- 退出客户端

  1. <span style="font-size:14px;">sounion@ubuntu:/usr/local/src/redis-2.6.16$ ./src/redis-cli
  2. redis 127.0.0.1:6379> set foo bar
  3. OK
  4. redis 127.0.0.1:6379> get foo
  5. "bar"
  6. redis 127.0.0.1:6379> quit
  7. </span>

d) 如果希望使用自己的 redis.conf 配置文件,可以使用如下命令:

./src/redis-server /path/to/redis.conf

e) 如果希望额外覆盖 redis.conf 配置文件中的某些参数,可以直接在命令行中使用参数:

./src/redis-server /etc/redis.conf  --loglevel debug

./sr/redis-server  --port 9999 --slaveof 127.0.0.1 6379

4.  开启多个redis 服务器实例

一台Redis服务器,分成多个节点,每个节点分配一个端口(6380,6381…),默认端口是6379。

如果已经开启了 一个redis 服务实例,再次执行 ./src/redis-server 会产生如下错误

  1. <span style="font-size:14px;">sounion@ubuntu:/usr/local/src/redis-2.6.16$ sudo ./src/redis-server
  2. [347] 19 Apr 07:47:00.859 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
  3. [347] 19 Apr 07:47:00.861 * Max number of open files set to 10032
  4. [347] 19 Apr 07:47:00.861 # Opening port 6379: bind: Address already in use
  5. </span>

每个节点对应一个Redis配置文件,如:redis6380.conf、redis6381.conf

cp redis.conf  redis6380.conf

vi redis6380.conf

pidfile : pidfile/var/run/redis/redis_6380.pid

port 6380

logfile : logfile/var/log/redis/redis_6380.log

rdbfile : dbfilenamedump_6380.rdb

启动多个redis实例:

./src/redis-server /usr/local/redis/redis6380.conf

./src/redis-server /usr/local/redis/redis6381.conf

5、安装 redis-server

如果只是偶尔测试使用,可以使用 ./src/redis-server 方式直接启动。

但是如果是生产环境,需要进行 redis-server 安装部署。

命令:

cd /us/local/src/redis-2.6.16//utils

sudo ./install_server.sh

这个悲催的install_server.sh 命令必须在进入 utils 目录后再执行!

因为它的脚本写法以来一些相对目录路径!

  1. sounion@ubuntu:/usr/local/src/redis-2.6.16/utils$ sudo ./install_server.sh
  2. Welcome to the redis service installer
  3. This script will help you easily set up a running redis server
  4. Please select the redis port for this instance: [6379]
  5. Selecting default: 6379
  6. Please select the redis config file name [/etc/redis/6379.conf]
  7. Selected default - /etc/redis/6379.conf
  8. Please select the redis log file name [/var/log/redis_6379.log]
  9. Selected default - /var/log/redis_6379.log
  10. Please select the data directory for this instance [/var/lib/redis/6379]
  11. Selected default - /var/lib/redis/6379
  12. Please select the redis executable path [] /usr/local/src/redis-2.6.16/src/redis-server
  13. s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
  14. Copied /tmp/6379.conf => /etc/init.d/redis_6379
  15. Installing service...
  16. update-rc.d: warning: /etc/init.d/redis_6379 missing LSB information
  17. update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
  18. Adding system startup for /etc/init.d/redis_6379 ...
  19. /etc/rc0.d/K20redis_6379 -> ../init.d/redis_6379
  20. /etc/rc1.d/K20redis_6379 -> ../init.d/redis_6379
  21. /etc/rc6.d/K20redis_6379 -> ../init.d/redis_6379
  22. /etc/rc2.d/S20redis_6379 -> ../init.d/redis_6379
  23. /etc/rc3.d/S20redis_6379 -> ../init.d/redis_6379
  24. /etc/rc4.d/S20redis_6379 -> ../init.d/redis_6379
  25. /etc/rc5.d/S20redis_6379 -> ../init.d/redis_6379
  26. Success!
  27. Starting Redis server...
  28. Installation successful!

6、添加到开机启动

如果进行了上述生产环境安装,则不再需要手动添加开机启动。

否则,需要修改

sudo vim /etc/rc.local

添加 /usr/local/src/redis-2.6.16/src/redis-server redis.conf

7、修改redis配置

如果 vm.overcommit_memory=0, 则在低内存状态时,后台redis 保存服务可能会失败。

需要修改配置文件/etc/sysctl.conf  添加 vm.overcommit_memory=1 然后重新启动使之生效。

刷新配置生效 sysctl vm.overcommit_memory=1

补充介绍

如果内存情况比较紧张的话,需要设定内核参数: /proc/sys/vm/overcommit_memory

这里说一下这个配置的含义:

/proc/sys/vm/overcommit_memory

该文件指定了内核针对内存分配的策略,其值可以是0、1、2。

0,表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。

1,表示内核允许分配所有的物理内存,而不管当前的内存状态如何。

2,表示内核允许分配超过所有物理内存和交换空间总和的内存

Ubuntu 安装 Redis的更多相关文章

  1. Redis --> Ubuntu安装redis

    Ubuntu安装redis   一.下载安装 root@21ebdf03a086:/# apt-cache search redis root@21ebdf03a086:/# apt-get inst ...

  2. Ubuntu安装redis并配置远程、密码以及开启php扩展

    一.前言 redis是当前流行的nosql数据库,很多网站都用它来做缓存,今天我们来安装并配置下redis 二.安装并配置redis 1.安装redis sudo apt-get install re ...

  3. Ubuntu安装redis缓存数据库

    参考:http://blog.csdn.net/xiangwanpeng/article/details/54586087 1.在下载目录下 sudo wget http://download.red ...

  4. Linux 和 ubuntu安装redis

    Linux 下安装reids 下载地址:http://redis.io/download,下载最新稳定版本. 本教程使用的最新文档版本为 2.8.17,下载并安装: $ wget http://dow ...

  5. ubuntu 安装redis以及phpredis

    一.安装redis 1. 去百度搜索 redis,然后去靠谱的地方下载最新的redisxxx.tar.gz 2. 解压后,sudo make 3. sudo make install 4. //安装完 ...

  6. Ubuntu安装Redis及使用

    NoSQL简介NoSQL,全名为Not Only SQL,指的是非关系型的数据库随着访问量的上升,网站的数据库性能出现了问题,于是nosql被设计出来 优点/缺点优点:高可扩展性分布式计算低成本架构的 ...

  7. Ubuntu 安装Redis体验

      背景:由于之前一直没有试过Linux的环境,今天加了内存之后,虚拟机开了3G,速度大大提高,对照博客试一下安装Redis的过程.   体验: 下载源码,解压,编译 $ wget http://do ...

  8. Ubuntu 安装 Redis和phpredis扩展

    服务器Ubuntu16.04 环境php7.0+Apache /****************************开始安装Redis****************************/ 1 ...

  9. Ubuntu安装redis和redis-php扩展

    通过apt-get安装的redis使用方法 sudo apt-get install redis-server sudo apt-get install php-redis vim /etc/redi ...

随机推荐

  1. ViewState 视图状态对象实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoViewState. ...

  2. C#部署安装,将用户安装路径记录下写入注册表,并启动

    安装部署程序,将安装目录写入注册表 (1)在“安装部署项目”上点击“注册表编辑器” (2)在HKey_LOCAL_MACHINE_SoftWare 下新建键 Manufacturer 代表软件的制造商 ...

  3. 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。

    package C; public class Bisai { public static void main(String[] args) { String a="xyz",b= ...

  4. 【leetcode❤python】232. Implement Queue using Stacks

    #-*- coding: UTF-8 -*-#双栈法class Queue(object):    def __init__(self):        """      ...

  5. acdream1197 Points In Cuboid

    题目链接:http://acdream.info/problem?pid=1197 题意:给出一些点.每次给出一个长方体,问在长方体中的点的个数. 思路:kd-tree. const int N=11 ...

  6. <转>32位移植到64位 注意事项

    32bit-64bit porting work注意事项 64位服务器逐步普及,各条产品线对64位升级的需求也不断加大.在本文中,主要讨论向64位平台移植现有32位代码时,应注意的一些细小问题. 什么 ...

  7. 【转载】为什么CPU有多层缓存

    原文:为什么CPU有多层缓存 http://mp.weixin.qq.com/s?__biz=MzI1NDM2Nzg5Mw==&mid=2247483712&idx=1&sn= ...

  8. R语言画图基础参数设置

    Graphical Parameters You can customize many features of your graphs (fonts, colors, axes, titles) th ...

  9. [POJ1753]Flip Game(异或方程组,高斯消元,枚举自由变量)

    题目链接:http://poj.org/problem?id=1753 题意:同上. 这回翻来翻去要考虑自由变元了,假设返回了自由变元数量,则需要枚举自由变元. /* ━━━━━┒ギリギリ♂ eye! ...

  10. DIV与IDIV的用法

    DIV (unsigned divide) 无符号数除法 格式:DIV SRC 执行的操作: 字节操作:16位被除数在AX,8位除数为源操作数,结果的8位商在AL中,8位余数在AH中.表示为 (AL) ...