In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to deploy the .NET 6 project to Linux". In the daily operation, I believe that many people have doubts about how to deploy the .NET 6 project to Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to deploy the .NET 6 project to Linux! Next, please follow the editor to study!
Set up Linux server
To build a server that deploys ASP.NET core, there are generally two options.
First, the purchase of CVM, recently Tianyi Cloud to engage in activities, a year of general-purpose CVM, only 60RMB, it is quite a discount. A test is enough to deploy a personal website. I will use the cloud server to do the following demonstration.
If you do not think it is necessary to buy a CVM, you can use your own virtual machine, and you can install Linux, depending on your personal preference.
After you have purchased the CVM, go to the control center to check the CVM. As a friendly reminder, there is a very unfriendly place in the control center of Telecom, that is, you must choose the right area where the CVM is located before it will be displayed. I will drop a hole here to remind you to avoid the pit.
Back to the point, I use the Ubuntu20.64 version, but you also choose other Linux systems, but you should pay attention to whether the Linux version you choose is compatible with the .core version. From https://docs.microsoft.com/zh-cn/dotnet/core/install/linux?WT.mc_id=dotnet-35129-website, you can see the detailed adaptation of each Linux system to the .NET version.
From the figure, we can see that currently only a maximum of 5.0 is supported, and the latest version 6.0 is also supported.
If you choose the wrong one when you buy it, it doesn't matter. You can change the system, and I changed it from CentOS to Ubuntu.
If you are not required to set a password at the time of purchase, you can also set a password in the control center for Linux system login.
Install the Liunx remote connection tool
Home free version of Xshell 7 (command line tool) and Xftp 7 (file transfer) download, install and log in using the CVM operating system account, you will not be surprised to see the interface.
Install the .NET runtime environment
Click to install .NET-.NET | Microsoft Docs on Ubuntu to install the corresponding version of the runtime environment.
Mine is ubuntu20.4, so I'll choose 20.4.
Add the package signature wget https://packages.microsoft.com/config/ubuntu/21.04/packages-microsoft-prod.deb-O packages-microsoft-prod.debsudo dpkg-I packages-microsoft-prod.debrm packages-microsoft-prod.deb by executing the following command in xshell
Install NET6 SDK sudo apt-get update;\ sudo apt-get install-y apt-transport-https & &\ sudo apt-get update & &\ sudo apt-get install-y aspnetcore-runtime-6.0
To test whether the installation is successful, execute
Dotnet-- version// shows the installed version number. Congratulations on your successful installation.
Note: this kind of environment installation method requires network support. Access to some enterprise network resources is limited and cannot be installed in this way. You need to download the installation package and install it manually. There are also detailed manual installation instructions, so I won't repeat them here.
Generate an ASP.NET Core website
Open vs2022 (currently only vs2022 supports .NET 6 development), create an ASP.NET CORE WEB application, take a favorite name, create it, the project looks like sauce, and a simple asp website is built.
In order to debug and release the website access port all the time, you need to change the configuration of appsettings.json. Add a "urls": "http://*:8880",'8880' is the access port of the website, which can be modified by yourself."
{"Logging": {"LogLevel": {"Default": "Information", "Microsoft.AspNetCore": "Warning"}}, "urls": "http://*:8880"," AllowedHosts ":" * "}
Publish a website
Open powershell and execute
Dotnet publish-framework net6.0-runtime ubuntu.20.04-x64-output "D:\ wb\ ubuntu2004"-configuration Release-no-self-contained
The release file is placed in "D:\ wb\ ubuntu2004". You can specify another directory by yourself.
After the release of the website, it is one step away from success, and I feel more and more excited.
Deploy the website
Open Xftp 7, log in with cloud users, and you can manipulate local files just as easily. Drag the release folder directly to the right, and the files will happily be transferred to the server.
For those of us who are not familiar with the Linux system, this operation is simply not too pleasant.
If the folder file is relatively large, compress it to zip, and then drag it over, it may be better.
If it is a zip package, you also need to install the zip decompression software on the server. Installation is also simple, and xshell executes
Sudo apt-get install unzip
Navigate to the zip package and execute
Unzip * * (compressed package name) .zip
After the website files are extracted, navigate to the website directory and execute
Dotnet apptest (usually with the same name as the project) .dll
If you see the address of the website, the website has been started successfully. At this point, it is done.
It's not over. Don't you want to see the result of the operation? Come and see.
Access address http:// server IP:8880
At this point, the study on "how to deploy a .NET 6 project to Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.