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 build asp.net core load balancing Cluster

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail how to build ASP.NET core Load Balancer cluster, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

overview

The purpose of this article is to build three ASP.NET core clusters, and with nginx to do Load Balancer

First prepare the source code to run

http://pan.baidu.com/s/1c20x0bA

Prepare three servers (or virtual machines) 192.168.182.129, 192.168.182.130, 192.168.182.131

The requested URL/root/aspnetcore/anuoapc/was not found on this server.

Set up the following environments on three machines

Step 1: NET Core installation (centos 7)

1.

sudo yum install libunwind libicu

curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/? LinkID=809131

sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet

sudo ln -s /opt/dotnet/dotnet /usr/local/bin

2.

mkdir hwapp

cd hwapp

dotnet new

3.

dotnet restore

dotnet run

Hello world is installed successfully!

Step 2: Install Nginx

1.

curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.

rpm -ivh nginx.rpm

yum install nginx

3.

systemctl start nginx to start nginx.

systemctl enable nginx to set up nginx boot

4. Close firewall centos 7

systemctl stop firewall.service #Stop firewall

systemctl disable firewall d.service #disable firewall boot

5.

Modify the/etc/nginx/conf.d/default.conf file.

Replace the file contents with:

upstream myserver {

server 192.168.182.129:9090;

server 192.168.182.130:9090;

server 192.168.182.131:9090;

}

server {

listen 80;

location / {

proxy_pass http://myserver;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection keep-alive;

proxy_set_header Host $host;

proxy_cache_bypass $http_upgrade;

}

}

Finally:

nginx -s reload makes it effective immediately

6. Close SELinux

cd /etc/selinux/

Open the config file and set the SELINUX value to disabled.

Restart centos to take effect

Step three. Configure daemon supervisor

1. Install supervisor

yum install python-setuptools

easy_install supervisor

2. configured

mkdir /etc/supervisor

echo_supervisord_conf > /etc/supervisor/supervisord.conf

3. Modify the supervisor.conf file

Change the configuration at the end of the file to:

[include]

files = conf.d/*.conf

4. start

supervisord -c /etc/supervisor/supervisord.conf

5. Create an AnuoApc.conf file that looks like this

[program:AnuoApc]

command=dotnet AnuoApc.Web.dll ; Command to run the program

directory=/root/netcore/anuoapc/ ; directory where command is executed

autostart =true ; Program unexpectedly exits Whether to restart automatically

stderr_logfile=/var/log/AnuoApc.err.log ; error log file

stdout_logfile=/var/log/AnuoApc.out.log ; Output log file

environment=ASPNETCORE_ENVIRONMENT=Production ; process environment variables

user=root ; The user identity of the process execution

stopsignal=INT

6.

Copy the file to: /etc/supervisor/conf.d/

supervisord reload to make it effective.

ps -ef | grep AnuoApc

If you see the dotnet AnuoApc.Web.dll process, it means it runs successfully

The fourth step is to modify the source code and publish it to three stations respectively.

Change I am Node3 in the source code to Node2 and publish it to one of the three.

Make the release effective with the following command:

supervisorctl restart AnuoApc

And so on, three different hello world ! I am node1; hello world ! I am node2; hello world ! I am node3;

This way, when you call the interface later, you can see that the load has reached that machine

Step 5 Call the interface with PostMan

Click three times in a row

Miraculously, the load reached three.

About "asp.net core Load Balancer cluster how to build" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

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