MongoDB for Developers with Python Transcripts
Chapter: Deploying MongoDB in production (and playing it safe)
Lecture: Creating a couple of cloud servers

Login or purchase this course to watch this video and the rest of the course contents.
0:01 To deploy our database and set up our production environment I'm going to use Digital Ocean, I've run web applications in MongoDB, in AWS, EC2,
0:12 I've done it in Azure, and various other places I'll talk about some of those,
0:16 and I found something like Digital Ocean really to be just such a nice service,
0:23 simple, extremely fast, extremely affordable compared to the other options. We're going to use Digital Ocean, but what I'm going to show you
0:30 is not specific Digital Ocean for the most part you can use any other server that lets you basically set up vms, and in a single data center.
0:40 We're going to use this and if we come down here we'll look at the various options, we'll see that we can basically choose different machines,
0:50 now it turns out for reasonable amounts of data I'll describe what I think but reasonable is, certainly ten dollars a month is absolutely fine,
1:00 we've got 30 gigs of disk space on an ssd disc, we've got tons of bandwidth and I don't even know if it counts within data center bandwidth,
1:08 1GB is not a ton a memory, but it is enough, this is really nice and cheap, the five dollar one,
1:14 but it's going to put you up against memory limits pretty quickly, if you have lots of data, so what do I mean by a lot,
1:19 so right now I'm running most of my websites using a shared MongoDB server, separate databases, but shared server
1:25 and it's running on one of these ten dollar machines and it's got about six million documents in there,
1:32 something around six million documents, and it takes about let's say 30 percent of the memory of 1GB, so about 300MB resident,
1:42 if I had lots more than six million things, than probably I'd need to move up. Also if I wanted to run a replica set on the same machine,
1:52 all these kinds of things, but this is probably a totally decent starting point, unless you really have quite a bit of data.
1:59 Anyway, we'll get started with Digital Ocean. The first thing we're going to do, what we're going to do in this video, in this lecture is
2:04 we're just going to create two servers, one that's going to be our web server that's just the thing that's going to try to access MongoDB our app
2:12 and the one that is the deployment production server that we've kind of locked down and hardened,
2:17 so let's switch over here for now, and we're going to go and create a droplet. I've done a tiny amount of work in advance,
2:26 I've created a certificate that I'm going to use to ssh in, I'll show you where the step is and there's a button you can click
2:32 and it basically says type this, put the contents here, you're good. When we come in here there's a couple of options,
2:38 the first thing is to choose an image, so we could choose all these different versions of Ubuntu,
2:43 I'll just take the default, I'm tempted to take the new one but it will take the long term to support one.
2:48 If you wanted to use another distribution, you totally could, also they've got this one click apps thing that is pretty interesting
2:53 and I could come down here and even click MongoDB but I don't want to assume that using Digital Ocean you have this button
2:59 I want to show you how to set up a fresh Linux machine running MongoDB in the end basically.
3:04 So I'm not going to click this, but this is a totally reasonable option to click this and it has ability to upgrade basically through apt update.
3:11 So for this, let's go with the ten dollar one, it's charged by the hour we actually pay for this course, it's going to be quite quite low,
3:21 I'm not going to leave it running for months at a time. We're going to do this, 10 dollars a month, standard Ubuntu,
3:26 I don't care about block storage, I'm on the West Coast of the US, so let's pick something somewhat nearby but you see there is other data centers,
3:34 probably you want monitoring, this allows you to go back and do a droplet and get graphs of like cpu, disk, memory, over time that's kind of cool,
3:41 maybe private networking, but again we're not going to do that here, I have already set up the ssh key,
3:46 so I'm going to pick this Digital Ocean course test key, which doesn't want for anything but this test bit that I'm doing right here,
3:53 we also create a new ssh key and there's a little help button you can click, and I'll just show you how to create and store one of these here.
3:59 Alright, so last thing we want to go over here, we got to give it a name, this Ubuntu name not the most amazing,
4:07 we'll call it the mongo server, that seems decent right, it doesn't like this, so we'll just go like—
4:15 so this is all looking good, we've got our ssh key we just need one of these types of things and we click go.
4:24 I'll let this go in real time, so not sure how long it's going to take today but I'm not going to speed up this part,
4:37 you can see this is just a real time creation here. And we're good, it says happy coding, I love it.
4:49 Alright, so let's copy this, let's go ahead, I think my ssh is already registered if not I might have to add that, let's go,
4:57 so we're going to go here like this, and it says you've never connected to this server, no it's brand new.
5:05 Apparently I have not added that, so go down here, add ssh-add at the k is added to my keychain, like so, so it's added
5:17 now if I ssh again, do this one, how about the one we're actually working with. Okay, look at that, we are connected,
5:28 so I had generated my key but I hadn't added it to this user profile, so this is great, and it should also be somewhat concerning
5:35 that there are 16 security updates right now, so first thing we are going to do, we're going to apt update,
5:41 go refresh the possible updates and a real quick upgrade, and we'll be back in a minute.
5:52 Okay, everything is done, now let's exit out real quick and just come straight back and notice, there's no more updates, but a restart is required
6:02 in order to make this basically finalize those changes, something deep down in the guts was updated,
6:10 so we'll just do a quick reboot and just to show you the time in here I will not speed this part up either. Usually it takes about ten seconds,
6:22 but with that many updates it might take a little bit longer; let's be optimistic give it a shot, and we're back,
6:34 so really quickly we updated our system, we rebooted so we've got Ubuntu 16.04.2 long term support, and it's all up to date.
6:44 This is great, this is our Mongo server, let's do this one more time let's go and do this for here, go back to the other stuff in a minute,
6:56 let's do this for the fake web app that we're going to have talk to this. We'll come down here and pick Ubuntu, five dollar one
7:04 we don't need block storage, sfo 1, same data center as before that's very important for latency; go ahead and add monitoring, use this ssh key,
7:17 and we'll call this the web server, and go— good, these are the same data center
7:28 and we'll do the same thing, I'll ssh into here I'll do apt update, apt upgrade
7:35 and give it a good reboot, and then we'll have two fresh up to date machines and we'll start configuring them afterwards,
7:42 let's just double check this one, so it's alive, but make those a little bit quick, there we go,
7:55 now it took a moment just to turn on, excellent, everything is good here let's say apt update, it says there's no packages
8:04 but I'm not so sure, it's basically running that right now so let's come back in a second, oh look, there's a whole bunch of stuff that we got to do
8:16 so apt upgrade and we'll do this, I'll kind of shorten the video here you've gone through this before, and we'll just let it do all the upgrades
8:26 and then we'll come back and talk about installing MongoDB on the Mongo server.


Talk Python's Mastodon Michael Kennedy's Mastodon