Compile and install Redis and master-slave replication configuration in Linux

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

Compile and install Redis and master-slave replication configuration in Linux

The installation and configuration of Redis is very simple, and Redis has been installed a long time ago. But I forgot some details when I installed it again these days. It seems that the good memory is not as bad as the pen, it is better to record it in the blog, at least you don't always have to hold your mother's thigh.

How many times have the files been compiled and installed today ?? After reading the results for half a day, I found that I used lowercase letters for the PREFIX...

It seems that you have to record the correct operation steps to avoid this embarrassment.

1. Select a version

Go to Official Website: http://www.redis.io/download

Choose a suitable stable version, such as the latest redis-3.0 stable version (stable), to get:

Http://download.redis.io/releases/redis-3.0.0.tar.gz

Ii. Compilation and Installation

Cd/usr/local/src
Wget http://download.redis.io/releases/redis-3.0.0.tar.gz
Tar zxvf redis-3.0.0.tar.gz
Cd redis-3.0.0
Make
# Optional command: make test

# Remember that the PREFIX is in upper case and the lower case does not take effect!
Make PREFIX =/usr/local/redis-3.0.0 install

# Creating soft links
Ln-s/usr/local/redis-3.0.0/usr/local/redis

# Create a directory and copy the default configuration file
Mkdir-p/usr/local/redis/{etc, var}
Cp redis. conf/usr/local/etc/

# If it is to provide services to other machines, we recommend that you set the listening IP address to 0.0.0.0 in redis. conf, and start a process. The default value is 2 and there is also 127.0.0.1.
Bind 0.0.0.0

Cd/usr/local/src

Wget http://download.redis.io/releases/redis-3.0.0.tar.gz

Tar zxvf redis-3.0.0.tar.gz

Cd redis-3.0.0

Make

# Optional command: make test

 

# Remember that the PREFIX is in upper case and the lower case does not take effect!

Make PREFIX =/usr/local/redis-3.0.0 install

 

# Creating soft links

Ln-s/usr/local/redis-3.0.0/usr/local/redis

# Create a directory and copy the default configuration file

Mkdir-p/usr/local/redis/{etc, var}

Cp redis. conf/usr/local/etc/
 

# If it is to provide services to other machines, we recommend that you set the listening IP address to 0.0.0.0 in redis. conf, and start a process. The default value is 2 and there is also 127.0.0.1.

Bind 0.0.0.0


After the installation is complete, the redis directory structure is as follows:

[Root @ cache-ns-4 ~] # Tree/usr/local/redis
/Usr/local/redis
── Bin # store various execution files under bin
│ ── Redis-benchmark
│ ── Redis-check-aof
│ ── Redis-check-dump
│ ── Redis-cli # redis client execution File
│ ├ ── Redis-sentinel-& gt;/usr/local/redis-3.0.0/bin/redis-server
│ ── Redis-server # redis server execution File
── Dump. rdb # the data file generated by default after startup. You can set the dir path parameter in redis. conf to specify other directories.
── Etc
│ ── Redis. conf
── Var

 

[Root @ cache-ns-4 ~] # Tree/usr/local/redis

/Usr/local/redis

── Bin # store various execution files under bin

│ ── Redis-benchmark

│ ── Redis-check-aof

│ ── Redis-check-dump

│ ── Redis-cli # redis client execution File

│ ├ ── Redis-sentinel-& gt;/usr/local/redis-3.0.0/bin/redis-server

│ ── Redis-server # redis server execution File

── Dump. rdb # the data file generated by default after startup. You can set the dir path parameter in redis. conf to specify other directories.

── Etc

│ ── Redis. conf

── Var

 

Iii. Registration Service

① Write a service control script

Vi/etc/init. d/redis

#! /Bin/bash
#
# Redis-this script starts and stops the redis-server daemon
#
# Chkconfig:-80 12
# Description: Redis is a persistent key-value database
# Processname: redis-server
# Config:/usr/local/redis/etc/redis. conf
# Pidfile:/usr/local/redis/var/redis. pid
 
