Ubuntu installation Redis

Source: Internet
Author: User
Tags redis version install redis redis server

1. Download and install Redis version 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. Verify that the compilation is correct

sudo make test

[CPP]View Plaincopyprint?
    1. <span style="FONT-SIZE:14PX;" >[email protected]:/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>


This compilation error can be resolved after TCL 8.5 is installed.

[HTML]View Plaincopyprint?
  1. <span style="FONT-SIZE:14PX;" >[email protected]:/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 were automatically installed and is no longer required:
  6. Tdb-tools
  7. Use the ' Apt-get autoremove ' to remove them.
  8. The following extra packages'll be installed:
  9. tcl8.5
  10. Suggested Packages:
  11. Tclreadline
  12. The following NEW packages'll 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 would be used.
  17. 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. Manually start Redis to test if Redis is functioning properly

A) Execute command to start Redis server manually : The command will use the default parameters

./src/redis-server

b) Check if the process has Redis: PS aux | grep Redis, you can see a process called "src/redis-server" in the list of processes.

[HTML]View Plaincopyprint?
    1. <span style=>[email protected]:~/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) Start the Redis-brought client and test:
# SRC/REDIS-CLI--Start the client and connect to local Redis
# set Foo Bar--Prompts "OK" to indicate normal setting of key values.
# get Foo--can prompt to return the correct "bar", indicating that it is working properly.
# Quit--Quit client

[HTML]View Plaincopyprint?
    1. <span style="FONT-SIZE:14PX;" >[email protected]:/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) If you want to use your own redis.conf configuration file, you can use the following command:

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

e) If you want to override some of the parameters in the redis.conf configuration file, you can use the parameters directly on the command line:

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

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

4. Open multiple Redis server instances

A redis server, divided into multiple nodes, each node assigned a port (6380, 6381 ... ), the default port is 6379.

If a Redis service instance is already open, execute again./src/redis-server will produce the following error

[HTML]View Plaincopyprint?
  1. <span style="FONT-SIZE:14PX;" >[email protected]:/usr/local/src/redis-2.6.16$ sudo./src/redis-server
  2. [347] 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] APR 07:47:00.861 * Max number of open files set to 10032
  4. [347] APR 07:47:00.861 # Opening Port 6379:bind:address already in use
  5. </span>

Each node corresponds to a redis configuration file, such as: 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

To start multiple Redis instances:

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

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

5, Installation Redis-server

If you are using only occasional tests, you can use the./src/redis-server method to start directly.

However, if it is a production environment, a Redis-server installation deployment is required.

Command:

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

sudo./install_server.sh

This sad install_server.sh command must be executed after entering the Utils directory!

Because it's scripting since some relative directory path!

[CPP]View Plaincopyprint?
  1. [Email protected]:/usr/local/src/redis-2.6.16/utils$ sudo./install_server.sh
  2. Welcome to the Redis service installer
  3. This script would 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 //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. Add to boot

If you install the above production environment, you no longer need to manually add a boot boot.

Otherwise, you need to modify

sudo vim/etc/rc.local

Add/usr/local/src/redis-2.6.16/src/redis-server redis.conf

7. Modify Redis Configuration

If Vm.overcommit_memory=0 is in a low memory state, the background Redis save service may fail.


You need to modify the configuration file/etc/sysctl.conf add Vm.overcommit_memory=1 and then restart it to take effect.

Refresh configuration takes effect Sysctl Vm.overcommit_memory=1

Supplemental information

If the memory situation is very tense, you need to set the kernel parameters:/proc/sys/vm/overcommit_memory

Here's what this configuration means:

/proc/sys/vm/overcommit_memory

This file specifies the kernel's policy for memory allocation, which can be 0, 1, 2.

0, indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process.

1, which means that the kernel allows all physical memory to be allocated regardless of the current memory state.

2, which indicates that the kernel allows allocating more memory than the sum of all physical memory and swap space

Ubuntu installation Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.