ASP.NET Core On Linux - How To Tame a Penguin | Brendan Richards

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I [Music] [Music] [Music] [Applause] okay my talk is entitled how to tame a penguin where penguin where this penguin here his name is tux and is universally considered to be the mascot for Linux denotes operating system and this is me I'm Brendon Richards I'm a solution architect at SSW I spend a lot of my time on client sites wiring websites and I've been a linux user for a long time and I've been a dotnet developer since 2004 so when the announcement came that um dotnet was going to run on Linux I got very excited and it's bringing kind of two areas I've been interested in for a long time they're coming together and I'm hoping to kind of able to use both sets of experience to deliver this talk so what am I going to talk about well mainly the overall theme is your dotnet developer if maybe heard of Linux maybe tried it a bit but you don't really know where to start or how to go about starting to use it so the real theme here is to give you the pieces of information you know you need to know to understand what it is you're looking at don't expect everyone to remember everything I say but if you sort of next time you're sat in front of the next you see an error message you think remember there's a way of getting around this there's a thing you can do and I can't be what it is but then you've got a kickstart of what to Google then it's going to going to help you in the future so my first section is called may you live in interesting times this is a general kind of history where we are and how we got here my second section is called packages all the way down so it wins understand how to install software under Linux you need to understand the package manager system next section is are logged into a Linux server and all I got was this lousy dollar prompt at some point now you can use Linux using a graphical user interface but most people at some point need to jump into the command line to do something so this goes straight in and teaches us some command line basics to get you going hopefully to make you slightly productive under that environment then when all that backgrounds in place we move on to installing dotnet core on the Linux box and then we'll create and deploy and asp.net web application so the first section may you live in interesting times well I think it's fair to say that the relationship between Microsoft and Linux hasn't always been a particularly good one if you don't know this guy this guy here is am Steve Ballmer he was the then CEO of Microsoft and this is a genuine screenshot from a register page so some point the last ten years we've gone from this to this quite a big change so how did that change happen let's take a look at the landscape so traditionally when you're talking about computers in the modern world there's generally one of two types now there are other systems out there there's the you know some educational departments have got their own kind of experimental operating systems but most systems you see out there in the world have one of two types of kernel one is the NT kernel that's running things like we first saw it in Windows NC 3.1 it was numbered 3.1 even though it was the first one that came out and that's the kind of pattern that stayed around in Microsoft for a while all the way through to Windows 10 Windows Server Windows Phone and Xbox one on the other side you've got what I've called a nix kernel that's pretty much everything that's evolved some way from UNIX from the 1970s now UNIX is very old and when it was created for computers were massive big wardrobe size things that everyone had you interacted with that computer through a terminal and it was built to support multiple users across one computer was used by 50 people for say since then that general pattern has been reimplemented number of times in both the Linux and the BSD systems but those then those two systems links and bxt are the base for Mac OS X of just Mac loss these days iOS running on Android on our iPhone story and the core of Android phones and I'm Chrome OS so what's interesting with this divided list is when you look at phones who here right now is using a Windows Phone and he hands up we've got one who here has got a Android phone quite a few here here has got a iphone so androids are winning but still quite a few iPhones one more question who here right now has a windows-based laptop with them so most people so pretty much you're looking at I would say at 5050 splits right now in this room there is many UNIX based operating systems and UNIX based computing devices in the room as they are NT based assistive devices and this is a dotnet user group will remarks off crowd so that's changed a lot in the past 10 years so that's the traditionally divided landscape and I think that um growth towards phone and the fact that I'm Windows Phone didn't take over the world has led to a big push towards Linux and kind of non NZ based systems so Microsoft have stepped up and they've got quite a few systems now they've done a lot of work they've made a lot of technologies that cross that divide first and foremost with Microsoft Azure so when they released the cloud they realized there's a huge amount of web systems out there that don't run either don't run at all on windows-based systems they run very poorly on Windows based systems so thousands and thousands of WordPress sites and all the rest of the web basically and so when you're launching a hosting provider you want to get people into hosting their stuff on you and giving you money Slater said we don't want don't care what you run songs you run it with Asia so that dry of a huge push within Microsoft to actually start accepting understanding this other technology then we had xamarin Wells a marine comes straight out of the phone system and they realized that there's this thing called mono lying out there that's been a completely open source project completely in the open source world that's a reimplementation or of the.net api's when they realize this and and bullet out and took an embrace it meant that you can now use your Windows skillset to develop software for iPhone and Android and it's still the number one way if you want to write code in dotnet code or dotnet style code and have it compile and run on a phone zamarons now your way forward personally I'm thinking with this in speed on their core stuff coming on I'm not sure where the mono is going to be around much longer right now there's been no announcements this is totally a personal opinion I know nothing but I can't see I can't see if you've got this open source asp.net core in five years time why you'd need to have mono as well that's right the announcement there was visual studio on a Mac and so that's a big change so all these systems are coming together and it's no longer quite important what operating system you're running it's more about what practice impact what practices and patterns you're using so the next thing on here is asp.net core a huge amount of work and we're in so easy just to one carry on and may connect and in a dotnet five but the realization is you cannot leave in a divided world anymore so they've out the amount of work in the amount of pain it's taken to get here is incredible but now we're looking at we've got an asp.net core program that runs on Windows Mac and on Linux Visual Studio code we love with your studio code we actually use it quite a lot for all our um JavaScript style work in typescript and angular and it's really small it's really fast and it runs really well and finally on the thought I'd never see this day even SQL Server has been pulled to one on Linux and it runs well it works it's fantastic okay so there's some good reasons for using Linux there how'd you get some well the first place you can look is of course Asia if you don't need developers there's a chance you've got an MCN subscription of some coins with that MSDN subscription you've got a bit of personal free hosting space so get yourself a Linux VM how's it that way or you can host in any other provider there's some free tiers on Amazon there's cheap and virtual private servers around from around $10 a month or you can start looking at virtualization that's something to show you today because for a presentation to get a really nice-looking and terminal up I'm using a Ubuntu instance on VirtualBox but there's other virtual providers there's VMware there's also hyper be that's built into Windows docker is very exciting technology it's a talking its own rights I'm not going to do much with it up up and mention it but what docker is is containers its instead of running full big virtual machines it's making tiny containerized virtual machines so it's much easier to deploy across lots of save on a web server it's shrinking down the server that is that web servant is just the web stuff and the stuff it needs and then putting it into these containerized systems now what containers do is they've got some really clever stuff that actually shares files between all the virtual machines on that box so straightaway you're shrinking down the amount of storage capacity you need to launch a big cloud of servers another way to get a Linux box is to pick up an old machine from somewhere chances are you ready to get it to run I've got our home desktop PC kicking around my lounge room it's used to be my desktop there born in 2006 so if can I swapped out a few bits put a new hard drive in put um Ubuntu on it and now my kids Jess and I click the chrome icon and type Netflix to browse Netflix and watch their cartoons I don't know it's the looks they just know I'll click here and type Netflix raspberry pi and raspberry PI's are pretty cool tarney systems cheap systems that will run a full-blown extend the amount of stuff a Raspberry Pi can do is growing each and every version Raspberry Pi 3 and they're a pretty decent system just in this tiny box and finally another very very cool new technology is the Ubuntu stack on top of Windows 10 the way this works is a very low level kind of area it will run a kind of cut down especially made Linux kernel it's not the first time there's been a kind of run a UNIX tar stack wantable windows there's a system called cygwin that's been around for quite some time but the problem with cygwin is you would install itself and I kind of drive a level as a system and then create a virtual system for the UNIX but all the programs wanted to run onto the cygwin had to be specifically piled compiled for cygwin so you were kind of limited to one distribution and one kind of weird package manager' what they've done with this subsystems for Ubuntu is they've made that call that they've just hacked to run on top of window stack and 100% binary compatible you banzi so you install the same packages from the paint same package sources okay so that's a little bit of history I've said the word packages already let's look at section called packages all the way down so what I'm going to talk about here it's a little bit more about the Linux architecture and how you have to understand packages to understand how to get software in and out of the system here's a quote quite liked by Jeff Atwood the coding horror guy and it's not that UNIX is particularly good it's just that everything else ended up being even worse than what I think it's meant by this is it no one tries to make a terrible things but every now and then best of intentions you'll make something that someway sucks I like gum I'm liking this a quote to UM the Leo Tolstoy quote where each unhappy family is unhappy in its own way so let's take a look a bit about UNIX architecture and the philosophy of Unix so the UNIX philosophy is write program to do one thing and do it well write programs to work together and write programs and text streams because that is a universal interface so the core concept here is don't make big over complicated programs don't reinvent the wheel try to avoid the nut invented here syndrome make a simple thing and then if you want to add features so that simple thing make another simple thing that wraps it and so on until you build up at are these symbol components so how does the UNIX philosophy hang together in the system architecture you know I put UNIX architecture here and not Linux architecture and that's deliberate because this is the system this is the kind of layout that applies to all UNIX systems including OSX including Android phones so what you've got here in them in the middle is something called a kernel so the kernel is the system is the lowest level system that sits between you and the hardware you interact it with system calls and that's the system that manages running processes managing those processes then on top of that there's generally something called the shell so the shell is basically sits around the system and gives you an environment to run programs in then around that you've got your applications sometimes they go via the shell sometimes to make direct system calls themselves and sometimes it may not many times they use various libraries to get their work done so when we talk about Linux what we're actually talking about is the kernel that's the bit in the middle so the Linux project is in fact ajust a UNIX kernel it's a system that sits between you and the hardware and gives you this this interface to run programs now the Linux kernel was released by 1990 in 1991 by Linus Torvalds on top of the Linux kernel there's something called the new project canoe is sands for canoes not Unix it's an example of a recursive acronym where the first Lane name letter with the acronym stands stands for acronym itself it's something that for some reason open-source people find hilarious but this system was actually first built way before Linux so when Linux came along there was already this library of open-source software written for a UNIX environment that they could just drop on top and turn it into a complete system so the story behind the GNU project is there was this guy called Richard Stallman who worked in a university I think it was Berkeley a bug might be wrong there but they stripped a printer to him had a brand-new printer come in and it couldn't quite do the things the previous printer good so he phoned them up and said hum as a few problems your printer driver send me some code and though you know tweak it and we'll work together and fix it up when for the first time this is way back in the 70s they turn around said you can't have our code that's our proprietary sub proprietary technology you can't have our source code and that never happened before because writing programs happened to universities people just shared everything they had and Richard stone was so infuriated they went under form the free software foundation and that started off with taking all the utilities they used on top of a UNIX system from day to day rewrote them as open source versions so all the real core util is a lot of the commands you'll see Rick today we're originally written by Richard Stallman as copies from what's provided by the eunuchs of the time then on top of that basic system you've got the unwashed hordes thousands of various projects for all kind of types of people nor types of places making all sorts of software and all this lives out on various CBS repositories subversion repositories sitting there and github and it's all there as code and so how do you make sense of all this mess that is where distributions come in so these might be more familiar libraries so what distributions do is take all this source code and turn it into a complete coherent system so what they do is take source code that's been released by any whatever open source project and they turn them into binary packages they put those packages on package repositories now as you can imagine with this whole concept of not inventing the wheel do one thing do it well and you wouldn't rewrite lots of bits what you do is you take dependencies on the other part so there's a huge tree structure of dependencies of programs of align other programs so what the package repositories do is keep track of those dependencies so when you save the system on to install X it'll say arts in for X the one you need Y Z let's download this to put on your system it'll run so with that the introduced system wise consistency by making sure the version of why that's dependency for X is the right version that it needs they then make installer programs and DVD so you take your DVD is I put in your system and install it is even them there's different types of distributions is even a simple boot off the CD distributions this boot off the CD one there in place and use them program sort of repair CDs that kind of thing and then distribute those that software and one support and forums so when I say packages all the way down what I mean is everything in the system including the kernel is a package many errors that you will see you using the system can be fixed just by getting the right version of the right package it also means you can update all the software with a single command so say you won Windows Update what you're updating is windows and maybe a few so other Microsoft pieces of software when you write an update on a unix linux machine you're updating everything that was installed via that package mets system which has messed the system so with that as a few places to get software from of course is what's called the official repositories these are the repositories provided by your own distribution and it's a pretty complete system in its own right most of the stuff you need is on there then you get what's called unofficial repositories now by unofficial repositories it's a perspective thing unofficial possible repositories from the respected of the distribution provider for example Microsoft have a bunch of repository so you can add Microsoft software to Ubuntu they're considered to be an unofficial repository from the point of view of Ubuntu even though they're the official repository for Mark's office is where marks are puts their stuff some languages and such as node or c-sharp they have their own package managers built-in in c-sharp you use a new gate with node you use NPM so sometimes you can install packages using those two dan direct download directly from node or down download directly from NuGet org the rule of thumb i use here is if i've got a piece of software that i'm installing just to use that software just to use as a system like some java program that i'm using to talk to my database I'll probably just download it through the official repository and not worry about it if that's the programming language I'm doing using to use my work so I'm doing some work with node I will get node from the node repository is unofficial for the distribution but know it's official between get the latest version and then use NPM to stall on my JavaScript packages because then I'm getting its the thing I'm working with it needs to be up-to-date so I have a base system that's kind of default and then the system that I need to be the latest go and get that from the unofficial source and some vendors still give you binary installers say Oracle database is a key example I know VirtualBox has some binary stuff they install when they go into your host system to make it work well in that hosting environment making drag-and-drop work between you and the host and the host program and finally you've got a nuclear option at the end if there's a piece of open-source software and there's no package available for it you can always download that source code and use the compiler to compile it yourself and install it that way I'm not going to do that for about ten years but it used to be something you had to do cut more often so with all these these packages you get a lot of modularity the next distributions can be big or small and they can run in many places I've even got a Linux box running on a little Asus wireless router it's got a board consisting on a chip and you can get some flush the BIOS and replace they're kind of pretty rubbish and web interface it having it with a complete the next system so you've got all the kind of standard Linux tools for running soft grounding your hardware running a network traffic all that kind of thing and with that modularity pretty much any component in there can be swapped out for an alternative there is a countless number of different graphical user interfaces for example this KDE there's genome there's unity which is the one built into Ubuntu and a whole bunch of other smaller cut-down ones built for lower spec hardware but with that modularity there is a drawback for every possible choice you will find an argument flamewar quite heated online I've got this particular cartoon in here not because I found it particularly funny but because just how old it is via new Macs were both text editors in the 1970s and there was arguments about which one was best stretching way back I'm a bit silly cos voice clearly best I logged into a Linux server and all I got this lousy dollar prompt so you log into a Linux system and you've given this black screen with a dollar prompt where is everything I'm used I'm you I've might have seen that before I've been messing around with Windows and weapons command and you know when I open up commands some generally somewhere in the C Drive well in Linux is now C Drive so you immediately lost there was also no registry everything is configured with text files sitting somewhere on the disk but where is that stuff well there is no sea drop what there is instead there's a single directory structure starting with a forward slash and everything between is forward slashes and when I say there's a single directory structure starting with a forward slash absolutely everything in the system is under that slash so you don't have your C Drive and everything on this from C down that's one high drive and a drive and that's where your floppy drive is and then if you want to look at your network drivers you'll go to the device manager you want to look at your printers you SM routes everything is under slash so all files that have been mounted on any hard drive across the system all the devices devices appear as raw block devices under slash if you knew enough about the hardware and knew what bits to send you can communicate directly with your hardware you've also got a virtual file system under proc and that and that's the kind of system that lets you see stuff about running processes and CPU information and the last thing I'm going to show you here there's symlinks symlinks basically little nodes on that file structure that point to other places in the posture like an alias think of it a bit like a shortcut in windows if you quite a shortcut in the Windows GUI you can click on it and opens like a directory but if you then go and open it up in in the command prompt it's just a file with dot LNK on the ends a symlink is a bit like a shortcut but it's much more low-level you look at it through a command-line it still looks like the file it's supposed to be it's a really low level thing that NC does have some stuff like that it's got something called a junction point that you can create and sit and work like a low-level redirect but symlinks are quite crucial understanding some of the bits and how we we hang things together inside a Linux system so let's have a quick look through a few of the locations where stuff has been put underneath that slash folder anything with bin in its standard binary that's actually executable programs slash dev is where you'll find devices you pretty much don't need to poke around in there unless you need to kind of ream atter a hard drive and you just need to know where your drive is et Cie is a folder that contains lots of text configuration files that's your general system configuration home is your user home folder x' and that's where any kind of users effect you've got a program that has some configuration that's stored per user it'll put a little hidden folder in your home folder and that's where you put stuff now you'll see this happening more on the unit windows side as well if you go to app data slash roaming you'll find more and more configuration files are sitting underneath that stuff I mean I know one you get and the windows now it puts a dot you get folder in your home folder or under app data roaming to put its configuration to be consistent because they want this stuff to work across both platforms then /proc is a virtual file system for system information it kind of puts nodes on that tree structure that lets you query stuff about your hardware query stuff about running processes and finally /var is the runtime files if you've got to sit a program that makes looks it'll write logs to slash bar if you've got say a database the data files for that database will typically see it under slash bar so let's move forward from that introduction to take a look at the shell so the shell was a program we used to interact with machine via the command line it's the command interpreter the equivalent of CMD commands in Windows and like pretty much everything there's more than one shell available but the default at the moment seems to be bash so it also provides an environment under which programs execute so what I mean by that environment is a typical command line program looks something like this you've got standard in which is a stream of input text it gets fed to the app and the app sense right set the standard out another stream of input text if something goes wrong it writes at the standard error so let's take a look at running some commands now I've got quite a few things to get through so I'm just going to run through a few things and then speech remember everything but just give you a pointer of the kind of things you can do starting with putting my right password in okay here it is here is the young blinking dollar cursor so let's start with a basic thing Who am I logged in as now I'm logged in as Brendan where am I PWD stands for print working directory now I can see I'm in a folder called slash home slash Brendan slash code you want to look at what's around me I can type LS and get a listing of flowers that's the crit of dir let's take a look at our first switches on a bit more information sorry so minyak make that bigger so I bear with me not something somewhere go edit this profile then get a custom font debit better let's look at our first switch so generally you have a command and then after the command there's an argument separated by space it's pretty much like in DOS and typically you have - and then some switches so that base gives us a bit more information from that so how do I know all about these command switches one of the most useful commands you can know is man it's short for manual type man and the name of a command and you'll get a few list of all the command line switches you can use and what you'll see here is quite often funny command line switch there's a kind of short variant and the long variant my rule of thumb is if I'm just typing it out once for myself just in front of a screen while I'm working I'll use if I know it I'll use a short variant as soon as I'm writing a script that's going to be read by somebody else I'll stick around for a while I'll switch to longer varying because that's more usable then you've got CD will change directory big difference is you can't do CDs or like you can endorse go to CD space dot another special character you've got if echo is a command that's a bit stuff straight back up to the screen take a look at tilde told us what kind of magic thing that's set back to my home folder so I can quickly get to things under my home folder with tilde slash code you'll notice that jumps there what done this command line has is very good tab-completion fight site start typing CD top Co hit tab it finds code that does working DOS but the one here is slightly better if I to create a couple of files that's going to make some files first so in this case what I've done is I've wrapped that command in quotes so in slip being two arguments it's now one argument and that spits out that value straight back just from standard into standard out the next thing when I show you is this redirect character same as in dos I can use that to redirect to a file one thing that's worth pointing out this dot txt this dot txt extension under the next means nothing there's no special interpretation of file names Finance mean anything you want them to be next I'm going to show you is cat cat this short cat at night and that's to print out the file next I'm going to show you is a variant of that so a single writes to a file a double a pins to the end of a file now I've got two lines when I create a second one to show you something else if I type ket H II and hit tab once you'll go it will find that it'll match as far as it can and those okay for the for those smoke switches for that vent that's that prefix hello is as far as I can I can get them be unique if I hit tab twice it will list all the files that start with H zero and if I type then two and hit tab then those hello to so it's quite faster so move around there find anything I'll show you cat doesn't just and print out fine so I'll go through the special proc folder CPU info he'll give me lots of information about the processor that's the first section let's move on to next now if I try and do something I'm not allowed to do it will tell me permission denied okay so this I think everyone probably knows this command there's a command called pseudo which stands for super user do so if I take that command and prefix it with su do it will ask me for my password and then work now there's no work and did this demonstration without showing you this because I've tried and people just tweet it to me anyway this is the classic xkcd on su Lee same in terracotta and so another thing I'm dear for gosu do Who am I it temporarily it so once you've typed in your password for sudo it will stick for about five minutes or so and that's configurable so I don't have to keep typing my password so methods could be short amount of time and so in that case I am got privilege escalated it ran that single commands Who am I said I'm root ok if I go straight back again the key thing is that privilege escalation is temporary and only lasts for as long as that one command it only once one command at a time next thing I want to show you is the shell itself so when we're looking at um what we're looking at here is two programs running one is called a terminal and what it does it takes the key presses I type and sends them to a program takes the output from that program and put it back on the on this terminal here the other one is this shut itself the shell program is what reads what I've typed interprets one stuff and sends it back I can do this a few times I'm now running a shell inside the shell I'm now running a shell inside the show and so it's still I'm running a different shell inside a shell inside the shell now I can exit to come back so it's kind of nesting programs and inside programs inside programs each one is taking its input passing through the next one pass the next one and finding this one excuse demands it bubbles all the way back up again okay next I'm going to show you is it happens quite a bit but you'd never sit down type Sh three times but shells inside shells do happen quite a lot and it's one of the key factors behind this next command which is SSH so SSH is secure shell what this does is opens up an encrypted connection to a remote server runs a child shell on the remote server on that machine so if I type commands from that point it tunnels through the network runs the commands on that shell on the remote system comes back through the network and displays a text type the wrong password okay so I'm now logged into a machine that's on the the cloud that's nazir virtual machine I've got it there so it's running a copy of ghosts which runs my blog using NPM and now from looking rounds I can just do my work on the remote machine so one thing that's useful to know if you are going to log into a remote machine is you do need some kind of text editor that works just inside the command line because now this machine I'm working on now has no user interface it's just a server machine so there's plenty of text editors out there the one I recommend you have a look at first even though I'll quite quite like VI is Pico the reason I'd go that it's actually quite friendly looks quite simple you can shift and control being controlled Peter paste and the commands listed there underneath so if you get that installed it's pretty useful to use next thing I'm going to show you is a program called apt so Apps is the name of the package manager program inside Ubuntu different distributions have different package managers in Red Hat is called rpm and young in my favorite name for the package managers is a program called in a distribution called Arch Linux they're one's called pacman but I'm on this particular system on Ubuntu there's actually two programs it's a case of not reinventing the wheel there's a much older program called dpkg which is the Demyan package manager and what that can do is going to take a package and install it on your system and uninstall it and manage dependencies what app does on top is add some network capabilities so when you install a package through debian the dpkg and is try to install it and there was the missing dependency it would exit and say there's a missing dependency now if you'd use apt-get we'll say desert it's a wrapper on top that not only caused the DPP cake the dpkg to run install it also picks up a missing dependency goes through the remote repositories on the web downloads those files and installs them so let's use app to look at some stuff if your apps show it gives us some information app show sorry a program we just saw suited let's take a look at that there's information all about um the sudou program the sudo package next thing I can show you is you can this pipe character that pipe character there means take the standard output of the program that was just been running and feed it into standard input of the next program so I can take these text dreams and stream them through a number of programs in this case the program going to show you is grip which is basically run through this stream of text and take up the lines that match this this um text and the text I'm going to put in is depends so if I do that I get a shortcut showing me the list of dependencies that sudu has you don't really need to worry about these dependencies and less something breaks but that's the name of the packages that sudo needs until I install sudo it install those for me side by side finally you can do a search for programs that's at there's list of all the packages that mentions Sulu and finally you can do some things the other way say I've got a file that's giving me an error message and it's the MMS has given me a file name I want to know what package that file belongs to it is probably most useful things for debugging something that MMS has come back something's not right here's the name of a file what felt package that far belong to it to do that you go to the lower level dpkg program - s let's go for something really simple like bin the let LS program and now tell me that that belongs to a package called core utils I get at show call utils there's information about that package which is basically a set of the gnu coreutils the real basic things like list and cat and it's something that's generally expected to be them a system for anything to work okay so taking a look at some processes how do we find out more about what's running our running processes the first thing to look at is top this is the same as right-click as your process manager this sits there and updates once a second and tells you what's running as you can see there's two things popping at the top one called comp it's that's a part of the windowing engine and the other is SQL Server so it truly is a cross-platform world I can sit here with SQL Server on my machine using resources when I'm not asking to do anything just like a can on Windows next thing I'm going to show you and I'll try and get a couple of terminals open for this side by side okay on the left-hand side I'm just going to type cat another filename it's now just sitting there waiting so what I've done I've told it to print out text but I'm not told what to print out this is sitting there waiting for and text to come in on standard input the reason I'm sitting that opens want to take a look at how do I find out about a misbehaving process like inside PS and I see the prices that are running underneath their context will go psh a I think I see a lot more prices running and I can see there's a process here called cat that is that process so what if I found out through top that prices are misbehaving how do I get rid of it well that's the kill command if I type a kill and then the number the process that comes up here five to six so it's terminated so what that does it sends a signal it's the same as a control C break signal and that's kind of a please shut yourself down message so the that program will accept that signal close any open foot prices it's got doing your cleanup it has to do and close itself down gracefully but what if I try that and it's in so much trouble that process that straightforward kill won't actually kill it then I can do - nine oh now you don't need to look at the prices number first okay I've looked at the new process number of that second process it's five to seven eight so if I did kill minus nine five to seven eight it doesn't say terminated anymore it says killed so if there prior to the matter what that post is doing they'll force it to die or just the kernel will just take away all its all its some life and just kill it immediately and that is an immediate death that is a pretty hard way of killing it but that's that's a media and that always works one more thing I'm going to show you is background processes there's a gooey type and text editor as well called g8 you can also one for just your decade from here I'll show you that later but I'll just show you this so this particular program runs there is running I can type into the text but you can see it's kind of running from that terminal if I kill that terminal kill that price of the control see it's dead what I can do instead it's put as amp and pans and after it that now runs in the backend prices you can see up returns here I can run more work cooking one more programs here if you want to take control of that program that I background it I can just type FG I've now got control of G edit if I control C from there I've killed it okay so that's quite a lot of commands I've shown you in a very short space of time and I don't you expect you to remember all of that but hopefully you've got an idea of some of the things you can do when a few styling points to get processes up and killed again one big tip is what you need is a cheat sheet so this is a product by xkcd it's a cheat sheet printed upside down so you can grants down on it and look up some command line switches while you're working away and it's also available as a skirt so everyone's covered okay so now we've gone through we've got a bit of background information on how to use a command line terminal let's actually go ahead and install dotnet I think you've realized by now that when you are dealing with Linux you need to use a package manager so you don't get to download an MSI install that MSI file people do in UNIX world do not like binary installers that much rather have a package manager and there's a good reason for that because if you've installed it through a package manager where an update comes it comes into your natural chain of your update process you've got a you know once every now and then you get your machine you say update the software updates and security fixes for your software will come through that channel so you go on to the websites and you find the page for you one two on the.net code and what you get on the dotnet website and what you get is this big pile of text to run to get it installed so let's take a quick look at what that does first line su do SH - see that's Suda you've seen that one a superuser we running a child shell and the superuser the reason we're in a child shell is because soon you can run one command and one command only you want to run a bit more than one command so you create as a kind of child shell and put that command install it so we've done a privilege escalation inside that privilege escalation we're doing it echo echo is send some stuff to HT output stream we're doing an echo some ticks redirect to a file handle so we're taking all the stuff that's in the orange here and redirecting it to the file dotnet dev lists you can see the location that file it's under et Cie so it's a configuration file it's in apt it's the configuration file for the package manager and it's in the folder called sources list D so this is where we keep our package manager sources so what effectively we're doing is adding a new package manager package source into our app configuration it's the same as adding a new package source in you get once we have done that all packages that you install on net are signs node needs to step up here and actually start signing their packages on NPM but um they're signs so them you can't people can't inject bad programs in their science packages from from Ubuntu and if you want to UM accept an unofficial what's that resource you add a key and say okay this source from Microsoft I trust it I'm going to accept packages from the Microsoft server so that installs the key into apps and finally you want apt-get update so there's quite a lot of information the system has to know about these packages what the dependencies are it has to really index and quickly so what app apt-get update does is it hits all those repository sources downloads metadata about them and indexes it so when you sort of query the system and say oh what packages does this depend on it will it will find it quickly so app get updates the first step to updating something it updates your your index then once you update your index its apt-get install to install your program and that's pretty much it so let's go through now and deploy an asp.net core web application okay move to my cold folder code folder and I'm going to create a new folder called MVC and inside that folder called MVC I'm going to start using net let's start take a look at the version make sure is installed probably double with s version there we go we have the dotnet command line installed I'm running on Linux so the first thing we can do is we can do dotnet dotnet new so what dotnet new does is it has a series of templates we can use to start our projects from we want to one take a list of those I can do - L and it lists the templates that are available and you can also install additional templates I'm going to start with an MVC template just because it gives you a little bit more to look at when I get it running so dotnet new MVC go that's it it's created a template so let's take a look at what it has created by type code dot - 1 Visual Studio code and here we are with a pretty basic MVC solution and the key thing here is what you've got here from the code basis you don't have a solution file but you can add one everything else is pretty much exactly the same as what you'd get if you did a new project with a right-click or a file new project in Visual Studio so we've got with dotnet core your web applications look a lot more like and console applications it's console applications let me yeah it's console application that runs bootstraps it's web host builder it says use kestrel which is the web server we'll talk about that a bit more it's got ice integration for running under RS which you're not using right now then go to the startup which sets up some more stuff but our hosting environment and then inside here we've got a few basic a controller a few views and a W a root folder for all our static resources ok so that's what we've got from the template let's try and run it it's the first thing to do is a dotnet well that downloads all our new get packages and it stalls them steps to do that I hope you on a good enough internet for this to work should be excitement Annette that's finished now I can do dotnet run and that's it it's built and it's running and it's now listening on port 5,000 so the big change here and this is of course all of them the.net asp.net core kind of system there's no need for is a lot of work has been going on the past two years to get rid of that system dot web namespace that assumes that is is somewhere behind the scenes bootstrapping the whole thing so now is is gone it can run quite happily in its own self-contained server called Kestrel there it is it's booted up it's listening let me um take a look at port 5,000 there it is it's running on Linux and so what's remarkable here is how unremarkable it is you type a few commands you hit run it works and there it is it's running a website pretty easy to work with pretty fast to work with and yeah it the thing is it just works it's now control see I've shut down that website let's take another look it's gone okay so that's one that's the first step it can run from the young code there but take a look around there's not much going on here this is still my development environment this isn't really production ready but what I can do to make it more production ready so I can publish it so in order to to run the publisher get the publishing to work you need to install a few things need to have NPM Bower and gulp installed on your path that's pretty basic but once that's installed if you can go dotnet publish give it an output folder it looks right to me let's now go to run a few things and that's now published let's take a look at that so take a look at that you can see there's far more dll files it's now um I lost it there's far more dll files in place now it's now taken all the dependencies all the frameworks every needs and wrapped it up and dropped it here now by default it wraps it up and builds a package that assumes there's a dotnet framework where it's going to run it what you can also do is send some extra commands with publish and actually include the whole dotnet framework with it as well so you can actually ship that to a server that doesn't even have the button that for a book installed and have it still boot up so if you've got issues where you want to have multiple versions on that framework or if you're bundling for say a container that you don't assume dotnet framework it's there you can actually push it to that container with the framework it needs so you've got a lot of options there and how you publish now when you want to run the app that's published you're still use a dotnet command but slightly different your type dotnet and the name of the entry at the entry point dll the name of the project you credits that will be MVC in our case dot DLL again that's that if you've noticed that the startup time now was a couple of seconds before now it's click bang saphan money so very very fast having said that there is a few seconds delay on the very first request I guess it's the first request it's starting up yeah I'm sure you could actually um set up a first hit request or something to speed it up but it's still it's still noticeably faster than using is ever was so let's close that down so kill all that okay so we've got an airspeed on that core web location it's built it's running let's take a look a little bit more about the web server so that works so quickly and work so well because of a built-in web server called cache dry that's kind of built into the asp.net and it's kind of running it's a self hosting web server it's a small fast web server in dotnet cool and there's been a lot of work on optimization lot of crazy stuff they're doing with um you know not writing c-sharp code in the normal way and you know so say I'm got a web request coming in and the code that look reads the web request and says it's getting this opposed what you'd normally do is write ok compare the string is it does it say get the say post that's not what Carol does it's got some crazy bit to link things in order get tiny bits of performance to excel of it so they've done some crazy things and they're getting some really big performance optimizations out of that so yep like I say it bents much much faster than is I will not put any particular numbers because any kind of test is fairly arbitrary but the baseline is if your actual code itself takes this much time to run it's always going to be that much time if you it in the code a certain way but if your framework is like that versus that you get that stuff for free that speed up is for free because a frameworks not taking up those resources so it's fully cross-platform it's the kestrel for version 1 is based on something called libuv which is a cross-platform library actually reinforced so this is a case of Microsoft not reinventing the wheel of this great library out there for doing fast web servers it was in use for nodejs they took that on when everyone building web server for for asp.net there is one issue though current recommendation for this casual server is don't expose it directly to the Internet see we look at that and think what what does that mean is totally fine and tightly expected and it's what everything else that's so if you look at a ruby if you look at Java this is pretty much what they do and there's a reason for that in the that modern web servers have to have a look a hardening code in there to react to things like certain types of attacks that they've added over the years so what program developers don't want to do what a language develops don't have to have think of all that stuff so what you do instead is you put a well-known hardened web server in between you and the Internet and then you use that as a reverse proxy server and forward those requests through to your application which means you've got a really well hard tested well known program at the front and you're free to kind of iterate a bit more with your actual um system in the backend and this is pretty much a standard way of doing things now like I said Ruby does it Java does it the other thing this is good for is for a long time like way back in the day with on PHP and and stay with ASP what would happen with your web application code is it run inside your web server which meant you were tied to the resources of your web server in quite a big way so when say PHP wants to integrate with Apache they have this feature called mod they have this binary code with mod PHP that's there too inside Apache spool up PHP and process request and send it back all within the context of Apache then to do it for nginx they have to write it again I'm Nigel for nginx if you have this proxy approach you can decouple the logic of your language PHP Ruby pearl dotnet whatever it is have it fully decoupled and put whatever webserver you want in front of you and after then we'll create custom modules for each your web servers to run your different languages so I think it's definitely the way things are going to go in the future to have that decoupling between your edge facing web and your actual performing web so let's take a look at how we then set this up how are we going to set up a reverse proxy to proxy to speed up core application so how did you go about finding like this pretty much the same way as you go about finding about anything you want to do on the Internet just because we've moved olynyk's nothing's changed we copy and paste from Stack Overflow we do a web search and we find what we're looking for so let's take a look at that so the first thing we do is install a web server and it's that simple get up to them install nginx I'm not going to hit go because I've done that already so let's take a look at the configuration for nginx and as you've seen before if you've got any configuration files they live in slash EDC slash the name of that program so let's take a look there there's a couple of important folders here ones called sites available ones called sites enabled so sites available it's really a folder to put all your kind of virtual hosts your virtual name hosts and sites enabled works by actually putting in you could have more sites in there that are actually turned on to turn one of those sites available files on you put a similar consience enabled into that other other thing so if I take a look in sites enabled just to give you an idea and do LS dash L this folder doesn't contain files it contains pointers to point to files in the other folder so if I want to turn on another another configuration file from that folder it's quite a new sim NIC in this folder to point across let's take a look at that sites available when I got the default there ok so right now what's there is default and configuration so if I go sudo engine X starts sudo sorry system CCL so what we're using here is a program called system D that it will install we install nginx so system control name with the program and stop it's pretty much zero p.m. services to MSC equivalent of what do that get it right sudo system control start in G and X that's the right way around okay it with that in place by brass to localhost okay I've got a web server running on my box and it is called nginx and it's got the default hello world page on there if I take a look at the configuration I will see by squadron listening on port 80 I don't have SSL configured and my home folder is via WW HTML okay that's the full configuration we don't want that default configuration we want to do something else I'm going to stop engine X bike and leave it running because you can change the files behind product while it's running I'm going to copy a different configuration file into place don't get the CD so if you do if you are doing a lot of um stuff that needs a root console or root privileges there's one little trick you can do that should never do and that is Sudi bash and that gives you a complete shell weather everything from that point on is then running as the super user you probably shouldn't do it I've got all the time so let's take a look at that now if I CP my proxy configuration to overwrite that file let's take a look at that file as well so what we've done is replaced the entire configuration for the nginx server and this entire block was literally cut and paste from Stack Overflow listening on port 80 everything that's underneath port 80 so everything under the slash location we're just going to proxy it through to port 5000 so let's take a look at that morning I just do system CTL and let's go reload in Gen X because we haven't accidentally to restart just need to reload configuration see if that works go to pour localhost now and let's put this to work because my arm website phone for 5000 is I'm running yet so we've configured a gateway a proxy but we're not actually running the asp.net side of it yet so let's go and start that up code MVC and it's got published then to run its dotnet MVC DLL okay so now running our asp.net side listing on port 80 we also got a proxy running on yes so the MVC is running on port 5,000 with the proxy running on port 80 we now hit go and now websites up on port Alex that's now ready to go out to the outside world would obviously leave port 5000 behind the firewall and that port 80 open for general purpose traffic so that's running as a proxy but there's one more thing to look at let's sit in there waiting for something to kill it finally kill this terminal if I was to hit patrol see I've just killed it and it's now not running so how do I set this asp.net side of it to run as a service well for do that we can use the program again called systemd and once again it's a piece of code we copy and paste from Stack Overflow hopefully by now if is one thing you've learnt it's where to find configuration files and that's under CT ATC so the EDC slash systemd let's take a look at system and I've got a configuration file I prepared earlier here's a configuration file for running a this particular service as a service a few interesting things you give it a working directory which is where that published folder is you give it a command to start up so there's a dotnet command and there's a dear Dao exactly the same as how we run it by hand there were a couple of interesting things one says restart always and restart ten seconds if it detects that system has gone down it'll automatically start it for you I think it's probably nicer to leave a few seconds with the finish crashing before you start up again um you could probably make it down to one second maybe but I guess you detecting it's crashed but I think um ten seconds is enough to in real terms get it get it back up again I think if if yes I've worried about sub ten second response time should probably have a farm of these things out anyway and have a load balancer okay so that's a pretty simple configuration file it fits on one screen most of it is where to run what to run and the fact when we start it and give it some properties let's take a look at how we run that so we do sister in sudo systemctl enable and that file name web oh one dot service okay that's now enabled in that we're enabled means is next time this machine starts up it's set up as a service it'll get started up with the machine I don't want to wait till I boot the system though so let's actually um take that and start it now so that system control start Webber one got service when I get wrong their pseudo system going to start web a one dot service okay that should have started if when I check to see that started I can type status okay that's looking green and you can see and here it's got the text out but we used to get when running it by hand okay it's let's take a look at the port 80 now what do it quick reload okay that's now running it's running as a service and this this is not accessed by anymore doesn't die i'ma spurt it just keeps on running and in fact I'll show you the next bit now is it keep on running but I'm you know you goes on is if a sites not being hit it gets taken off for some reason I've never understood but yeah and it's is seems to be tuned for a high workload so if it's workloads coming through or keep it alive some reason it thinks no one's hit it I'm going to straight it down and open a favor and the might trouble that causes me no end so this stays up and I need it stay up let's be really nasty to it now so we know it's running let's see if we can find that okay we found this dotnet process you see whenever you search for something using grip in the PS you'll also find the processes actually running the graph as well so that's the price that is the price that's finding itself and here is our actual process there is user bin net and it's got a ID of 6507 and it's running as me so I can just log get a gap to it and kill it so let's do that and let's be really nasty kill - nine six five zero seven so that's about as nasty as you can be that immediately terminate the program won't turn it nicely it's going to kill it dead six one zero seven done let's take another look at that thing in a few seconds time maybe there what's this is the process running it's called dotnet and it's been given a new process ID so if I come to my website you should see my website still lives even though I killed the process completely it's been immediately restarted by the system D system so there it is I live on up and it stays up on it you know comes back up really quickly one final thing I want to show you and I will spend too long on it is okay a worm you've got SQL server running on Linux and the way you install SQL server on Linux as you can probably guess is you need to install a package source into Apps and then do apt-get update at the install so once you've learnt this thing once you can use it for anything everything that's the whole point really yeah I'm googling it and they should all look really quite familiar so what you've got here is as you've seen some text across slice into the terminal it's slightly different text they're using a different command called curl they're downloading something and they're passing it through to apps and they're doing ad but actually you're doing exactly the same thing you're taking this file and you're adding it to the package sources then you merge through a key then it's apt-get update apt-get install and if I go to my package sources here you can see I've got quite a few and different package sauce in there but a.net google crime I've got a custom one for Google Chrome in there and I've got ms SQL Server in there as well so there it is and that's how you install it I've also installed something called an SQL Server tools which means I can go to here I've got a couple of old text commands here SQL command and BCPs these are the me low-level command line ways of interacting with SQL Server so I type dot slash SQL command - I'll just talk about to get the switches up - s localhost and let's give it - you might just do the Northwind database here password or use one Northwind database go if i select star from contacts i think it is now I should be going good questions there question there is there a GUI for a sequel server on linux and i will come to that in a second and provides one this because yet this isn't quite experiences it there's um there's plenty of other text down bastes most dumb unix based um databases have a text-based option for interacting with a server I think SQL command is about basic one out there it does work it's probably good for invoking SQL as part of an automated scripts but it's not it's not that fun to work with sip on get it to actually do something use Northwind you go type capital go in capitals fit to work there we go it does at least have some history there now forgo select star from I think it's customers from memory most most systems that would be enough to put in the semicolon I've got type of go as well there we go we've got some a query earning so it's pretty basic but there are some options for doing that from a GUI so there's plenty of open source user interfaces for databases that work on pretty much any ODBC data source or any um a lot of Java ones and they have this thing called JDBC which is a Java wrapper between you in the database and they will all work with ms SQL and your other option is you can actually exit this come straight in here and if you set up the right path you can just use from you can connect from your windows thing here through to ms SQL so you can tree see this very well but that's um local hosts and for some reason that I really don't understand if you want to specify a port in an SQL string for a box on this web server you put a comma and little : like everywhere else if it works in the world you put path : port in here it's a comma so what I've done this is running on VirtualBox and it's running on VirtualBox with nap na T style networking so what I've done is in VirtualBox of syllable port forward so 1 4 3 3 on the host system for now 1 4 3 3 3 and extra 3 on the end I've set that up to 4 through 2 1 4 3 3 on the UNIX box so that's now going to let me connect sub I connect through my password right now again there I am and it looks just like an on rescure database that's done change someone's name or something let's do something to prove I've actually been here let's go to a customer let's edit the top 200 rows Oh won't let me do that okay it's not quite like any other one but right click and type select top 2,000 rise okay let's just set someone's name update customers set customer ID equals Mickey Mouse call it em where customer ID equals one see if that runs update customers that customer ID equals M Mouse where custom ID was once that's this first guy here oh yeah course yeah good yeah a FKI and hey I thanks for that it's Bob programming string or binary that it would be truncated it must be let's make it mouse that's obviously a al f ki MOU se it's also going switch there's ideas off that let's change something else set company name yeah I can make that much bigger than a year company let's have a look this work no it doesn't I'd have to you there we go it's more like it what was it we're going to change company name there it is company because mass per customer ID equals a okay boy okay which we've changed something from there let's prove that that is actually something we've done in here okay set now use Northwind select star from customers where customer ID and hick remember it's al KFI sorry hey o FK I thank you very much go ok so that really is SQL server running on an Xbox and yet as I said before just like on Windows it is quite resourceful but it's there it works and it up not there's a few teething problems so that's a good question the question was what version of a sequel does it run and I'm not entirely sure let's have a look at the now I know there's quite a few things that don't work like I know full-text searching does is installable but a lot of the business intelligence tools aren't there yet so it is their kind of base interpreter so when you're talking about say Enterprise it's got all these Enterprise extra features the features on top I love that stuff so if a lot that stuff isn't in there not the business intelligence reporting services that kind of stuff isn't there so it works as a core database it's not got a lot of features yet I guess that will change as and when demand but you know if you want those big corporate features you probably wouldn't wanting to to run with them the fourth or folks like an ey this is more for people that are looking to is this gives you what kind of database that you familiar with to run your web apps Innoko not familiar stack they're looking to compete with say the lamp stack the Linux Apache MySQL and PHP stack this is now a place that fits into that slot it's not a complete line of Microsoft sequel server yet and I'm pretty sure they'll be features that they're not planning to to put across but as a working database it's there it works not too many surprises yeah yes a previously yeah best option was well you could always go for Oracle but I find that introduces more problems themselves and one of them being um you've got no money left and so yeah you a great option for running databases on open source stack is Postgres it's the thing I've probably recommend first and foremost but I'm use everything about it it's it's because obviously MySQL is the one that everyone talks about but uh it just never liked it never seemed to have transactional support from the get-go it was kind of bolted on later and it always ended a bit rough and reddit you like it was sometimes very my MySQL so sometimes very fast it reads and used a lot for web content management because you could get really fast reads out of it because doesn't do proper transactions at the time but um Postgres has always been a very good proper acid comply really good solid database enough you know I've actually been involved in taking a national franchise and moving them from Oracle to Postgres and being much happier because you know we could maintain it ourselves and not to spend ongoing money to contractors just to come in once a month and make sure as I keep you ticking over we're Postgres just you put it in it worked it did everything we asked it to do and it wasn't too difficult to use so I've got a lot of Postgres so I recommend trying that out at all same you know this is great so it's got a server on the next works give that a go yeah that's right there's all kinds of weird stuff around basically the projects behind my school had a bit of a split and they folk the code one pocos went somewhere and one code base went the other way it's a bit like the split between Libre Office and Open Office basically the developers disagreed so they went marching off both to copy the code and marching up in different directions and it's never a sign of health when that happens but I've always found the post Christian community to be really supportive like you you know yeah reading mailing lists and you're talking to the developer or Postgres and some you know the really helpful people and I've always found it to be you know better supported and support that I'm paying for that's my experience you know you might you'll manage might vary but I've I've recommended or something to joy it's got our learning curve Postgres but it's what ice like I've only covered in it because once you learn it it makes coherent sense and things flop together and it's a you know well architected solution you stand back and think I can see what they're done muck and you know see how it fits together and it's you know nice and clean and simple let's get back to the slides okay so what did we talk about we talked about may live in interesting times a little bit of history we talked about package managers and if it's one thing to take away there's one to big things et Cie is where configuration files are and packages is how you get system installed on your Linux box those are the only two things you come away with then you're going to have a much easier time next time the NFIB Linux box we've talked about the command line we're still dotnet and saw just how a few commands get you from nothing so it's running a website and we then went on to the full asp.net web application behind a proxy server everything ready for production and then find a little bit of time left over so we also looked at across server to complete that stack please please please on your way out competing at evaluation form it's really helpful for us it helps us know what your likes what you didn't like how we can improve and for me person is going to be great feedback because I'm looking to take this same talk more places I think I need to shrink it down some more but um it is really really helpful for us to complete an evaluation form moving forward I really really hope that some of you give dorton it on Nix or try and please get in contact with me find me on Twitter and take one of my business cards and you know getting in touched and keeping out my blog thank you for your time [Applause] [Music] [Music]
Info
Channel: SSW TV | Videos for developers, by developers
Views: 8,632
Rating: undefined out of 5
Keywords: brendan richards, ssw, sswtv, .net, dot net, linux, dotnet linux, dot net linux, .net linux, ubuntu, ssw ug, asp.net, asp.net core, .net core, dot net core, dotnet core, asp dot net core
Id: XAe0sBIQs3k
Channel Id: undefined
Length: 88min 34sec (5314 seconds)
Published: Thu May 18 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.