Lvs+redis Deployment Manual

Source: Internet
Author: User
Tags syslog redis cluster

Redis is an open source, advanced key-value Storage and a perfect solution for building high-performance, scalable Web applications.

The three main features that Redis inherits from its many competitions are:

Redis The database is completely in memory and the disk is used for persistence only.

Redis has a rich set of data types compared to many key-value data stores.

Redis data can be copied to any number of slave servers.

Redis Benefits

Exceptionally fast: Redis is very fast and can perform about 110,000 episodes per second, about 81000 + records per second.

Support for rich data types: Redis support Most developers already know like lists, collections, ordered collections, hash data types. This makes it very easy to solve a wide variety of problems because we know which issues are better than the data types that can be handled through it.

Operations are atomic: All Redis operations are atomic, which ensures that Redis servers accessed by two clients at the same time will get the updated values.

Multifunction utility: Redis is a versatile tool that can be used in multiple uses such as cache, message, queue (Redis native support publish/subscribe), any transient data, applications such as Web application sessions, Web page hits count etc.

Redis Installation

Download the latest source package on the Redis website

Http://download.redis.io/releases/redis-2.8.3.tar.gz

    1. Extract

# tar Xzf redis-3.0.0.tar.gz

    1. Copy Directory

# MV Redis-3.0.0/usr/local/redis

    1. Go to Catalog

# Cd/usr/local/redis

    1. Compile

# Make && make install

    1. View command run results, if 0 is successful

# echo $?

Redis Boot

# Redis-server

The first boot may have a hint of the warning information, can be ignored, but it is best to follow the instructions to modify the method.

Redis Client Startup

# REDIS-CLI

Verifying client Actions

# redis> Set IOM Dtsoft

Ok

# redis> Get IOM

"Dtsoft"

Redis Master-Slave synchronization Edit Host profile

# Vim Redis.conf

Daemonize yes– Process Background boot

logfile/usr/local/redis/redis.log– log files

syslog-enabled no– log is not written into the system log

dir/usr/local/redis/data– Data File storage

Requirepass system– Authentication Password

To edit a Slave configuration file

# Vim Redis.conf

Daemonize Yes

Logfile/usr/local/redis/redis.log

Syslog-enabled No

Dir/usr/local/redis/data

Slaveof 192.168.10.5 6379– The IP address and port of the primary server

Masterauth system– The authentication password on the primary server

Start service 1, host node:

# cd/usr/local/redis/src/

#./redis-server. /redis.conf– The following configuration file must be added

2. Slave node:

# cd/usr/local/redis/src/

#./redis-server. /redis.conf– The following configuration file must be added

3. Check the port

Perform on the master and slave machines separately to see if the two connected ports are established status.

# NETSTAT-ANTP | grep 6379

4. Verifying synchronization

Host node:

#./redis-cli

127.0.0.1:6379> Set IOM 123456

(Error)        Noauth Authentication required. – Requires authentication permission

127.0.0.1:6379> Auth System

Ok

127.0.0.1:6379> Set IOM 123456

Ok

127.0.0.1:6379> Get IOM

"123456"

Slave node:

#./redis-cli

127.0.0.1:6379> get iom– does not require authentication permissions from the server

"123456"

keepalived Configuring the Routing machine configuration

Edit/etc/keepalived/keepalived.cnf File

Global_defs {

router_id Lvs_master #BACKUP上修改为LVS_BACKUP

}

Vrrp_instance Vi_1 {

State MASTER

Interface eth0

VIRTUAL_ROUTER_ID 51

Priority 100

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

192.168.10.252 #redis

}

}

Virtual_server 192.168.10.252 6379 {

Delay_loop 6

Lb_algo RR

Lb_kind DR

#lb_kind NAT

# Persistence_timeout 3

Protocol TCP

Real_server 192.168.10.3 6379 {

Weight 3

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 6379

}

}

Real_server 192.168.10.5 6379 {

Weight 3

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 6379

}

}

}

Restart keepalived Service

# Service Keepalived Restart

Redis slave-to-machine configuration

Writing Execution Scripts

#vi Lvs_real

    1. #!/bin/bash
    2. #description: startrealserver
    3. vip=192.168.10.252
    4. case "$" in
    5. start)
    6. echo "Startlvsofrealserver"
    7. /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
    8. echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    9. echo "2" >/proc/sys/net/ipv4/conf/lo/arp_ Announce
    10. echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    11. echo "2" >/proc/sys/net/ipv4/conf/ All/arp_announce
    12. sysctl–p >/dev/null 2>&1
    13. ;;
    14. stop) d
    15. /sbin/ifconfig lo:0 down
    16. echo "Closelvsdirectorserver"
    17. echo "0" >/proc/sys/ Net/ipv4/conf/lo/arp_ignore
    18. echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
    19. echo "0" >/ Proc/sys/net/ipv4/conf/all/arp_ignore
    20. echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    21. ;;
    22. *)
    23. echo "Usage:$0{start|stop}"
    24. Exit 1
    25. Esac

Execute script

#/lvs_real Start

System test 1, test environment

vip/Routing machine: 192.168.10.252

Redis Master: 192.168.10.3

Redis Standby: 192.168.10.4

Client: 192.168.10.1

2. Test process

The client runs the Redis client:

# redis-cli–h 192.168.10.252–p 6379

redis:6379> auth system– need to enter the password for the first time

Ok

Redis:6379> Get IOM

"123456"

Turn off the Redis mainframe

Client running Redis Client

Redis:6379> Get IOM

"123456" – can still get IOM value

Starting a Redis Host

Client Restarts Redis Client

# redis-cli–h 192.168.10.252–p 6379

The routing machine runs the LVS monitoring command.

# Watch IPVSADM–LC

You can see that the destination shows the primary node IP.

Each time the client restarts the Redis client, the destination display IP is replaced in the primary standby node (the LVS route is configured for polling, that is, the Lb_algo RR

)。

3. Test note
    • Redis is configured to read-only from the node by default, and client connections can only perform query operations after they are assigned to the slave node, and cannot be deleted. From the node, if you want to, you can change the slave-read-only option of the Redis configuration file to No.
    • As long as the client has not exited the Redis client, the same Redis node will be attached.
    • After the Redis node fails to recover, keepalived will immediately incorporate it into the Redis cluster, but at this point it is possible to restore the Redis node data older than the other nodes, and be sure to synchronize the data before merging it into the cluster.

Lvs+redis Deployment Manual

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.