Home Backend Development PHP Tutorial Complete steps for laravel project to deploy redis cluster using twemproxy_php example

Complete steps for laravel project to deploy redis cluster using twemproxy_php example

Jun 01, 2018 pm 01:35 PM
laravel php

Twemproxy is a proxy server that can reduce the number of connections opened by the Memcached or Redis server. The following article mainly introduces you to the relevant information about the Laravel project using twemproxy to deploy the redis cluster. The article introduces it in detail through the sample code. Friends in need can refer to it

Preface

twemproxy is a redis proxy proxy developed by Twitter. Twemproxy can use multiple redis servers as one. When developers access these redis servers through twemproxy, they don’t have to worry about which one to go to. A redis server reads k-v data or updates k-v data into the data set, which also solves the problem of redis sharing among multiple servers. With the help of redis's master-slave replication, it can be guaranteed that even if any redis fails to work, an entire data set can still be guaranteed to exist.

What is Twemproxy used for? It can:

  • Reduce the number of cache server connections through proxy

  • Automatically share data among multiple cache servers

  • Support consistent hashing through different strategies and hashing functions

  • Disable failed nodes through configuration

  • Run on multiple instances, the client can connect to the first available proxy server

  • Supports streaming and batch processing of requests, thus reducing round-trip consumption

The following introduces the installation and configuration of twemproxy:

1. You need to install m4 before installing twemproxy , autoconf, automake, libtool, gcc, otherwise various errors will be reported

Install m4

wget http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
&& tar -xzvf m4-1.4.13.tar.gz
&& cd m4-1.4.13
&& ./configure –prefix=/usr/local 
make && make install
Copy after login

Install autoconf, automake, libtool, gcc

yum -y install autoconf automake libtool gcc
Copy after login

2. Install twemproxy

git clone https://github.com/twitter/twemproxy.git
autoreconf -fvi #生成configure文件
.configure
make && make install
Copy after login

3. Edit the configuration file

vim conf/nutcracker.yml

alpha:
 listen: 127.0.0.1:22121 #监听端口
 hash: fnv1a_64  #key值hash算法,默认fnv1a_64
 distribution: ketama  #分布算法 
#ketama一致性hash算法;modula非常简单,就是根据key值的hash值取模;random随机分布
 auto_eject_hosts: true  #摘除后端故障节点 
 redis: true   #是否是redis缓存,默认是false
 timeout: 400   #代理与后端超时时间,毫秒
 server_retry_timeout: 200000 #摘除故障节点后重新连接的时间,毫秒
 server_failure_limit: 1  #故障多少次摘除
 servers:
 - 172.16.175.145:6379:1 
 - 172.16.175.122:6379:1
Copy after login

4. Change the redis configuration file

The IP and port monitored by redis must correspond to twemproxy (because I only installed twemproxy on one of the machines, if it is installed on both machines, there is no need to change it. )

Change the bind option in redis.conf of the two servers respectively, change 127.0.0.1 to 172.16.175.145 and 172.16.175.122 in this example

5. Turn on twemproxy

nutcracker -t -c /twemproxy/conf/nutcracker.yml 
#测试配置文件 如果不加-c 默认是检测conf/nutcracker.yml
Copy after login

nutcracker -d -c /twemproxy/conf/nutcracker.yml -p -o /data/logs/twemproxy/redisproxy.log 
#启动并将日志记录到/data/logs/twemproxy/redisproxy.log
Copy after login

6. Change the redis connection in the project to twemproxy ip and port

My project uses laravel, just set the REDIS_HOST and REDIS_PORT in the .env to 127.0.0.1 and 22121

Note, you also need to set the config Comment out 'database' => 0 in the redis configuration in database.php under the folder. Predis will perform a select operation on this configuration by default, which will cause a connection error.

Do a redis read and write test. If nothing unexpected happens, twemproxy can be used normally!

Related recommendations:

Laravel framework implements the addition, deletion, modification and query (CURD) operation example of the model layer

The above is the detailed content of Complete steps for laravel project to deploy redis cluster using twemproxy_php example. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

See all articles