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?
- <span style="FONT-SIZE:14PX;" >[email protected]:/usr/local/src/redis-2.6.16$ make Test
- CD src && make test
- MAKE[1]: Entering directory '/USR/LOCAL/SRC/REDIS-2.6.16/SRC '
- You need TCL 8.5 or newer in order to run the Redis test
- MAKE[1]: * * * [Test] Error 1
- MAKE[1]: Leaving directory '/USR/LOCAL/SRC/REDIS-2.6.16/SRC '
- Make: * * * [Test] Error 2
- </span>
This compilation error can be resolved after TCL 8.5 is installed.
[HTML]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >[email protected]:/usr/local/src/redis-2.6.16$ sudo apt-get install tcl
- Reading Package Lists ... Done
- Building Dependency Tree
- Reading state information ... Done
- The following package were automatically installed and is no longer required:
- Tdb-tools
- Use the ' Apt-get autoremove ' to remove them.
- The following extra packages'll be installed:
- tcl8.5
- Suggested Packages:
- Tclreadline
- The following NEW packages'll be installed:
- Tcl tcl8.5
- 0 upgraded, 2 newly installed, 0 to remove and 565 not upgraded.
- Need to get 1,102 KB of archives.
- After this operation, 3,862 KB of additional disk space would be used.
- Want to continue [y/n]? Y
- Get:1 http://mirrors.sohu.com/ubuntu/precise/main tcl8.5 amd64 8.5.11-1ubuntu1 [1,098 KB]
- Get:2 http://mirrors.sohu.com/ubuntu/precise/main tcl all 8.5.0-2 [4,690 B]
- Fetched 1,102 KB in 3s (303 kb/s)
- Selecting previously unselected package tcl8.5.
- (Reading database ... 199470 files and directories currently installed.)
- Unpacking tcl8.5 (from .../tcl8.5_8.5.11-1ubuntu1_amd64.deb) ...
- Selecting previously unselected package Tcl.
- Unpacking Tcl (from .../archives/tcl_8.5.0-2_all.deb) ...
- Processing triggers for man-db ...
- Setting up tcl8.5 (8.5.11-1UBUNTU1) ...
- update-alternatives:using/usr/bin/tclsh8.5 to Provide/usr/bin/tclsh (TCLSH) in Auto mode.
- Setting up Tcl (8.5.0-2) ...
- Update-alternatives:using/usr/bin/tclsh-default to Provide/usr/bin/tclsh (TCLSH) in Auto mode.
- Processing triggers for libc-bin ...
- Ldconfig deferred processing now taking place
- </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?
- <span style=>[email protected]:~/desktop$ ps aux | grep redis
- sounion 65350 0.0 0.0 35024 1960 pts/1 Sl+ 07:28 0:00 ./src/redis-server
- sounion 65441 0.0 0.0 13584 916 pts/4 S+ 07:31 0:00 grep --color=auto redis
- </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?
- <span style="FONT-SIZE:14PX;" >[email protected]:/usr/local/src/redis-2.6.16$./src/redis-cli
- Redis 127.0.0.1:6379> set foo bar
- Ok
- Redis 127.0.0.1:6379> get foo
- "Bar"
- Redis 127.0.0.1:6379> Quit
- </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?
- <span style="FONT-SIZE:14PX;" >[email protected]:/usr/local/src/redis-2.6.16$ sudo./src/redis-server
- [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
- [347] APR 07:47:00.861 * Max number of open files set to 10032
- [347] APR 07:47:00.861 # Opening Port 6379:bind:address already in use
- </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?
- [Email protected]:/usr/local/src/redis-2.6.16/utils$ sudo./install_server.sh
- Welcome to the Redis service installer
- This script would help you easily set up a running Redis server
- Please select the Redis port for this instance: [6379]
- Selecting default:6379
- Please select the redis config file name [/etc/redis/6379.conf]
- Selected Default-/etc/redis/6379.conf
- Please select the Redis log file name [/var/log/redis_6379.log]
- Selected Default-/var/log/redis_6379.log
- Please select the data directory for this instance [/var/lib/redis/6379]
- Selected Default-/var/lib/redis/6379
- Please select the Redis executable path []/usr/local/src/redis-2.6.16/src/redis-server
- 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#;
- copied/tmp/6379.conf =/etc/init.d/redis_6379
- Installing service ...
- Update-rc.d:warning:/etc/init.d/redis_6379 Missing LSB information
- Update-rc.d:see //wiki.debian.org/lsbinitscripts>
- Adding system startup for/etc/init.d/redis_6379 ...
- /etc/rc0.d/k20redis_6379. /init.d/redis_6379
- /etc/rc1.d/k20redis_6379. /init.d/redis_6379
- /etc/rc6.d/k20redis_6379. /init.d/redis_6379
- /etc/rc2.d/s20redis_6379. /init.d/redis_6379
- /etc/rc3.d/s20redis_6379. /init.d/redis_6379
- /etc/rc4.d/s20redis_6379. /init.d/redis_6379
- /etc/rc5.d/s20redis_6379. /init.d/redis_6379
- success!
- Starting Redis Server ...
- 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