ASP.NET Core Quick Start Environment

Time:2022-9-19

foreword

ASP.NET Core is an open source and cross-platform framework for building modern Internet-connected cloud-based applications such as web applications, Internet of Things (IoT) applications, and mobile backend applications. ASP.NET Core apps can run on .NET Core and the full .NET Framework. It integrates the MVC and WebApi frameworks in the original ASP.NET, you can develop and run your ASP.NET Core applications cross-platform on Windows, Mac and Linux.

vmware virtual machine installation

Where to download vmware? 360 software housekeeper can download. Then find the serial number online.

I installed 12.1.1 here

The installation is very simple and just go to the next step.

CentOS7.3 installation

Download CentOS http://isoredirect.centos.org/centos/7/isos/x86_64/ We can choose 163 or Alibaba Cloud nodes, the speed will be faster.

After the download is complete, open vmware to prepare for installation

The rookie can choose the interface

After selecting it, start the installation, then set the password, and then restart.

Client software for Windows

Download and install Xshell https://www.baidu.com/baidu?word=Xshell
Download and install WinSCP https://www.baidu.com/baidu?word=WinSCP (You can also use Xftp, remember to choose sftp, otherwise the server needs to support ftp)
Enter CentOS, right click

Start the first command. View IP

ifconfig -a

Next, it can all be manipulated by Xshell.

Open Xshell

Then enter the username and password to log in. (login with root)

.NET Core1.1 installation

According to Microsoft data https://www.microsoft.com/net/core

Execute on the command line:

sudo yum install libunwind libicu # (install libicu dependencies)
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821 # (download the sdk compressed package) Depending on the network speed, it may be faster or slower
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet #(解光前)
sudo ln -s /opt/dotnet/dotnet /usr/local/bin # (create link)
dotnet new console -o hwapp # We initialize a sample Hello World application (this is a bit time consuming)
cd hwapp
dotnet restore
dotnet run #Run the application

Seeing the printed hello world proves that the .net core environment has been installed.

