The most complete solution for deploying. Net core to Linux (CentOS), high level (docker + nginx or jexus)

Me, me 2021-01-22 20:29:36
complete solution deploying. deploying core

We are right. .netcore Deploy to linux With a full understanding , It can meet the application requirements , In this article, we will continue to take you to understand the use of Doker+jexus or Nginx To deploy .net core application .

1、 Use Jexus As web The server

Jexus Is a Linux High performance on the platform WEB Server and load balancing gateway server , To support the ASP.NET、ASP.NET CORE、PHP As a feature , At the same time, it has reverse agent 、 Intrusion detection and other important functions . It can be said that ,Jexus yes .NET、.NET CORE The best hosting server across platforms , If we think it's Linux Platform IIS, It's not too much , because ,Jexus Not only very fast , And have IIS And other Web A high degree of security that servers don't have . meanwhile ,Jexus Web Server It is a domestic software developed by Chinese people independently , And it did “ Security 、 reliable 、 controllable ”, It has the ability of information construction of our party and government organs and important enterprises and institutions Remote desktop Key qualities needed .

jexus Official website :

1.1、Jexus Installation

jexus The installation of is very simple , Execute the following command :

curl sh

notes : Run the install command , The operator is required to have root jurisdiction .

1.2、Jexus Configuration and use of

After installation , Switch to /usr/jexus Catalog , modify /usr/jexus/siteconf In the catalog default, The contents are shown below :

notes : Because in the previous chapter we used nginx, Used 80 port , So here I use 8099 port .

port=8099 # port hosts=*    # domain name AppHost={cmd=dotnet Core50Test.dll; root=/root/app_data/core50test/publih; ort=5000}

Next , We have to restart jexus, Execute the following command :

/usr/jexus/jws restart

Tips Ok after , Our application is up .

You can do this by executing the following command , Look at the results of the execution :

ps -aux

You can see that our app has started , Go to the browser to use 8099 Port view to see the effect .

About jexus More detailed instructions for use , Please refer to the official documentation .

1.3、Jexus Operation command of

Jexus Including the following operation commands ( First cd /usr/jexus):
start-up :sudo ./jws start
stop it :sudo ./jws stop
restart :sudo ./jws restart

2、Docker+Nginx or Jexus Deploy

In the introduction of the previous article , Whether it's supervisor+nginx still jexus, All need to be installed on the server .NET Core Of SDK Or runtime , If we have multiple applications , For each application .net core The versions are different , The above practice requires us to install the corresponding SDK Or runtime , Maintenance is troublesome .Docker Appearance , It can solve the above problems perfectly .

2.1、Docker What is it? ?

docker Is an open source software deployment solution ;

docker It's also a lightweight application container framework ;

docker It can be packed 、 Release 、 Run any application .

Docker It has the following advantages :

1、 Fast , Deliver your applications consistently

Docker Allows developers to work in a standardized environment using local containers for your provided applications or services , This simplifies the development life cycle .

Containers are great for continuous integration and continuous delivery (CI / CD) Workflow , Consider the following example scenario :

Your developers write code locally , And use Docker Containers share their work with colleagues .

They use Docker Push its application into the test environment , And perform automatic or manual tests .

When developers find errors , They can fix it in the development environment , Then redeploy it to the test environment , To test and verify .

After the test is completed , Push patches to production , It's as simple as pushing an updated image to the production environment .

2、 Reactive deployment and expansion

Docker It's a container based platform , Allow highly portable workloads .Docker The container can be on the developer's native machine , On physical or virtual machines in the data center , Running on a cloud service or in a hybrid environment .

Docker Portability and lightweight features , You can also easily complete the workload of dynamic management , And according to the business requirements , Expand or dismantle applications and services in real time .

3、 Run more workloads on the same hardware

Docker Light and fast . It provides the possibility of virtual machine based on hypervisor 、 economic 、 Efficient alternatives , So you can use more computing power to achieve business goals .Docker Very suitable for high-density environment and small and medium-sized deployment , And you can do more with fewer resources .

2.2、docker install

Execute the following command :

sudo yum install docker


Error report Another app is currentlty holding the yum lock ,waiting for it to exit…

resolvent : rm –r /var/run/ This command Just unlock it
After installation , Execute the following command to set docker Boot up :

systemctl enable docker

Execute the following command to start docker:

systemctl start docker

see docker Start state :

ps: If there's a problem with the installation process , It may run directly, such as command installation .

yum install docker-ce-cli

see docker Version command :

2.3、.net core docker Support

install docker after , We need to add... To the code dockerfile file .

adopt Visual Studio Can help us automatically generate , In the solution , Right-click the project name , Choose in turn 【 add to 】->【Docker Support 】, As shown in the figure below :
Generated dockerfile The file is shown below :

See to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM AS base



FROM AS build


COPY ["Core50Test.csproj", ""]

RUN dotnet restore "./Core50Test.csproj"

COPY . .

WORKDIR "/src/."

RUN dotnet build "Core50Test.csproj" -c Release -o /app/build

FROM build AS publish

RUN dotnet publish "Core50Test.csproj" -c Release -o /app/publish