Source/etc/init. d/functions
 
BIN = "/usr/local/redis/bin"
CONFIG = "/usr/local/redis/etc/redis. conf"
PIDFILE = "/var/run/redis. pid"
 
 
### Read configuration
[-R "$ SYSCONFIG"] & source "$ SYSCONFIG"
 
RETVAL = 0
Prog = "redis-server"
Desc = "Redis Server"
 
Start (){
 
If [-e $ PIDFILE]; then
Echo "$ desc already running ...."
Exit 1
Fi
 
Echo-n $ "Starting $ desc :"

# In use, I occasionally find that the server is not transferred to the background after it is started, so I added an "&"
Daemon $ BIN/$ prog $ CONFIG &
 
RETVAL =$?
Echo
[$ RETVAL-eq 0] & touch/var/lock/subsys/$ prog
Return $ RETVAL
}
 
Stop (){
Echo-n $ "Stop $ desc :"
Killproc $ prog
RETVAL =$?
Echo
[$ RETVAL-eq 0] & rm-f/var/lock/subsys/$ prog $ PIDFILE
Return $ RETVAL
}
 
Restart (){
Stop
Start
}
 
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Restart
;;
Condrestart)
[-E/var/lock/subsys/$ prog] & restart
RETVAL =$?
;;
Status)
Status $ prog
RETVAL =$?
;;
*)
Echo $ "Usage: $0 {start | stop | restart | condrestart | status }"
RETVAL = 1
Esac
 
Exit $ RETVAL

 

 

#! /Bin/bash

#

# Redis-this script starts and stops the redis-server daemon

#

# Chkconfig:-80 12

# Description: Redis is a persistent key-value database

# Processname: redis-server

# Config:/usr/local/redis/etc/redis. conf

# Pidfile:/usr/local/redis/var/redis. pid

 

Source/etc/init. d/functions

 

BIN = "/usr/local/redis/bin"

CONFIG = "/usr/local/redis/etc/redis. conf"

PIDFILE = "/var/run/redis. pid"

 

 

### Read configuration

[-R "$ SYSCONFIG"] & source "$ SYSCONFIG"

 

RETVAL = 0

Prog = "redis-server"

Desc = "Redis Server"

 

Start (){

 

If [-e $ PIDFILE]; then

Echo "$ desc already running ...."

Exit 1

Fi

 

Echo-n $ "Starting $ desc :"

 

# In use, I occasionally find that the server is not transferred to the background after it is started, so I added an "&"

Daemon $ BIN/$ prog $ CONFIG &

 

RETVAL =$?

Echo

[$ RETVAL-eq 0] & touch/var/lock/subsys/$ prog

Return $ RETVAL

}

 

Stop (){

Echo-n $ "Stop $ desc :"

Killproc $ prog

RETVAL =$?

Echo

[$ RETVAL-eq 0] & rm-f/var/lock/subsys/$ prog $ PIDFILE

Return $ RETVAL

}

 

Restart (){

Stop

Start

}

 

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Restart)

Restart

;;

Condrestart)

[-E/var/lock/subsys/$ prog] & restart

RETVAL =$?

;;

Status)

Status $ prog

RETVAL =$?

;;

*)

Echo $ "Usage: $0 {start | stop | restart | condrestart | status }"

RETVAL = 1

Esac

 

Exit $ RETVAL


② Register and start the service

# Grant execution permission
Chmod + x/etc/init. d/redis

# Start startup
Chkconfig redis on

# Start the service
Service redis start

