In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to deploy the ASP.NET Core program to the Linux system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to deploy the ASP.NET Core program to the Linux system".
I. Preface
In this article we will show you how to deploy ASP.NET Core programs to Linux. Here we are using the Centos7 installed in the virtual machine. The ASP.NET Core program here is explained by the framework dependency file published in the above article as an example.
Installation of runtime environment 1. Online installation
We just deploy the application on top of the Linux system, so we just need to install ASP.NET Core Runtime. Before installing .NET, we need to register the Microsoft key and source and execute the following command in the terminal:
Sudo rpm-Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
Update the products available for installation:
Sudo yum update
As shown in the following figure:
Finally install the ASP.NET Core runtime
Sudo yum install aspnetcore-runtime-3.1
As shown in the following figure:
At this time, the network speed will be tested. If the network speed is faster, the installation will be very fast. View the current environment after the installation is complete:
Refer to Microsoft's official documentation: https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-package-manager-centos7
2. Offline package installation
If the Linux virtual machine can be connected to the public network, it is recommended to use the above method to install it directly. How to install Runtime in a production environment? Let's install it using the offline installation package provided by Microsoft. First download tar.gz 's offline package and download the URL:
Https://dotnet.microsoft.com/download/dotnet-core/3.1
Here, select the offline package download of the architecture corresponding to Linux:
Let's first create a directory on Linux:
Mkdir-p / var/lib/dotnet
As shown in the following figure:
After the creation is completed, we use Xftp to upload the tar.gz offline package downloaded above to the directory we just created:
Go to the directory you just created and extract the tar.gz file into the directory:
Tar zxf aspnetcore-runtime-3.1.1-linux-x64.tar.gz-C / var/lib/dotnet
As shown in the following figure:
Then execute the following command to set the environment variable:
Export DOTNET_ROOT=/var/lib/dotnetexport PATH=$PATH:/var/lib/dotnet
As shown in the following figure:
Then check the environment:
You can see that Runtime has been successfully installed.
Note: this way of setting environment variables works only for the current session window, but not for another session window, as shown in the following figure:
To solve this problem, we need to create a soft link method to set the environment variable.
Ln-s / var/lib/dotnet/dotnet / usr/local/bin
As shown in the following figure:
After you have created the soft link, you can access it in all session windows:
If you are installing using online rpm, this problem will not occur, and all session windows can be accessed.
3. Upload files
After the environment is installed, we upload the published files to the server.
Create a new folder in the terminal to store the files we uploaded:
Sudo mkdir / NetCoreDemo
As shown in the following figure:
After the creation is completed, we will view the newly created folder in XFtp:
You can see that the folder has been created successfully. Then we use Xftp to upload the file to the folder we just created:
Then we can deploy.
4. Deployment 1. Start using Kestrel
We go into the folder and start it directly using the command line:
You can see the service and start it up. We browse the web page:
The web page does not have any input. Why is that? Because localhost is a private network address, you need to add-- urls parameter here.
Dotnet AspNetCoreDeployDemo.dll-- urls http://*:5000
As shown in the following figure:
At this time, we are visiting the web page:
What is the reason for finding or not being able to access it? Originally, in Linux, the firewall is enabled by default, so if you want to access the public network, you also need to turn off the firewall or add port 5000 to the firewall, and check the firewall status command:
Service firewalld status
As shown in the following figure:
As you can see, now that the firewall is on, we add port 5000 to the firewall:
Firewall-cmd-zone=public-add-port=5000/tcp-permanent
As shown in the following figure:
Permanent: this parameter indicates permanent existence, otherwise rebooting the firewall configuration will be lost.
After adding the port, you need to restart the firewall:
Firewall-cmd-reload
As shown in the following figure:
You can see that it can be accessed at this time.
We can also turn off the firewall:
Service firewalld stop
As shown in the following figure:
In a production environment, it is not recommended to turn off the firewall, it is recommended to turn on the firewall, and then add the corresponding port number to the firewall.
2. Use Nginx as the reverse proxy
Above we use the console to start, this method can not deal with reverse proxy, load balancing, etc., so we recommend using Nginx as the reverse proxy server on Linux. We install Nginx.
Because Nginx is not in the repository of CentOS by default, first execute the following command to add Nginx to the repository:
Rpm-Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
As shown in the following figure:
Then you can install Nginx:
Yum install nginx
As shown in the following figure:
Start Nginx after installation:
Systemctl start nginx
As shown in the following figure:
Set Nginx to boot:
Systemctl enable nginx
Port 80 is enabled by Nginx by default. We need to add port 80 to the firewall, and restart the firewall after adding it:
Firewall-cmd-zone=public-add-port=80/tcp-permanent
As shown in the following figure:
At this time, we visit Nginx on the public network:
We see that we can now access Nginx. Next we configure the reverse proxy for Nginx.
First go to the installation directory of Nginx, and then view all the files:
As shown in the figure above, nginx.conf is the main configuration file, open it using the vim editor:
You can find in the figure above: there is a sentence include / etc/nginx/conf.d/*.conf below, which shows that some are still configured in the conf.d directory, while we configure the reverse proxy, mainly in the conf.d file, using the following command to enter the conf.d command:
Cd conf.d
Then look at all the files:
Find a default.conf file in it, open it with a Vim editor, and modify it as follows:
Listen represents the port on which you are listening, and this is port 80. Proxy_pass is used to set the address of the agent. Be careful not to forget the last ";" here.
After saving, use the following command to check that the changes are correct:
This means that there is no error in the modified file. After the configuration is successful, we need to restart the Nginx service:
Nginx-s reload
As shown in the following figure:
After reboot, we visit:
This indicates that there is an error. The message tells us to view the Nginx log, and we check the log path in nginx.conf:
Then we enter the path and view all the following files:
We find that there are two logs below. Let's first look at error.log:
Use the following command to resolve:
Setsebool-P httpd_can_network_connect 1
We revisit:
This can be accessed. We successfully deployed it on Linux.
Thank you for your reading, the above is the content of "how to deploy ASP.NET Core programs to Linux systems". After the study of this article, I believe you have a deeper understanding of how to deploy ASP.NET Core programs to Linux systems, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.