Introduction and installation of redis
In the previous two articles, we briefly learned about the installation of memcached and the combination of php. Now I introduce another nosql key database redis. Through learning to look up the information, I found that redis is used more frequently than memcached, and its function is more powerful. The following will slowly introduce redis through a few articles to let you have a better understanding of redis.
First of all, a brief introduction to redis.
1) redis is a key-value storage system, the official site http://redis.io
2) similar to memcached, but supports data persistence
3) support more value types, including hash, lists (linked list), sets (collection) and sorted sets (ordered set) data types in addition to and string
4) redis uses two file formats: full data (RDB) and incremental request (aof). The full data format is to write the data in memory to disk so that the file can be read and loaded next time. The incremental request file serializes the data in memory into operation requests, which are used to read the file and replay to get the data.
5) redis storage is divided into three parts: memory storage, disk storage and log files.
Then comes the installation of redis.
Wget https://codeload.github.com/antirez/redis/tar.gz/2.8.21
Mv 2.8.21 redis-2.8.21.tar.gz
Tar zxvf redis-2.8.21.tar.gz
Cd redis-2.8.21
Yum install-y gcc epel-release jemalloc-devel
If make makes an error, run the following command:
Cd deps; make hiredis lua jemalloc linenoise; cd..; make
Make PREFIX=/usr/local/redis install
Mkdir / usr/local/redis/etc
Write a configuration file (you can find it by searching on the Internet)
Vim / usr/local/redis/etc/redis.conf / / is as follows:
#
Daemonize yes
Pidfile / usr/local/redis/var/redis.pid
Port 6379
Timeout 300
Loglevel debug
Logfile / usr/local/redis/var/redis.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump.rdb
Dir / usr/local/redis/var/
Appendonly yes
Appendfilename "appendonly.aof"
Appendfsync always
#
I will explain the configuration parameters of redis separately in the following articles about the above configuration.
And then edit the startup script.
Vim / 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"
Basedir= "/ usr/local/redis"
Exec= "$basedir/bin/$name"
Pidfile= "$basedir/var/redis.pid"
REDIS_CONFIG= "$basedir/etc/redis.conf"
[- 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 "$1" in
Start)
Rh_status_q & & exit 0
, 1
Stop)
Restart)
, 1
Reload)
Rh_status_q | | exit 7
, 1
Force-reload)
Force_reload
Status)
Rh_status
Condrestart | try-restart)
Rh_status_q | | exit 0
Restart
*)
Echo $"Usage: $0 {start | stop | status | restart | condrestart | try-restart}"
Exit 2
Esac
Exit $?
# #
Finally, create the user and join the system service
Useradd-s / sbin/nologin redis
Mkdir / usr/local/redis/var
The chmod777 / usr/local/redis/var / / var directory is used to store pid files and log files.
Chmod755 / etc/init.d/redis
Chkconfig-add redis
Service redis start
-the data structure and configuration file of redis will be introduced later.