Server setup Flashcards

1
Q

What are the types of DNS records?

A

A records: map a name to an IP address.

CNAME: maps name to name (e.g. a subdomain first maps to the domain name, which then maps to the IP address).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bash command for running previous command as sudo?

A

sudo !!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

bash command for opening a file and showing me anything new that happens in it in real time

A

sudo tail -f /var/log/auth.log (tail shows end of the file, -f is for follow, which means it always shows the bottom even after updates)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a very good way to debug a server when you can’t figure out what is going on?

A

“sudo tail -f” your log files and then log in to the server and see what the log file reveals…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does sshd stand for?

A

ssh daemon. it is a service that is always running in the background. you can edit it (for example to prevent root login) using $vi /etc/ssh/sshd_config.
If you updated it, you would have to restart the service so it picks up the new config: $sudo service sshd restart

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is nginx?

A

One of the most popular web servers (another popular one is apache…which goes super well with PHP). Nginx is lightweight and extremely fast.

  • reverse proxy (takes a single request and can route it to a number of different places)
  • web server
  • proxy server (takes a number of requests and can route them to a single place)
  • file server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a web server do?

A

It receives web traffic and does something with it (routes it somewhere).
When a request hits the server, it has to figure out where to go - should it go to the app, should it go to the db, should it go to a different server?
Nginx helps route the requests to the correct place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a proxy server? What is a reverse proxy server?

A
  • proxy server (takes a number of requests and can route them to a single place)
  • reverse proxy (takes a single request and can route it to a number of different places)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a directive in nginx?

A

A directive is a macro for doing something, e.g. try_files, which tries to find any of the files listed, and if it can’t find them it 404s, or proxy_pass, which passes your requests to another part of the server.

e.g.
location / {
proxy_pass http://127.0.0.1:3000/;
}

This basically tells nginx that any request it receives to / should be forwarded to port 3000 at this ip address, which is the port on which the express server is running, so it is basically saying let our app server handle any requests to /.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between a web server and an application server?

A

The web server just receives web traffic and does something with it. The application server does all the heavy lifting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is node.js?

A

It’s a single-threaded JS engine that executes JS and can handle requests.
It is a JS engine that runs on top of V8 (which was developed by google chrome) .
Single-threaded means that it can handle async very well, i.e. it doesn’t block the execution until a request returns a response. It’s easy for JS developers to take this single-threaded async nature for granted, but almost all other languages (e.g. python or java) are not like this, and if you make a request for a large piece of data it will block everything while you are waiting for the request to resolve.
This async nature of node is what is known as the event loop.
This is a good reason to use node for servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a good reason for using node for a server?

A

Because it is single-threaded. Single-threaded means that it can handle async very well, i.e. it doesn’t block the execution until a request returns a response. It’s easy for JS developers to take this single-threaded async nature for granted, but almost all other languages (e.g. python or java) are not like this, and if you make a request for a large piece of data it will block everything while you are waiting for the request to resolve.
This async nature of node is what is known as the event loop.

It is not the fastest, java or go are probably the fastest. You will rarely be limited by the speed of the engine that you’re using, but by the code that you wrote.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why is application architecture important?

A
Thinking about this is the difference between a junior engineer/programmer and a senior software engineer.
Thinking about:
- long-term maintainability
- how you arrange:
-- files
-- code

Migrating files is not fun.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a very basic example app architecture?

A
  • UI
    • css
    • js
    • html
  • helpers
  • utils
  • authentication
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Command line: how would you change a user’s permissions for a folder?

A

sudo chown -R $USER:$USER /opt/iul

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Command line: how can you chain two commands?

A

pwd && ls

17
Q

Command line: how do you set up a package.json, node modules, license, etc.

A

npm init

18
Q

Command line: what does npm init do?

A

It sets up the package.json, node modules, license, etc.

Basically a bunch of the stuff that create-react-app does under the hood.

19
Q

What is the difference between apt install and npm install?

A

apt install is for my linux machine, npm install is for my app. npm manages packages for my app, apt manages packages for my computer.

20
Q

Command line: how to install a node package and ensure that it persists if you pull the code to another device?

A

npm i express –save

without the save it only installs once

21
Q

Command line: what do you have to do if you update any files related to nginx config?

A

sudo service nginx reload

The service command is the high-level command for any daemon running in the background. For something like nginx, which you always want running, service is a good command.
systemctl is a way of managing your services at a lower level.

22
Q

What is a process manager?

A
  • keeps your application up and running
  • can handle errors and restarts
  • handles logging and clustering

example process managers: pm2 and forever
pm2 a bit cleaner to use

when you use pm2 you need to modify the startup file so that it creates a daemon that always runs/restarts the server. this is important, bc otherwise if you shut off the server everything will just go down.

23
Q

What are the steps of setting up an app from scratch?

A

Connect an IP, to a domain, to a server, to a web server (e.g. nginx), to an application server (e.g. express) and serve out data.

24
Q

What is the auth.log file? Where is it kept?

A

This is where you can see all attempts to access your server. It is located in /var/log/auth.log

25
Q

What is fail2ban?

A

It’s an application that dynamically alters firewall rules to ban addresses that have repeatedly attempted to access your server without authorisation.
If you are setting up a server for production, you will almost certainly want to use fail2ban.