Compilation and installation of Redis under Linux

Source: Internet
Author: User
Tags benchmark download redis error handling redis version redis cluster redis server

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.19.tar.gz

Unzip Redis
[Email protected] ~]# tar xzf redis-2.8.19.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.19
[[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

Configuring Redis configuration Files
[[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方式运行, the default is not to run in the background
  &NBSP ; 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
    logfile/var/log/redis/redis.log    #104行   #定义log文件位置, mode log information directed to stdout, output to/dev/null
    Save 1000                        #145行 &NB Sp #重新定义快照的频率
    dir/usr/local/rdbfile              #188行   #本地数据库存放路径 , the default is./, the compilation installation 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 Redis
LISTEN 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 6379
10.168.85.25:6379> Set Test Hello
Ok
10.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] 15:47:05.380 * The server is now a ready-to-accept connections on port 6379
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 BGSAVE
Background 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
#
# 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" # Specifies the location of the Redis-server command (Whereis redis-server)
Pidfile= "/var/run/redis/redis.pid" # Specifies the path of the PID file for Redis (consistent with the configuration file)
Redis_config= "/etc/redis.conf" # Specify the profile path for Redis
[-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 "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart
$
;;
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 2
Esac
Exit $?
[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]# make
CD src && make all
MAKE[1]: Entering directory '/ROOT/REDIS-2.8.19/SRC '
CC ADLIST.O
In file included 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
########### #解决方法 #############
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

a detailed introduction to Redis : please click here
Redis's : please click here

This article permanently updates the link address : http://www.linuxidc.com/Linux/2015-01/111364.htm

Compilation and installation of Redis under Linux

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.