(MVC) MVC (2020)

Deploy ASP.NET Core application from scratch (install and tune SSH/VNC/FTP/NGINX/Daemon/Db)

I have a dozens various instructions about tuning linux, look for example to this page:

and now I want to do clear installation.

and I want to list all needed steps to deploy ASP.NET Core application in OpenSuse.

1. Install linux (set enough resources, IP addr, timeout and so on)

During installation need to configuring IP address in Linux machine and set router to access to this machine from inet.

To check IP address your machine use special SUSE command instead common linux Ifconfig command.

If you install Linux with GUI to VmWare, main problem is too low memory of VideoCard. Need to increase video memory.

As default SUSE and other Linux has inconvenient timeout of power saving, you must be login again and again each minutes. Need to delete this stupid function in server.

Similar incomprehensible functionality has any client for remote access to your server, it forced you login again and again each minutes. Need to increase this timeout at least to 10-100 times.

2. Start and configure sshd (and sftp).

Firstly. for developer server I would recommend you turn off Linux Firewall for beginners, you will tune it in any time later. You can do manipulation with Firewall service in command line systemctl status/stop/stop/status firewalld or in Yast dialog.

SSHD no need to configure in actual version of SUSE - need only start it and set start it in boot time. For restart and check sshd service use systemctl restart sshd or rcsshd restart.

And next tune is increase timeout.

SFTP is very useful service, because WinScp allow you navigate and change any file fast as possible and this is independent from full FTP server/

3. Start and configure vncmanager.service.


VNC server need to prepare more carefully.

Then need to set at least two command vncpasswd and I recomend you install minimum resolution for start vncserver -geometry 640x480 manually by command or in config. Need provide start VNC server in boot time too.


Also need to prepare client.

If VNC server working in minimal resolution, you can change resolution to bigger by xrandr.

Main command to working with VNC server is check service status systemctl status vncmanager.service. This is config of vncservice, it placed in /home/admin/.vnc/config, but vnc server (X11) usually can start only from root.

In practice not need to install to Windows computer Putty, I always use mRemoteNG from win machine or command string in Linux machine. From Windows machine is exist two great VNC client - RealVnc amd TigerVnc. Also you can connect remote GUI over SSH tunnel, this is examples - 1, 2, 3, 4.

Also in practice VNC server can shut down unexpectedly for many-many reason, for example VNC black screen. There are a lot of command to restory VNC functionality. Firtly need to check VNC locally.

And check server log tail -n 1000 /var/log/messages.

Need to agree conditions of connection between client and server.

Need to restart XDM service (all graphical subsystem) systemctl restart xdm.service. Need to select right choice of display manager update-alternatives --config default-displaymanager command. And display manager also can be restarted service lightdm restart.

Need to start manually vncserver --help with different parameters as alternatives to vncmanager.services, for example vncserver -kill :2 and then vncserver.

   1:  usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]
   2:                   [-geometry <width>x<height>]
   3:                   [-pixelformat rgbNNN|bgrNNN]
   4:                   [-fp <font-path>]
   5:                   [-fg]
   6:                   [-autokill]
   7:                   [-noxstartup]
   8:                   [-xstartup <file>]
   9:                   <Xvnc-options>...
  11:         vncserver -kill <X-display>
  13:         vncserver -list

In some case firstly need to check listen port by systemctl status xvnc.socket and sudo lsof -i -P -n, top/pkill, vncserver :4 -geometry 640x480. And look to various inet recopies VNC connection black screen.

This is one of example to restore X11.

4. FTP server

Without FTP will be impossible to upload and update you program to server. FTP service need to add zypper -n install vsftpd, than need to create config files, for development I use this ftp config, also I set extended permission to folder and files by command chmod -R 755 /srv/ftp - this is developer mode server, for production server need set permission more carefully.

To control FTP server use command systemctl start/stop/status vsftpd.

5. Install .net core

There are some choice to install .net core, this is full developer machine, therefore I install to it full net core, in production more runtime version is enough. Need firstly adding a repository with dot net, than install dotnet core. Below you can see a list on command to add repository

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
wget https://packages.microsoft.com/config/opensuse/15/prod.repo
sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo

Than need to install .net core zypper install dotnet-sdk-3.1. And than reboot shutdown -r now .

6. Deploy application

There are some choice to deploy application for server, for me is so stupid to copy source code to server and compile source code in server. I doing this work in VS2019 in Windows machine. Therefore I simple copy framework independent DLL (result of compilation from debug folder) to server. Another options is self-contained DLL (with all library), but its also stupid case for public site, because goal of kestrel is automatically uploading all application dependency. Maybe another choice has sense to embedded device isolated from inet or for developer used VS Code, but these choice is not applicable for me.

