


Laravel project uses twemproxy to deploy the complete steps of redis cluster php instance
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
Install autoconf, automake, libtool, gcc
yum -y install autoconf automake libtool gcc
2. Install twemproxy
git clone https://github.com/twitter/twemproxy.git autoreconf -fvi #生成configure文件 .configure make && make install
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
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
nutcracker -d -c /twemproxy/conf/nutcracker.yml -p -o /data/logs/twemproxy/redisproxy.log #启动并将日志记录到/data/logs/twemproxy/redisproxy.log
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 that 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!
Summary
Articles you may be interested in:
How to open PHP7 Opcode creates powerful performance with detailed explanation of php skills
##PHP solves the problem of rabbits giving birth to rabbits based on recursive algorithm php skills
About ThinkPHP Detailed explanation of exception handling in_php example
The above is the detailed content of Laravel project uses twemproxy to deploy the complete steps of redis cluster php instance. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

In the Laravel framework version selection guide for beginners, this article dives into the version differences of Laravel, designed to assist beginners in making informed choices among many versions. We will focus on the key features of each release, compare their pros and cons, and provide useful advice to help beginners choose the most suitable version of Laravel based on their skill level and project requirements. For beginners, choosing a suitable version of Laravel is crucial because it can significantly impact their learning curve and overall development experience.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

To learn Laravel 6, you can get video tutorials from Laracasts (recommended), official documentation and YouTube. Recommended courses include Laracasts’ “Laravel 6 From Beginner to Mastery” and “Official Laravel 6 Tutorial” produced by the official team. When choosing a video course, consider skill level, teaching style, project experience and frequency of updates.
