1. centos 7 install asp.net core 3.0
Run: yum install dotnet-sdk- 3.0 -y
Check whether the installation is successful: dotnet -v
2. Create and publish the project
I am using vs 2019
2.1 ASP.NET Core Web application
After choosing, click Next
2.2 Set the project name and location
After setting, click create
2.3 Version selection ASP.NET Core 3.0
, project selectionWeb 应用程序
After selecting, click Create, a project will be generated, the project structure is as follows:
2.4 Create a hosting.json file
The contents of the file are as follows:
{ "server.urls": "http://*:8081" }
The current project structure is as follows:
2.5 modify Program.cs
file
change into:
public static void Main(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .Build(); var host = new WebHostBuilder() .UseKestrel() .UseConfiguration(config) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); }
2.6 Right-click on the project and click Publish
Select the file, and then click Advanced
2.7 The configuration is as follows, click Save
2.8 Click to create a configuration file
2.9 Click to post
2.10 Successful release
After successful publishing, hold down Ctrl and click this link to enter the published program directory
The directory structure is as follows:
3. Upload the project to the server
I use xftp
Just drag the selected folder to the right
I uploaded it to the /root
directory, and the directory name is:publish
4. Server deployment
Enter the publish
directory:cd /root/publish
Start the project: dotnet centos.dll Because the project name is centos, the project generates a centos.dll. If the project name is other, the format of the dll name is: project name + dll
It is okay if the following situation occurs:
Then click Ctrl+C
Stop Project
5. Configure the firewall
Alibaba Cloud's firewall is turned off by default, but you can also check whether the firewall is turned off.
Run this command to view the firewall status: systemctl status firewalld
In this case, the firewall is turned off, because the status is:dead
If the following situation means that the firewall is open, there is no need to take the step of opening the firewall
5.1 Turn on the firewall
Run: systemctl start firewalld
If there is no prompt, it means the opening is successful. You can run systemctl status firewalld and check the startup status again. This time it should be booting.
5.2 Open 8081 port
run:
firewall-cmd --permanent --add-port=8081/tcp
-
--permanent
: Means permanently effective
5.3 View all open ports
run:
firewall-cmd --permanent --list-port
If port 8081 is already open, you can run the project first
6. Set up Alibaba Cloud Security Group
6.1 Log in to Alibaba Cloud's official website and click on the cloud server
6.2 Select an instance
6.3 Select the security group of this instance in the right menu bar
6.4 Click in
6.5 Click Quick Create Rule
6.6 Enter the following and click OK
And then ok
7. View project
Type in the browser: ip:8081
you can access the project