7. First start your program

This is a good time to check success of all previous step. Connect after reboot to your server by VNC, upload you program, check working directory to /srv/ftp and do first start you program /usr/bin/dotnet /srv/ftp/CoreLinux.dll. Changing folder before start cd srv/ftp/ is important, without this changing root directory would to /home.

Check site locally by Firefox in VNC is often impossible, then I recommend you to install elinks - it working fine in any case.

If you have success in this step this is a good time to moving forward.

8. Install and tune Nginx

There are some choice to forwarding kestrel to internet, Apache or Nginx web servers, in this case I select Nginx sudo apt-get install nginx.

In the screen below you can see Nginx config after installation, need to change this config to force Nginx as reversyProxy. In my developer SUSE-server config looks as this - nginx.conf, then service nginx restart.

And finally, if forwarding to inet is working fine, you can check your site outside.

If this step will be success you immediately see attack to you site. This is normal, simple ignore it, because any crack in our world is expected PHP installation in server.

9. Change source code to apply Nginx reversyProxy mode

Working with Nginx to cache Kestrel need to add two header to your web site.

10. Demonize kestrel application as a background service

In this step I have full workable application, I use this public template VB.NET.ASP.NET.Core.3.1.AuditAttribute and I see all headers of request.

Next step is creation service from kestrel apps. The goal of this step is automatically restart application in linux boot process, restart after errors and show this journal in filesystem instead console.

For demonize my apps I use file kestrel-1.service and place it to /etc/systemd/system/, then start service systemctl enable kestrel-1.service, systemctl start kestrel-1.service. For check status I use a GUI.

In linux there are so many various log, I recommended you install and use KSystemLog and show kestrel log and your application log by this program.

11. Install MariaDB

This is optional step, in NET CORE you have many another options to work without MySQL, for example I have a lot of project with InMemoryDatabese, look for example to this page - How Linux Net Core 3.1 daemon (in VB.NET) can read/write data from/to ancient MS SQL 2005, but for simple WebSite and simple solution you will need a MySQL.

Firstly, if you use OpenSuse, then you always have MariaDB after installation (not a MySQL).

Attempt to install MySQL induce full changing all working environment in OpenSuse.

But MariaDB is not a bad choice, even MySQL Workbench working with it (with a lot of warning).

I would not recommend you install Workbench to production system, because so many unneeded vulnerable you must be install to server. But in developer zone is good choice.

Do not forget changing StartMode of MySQL server before using it.

Main collision of using MariaDB is possible if you have MySQL in Windows development computer.

But this collision problem is solvable by pomelo.entityframeworkcore.mysql provider supported simultaneously both of server.

By default MariaDC allow only local connection, to accept remote connection need to comment one line in config and restart server.

12. Database deployment from EF Code First

Database deployment process in Net Core is different rather then EF 6 - Entity Framework missing FAQ (Part 4), for example command Enable-Migrations is missing.

In EF Core firstly need to load to Linux Dotnet engine library for support EF deployment. Unfortunately, from version to version NET CORE sets of command is permanently changing by MS NET Core CLI. In NET Core 3.1 first command is "dotnet tool install --global dotnet-ef", second command is "dotnet add package Microsoft.EntityFrameworkCore.Design" , third command is "dotnet restore" and finally checking is "dotnet ef". And unfortunately installation EF Core library to Linux server is unclear process, for example, despite I was uploaded clear project file with 3.1.3 version "dotnet restore" command unexpectedly was changing my project file to another version 3.1.5 and restore library was filed.

Main trouble of deployment DB in NET Core is unclear and misunderstandable process of deployment db from binary compiled files. I'm looking to my compiled portable library and I see all needed part of EF deployment - POCO class with DB definition, ApplicationDBContext, all attributes, migration and so on.

Theoretically deployment command would be look as "dotnet ef database update --project XXX --context YYY" or "dotnet ef database update migration-name", but no, I could not receive result of deployment.

But alternative way to deployment DB from full source code and compilation full source code in place is working.

This alternative way to deploymentDB with uploading full source code to server is not a good choice, its violation of all logic of development - to do development in one place and upload binary result of development to remote server. I do not recommend you to use this method, especially in production server.

And finally, this is result of deployment the same db to MySQL and MariaDB from the same code by pomelo.entityframeworkcore.mysql provider.

Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/DeployCoreToLinux/Index.htm