Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Appendix: Installing MongoDB
Lecture: Setting up MongoDB on Linux
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Are you taking this class using your Linux desktop? Well, let's get your machine all set up and configured with MongoDb.
0:08
So here we are just on the homepage mongodb.com, I am going to go click download, and it's totally possible to click and say
0:17
download the tarball, but we could also say I would like to see how to set this up on let's say Ubuntu, as you change this,
0:24
notice different things happen, so if we go to Amazon it says here are instructions for installing with yum, that's the package manager there,
0:32
if I go to Ubuntu, so here's the instructions for installing with aptitude, so we're going to go over here to that one,
0:37
make sure you pick the right distribution, do we want to read this— no. So there's a couple of steps that we need to go through
0:44
and they're pretty simple, most importantly they just like walk us through it so notice here that there is a package named mongodb.org
0:53
let's try to just install that, sudo apt install that, oh it needs my password, okay, and nope, there's no mongodb,
1:06
darn, doesn't it say right here, here's how you install all the pieces? It is true, but we got to go through a few steps to get there.
1:12
So first thing that we got to do is basically add a source to aptitude, so we're going to go over here, and we're going to set a key,
1:20
so you're just going to go through a few copy paste steps, so we're going to do our apt key here, it takes a moment,
1:27
and all right, that's all good, next thing to do is we're going to create a list file, all right, great.
1:35
Be really careful about the version numbers here, later is probably better, pick the one that matches yours.
1:41
So the next thing we need to do, is run a sudo apt update and you can do apt.get or just apt, whatever
1:48
but you need to tell it hey, go pull all the sources now the new one included and just have that list there.
1:54
We don't need to back up anything, so go away. Alright, now everything is registered, we're pointing at the right package source,
2:03
we've updated it, now we can go over here and do our thing that we tried to do originally. So we wanted a sudo apt installed mongodb.org,
2:15
this time it knows what that means, hey look that's mongodb, mongos which is a sharding server, mongo server, mongo shell, mongo tools,
2:23
I am just going to install them all. Perfect, okay, so we have MongoDB all set up and ready to go,
2:36
and now we can just type mongo, and it tries to connect, we have mongo now but we really need to start it.
2:52
So we started up mongod, great, now we can connect to it. Awesome so it has some warnings again about access control
3:00
when we get to the deployment chapter, we're actually going to set up Ubuntu as a cloud server with some of these errors removed,
3:08
we're going to set it up with access control, with authentication, with firewalls, all sorts of things, but for now, for the dev version,
3:14
we're going to just use this, okay. So it looks like it's up and running, that's cool, now the last thing is maybe we want to configure our server;
3:23
so, we can come over here to /etc/mongod/conf and you can see we've got our storage path,
3:34
like here's where our data files are going to go, change that if you like, journaling, you generally want that on,
3:39
it's going to be running with wired tiger, it is an older style of database storage engine called this mmapv1,
3:46
that's how things used to work, they've switched the default to wired tiger
3:50
because it's faster, I believe it's much faster for inserts a little faster for reads,
3:54
here's where the log file goes, if it's not working and you want to see what's going on.
3:59
So most importantly though is this bit right there, this bindIp. So the bindIp is set to 127.0.0.1, we should have our firewall turned on anyway,
4:09
we shouldn't be exposing this port, but we're only listening on the local host, I think this machine actually right now has two ip adresses,
4:17
one public ipv6 and one net ipv4 ip address, but it's not listening on either of them because of this, right.
4:25
So it's super important that this is here, otherwise if someone can get to this port on your machine
4:31
and you don't set up authentication, bad things happen. All right, so make sure this is here, and only change that on your staging servers
4:39
and other things where you control the network, much more carefully. Again, we'll talk way more about this in the deployment section
4:45
but for now, this should do for our development environment. The other things we'll have to do is we want to set up a RoboMongo,
4:51
we want to set up PyCharm, and we want to make sure that we have Python 3 on here, I believe we do, 3.5.3 is more than late enough,
5:01
so we don't need to install any Python, but be sure to get RoboMongo and PyCharm, whichever version you want set up so that you can follow along.