FROM base AS final


COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Core50Test.dll"]

Push the code to git Warehouse , And then again linux Pull the latest code from the server .

Switch to /root/app_data/source/core50test Catalog , Execute the following command , Pull the latest code :

git pull


Then execute the following command , Package the code as a mirror :

docker build -f Dockerfile -t core50test .

The first packaging image involves pulling .NET Core The official mirror image of , The pulling speed may be slower , Please be patient .
After packing , Execute the following command , You can view the existing image of the current server :

docker images

When the image is packaged , We can execute docker run Command enabled our app :

docker run -p 81:80 -dit --restart=always --name core50test core50test

The results are as follows :
Access... Through a browser :http://ip:81. If no accident , We can see that the application has run successfully .
docker run : Create a new container and run a command


docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS explain :

-a stdin:  Specify the standard I / O content type , Optional STDIN/STDOUT/STDERR Three items ;

-d:  Background running container , And return to the container ID;

-i:  Run container in interactive mode , Usually with -t Use at the same time ;

-P:  Random port mapping , The internal port of the container is randomly mapped to the port of the host

-p:  Specify port mapping , The format is : host ( host ) port : Container port

-t:  Reassign a pseudo input terminal to the container , Usually with -i Use at the same time ;

–name=“nginx-lb”:  Specify a name for the container ;

–dns  Specify the DNS The server , The default is the same as the host ;

–dns-search  Specify the container DNS Search for domain names , The default is the same as the host ;

-h “mars”:  Of the specified container hostname;

-e username=“ritchie”:  Set the environment variable ;

–env-file=[]:  Read environment variables from the specified file ;

–cpuset=“0-2” or --cpuset=“0,1,2”:  Bind container to specified CPU function ;


–net=“bridge”:  Specify the network connection type of the container , Support bridge/host/none/container: Four types ;

–link=[]:  Add a link to another container ;

–expose=[]:  Open a port or a group of ports ;

–volume , -v:  Bind a volume

2.4、 adopt shell Script implementation docker One click Update app

You can write shell Script , Realize one click Update application . stay /root Directory , establish file , The contents of the document are as follows :


cd /root/app_data/source/core50testgit pullimtag=$(uuidgen |sed 's/-//g')docker build -f Dockerfile -t core50test:${imtag} .docker stop core50testdocker rm core50testdocker run -dit --restart=always --name core50test -p 81:80  core50test:${imtag}

to File set execution permissions , The order is as follows :

chmod 777

When new code is pushed to git Warehouse time , Enter server , perform You can quickly update the application .

thus ,.net core Use docker The deployment mode is introduced .

2.5、docker Common commands

Docker Common commands , Generally speaking, it can be divided into the following categories :

Docker environmental information — docker [info|version]

Container lifecycle management — docker [create|exec|run|start|stop|restart|kill|rm|pause|unpause]

Container operation and maintenance — docker [ps|inspect|top|attach|wait|export|port|rename|stat]

Containers rootfs command — docker [commit|cp|diff]

Mirror warehouse — docker [login|pull|push|search]

Local image management — docker [build|images|rmi|tag|save|import|load]

Container Resource Management — docker [volume|network]

System log information — docker [events|history|logs]

from docker Order the use of departure , Comb out the following command structure diagram :
To see more detailed commands , You can check the official website or order help

docker --help

3、 summary

Through the introduction of the first three articles , We're right .net core Multiple solutions to linux I have a very comprehensive understanding of , Small teams are enough to use . Attentive students will notice , Although the current solution can achieve one click deployment update , But you still need to log in to linux The server executes the corresponding command .

Show , This is not the best solution , So is there a better solution ? such as : When we submit to git After warehouse , Is it more convenient to deploy the command automatically ?

The answer is yes , We can use jenkins To achieve . If you are interested in , You can do your own research , Or please look forward to the following explanation . And in large projects based on k8s Realized devops. Actually k8s Realization devops The principle is similar to the introduction above , Based on is with the help of gitlab Of runner perhaps jenkins, monitor git The state of the warehouse , When the specified branch is found to have changed , Packaging mirroring , And then by replacing k8s Of deployment To achieve automatic update . meanwhile ,k8s Elastic scaling is realized 、 Rolling update and other functions .

Several years along the way , thank RDIFramework.NET Supporters and users of the framework , You can find out the details through the following address .

RDIFramework.NET Official website :

RDIFramework.NET The official blog :

In particular , Please refer to the official website for framework related technical articles , Welcome to collect !

RDIFramework.NET The framework is long-term built by the professional team of Hainan Guosi Software Technology Co., Ltd 、 Keep updating 、 Upgrading all the time , Please feel free to use !

In the first two :

.NET Core Deploy to linux(CentOS) The most comprehensive solution , Routine

.NET Core Deploy to linux(CentOS) The most comprehensive solution , Advanced (Supervisor+Nginx)

We are right. .netcore Deploy to linux With a full understanding , It can meet the application requirements , In this article, we will continue to take you to understand the use of Doker+jexus or Nginx To deploy .net core application .

本文为[Me, me]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云