Linux compile installation Redis and master-slave configuration steps

Source: Internet
Author: User
Tags lowercase memory usage redis redis version install redis redis server


Redis installation configuration is very simple, and very early before the installation of Redis, can be installed in the last few days and then forgotten some details, it seems good memory is not as bad as the pen, or in the blog record better, at least not always hug Niang thigh.

Today compiled several times to install, found unexpectedly not in prefix specified directory generation file?? After looking at the results found prefix I used the lowercase letter ...

It seems that it is time to record the correct procedure to avoid this embarrassment.

Redis

One, select version

Go to official website: http://www.redis.io/download

Select a suitable stable version, such as the latest redis-3.0 stable version (Stable), to obtain the download address:

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

Ii. Compiling and installing



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
#可选执行命令: Make Test

#这里记得PREFIX是大写, lowercase does not take effect!
Make prefix=/usr/local/redis-3.0.0 Install

#建立软链接
Ln-s/usr/local/redis-3.0.0/usr/local/redis

#创建目录并拷贝默认配置文件过去
Mkdir-p/usr/local/redis/{etc,var}
CP redis.conf/usr/local/etc/

#如果是对其他机器提供服务, it is recommended to set up a listening IP of 0.0.0.0 in redis.conf and start a process with a default of 2, and a 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 #bin下面存放各种执行文件
│├──redis-benchmark
│├──redis-check-aof
│├──redis-check-dump
│├──REDIS-CLI #redis客户端执行文件
│├──redis-sentinel->/usr/local/redis-3.0.0/bin/redis-server
│└──redis-server #redis服务端执行文件
├──dump.rdb #启动后默认生成的数据文件, you can set Dir's path parameter in redis.conf to specify to a different directory
├──etc
│└──redis.conf
└──var

Third, registration services

①, writing service control scripts


#!/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:"

#使用中偶尔发现服务器启动后居然不转入后台, so I added a "&" at the end.
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 "$" in
Start
Start
;;
Stop
Stop
;;
Restart)
Restart
;;
Condrestart)
[-e/var/lock/subsys/$prog] && restart
Retval=$?
;;
Status
Status $prog
Retval=$?
;;
*)
echo $ "Usage: $ {Start|stop|restart|condrestart|status}"
Retval=1
Esac
Exit $RETVAL

②, registration service and startup


#给执行权限
chmod +x/etc/init.d/redis

#开机启动
Chkconfig Redis on

#启动服务
Service Redis Start

#下面是启动记录
[root@localhost ~]# Service Redis start
Starting Redis Server:
[Root@localhost ~]# _._
_.-``__ ''-._
_.-``    `.  `_. "'-._ Redis 3.0.0 (00000000/0) bit
.-`` .-```. ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    ) Running in Stand alone mode
|`-._`-...-` __...-.``-._|'     ` _.-'| port:6379
|     `-._   `._    /     _.-'    | pid:28584
`-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|           `-._`-._        _.-'_.-'    | Http://redis.io
`-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
| `-._`-._        _.-'_.-'    |
`-._    `-._`-.__.-'_.-'    _.-'
`-._    `-.__.-'    _.-'
`-._        _.-'
`-.__.-'

[28584] APR 23:48:55.614 # Server started, Redis version 3.0.0
[28584] 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.overcom Mit_memory=1 ' for this to take effect.
[28584] APR 23:48:55.614 # WARNING You have transparent Huge Pages (THP) support be 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 the THP is disabled.
[28584] April 23:48:55.614 # warning:the TCP Backlog setting of 511 cannot be enforced BECAUSE/PROC/SYS/NET/CORE/SOMAXC Onn is set to the lower value of 128.
[28584] APR 23:48:55.615 * DB loaded from disk:0.000 seconds
[28584] APR 23:48:55.615 * The server is now ready to accept connections on port 6379

Iv. Master-Slave configuration
①, configuration

Follow the steps above to install Redis on the machine, and then add the following configuration items to the redis.conf from the machine:

#指定redis主机的IP地址和端口 (password authentication is not set by default) slaveof 192.168.10.124 6379


#指定redis主机的IP地址和端口 (password authentication is not set by default)

Slaveof 192.168.10.124 6379

After saving, start Redis can complete simple master-slave configuration.
②, testing

The test is simple, first on the host by the client REDIS-CLI to execute the new key value command:


[Root@localhost ~]#/usr/local/redis/bin/redis-cli
127.0.0.1:6379> Set Newkey slavetest
Ok

The login then executes the redis-cli Execution Query command from the machine:


[Root@localhost ~]#/usr/local/redis/bin/redis-cli
127.0.0.1:6379> Get Newkey
"Slavetest"

It is obvious that the new key on the host has been automatically synchronized to the machine, master-slave synchronization success!

This article only records the basic compilation installation and the master-slave configuration, of course, Redis also has its can carry on the custom setting or the optimization project, the follow-up has the opportunity to continue to organize to add.

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.