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

Why is the use of clusters a common means for websites to solve the problems of high concurrency and massive data?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

The following brings you that the use of clusters is a common means for websites to solve the problems of high concurrency and massive data. I hope it can bring some help to everyone in practical application. Load balancing involves many things and few theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Preface

Using cluster is a common means for websites to solve the problem of high concurrency and massive data. When a CVM's processing capacity and storage space are insufficient, do not attempt to replace a more powerful server. For a large website, no matter how powerful the server is, it cannot meet the growing business needs of the website. In this case, it is more appropriate to add a server to share the access and storage pressure of the original server. Through the load balancer scheduling server, the access request from the browser is distributed to any server in the application server cluster. If there are more users, more application servers are added to the cluster, so that the load pressure of the application cloud server is no longer the bottleneck of the entire website.

Environmental preparation

192.168.0.221:nginx + keepalived master

192.168.0.222:nginx + keepalived backup

192.168.0.223:tomcat

192.168.0.224:tomcat

Virtual ip (VIP): 192.168.0.200, an ip that provides services, also known as floating ip

The diagram between the various components is as follows:

Tomcat acts as an application server

The installation of tomcat is not within the scope of this blog. Please refer to virtualBox to install centos, and remember to put your own application under the webapps of tomcat,tomcat. Mine is myWeb. If you also use my myWeb, then the ip in index.jsp needs to be replaced with your own.

Start the tomcat on 192.168.0.223 and 192.168.0.224. The path of tomcat may be inconsistent with mine and need to be written as your own.

# cd / usr/local/tomcat7/bin

#. / startup.sh

Visit the myWeb as follows

Nginx does load balancing.

The installation of nginx will not be discussed in this article. For more information, please refer to LVS + keepalived + nginx + tomcat to achieve master-slave hot backup + load balancing.

The nginx.conf content is as follows

Copy the code

User root; # running user

Worker_processes 1; # start the process, usually set to equal the number of cpu

# Global error log and PID file

Error_log / usr/local/nginx/logs/error.log

Error_log / usr/local/nginx/logs/error.log notice

Error_log / usr/local/nginx/logs/error.log info

Pid / usr/local/nginx/logs/nginx.pid

Working mode and number of connections online

Events

{

Use epoll; # epoll is a way of multiplexing IO (I _ Multiplexing O Multiplexing), but only for kernels above linux2.6, it can greatly improve the performance of nginx.

Worker_connections 1024; # maximum number of concurrent links for a single background worker process process

}

# configure the http server and use its reverse proxy function to provide load balancing support

Http

{

Include mime.types

Default_type application/octet-stream

# set request buffers server_names_hash_bucket_size 128bot clientbound headers buffers size 32K 432kbot buffers # buffers 8m The # sendfile instruction specifies whether nginx calls the sendfile function (zero copy mode) to output the file. For ordinary applications, # must be set to on. If it is used for downloading and other application disk IO overloaded applications, it can be set to off to balance the processing speed of disk and network Igamo, and reduce the uptime.sendfile on;tcp_nopush on;tcp_nodelay on;# connection timeout keepalive_timeout 65 of the system. # enable gzip compression to reduce transport traffic: gzip on;gzip_min_length 1kt weight buffers 4 16kb port number weight, the greater the weight, the more likely it is to be assigned.

Server 192.168.0.223:8080 weight=4 max_fails=2 fail_timeout=30s

Server 192.168.0.224:8080 weight=4 max_fails=2 fail_timeout=30s

}

Server {listen 80; # listening port server_name localhost;# default request setting location / {proxy_pass http://tomcat_pool; # switch to tomcat processing} # all jsp pages are processed by tomcat location ~\. (jsp | jspx | dp)? ${proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://tomcat_pool; # turn to tomcat processing} # all static files can be read directly without tomcat,nginx processing location. *\. (htm | html | gif | jpg | jpeg | png | bmp | swf | ioc | rar | txt | flv | mid | doc | ppt | pdf | xls | mp3 | wma) ${expires 30d;} location ~. *\. (js | css)? ${expires 1h;} # define error page error_page 500 502 503 504 / 50x.htl; location = / 50x.html {root html;}}

}

Copy the code

The configuration file of master-slave nginx is exactly the same, and the configuration of nginx.conf can be complex or simple. Everyone can configure it according to their own situation, and it is also possible to copy the above configuration.

Once configured, start nginx and write your own path

# cd / usr/local/nginx/sbin

#. / nginx

Access nginx, and the results are as follows:

The service of the two nginx servers is normal, and there is no master-slave distinction at this time. The two are of the same high level. When keepalived is configured, there will be a master-slave distinction.

Keepalived to achieve nginx High availability (HA)

The installation of keepalived will not be described in this article. For more information, please see Master / Slave Hot backup + load balancing (LVS + keepalived)

The role of keepalived is actually reflected in the first figure, which plays two main roles: implementing the mapping of VIP to local ip, and detecting the state of nginx.

The keepalived.conf on master is as follows:

Copy the code

Global_defs {

Notification_email {997914490@qq.com

Br/ > 997914490@qq.com

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