# The following is the startup record
[Root @ localhost ~] # Service redis start
Starting Redis Server:
[Root @ localhost ~] #_._
_.-''__''-._
_.-'''. '_. ''-. _ Redis 3.0.0 (00000000/0) 64 bit
.-''.-'''.'''\/_.,_''-._
(',.-' | ',) Running in stand alone mode
| '-. _'-...-'_...-.'-. _ | ''_.-'| Port: 6379
| '-. _'. _/_.-'| PID: 28584
'-._'-._'-./_.-'_.-'
| '-. _.-' |
| '-. _'-. _.-'_.-' | Http://redis.io
'-._'-._'-.__.-'_.-'_.-'
| '-. _.-' |
| '-. _'-. _.-'_.-' |
'-._'-._'-.__.-'_.-'_.-'
'-._'-.__.-'_.-'
'-.__.-'
'-.__.-'

[28584] 16 Apr 23:48:55. 614 # Server started, Redis version 3.0.0
[28584] 16 Apr 23:48:55. 614 # 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.
[28584] 16 Apr 23:48:55. 614 # 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.
[28584] 16 Apr 23:48:55. 614 # WARNING: The TCP backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn is set to the lower value of 128.
[28584] 16 Apr 23:48:55. 615 * DB loaded from disk: 0.000 seconds
[28584] 16 Apr 23:48:55. 615 * The server is now ready to accept connections on port 6379


# Grant execution permission

Chmod + x/etc/init. d/redis

# Start startup

Chkconfig redis on

# Start the service

Service redis start


# The following is the startup record

[Root @ localhost ~] # Service redis start

Starting Redis Server:

[Root @ localhost ~] #_._

_.-''__''-._

_.-'''. '_. ''-. _ Redis 3.0.0 (00000000/0) 64 bit

.-''.-'''.'''\/_.,_''-._

(',.-' | ',) Running in stand alone mode

| '-. _'-...-'_...-.'-. _ | ''_.-'| Port: 6379

| '-. _'. _/_.-'| PID: 28584

'-._'-._'-./_.-'_.-'

| '-. _.-' |

| '-. _'-. _.-'_.-' | Http://redis.io

'-._'-._'-.__.-'_.-'_.-'

| '-. _.-' |

| '-. _'-. _.-'_.-' |

'-._'-._'-.__.-'_.-'_.-'

'-._'-.__.-'_.-'

'-.__.-'

'-.__.-'

 

[28584] 16 Apr 23:48:55. 614 # Server started, Redis version 3.0.0

[28584] 16 Apr 23:48:55. 614 # 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.

[28584] 16 Apr 23:48:55. 614 # 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.

[28584] 16 Apr 23:48:55. 614 # WARNING: The TCP backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn is set to the lower value of 128.

[28584] 16 Apr 23:48:55. 615 * DB loaded from disk: 0.000 seconds

[28584] 16 Apr 23:48:55. 615 * The server is now ready to accept connections on port 6379

 

4. Master-slave Configuration

1. Configuration

Install redis on the slave machine according to the above steps, and then add the following configuration items in the slave redis. conf:


# Specify the IP address and port of the redis host (no password authentication is set by default)
Slaveof 192.168.10.124 6379


# Specify the IP address and port of the redis host (no password authentication is set by default)

Slaveof 192.168.10.124 6379


After saving, start redis to complete simple master-slave configuration.

② Test

The test is simple. First, run the Add key-value command on the host through the redis-cli client:


[Root @ localhost ~] #/Usr/local/redis/bin/redis-cli
127.0.0.1: 6379> set newkey slavetest
OK

 

[Root @ localhost ~] #/Usr/local/redis/bin/redis-cli

127.0.0.1: 6379> set newkey slavetest

OK


Then, log on to the slave machine and execute redis-cli to execute the query command:


[Root @ localhost ~] #/Usr/local/redis/bin/redis-cli
127.0.0.1: 6379> get newkey
"Slavetest"

[Root @ localhost ~] #/Usr/local/redis/bin/redis-cli

127.0.0.1: 6379> get newkey

"Slavetest"


Obviously, the new key value on the host has been automatically synchronized to the slave, and the master-slave synchronization is successful!

This article only records the basic compilation, installation, and master-slave configuration. Of course, redis also has a project that can be customized or optimized. We will continue to sort out and supplement the configuration later.

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:

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.