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

How to synchronize multiple server codes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

In this article, the editor introduces in detail "how to synchronize multiple server code". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to synchronize multiple server code" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.

Cluster

If our project runs on a machine, if there is something wrong with the machine, or if the number of user requests is relatively high, and a machine cannot support it. Our website may not be accessible. Then how to solve it? You need to use multiple machines, deploy the same program, and let several machines run our website at the same time. So how do you distribute the request on all our machines. So the concept of load balancing came into being.

Load balancing

Load balancing means that based on the reverse proxy, all requests can be distributed to different servers according to the specified policy algorithm. Nginx,lvs can be used to achieve load balancing. But now there is a problem, what if there is a problem with the load balancing server? All the concepts of redundancy emerge.

redundancy

Redundancy is actually two or more servers, one master server and one slave server. Suppose there is a problem with the load balancing server of a master server, and the slave server can replace the master server to continue load balancing. The way to do this is to use keepalive to preempt virtual hosts.

Distributed system

Distribution is actually splitting up a large project and running it separately.

Give me the above example. Suppose we have a large number of visitors. We can make it distributed, the same mechanism as cdn. An identical cluster has been set up in Beijing, Hangzhou and Shenzhen. Users close to Beijing will visit the cluster in Beijing, and those close to Shenzhen will visit the cluster on the Shenzhen side. In this way, our cyber war will be divided into three regions, each independent.

Take another example, for example, we redis distributed. Redis distribution is to distribute the data in redis to different servers, each server stores different content, while mysql cluster is to put the same data on each server. This also understands the concepts of distribution and clustering.

MySQL master and slave

The mysql master server writes the sql operation log to the bin.log log. The slave server reads the master bin.log log and then executes the sql statement.

The master and subordinate have the following problems.

The 1.master server can write and read, but slave can only write.

The data read by slave has not been written yet, so what should be done?

If cached, read from the cache.

Force read from master.

With pxc clusters, any node is readable and writable, with strong read-write consistency.

How to solve data inconsistency

Set sticky to true in the config/database.php mysql configuration block

Sticky is an optional value that can be used to immediately read records that have been written to the database during the current request cycle. If the sticky option is enabled and a write operation has been performed during the current request cycle, any read operation will use a write connection. This ensures that data written in the same request cycle can be read immediately, thus avoiding the problem of data inconsistency caused by master-slave delay. However, whether or not to enable it depends on the requirements of the application.

Synchronize code to multiple servers

Laravel provides us with the extension package laravel/envoy, which provides a concise, lightweight syntax for defining the daily tasks of remote servers. Blade-style syntax can be used to configure deployment tasks, execute Artisan commands, and so on.

Composer global require laravel/envoy

Envoy tasks should be defined in Envoy.blade.php under the root of the project. Write down the content

@ servers (['web-1' = >' 192.168.1.1', 'web-2' = >' 192.168.1.2']) @ task ('deploy', [' on' = > ['web-1',' web-2']]) cd site git pull origin {{$branch}} composer update php artisan migrate@endtask

The above code means that when we envoy run deploy on the command line, we will ssh to the web-1,web-2 to execute

Cd site git pull origin {{$branch}} php artisan migrate has read this article entitled "how to synchronize multiple server codes". If you want to master the knowledge points of this article, you still need to practice and use it. If you want to know more about related articles, please follow the industry information channel.

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

Internet Technology

Wechat

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

12
Report