Redis build combat record on CentOS 6

Source: Internet
Author: User
Tags benchmark redis version redis server

Redis is a memory-based high-performance Key-value database, which is stored in memory and periodically flushed to disk for high read and write efficiency. He is characterized by support for various data structures, 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 checks for normal and encounters 2 errors

[[email protected] 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/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ Geffzhang/bin)
You need ' tclsh8.5 ' on 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
[Email protected] redis-stable]#

No tcl installed

Follow the installation on official website http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html (can also be used: Yum install TCL command installation)

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 '
[Email protected] redis-stable]#

Okay, now Redis 's installed.

Redis consists of four executables:redis-benchmark,redis-cli,redis-server,redis-stat four files, plus a The redis.conf constitutes the final available package for the entire redis. Their role is 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-stat:redis Status Detection Tool to detect Redis current status parameters and delay status

Redis can now be started, and Redis has only one boot parameter, which is his profile path.

Redis-server/etc/redis.conf

Note that the daemonize parameter for the default copy of the past redis.conf file is no, so Redis does not run in the background, so we need to reopen a terminal to test it. Modify to Yes to run Redis in the background. In addition, the configuration file specifies the address of the PID file, log file and data file, if necessary, the default log information is directed to stdout.

The following are the meanings of the main configuration parameters of redis.conf:

    • Daemonize: Whether to run daemon mode later
    • Pidfile:pid File Location
    • Port: Port number for listening
    • Timeout: Request time-out
    • Loglevel:log Information level
    • Logfile:log File Location
    • Databases: number of open databases
    • Save *: How often the snapshot is saved, the first * indicates how long, and the third * indicates how many times the write operation is performed. Snapshots are automatically saved when a certain number of writes are performed within a certain amount of time. You can set multiple conditions.
    • Rdbcompression: Whether to use compression
    • Dbfilename: Data Snapshot file name (only file name, excluding directory)
    • Dir: Save directory for Data snapshot (this is the directory)
    • AppendOnly: If the appendonlylog is turned on, each write will record a log, which will improve the data anti-risk ability, but affect the efficiency.
    • Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, Fsync per second, do not call Fsync wait for the system to synchronize itself)

At this point you can open a terminal for testing, the default listening port in the configuration file is 6379

2. Create user and log directory

Recommended setting up user and log directories for Redis on first boot

[Email protected] redis-stable]# Useradd Redis
[Email protected] redis-stable]# mkdir-p/var/lib/redis

#db文件放在这里, you need to modify redis.conf

# The working directory.
#
# The DB would be is written inside this directory, with the filename specified
# above using the ' dbfilename ' configuration directive.
#
# Also The Append only File is created inside this directory.
#
# Note that you must specify a directory here, not a file name.
Dir/var/lib/redis
[Email protected] redis-stable]# mkdir-p/var/log/redis

# Specify the log file name. Also ' stdout ' can is used to force
# Redis to log on the standard output. Note If you use the standard
# Output for logging but daemonize, logs'll be sent To/dev/null
Logfile/var/log/redis/redislog
[Email protected] redis-stable]# chown Redis.redis/var/lib/redis
[Email protected] redis-stable]# chown Redis.redis/var/log/redis

3. Configuring the Init Script

Redis Admin script based on Ubuntu release version, Ubuntu can read this article Ubuntu installation boot Redis, on CentOS Linux is not available, below a script can be used for CentOS.

Before you can use this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will error when restarting or stopping Redis, and cannot automatically synchronize data to disk before stopping the service:

# vi/etc/sysctl.conf

Vm.overcommit_memory = 1

Then the app takes effect:

# sysctl–p

To establish 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 "$" 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

Then increase the service and boot from the boot:

# chmod 755/etc/init.d/redis
# chkconfig--add Redis
# chkconfig--level 345 Redis on
# chkconfig--list Redis

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

CentOS 6.3 Server Installation redis-2.4.15

Easily implement Redis data master-slave replication on multiple servers
Sentinel-redis High-availability Scenario (i): Master-slave replication

Sentinel-redis High-availability Scenario (ii): master-Slave switching

Redis Sentinel: Cluster failover solution (reprint)

Redis build combat record on CentOS 6 (GO)

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.