【Little White Skills】

  • "#" is a comment
  • shirf + insert paste (can't ctrl + cv is a bit unaccustomed)
  • ctrl + insert copy

nginx1.12.1 installation

curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx.rpm
yum install nginx #installation

systemctl start nginx #Start nginx
systemctl enable nginx #Set the startup of nginx

Then log in to the CentOs system, open the browser and enter: 192.168.233.129 (the IP found earlier)

When you see this page, the installation is successful.

Configure the firewall

If you access it in the browser of the physical machine, you will find that you cannot access it.
That's because CentOs' firewall blocked and we opened the port.

firewall-cmd --zone=public --add-port=80/tcp --permanent # (open port 80)
systemctl restart firewalld # (restart the firewall to make the configuration take effect immediately)

Then the access is successful.

Deploy an ASP.NET Core application

Open VS2017 and create a new .net core project

Right-click to publish (before publishing, it is best to run it locally to see if it is normal)

Then open our WinSCP (downloaded earlier)

Click Login, and then you can see the file directory of the CentOs system. Then create a folder at will, ready to put our published programs.

Right click to upload

then the command runs

cd /home/NetCoreDemo #This directory needs to enter your own corresponding directory
dotnet netcoreDemo.dll # netcoreDemo.dll This corresponds to the dll generated by the project you built

I saw a URL on port 5000, which proved that it was deployed.
Then visit http://localhost:5000 in the virtual machine, ok.

nginx configuration

Earlier we only talked about nginx, and did not say what it was. The role of nginx is a bit first IIS, which is a web server. Do forwarding.
We found http://localhost:5000 accessible. But can not access through ip. Then we can now access nginx through 80, and then nginx will help us access 5000.

Open the path /etc/nginx/conf.d
Edit the default.conf file content and replace it with


server {
    listen 80;
    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Add nginx to the SELinux whitelist, otherwise a 502 error will be reported.

nginx -s reload #make it take effect immediately
[Note] Then visit http://192.168.233.130/ here (corresponding to your own centos ip, this step is very important. You should actively trigger this 502 error first.)
yum install policycoreutils-python #(选y)
cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
semodule -i mynginx.pp

The impact of SELinux on nginx access directories
https://www.cnblogs.com/mywebnumber/p/5572984.html

Then we can access it through ip on the physical machine (no need to bring the port, directly 80 and then nginx goes to 5000).

Configuring the Guardian Service (Supervisor)

yum install python-setuptools
easy_install supervisor #Install Supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf # deploy Supervisor

the end of the file


;[include]
;files = relative/directory/*.ini

Change it to ([Note] remove; and there can be no spaces)


[include]
files = conf.d/*.conf

Enter the directory /etc/supervisor/ and create a new conf.d folder, and create a new netcoreDemo.conf file under the conf.d folder
content([Note] Look at the comments on the second line and the third line, and fill in according to the actual name.

[program:netcoreDemo]
command=dotnet netcoreDemo.dll ; (note) the command to run the program
directory= /home/NetCoreDemo/ ; (pay attention) the corresponding storage directory of your project, many beginners make mistakes in this place! ! !
autorestart=true ; Whether the program will automatically restart if the program exits unexpectedly
stderr_logfile=/var/log/WebApplication1.err.log ; error log file
stdout_logfile=/var/log/WebApplication1.out.log ; output log file
environment=ASPNETCORE_ENVIRONMENT=Production ; Process environment variables
user=root ; the user identity of the process execution
stopsignal=INT
supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep netcoreDemo #[Note] netcoreDemo is the name of the above program:netcoreDemo 
supervisorctl reload #Reload

Then just fine, now you can also access the 5000 interface by turning off that.

Configure Supervisor to start up

Open the directory /usr/lib/systemd/system/ and create a new file supervisord.service

content:


# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Excuting an order:

systemctl enable supervisord  
systemctl is-enabled supervisord #To verify whether it is booting

systemctl stop supervisord #Close
systemctl disable supervisord #disable

At this point, it's done. Now you don't need to worry about restarting the computer, you can directly access the deployed website.

MySql5.6.37 installation

http://www.cnblogs.com/starof/p/4680083.html (method 2 I use)

Install rar compression

Download http://www.rarsoft.com/download.htm

Put the file on the server. Then cd to this directory and execute

tar -zxvf rarlinux-x64-5.4.0.tar.gz # rarlinux-x64-5.4.0.tar.gz is the file name you downloaded
cd rar
make
rar #install

Once installed, we can run the command to unzip the file.

cd #jump to the compressed file directory
rar x ceshi.rar #Extract to the current folder ceshi.rar is the compressed file name
rar a abc.rar ceshi #Compress the folder to abc.rar

After installing the rar command in CentOS, the zip command will be automatically installed

cd /home #Enter the /home directory
zip -r mydata.zip mydata #Compress the mydata directory under the /home directory into mydata.zip
unzip mydata.zip -d mydatabak #Unzip mydata.zip under the /home directory to the mydatabak directory
zip -r abc123.zip abc 123.txt #Compress the abc folder and 123.txt under the /home directory into abc123.zip
unzip wwwroot.zip #Unzip wwwroot.zip under the /home directory directly into the /home directory
unzip abc\*.zip #Decompress the abc12.zip, abc23.zip, abc34.zip under the /home directory to the /home directory at the same time
unzip -v wwwroot.zip #View the contents of wwwroot.zip under the /home directory
unzip -t wwwroot.zip #Verify whether the wwwroot.zip under the /home directory is complete
unzip -j wwwroot.zip #Unzip all the files in wwwroot.zip under the /home directory to the first level directory

Common linux commands

cd #directory jump
cd / # go back to the previous directory
ls #View the files in the directory
df -h #View file usage
mkdir #create folder folder
vi # edit file
:wq! #Force save the file and exit vi

ifconfig -a #View ip
free #View system resource usage http://blog.csdn.net/zhongluhuaok/article/details/52804187

firewall-cmd --zone=public --add-port=80/tcp --permanent #Open port 80, or other ports
firewall-cmd --zone=public --remove-port=80/tcp --permanent # Close the port
systemctl restart firewalld #Restart the firewall to make it effective

service mysqld restart #Restart mysql
nginx -s reload # nginx takes effect
reboot # reboot the system

supervisorctl start program_name #Start a process (program_name=the program name written in your configuration)
supervisorctl stop program_name #Stop a process (program_name=the program name written in your configuration)
supervisorctl reload #Restart all programs in the configuration
supervisorctl stop all #Stop all processes
supervisorctl update #Update the new configuration to supervisord    
supervisorctl restart program_name #Restart a process (program_name=the program name written in your configuration)
supervisorctl #View the process that is waiting
http://blog.csdn.net/shudaqi2010/article/details/51153961

clear #Refresh the terminal screen (or ctrl + l)
exit #exit
shift + insert #paste
ctrl + insert #copy

Replenish

To upgrade .net core 2.0 on centos, you need to execute the official website command first


curl -sSL -o dotnet.tar.gz https://aka.ms/dotnet-sdk-2.0.0-linux-x64
mkdir -p ~/dotnet && tar zxf dotnet.tar.gz -C ~/dotnet
export PATH=$PATH:$HOME/dotnet

Then delete the original folder

rm -rf /opt/dotnet #delete the original folder
rm -rf /usr/local/bin/dotnet #Delete the originally defined dotnet command
sudo ln -s /root/dotnet/dotnet /usr/local/bin #Redefine the dotnet command

The project program must also be upgraded to 2.0, otherwise the dotnet dll will not succeed.

The above is the detailed content of the ASP.NET Core Quick Start Environment. For more information about the ASP.NET Core environment, please pay attention to other related articles on developpaer!