Introduced
Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis.
Linux under compilation installation
Download Redis
########### #目前最新稳定版 ##########
[[email protected] ~]# wget http://Download.redis.io/releases/ Redis-2.8. tar.gz.
Unzip Redis
[[email protected] ~]# tar xzf redis-2.8. tar.gz.
Compiling Redis
The Redis compilation is very simple and already has a ready-made makefile file, run the make command directly
[[email protected] redis-2.8.19]# cd Redis-2.8. +
[[email protected] redis-2.8.19]# make
When the make command is completed, 6 executables are generated in the SRC directory, namely Redis-server, REDIS-CLI, Redis-benchmark, redis-check-aof, Redis-check-dump, Redis-sentinel, they function as follows:
Redis-server:redis Server Daemon Startup program
Redis-cli:redis command-line operation tool. Of course, you can also use Telnet to operate on its plain text protocol.
Redis-benchmark:redis Performance testing tools to test the read and write performance of Redis in your system and in your configuration
Redis-check-aof: Update log check
Redis-check-dump: for local database checking
Monitoring management, notification, and instance failover services for Redis-sentinel:redis instances, a management tool for Redis clusters
Installing Redis
[[email protected] src]# make install
Configure the Redis configuration file
[email protected] redis-2.8.19]# CP redis.conf/etc/
######### #编辑Redis配置文件 ###################
[[email protected] redis-2.8.19]# vim/etc/redis.conf daemonize Yes #37行 #是否以后台daemon方式运行, default is not run in the background Pidfile/var/run/redis/redis.pid #41行 #redis的PID文件路径 bind 10.168.85.25 #64行 #绑定主机IP, The default value is 127.0.0.1, we are running across machines, so we need to change the logfile/var/log/redis/redis.log #104行 #定义log文件位置, the pattern log information is directed to stdout, Output to/dev/null save #145行 #重新定义快照的频率 dir/usr/local/rdbfile #188行 #本地数据库存放路径, The default is./, compile and install default exists under/usr/local/bin
Start the test Redis server
############ #启动Redis服务器 ############
[Email protected] redis-2.8.19]# redis-server/etc/redis.conf
############ #查看是否启动成功 ###########
[Email protected] redis-2.8.19]# SS-TANLP | grep redislisten 0 10.168.85.25:6379 *:* Users: (("Redis-server", 17379,4))
############ #测试Redis ##################
[Email protected] redis-2.8.19]# redis-cli-h 10.168.85.25-p 637910.168.85.25:6379> set Test helloOK10.168.85.25 :6379> get Test "Hello"
changing kernel information
############ #查看日志信息 ###############
[[email protected] redis-2.8.19]# tail-f/var/log/redis/redis.log[5033] Jan 15:47:05.378 # Server started, Redis Version 2.8.19[5033] 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.overcom Mit_memory=1 ' for the take effect. [5033] 15:47:05.379 # WARNING you are Transparent Huge Pages (THP) support enabled in your kernel. This would 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 you R/etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [5033] Jan 15:47:05.380 # warning:the TCP Backlog setting of 511 cannot be enforced BECAUSE/PROC/SYS/NET/CORE/SOMAXCO NN is set to the lower value of 128. [5033] Jan 15:47:05.380 * DB loaded from disk:0.000 seconds[5033] Jan 15:47:05.380 * The server was now ready for accept connections on port 63 79
The log shows two warning messages about the kernel settings!
############# #sysctl文件 ###############
[[email protected] ~]# echo "Vm.overcommit_memory=1" >>/etc/sysctl.conf[[email protected] ~]# sysctl-p
############ #kerbel ####################
[Email protected] ~]# echo never >/sys/kernel/mm/transparent_hugepage/enabled
Restarting the Redis server
###### #将缓存保存到硬盘上 #####
[Email protected] ~]# redis-cli-h 10.168.85.25-p 6379 bgsavebackground Saving started
###### #关闭Redis #############
[Email protected] ~]# redis-cli-h 10.168.85.25-p 6379 SHUTDOWN
####### #启动Redis ############
[Email protected] ~]# redis-server/etc/redis.conf
Edit a Redis startup script
[[email protected] ~]# vi/etc/init.d/redis#!/bin/sh## redis init file for starting up the Redis daemon## CHKC Onfig:-80# description:starts and stops the Redis daemon.# Source function library. /etc/rc.d/init.d/functionsname= "Redis-server" exec= "/usr/local/bin/$name" # Specify Redis-server The location of the command (Whereis redis-server) pidfile= "/var/run/redis/redis.pid" # Specifies the path to the PID file for Redis (consistent with the configuration file) Redi S_config= "/etc/redis.conf" # Specifies the configuration file path for Redis [-e/etc/sysconfig/redis] &&. /etc/sysconfig/redislockfile=/var/lock/subsys/redisstart () {[-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 "$" in start) Rh_status_q && exit 0 $ ;; Stop) rh_status_q | | Exit 0 $;; restart) \ n; Reload) Rh_status_q | | Exit 7 $;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q | | Exit 0 restart;; *) echo $ "Usage: $ Start|stop|status|restart|condrestart|try-restart}" Exit 2esacexit $? [[email protected] ~]# chmod 700/etc/init.d/redis[[email protected] ~]# servcie Redis Restart additional information Redis failed to compile and install error handling? ########## #make时错误信息 #########[[email protected] redis-2.8.19]# makecd src && make allmake[1]: Entering Directory '/root/redis-2.8.19/src ' CC adlist.oin file included from Adlist.c:34:zmalloc.h:50:31:error:jemalloc/jemalloc.h:no such file or Directoryzmalloc.h:55:2: Error: #error "Newer version of JE malloc Required "make[1": * * * [ADLIST.O] Error 1make[1]: Leaving directory '/ROOT/REDIS-2.8.19/SRC ' make: * * * [ALL] Error 2
########### #解决方法 #############
Make MALLOC=LIBC
Vm.overcommit_memory parameter Resolution
If the memory situation is very tense, you need to set the kernel parameter overcommit_memory, specify the kernel for memory allocation policy, the value 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
Redis in the dump data, will fork out a sub-process, in theory the child process occupies the same memory and the parent is the same, such as the parent occupies 8G of memory, this time also to allocate 8G of memory to child, if the memory is not affordable, Will often cause the Redis server down or IO load is too high, inefficient. So the more optimized memory allocation policy here should be set to 1 (indicating that the kernel allows all physical memory to be allocated regardless of the current memory state).
There are two ways to set the current user's permissions to live with the root user modification:
1: Reset file echo 1 >/proc/sys/vm/overcommit_memory (default = 0)
2:echo "Vm.overcommit_memory=1" >>/etc/sysctl.conf && sysctl-p
Ubuntu 14.04 Redis installation and simple test http://www.linuxidc.com/Linux/2014-05/101544.htm
Redis Cluster Detail Document Http://www.linuxidc.com/Linux/2013-09/90118.htm
Installation of Redis under Ubuntu 12.10 (graphic) + Jedis connection Redis http://www.linuxidc.com/Linux/2013-06/85816.htm
Redis Series-Installation and deployment Maintenance Chapter Http://www.linuxidc.com/Linux/2012-12/75627.htm
CentOS 6.3 Installation Redis http://www.linuxidc.com/Linux/2012-12/75314.htm
Redis Installation Deployment Learning Note http://www.linuxidc.com/Linux/2014-07/104306.htm
Redis configuration file redis.conf detailed http://www.linuxidc.com/Linux/2013-11/92524.htm
Redis compiled installation