Redis construction practices on centos 6 are recorded on multiple servers for simple master-slave redis Data Replication

Source: Internet
Author: User
Tags redis version

RedisIt is a memory-based high-performance Key-value database that stores data in the memory and regularly refreshes the data to the disk. This is a concern for high read/write efficiency. It supports various data structures, such as stirng, hashes, list, set, and sorted sets.

1. Download and install

Wget http://download.redis.io/redis-stable.tar.gz

Tar-zxvf redis-stable.tar.gz

CD redis-stable

Make

Make test check whether it is normal. Two errors are encountered.

[Root @ localhost redis-stable] # Make Test
Cd src & make test
Make [1]: Entering directory '/usr/local/src/redis-stable/src'
Which: No tclsh8.5 in (/usr/lib64/qt-3.3/bin:/usr/local/sbin: /usr/sbin:/home/geffzhang/bin)
You need 'tclsh8. 5' in order to run the redis Test
Make [1]: *** [test] Error 1
Make [1]: Leaving directory '/usr/local/src/redis-stable/src'
Make: *** [test] Error 2
[Root @ localhost redis-stable] #

Not InstalledTCL

According to the installation on the official http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html

Make install

Mkdir-P/usr/local/bin
CP-PF redis-server/usr/local/bin
CP-PF redis-benchmark/usr/local/bin
CP-PF redis-cli/usr/local/bin
CP-PF redis-check-dump/usr/local/bin
CP-PF redis-check-Aof/usr/local/bin
Make [1]: Leaving directory '/usr/local/src/redis-stable/src'
[Root @ localhost redis-stable] #

Okay, nowRedisThe installation is successful.

Redis consists of four executable files:Redis-Benchmark,Redis-cli,Redis-Server,Redis-statAdd one of the four filesRedis. confIt constitutes the final available package of the entire redis. Their functions are as follows:

    • Redis-server: Daemon startup of the redis ServerProgram
    • 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-stat: redis status detection tool that can detect redis's current status parameters and latency

Now you can start redis. redis has only one startup parameter, that is, its configuration file path.

Redis-server/etc/redis. conf

Note: by defaultRedis. confFileDaemonizeThe parameter isNoSo redis will not run in the background. To test this, we need to re-open a terminal. ChangeYesRun redis in the background. In addition, the PID file, log file, and data file address are specified in the configuration file. If you need to modify the address first, the default log information is directed to stdout.

The main configuration parameters of redis. conf are as follows:

    • Daemonize: whether to run in daemon mode
    • Pidfile: PID File Location
    • Port: the port number of the listener.
    • Timeout: Request timeout
    • Loglevel: log information level
    • Logfile: Location of the log file
    • Databases: number of databases Enabled
    • Save **: the frequency at which snapshots are saved. The first "*" indicates the duration and the third "indicates the number of write operations performed. Snapshots are automatically saved when a certain number of write operations are performed within a certain period of time. You can set multiple conditions.
    • Rdbcompression: whether to use Compression
    • Dbfilename: Data snapshot file name (only file name, excluding directory)
    • Dir: directory for storing data snapshots (this is the Directory)
    • Appendonly: whether to enable appendonlylog. If it is enabled, a log is recorded for each write operation, which improves data risk resistance but affects efficiency.
    • Appendfsync: How to synchronize appendonlylog to the disk (three options are force-call fsync for each write, enable fsync once per second, and do not call fsync to wait for the system to synchronize itself)

Now you can open a terminal for testing. The default listening port in the configuration file is6379

2. Create a user and log directory

We recommend that you create a user and log directory for redis at the first startup.

[Root @ localhost redis-stable] # useradd redis
[Root @ localhost redis-stable] # mkdir-P/var/lib/redis

# Put the DB file here and modify redis. conf

# The working directory.
#
# The dB will be written inside this directory, with the filename specified
# Above using the 'dbfilename' configuration ctive ve.
#
# Also the append only file will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
DIR/var/lib/redis
[Root @ localhost redis-stable] # mkdir-P/var/log/redis

# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output. Note that if you use standard
# Output for logging but daemonize, logs will be sent to/dev/null
Logfile/var/log/redis/redislog
[Root @ localhost redis-stable] # chown redis. redis/var/lib/redis
[Root @ localhost redis-stable] # chown redis. redis/var/log/redis

3. Configure the init script

The redis management script is based on the Ubuntu release. You can refer to this article for Ubuntu.ArticleUbuntu installs and starts redis, which is not available on centos Linux. The following script can be used for centos.

Before using this script for management, you must configure the following kernel parameters. Otherwise, an error will be reported when the redis script restarts or stops redis, data cannot be automatically synchronized to the disk before the service is stopped:

# Vi/etc/sysctl. conf

VM. overcommit_memory = 1

Then the application takes effect:

# Sysctl-P

Create a redis STARTUP script:

# Vim/etc/init. d/redis

#! /Bin/bash
#
# Init file for redis
#
# Chkconfig:-80 12
# Description: redis daemon
#
# Processname: redis
# Config:/etc/redis. conf
# Pidfile:/var/run/redis. PID
Source/etc/init. d/functions
# Bin = "/usr/local/bin"
Bin = "/usr/local/bin"
Config = "/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 :"
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

Then add the service and start it automatically:

# Chmod 755/etc/init. d/redis
# Chkconfig -- add redis
# Chkconfig -- level 345 redis on
# Chkconfig -- list redis

[Root @ localhost redis-stable] # service redis start
Starting redis server: [OK]
[Root @ localhost redis-stable] # Cat/var/log/redis/redislog
[14250] 14 Jul 22:23:15 * server started, redis version 2.4.15
[14250] 14 Jul 22:23:15 * the server is now ready to accept connections on port 6379
[14250] 14 Jul 22:23:15-0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:20-0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:25-0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:30-0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:35-0 clients connected (0 slaves), 717512 bytes in use
[Root @ localhost redis-stable] #

Centos 6.3 Server Installation redis-2.4.15 

Simple master-slave data replication for redis on multiple servers
 

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.