ASP.NET Core负载均衡集群搭建(CentOS7+Nginx+Supervisor+Kestrel)
asp.net core在linux运行下,一但命令行退出,程序将停止,而且asp.net core的监听以及负载问题将在这里说明
参考连接:http://www.linuxidc.com/Linux/2016-11/136997.htm http://www.sohu.com/a/192683690_468635 https://www.cnblogs.com/ants/p/5732337.html
- 跨平台是ASP.NET Core一个显著的特性,而KestrelServer是目前微软推出了唯一一个能够真正跨平台的Server。KestrelServer利用一个名为KestrelEngine的网络引擎实现对请求的监听、接收和响应。KetrelServer之所以具有跨平台的特质,源于KestrelEngine是在一个名为libuv的跨平台网络库上开发
- Supervisor 实现监听的守护,保证监听在后台持续运行,避免命令行形式
- 配置Supervisor 为服务,开机启动,这样Supervisor监听的网站就可以开机自动启动
- Nginx 负载
在asp.net core项目中,默认使用的是Kestrel Server ,进行请求监听
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args) //这句代码默认使用了Kestrel F12查看源,如下:
.UseUrls("http://*:8080";)
.UseStartup<Startup>()
.Build();
// 备注:
// The following defaults are applied to the returned Microsoft.AspNetCore.Hosting.WebHostBuilder:
// use Kestrel as the web server, set the Microsoft.AspNetCore.Hosting.IHostingEnvironment.ContentRootPath
// to the result of System.IO.Directory.GetCurrentDirectory, load Microsoft.Extensions.Configuration.IConfiguration
// from 'appsettings.json' and 'appsettings.[Microsoft.AspNetCore.Hosting.IHostingEnvironment.EnvironmentName].json',
// load Microsoft.Extensions.Configuration.IConfiguration from User Secrets when
// Microsoft.AspNetCore.Hosting.IHostingEnvironment.EnvironmentName is 'Development'
// using the entry assembly, load Microsoft.Extensions.Configuration.IConfiguration
// from environment variables, load Microsoft.Extensions.Configuration.IConfiguration
// from supplied command line args, configures the Microsoft.Extensions.Logging.ILoggerFactory
// to log to the console and debug output, enables IIS integration, enables the
// ability for frameworks to bind their options to their default configuration sections,
// and adds the developer exception page when Microsoft.AspNetCore.Hosting.IHostingEnvironment.EnvironmentName
// is 'Development'
public static IWebHostBuilder CreateDefaultBuilder(string[] args);
supervisor,主要负责进程服务的监听,在asp.net core以及supervisor安装部署配置完成之后,一个为Supervisor管理界面,一个为asp.net core网站,可通过Supervisor管理网站的启停,可管理多个网站
安装Nginx
然后修改配置文件 /etc/nginx/con.d/default.conf,需要关闭Selinux,否则负载不会成功