Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction and installation of redis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report