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

Installation and use of redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains the "installation and use of redis", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "the installation and use of redis"!

Port: 6379

Config file: / etc/redis/6379.conf

Log file: / var/log/redis_6379.log

Data dir: / var/lib/redis/6379

Executable: / usr/redis/bin/redis-server

Cli Executable: / usr/redis/bin/redis-cli

Redis-cli

1. Install redis on a single node

CentOS 6.5

# yum-y install gcc tcl

# tar xf redis-2.8.18.tar.gz

# mv redis-2.8.18/ redis

# cd redis

# make

If you make an error, you need to go to the redis directory

# cd deps

# make jemalloc

# make lua

# make linenoise

# make hiredis

# cd..

It can be tested. Skip here.

# make test

# mkdir-p / opt/sxt/redis

Installation

# make install / / this is the default installation, but we do not use it here (it is still in the / usr/local/bin/ directory by default); here we use the following installation directory

# make PREFIX=/opt/sxt/redis install

Install to / usr/local/bin by default

Executable file

Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server

Environment variable

Export REDIS_HOME=/opt/sxt/redis

Export PATH=$PATH:$REDIS_HOME/bin

# redis-server-help

Utils directory

#. / install_server.sh

When finished, the configuration file is in / etc/redis/6379.conf

You can turn redis into a service.

# mv / etc/init.d/redis_6379 / etc/init.d/redisd

# chkconfig redisd on

# service redisd start

# service redisd start | stop | restart | status

# ss-tanl

# vim / etc/redis/6379.conf

Redis.conf

# backend service

Daemonize yes

Port 6379

# default DB is 0, set the number of DB

Databases 16

2. Master-slave replication of redis cluster

Sentinel experiment

Compile and install 3 redis,node1, node2 and node3

Node1 is master

Node2, node3 is Slaves, slaveof 192.168.56.201 6379 in configuration file (configuration file location / etc/redis/6379.conf)

Start the redis service of node1, node2 and node3 respectively

Sentinel configuration

Under the 3-node home directory, create a sentinel.conf

Vim sentinel.conf

Port 26379

Sentinel monitor node1 192.168.56.201 6379 2

# cp redis-2.8.18/src/redis-sentinel / opt/sxt/redis/bin

# redis-sentinel sentinel.conf

Using redis-cli on 3 nodes

Test the effect of redis master-slave replication

Stop the node1 service

# service redisd stop

Start failover every once in a while

Test on node2 and node3

# redis-cli-h 192.168.56.201-p 26379 info sentinel

# redis-cli-p 26379 SENTINEL master node1

# redis-cli-p 26379 SENTINEL slaves node1

# redis-cli-p 26379 SENTINEL get-master-addr-by-name node1

3 、 Redis Twemproxy

Twemproxy installation configuration

Twemproxy can be downloaded from github.

Https://github.com/twitter/twemproxy

$tar xf twemproxy-0.4.0.tar.gz

Install autoconf

Because CentOS 6.x autoconf version is too low, do not need yum installation, manual installation

# tar xf autoconf-2.69.tar.gz

# cd autoconf-2.69

#. / configure-prefix=/usr

# make & & make install

# autoconf-V # check whether the installation is successful

Download automake

Automake-1.15.tar.gz

#. / configure-prefix=/usr

# make & & make install

Download libtool

Libtool-2.4.5.tar.gz

#. / configure-prefix=/usr

# make & & make install

Install twemproxy

# tar xf twemproxy-0.4.1.tar.gz

# cd twemproxy-0.4.1

# aclocal

# autoconf

# mkdir config

# autoheader

# libtoolize

# automake-a

#. / configure

# make

# make install

Installation completed

Profile description

Sxt:

Listen: 192.168.56.201:22121

Hash: fnv1a_64

Distribution: ketama

Auto_eject_hosts: true

Redis: true

Server_retry_timeout: 2000

Server_failure_limit: 3

Servers:

-192.168.56.201379

-192.168.56.202 purl 6379purl

-192.168.56.203 purl 6379purl

Sxt, the name of the server pool. You can create multiple server pools.

Listen: 192.168.56.20115: 22121, the listening address and port number of this server pool

Hash: fnv1a_64, key hash algorithm, used to map keys to a hash value

Distribution: ketama, the key distribution algorithm that determines which server the key is distributed to

Redis: true, proxy redis command request, no timing default proxy memcached request

Servers, address and port number and weight of each server in the pool

Auto_eject_hosts 、

Server_failure_limit: when twemproxy encounters an error in sending command requests to the same server three times in a row, twemproxy marks the server as offline and hands it over to other online servers in the pool

Start the redis service

3 nodes start manually

# service redisd start

Start twemproxy

# nutcracker-d-c / opt/sxt/twemproxy/conf/nutcracker.sxt.yml

Connect

# redis-cli-p 22121-h 192.168.56.201

test

SET msg "hello world"

SADD numbers 1 3 5 7 9

RPUSH lst a b c d e

Offline and online testing of Redis nodes

Note: when you want to remove master-slave replication when configuring master-slave replication, but the configuration in the configuration file is missing, you can execute the SLAVEOF NO ONE configuration file / etc/redis/6379 to restore the configuration, and comment out the configuration at this time.

Thank you for your reading, the above is the content of "installation and use of redis", after the study of this article, I believe you have a deeper understanding of the installation and use of redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report