Compiling and installing Redis in Linux
Introduction
Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types, including string, list, set, and zset) and hash (hash type ). These data types support push/pop, add/remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic. On this basis, redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization.
Compiling and installation in Linux
Download redis
########### Latest stable version ##########
[Root @ redis ~] # Wget http://download.redis.io/releases/redis-2.8.19.tar.gz
Decompress redis
[Root @ redis ~] # Tar xzf redis-2.8.19.tar.gz
Compile redis
Redis compilation is very simple. There are already ready-made Makefile files, just run the make command directly.
[Root @ redis redis-2.8.19] # cd redis-2.8.19
The [root @ redis redis-2.8.19] # make
After the make command is executed, six executable files are generated in the src directory, they are redis-server, redis-cli, redis-benchmark, redis-check-aof, redis-check-dump, and redis-sentinel. Their functions are as follows:
Redis-server: daemon Startup Program of the Redis server
Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate based on its plain text protocol.
Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration
Redis-check-aof: Update log check
Redis-check-dump: used for local database check
Redis-sentinel: the monitoring and management, notification, and instance failure backup service of Redis instances. It is a management tool for Redis clusters.
Install redis
[Root @ redis src] # make install
Configure the redis configuration file
[Root @ redis redis-2.8.19] # cp redis. conf/etc/
######### Edit the Redis configuration file ###################
[Root @ redis redis-2.8.19] # vim/etc/redis. conf
Daemonize yes # line 37 # whether to run in daemon mode later, not in the background by default
Pidfile/var/run/redis. pid #41 rows # redis PID file path
Bind 10.168.85.25 #64 lines # bind the Host IP address. The default value is 127.0.0.1. It runs across machines, so we need to change
Logfile/var/log/redis. log # Row 104 # defines the location of the log file. The mode log information is directed to stdout and output to/dev/null.
Save 60 1000 #145 rows # redefine the snapshot frequency
Dir/usr/local/rdbfile #188 # local database storage path. The default value is./. The default value for compiling and installation is/usr/local/bin.
Start the test Redis Server
############ Start a Redis server ############
[Root @ redis redis-2.8.19] # redis-server/etc/redis. conf
############ Check whether the startup is successful ###########
[Root @ redis redis-2.8.19] # ss-tanlp | grep redis
LISTEN 0 128 10.168.85.25: 6379 *: * users :( ("redis-server", 172.16,4 ))
############ Test Redis ##################
[Root @ redis redis-2.8.19] # redis-cli-h 10.168.85.25-p 6379
10.168.85.25: 6379> set test hello
OK
10.168.85.25: 6379> get test
"Hello"
Change kernel information
############ View log information ###############
[Root @ redis redis-2.8.19] # tail-f/var/log/redis. log
[5033] 04 Jan 15:47:05. 378 # Server started, Redis version 2.8.19
[5033] 04 Jan 15:47:05. 379 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. to fix this issue add'vm. overcommit_memory = 1' to/etc/sysctl. conf and then reboot or run the command 'sysctl vm. overcommit_memory = 1' for this to take effect.
[5033] 04 Jan 15:47:05. 379 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. this will create latency and memory usage issues with Redis. to fix this issue run the command 'echo never>/sys/kernel/mm/transparent_hugepage/enabled 'as root, and add it to your/etc/rc. local in order to retain the setting after a reboot. redis must be restarted after THP is disabled.
[5033] 04 Jan 15:47:05. 380 # WARNING: The TCP backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn is set to the lower value of 128.
[5033] 04 Jan 15:47:05. 380 * DB loaded from disk: 0.000 seconds
[5033] 04 Jan 15:47:05. 380 * The server is now ready to accept connections on port 6379
The log shows two warnings about Kernel settings!
############# Sysctl file ###############
[Root @ redis ~] # Echo "vm. overcommit_memory = 1">/etc/sysctl. conf
[Root @ redis ~] # Sysctl-p
############# Kerbel ####################
[Root @ redis ~] # Echo never>/sys/kernel/mm/transparent_hugepage/enabled
Restart the Redis Server
####### Save the cache to the hard disk #####
[Root @ redis ~] # Redis-cli-h 10.168.85.25-p 6379 BGSAVE
Background saving started
####### Disable Redis #############
[Root @ redis ~] # Redis-cli-h 10.168.85.25-p 6379 SHUTDOWN
######## Start Redis ############
[Root @ redis ~] # Redis-server/etc/redis. conf
Edit Redis Startup Script
[Root @ redis ~] # Vi/etc/init. d/redis
#! /Bin/sh
#
# Redis init file for starting up the redis daemon
#
# Chkconfig:-20 80
# Description: Starts and stops the redis daemon.
# Source function library.
./Etc/rc. d/init. d/functions
Name = "redis-server"
Exec = "/usr/local/bin/$ name" # specify the location of the redis-server command (whereis redis-server)
Pidfile = "/var/run/redis. pid" # specify the redis pid file path (consistent with the configuration file)
REDIS_CONFIG = "/etc/redis. conf" # specify the path of the redis configuration file
[-E/etc/sysconfig/redis] &./etc/sysconfig/redis
Lockfile =/var/lock/subsys/redis
Start (){
[-F $ REDIS_CONFIG] | exit 6
[-X $ exec] | exit 5
Echo-n $ "Starting $ name :"
Daemon -- user $ {REDIS_USER-redis} "$ exec $ REDIS_CONFIG"
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}
Stop (){
Echo-n $ "Stopping $ name :"
Killproc-p $ pidfile $ name
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}
Restart (){
Stop
Start
}
Reload (){
False
}
Rh_status (){
Status-p $ pidfile $ name
}
Rh_status_q (){
Rh_status>/dev/null 2> & 1
}
Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
Restart
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart }"
Exit 2
Esac
Exit $?
[Root @ redis ~] # Chmod 700/etc/init. d/redis
[Root @ redis ~] # Servcie redis restart
Additional information
Why can't I handle Redis compilation and installation errors?
########## Make error message #########
The [root @ redis redis-2.8.19] # make
Cd src & make all
Make [1]: Entering directory '/root/redis-2.8.19/src'
CC adlist. o
In file sorted ded from adlist. c: 34:
Zmalloc. h: 50: 31: error: jemalloc/jemalloc. h: No such file or directory
Zmalloc. h: 55: 2: error: # error "Newer version of jemalloc required"
Make [1]: *** [adlist. o] Error 1
Make [1]: Leaving directory/root/redis-2.8.19/src'
Make: *** [all] Error 2
############ Solution #############
Make MALLOC = libc
Vm. overcommit_memory Parameter Parsing
If the memory condition is tight, you need to set the Kernel Parameter overcommit_memory to specify the kernel's memory allocation policy. The value can be 0, 1, or 2.
0 indicates that the kernel will check whether there is enough available memory for use by the process. If there is enough available memory, the memory application will be allowed; otherwise, the memory application will fail, and return the error to the application process.
1 indicates that the kernel allows all physical memory allocation regardless of the current memory status.
2. indicates that the kernel is allowed to allocate more memory than the total physical memory and swap space.
Redis generates a sub-process when dumping data. In theory, the memory occupied by the child process is the same as that of the parent. For example, the parent occupies 8 GB of memory, at this time, 8 GB of memory should also be allocated to the child. If the memory is not enough, it will often cause the redis server to go down or the IO load is too high, and the efficiency is reduced. Therefore, the optimized memory allocation policy should be set to 1 (indicating that the kernel allows allocation of all physical memory, regardless of the current memory status ).
There are two ways to set this parameter:
1: reset the file echo 1>/proc/sys/vm/overcommit_memory (0 by default)
2: echo "vm. overcommit_memory = 1">/etc/sysctl. conf & sysctl-p
Install and test Redis in Ubuntu 14.04
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: