.NET CORE deployed to Linux (CentOS) is the most complete solution, conventional articles

This article introduces you to the use of .NET Core to deploy to the Linux server. By this article you will learn about the installation of Linux in the virtual machine, Xshell, XFTP usage method, Git interact under Linux and .NET Core under Linux The release and operation of the operation, this article is summarized some of the problems encountered with notes in the deployment process, and share it with you, for your reference, welcome to discuss communication.

1, Linux operating system, XShell, XFTP installation

The operating system selects you more familiar Linux distribution, if you are in contact with Linux, it is recommended to use CentOS because the contents of this article are demonstrated in CentOS.

As for the installation of the system, you can select a cloud server or install it using a virtual machine. The way virtual machine installation CentOS can be referred to: one network is exhausted, one text talks virtual machine installation and Linux use

1.1, xshell connection tool

We recommend using xshell as a connectivity tool, download address: https://www.netsarative.com/en/xshell-download/

XShell is a powerful security terminal simulation software that supports SSH1, SSH2, and a Telnet protocol for Microsoft Windows platforms. Xshell’s secure connection to the remote host and its innovative design and feature help users enjoy their work in a complex network environment.

XShell can use to access the remote control terminals in a Windows interface to access the remote control terminals. In addition, it also has a rich appearance color scheme and style selection.

After the installation is complete, open the software, click New Reset button in the upper left corner to open the new return attribute, as shown below:

Fill in the IP address of the server in [Host], the corresponding user is set, and then click the [Connection] button. The connection successful interface is as follows:

1.2, XFTP file upload tool

External and Linux service file interactions can use the XFTP tool upload or other methods such as the Git warehouse to transfer, this article demonstrates the transfer of code files using XFTP and Git warehouses. XFTP Tools, Downloads: https://www.netsarative.com/en/xftp-download/

XFTP is a powerful SFTP, FTP file transfer software. After using XFTP, MS Windows users can safely transfer files between UNIX / Linux and Windows PCs.

After the installation is complete, you can open the XFTP through the XShell one button. After the XFTP is turned on, you can switch the target path to upload the file on the right side of the software, then drag the file to the right to release it, it will be automatically uploaded.

1.3, transfer using a git warehouse

Relatively developed, the way to transfer in the Git warehouse is the way we recommend. In frequent iterative updates, first copy the file to the server, this operation process is slightly cumbersome. The way to transfer through the Git warehouse is relatively simple. Developers only need to promote the development of good code to the Git warehouse, and then execute build, public, public, Publish, etc. in the server, reduce the process of cumbersome copy files, Because Build and Publish are executed in the server, it can eventually be quickly deployed by writing a shell deployment script.

To use git to install the git client on the server, and configure the SSH public key (the purpose of configuring the public key is to pull the private warehouse, the public warehouse does not need to be configured).

Let’s explain the specific steps:

First install the git client, execute the following command:

Yum -y Install Git

If an error occurs in the installation process: COULDN’T Resolve Host

General because the DNS server is not configured correctly, the solution:

1. Open the file /etc/resolv.conf Add:

2. Restart the network after exiting the store:

Service Network Restart

After the Git installation, generate sshkey by the following command:

# The [email protected] just the name of the generated SSHKEY, and does not binding the goods requires a specific name to a mailbox. SSH-KEYGEN -T RSA-C “[email protected]

According to the prompt, press three cycles to generate SSHKEY, as shown below:

You can view the public key by the following command:

Cat ~ / .ssh / id_rsa.pub

Copy the generated SSHKEY, configure it to the public key of the code warehouse.

The public key has been generated, how to configure the code hosting platform?

Next we will learn how to configure public keys (GitHub like) under Gitee code managed platforms. Enter the [Management] page of private repository, find [public key management], click [Add Public Key], copy the public key you just generated, as shown below:

The words similar to HI XXX appear, the Git public key configuration is successful.

ssh -t [email protected]

Secondary Use needs to confirm and add a host to the local SSH trusted list, as shown below:

After entering YES, the word similar to HI XXX appears, indicating that the Git public key configuration is successful.

2, install .NET Core SDK and runtime

In front of us, we have been prepared before deployment, install xshell, XFTP, git, configure public key to the warehouse.

Next we will install .NET Core SDK on the Linux server.

The .NET runtime is a prerequisite for the .NET program, and the SDK is not necessary, but if the file is transferred through the Git mode, you need to compile on the server side, so SDK also needs to be installed. (Note: Docker deployment does not need to install SDK and run in the server, we introduce in the following article)

Let’s take a look at how to install SDK and runtime in CentOS (other environments can refer to the official document: https: //docs.microsoft.com/en z-/dot/core/install/linux).

Before installing .NET, we need to add the Microsoft package key key to the trusted key list and add a Microsoft Package Repository. If you have installed .NET Core3.1, then this step can be omitted

Run the following command to add the Microsoft package name key to the trusted key list and add the Microsoft Package Repository.

Sudo rpm -uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

Install SDK by the following command:

Sudo Yum Install -Y DotNet-SDK-5.0

.NET Core SDK allows you to develop our app over .NET Core.

After the installation is complete, you can verify the installation.

DOTNET –INFO

Install NetCore runtime by the following command:

Sudo Yum Install -y AspnetCore-Runtime-5.0

Note: The last 5.0 in the above command indicates the version number. If you install additional versions such as: 3.1, modify the corresponding version number. Reference: https://dotnet.microsoft.com/download/dotnet-core

If you have already installed .Net Core SDK, you do not need to install the appropriate runtime, on the above we have installed SDK, then install the run, you will be installed, as shown below.

3, release procedure to server

In the previous preparation, we introduced two ways to publish the file to the server, respectively: XFTP and GIT, and we demonstrate the methods and steps of these two ways, respectively.

3.1, released to the server via XFTP

First, prepare the procedures to be released,

The picture below is a sample code I created. Net5.0:

You can perform the following command to publish by opening the VS package manager console:

DOTNET PUBLISH -O ./publish

You can also right-click project release, publish it into the folder, as shown below.

What needs to be counted here is that the framework depends on the deployment mode, because we have installed the .Net Core environment, this is not used by independent deployment mode, the default is “framework dependence”.

Frame relying on deployment:

Relying on the deployment of the framework (FDD) Relying on the .NET CORE that exists on the target system. Due to the existing .Net Core, it is also portable between the .NET Core installation program. Applications only include its own code and any third-party dependencies outside the .NET Core library. The FDD contains a .dll file that can be started by using the DOTNET utility in the command line. For example, DOTNET App.dll can run a app called app.

For FDD, only applications and third-party dependencies are deployed. No need to deploy .NET Core, because the application will use the .NET Core version that exists on the target system. This is the default deployment model of the .NET Core .NET Core. Net Core and ASP.NET Core applications:

1, do not need to define in advance .Net Core app will run on it. Because no matter what operating system, .NET Core’s executable and libraries are in general PE file formats, so no matter what the basic operating system, .NET Core can perform applications.

2, deployment packs very small. Just deploy application and its dependencies without deploying .NET Core itself.

3, many applications can be installed using the same .NET Core, thereby reducing disk space and memory usage on host systems.

shortcoming:

1. Apply only when you have set it to the target .Net Core version or later, the application can run.

2, if you don’t understand the future version, .NET Core runtime and libraries may change. In a very small number of cases, this may change the behavior of the application.

Independent deployment:

Independent Deployment (SCD) does not rely on shared components in the target system. All components (including .Net Core libraries and .Net Core runtime) are included in the application and are independent of other .NET Core applications. The SCD includes an executable (app.exe, such as an application on the Windows platform app.exe), is a rename version of the platform-specific .NET Core host, as well as a .dll file (such as app.dll) And it is an actual application.

For independent deployment, the application and the required third-party dependencies, and the .NET CORE version used to generate applications. Creating an SCD does not include .NET Core native dependencies on a variety of platforms, so these dependencies must already exist before running applications.

advantage:

1, you can deploy the .NET Core version with the application with separate control

2, the target system can run your .NET Core application, because you provide .Net Core version that the application will run

shortcoming:

1. Since .NET Core is included in the deployment package, you must select the target platform to generate a deployment package in advance.

2, deployment packs are relatively large, because it is necessary to include .NET Core and applications and its third-party dependencies.

3, deploy a large number of independent .NET Core applications to the system may use a large amount of disk space because each application is copied .NET CORE file

As can be seen in the figure, the path to the file after the release is: bin / release / net5.0 / public /

Open XFTP and drag the Publish folder to the right window of the XFTP to complete the upload.

Switch to the published directory, start the run, as shown in the following figure, successfully run.

You can also specify ports

# Æô Õ¾ µã, custom port number, running environment DOTNET CORE 50TEST.DLL –URLS = “http: // *: 8081; http: // *: 8082” –environment = developmentPMent

Here URLS configuration, if you need a local area network or external network access, you cannot fill it into urls = “http: // localhost: 8081; http: // localhost: 8082”

3.2, released through Git transfer

First, push the code to the Git repository, copy the SSH address. As shown below:

Then in the server, execute the clone command:

Mkdir core50testcd core50testgit clone [email protected]: ****** / Core50Test.git

The execution result is shown in the figure below:

At this point, the project code has been downloaded to the server, switching the catalog to the solution to the solution.

CD core50test

Then execute the DOTNET PUBLISH command to compile the program.

DOTNET PUBLISH -O / YONGHU / Web / Publish

After the execution is completed, the file after compiling will be saved in the / Yonghu / Web / Publish directory.

Switch the working directory to / yonghu / web / publish, execute the following command:

DOTNET CORE50TEST.DLL

The execution result is as follows:

So far, our procedures have been running in the Linux server.

Through the introduction, I believe that many small partners have already issued a deep understanding of the .NetCore project to Linux, but these operations are still slightly cumbersome, start, stop, picking, etc. are separate dealing, the next articleArticle We will introduce the use of Supervisor + Nginx, and the shell script to implement the efficient deployment of .NET CORE.All the way, thanks to the supporters and users of the RDIFramework.net framework, you can learn more about the following address.

RDIFramework.net official website: http://www.rdiframework.net/

RDIFramework.net official blog: http://blog.rdiframework.net/


Special note, framework-related technical articles please take the official website, welcome everyone to collect!

The RDIFramework.net framework is created by Hainan Guis Software Technology Co., Ltd., has been updated, has been upgraded, please use it with confidence!

Welcome to the official WeChat public number (micro signal: guosisoft), timely understand the latest developments.

Use WeChat scan QR code to pay attention to

Related Posts