1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Slides kho tài liệu bách khoa

140 63 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 140
Dung lượng 4,38 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Things you’ll learn● Learn how to use Node and Bash to create shell scripts ● Learn advanced Nginx configuration ● Common server vulnerabilities and how to mitigate them ● How to add HTT

Trang 1

Full Stack

for

Trang 2

Jem Young

Senior Software Engineer

Trang 3

Serious Business ● Slides ○ jemyoung.com/fsfe2

● Part 1

○ https://frontendmasters com/courses/full-stack/

○ jemyoung.com/fsfe

Trang 4

Things you’ll learn

● Learn how to use Node and Bash to create shell scripts

● Learn advanced Nginx configuration

● Common server vulnerabilities and how to mitigate them

● How to add HTTPS to your server

● Understand databases

● Containers and automating deployments

Trang 5

Full Stack For Frontend

Recap

Trang 6

● How the internet works

Trang 8

● How the internet works

● Command line basics

ping

traceroute

vi

Trang 10

● Command line basics

● How the internet works

● How to create and manage a web server

(your sweet new server)

Trang 11

● Build a basic web page

● Command line basics

● How the internet works

● How to create and manage a web server

● Create a deploy system for a Node app

Trang 12

Why full stack?

Trang 14

1 Create a new Ubuntu server

a Use Ubuntu 16.04.x

b Be sure to use an SSH key

2 Point domain to new server

3 Log into server as root

Create a server

Trang 15

Server setup

4 Update server

5 Add a new user ‘test’

6 Grant ‘test’ sudo access

7 Switch to ‘test’ user

Trang 16

Server setup - Node

$ curl -sL https://deb.nodesource.com/setup_6.x

| sudo E bash

-update apt repo for nodejs

https://explainshell.com/explain?cmd=curl+-sL

Trang 17

Server setup - Node

$ npm config get prefix check npm directory

$ sudo apt install nodejs install nodejs and npm

Trang 18

If the npm directory is not /usr/local,

follow instructions here

WARNING

Trang 19

Server setup - Node

https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-defau lt-directory-to-another-directory

Trang 20

Server setup - Node

$ npm i -g forever install forever module

Trang 21

Change working directory

Change working directory

Trang 22

Part 2

Server security

● Controlling access

● Securing applications

Trang 23

Secure your applications

- Keep software up to date

- Limit application use

Trang 24

Server security - add ssh key

$ mkdir -p ~/.ssh create a new directory

$ vi ~/.ssh/authorized_keys paste public key into

authorized_keys file

Trang 25

Be sure to test logging in with your

new user

WARNING

Trang 26

Server security

a use the passwd command

2 Disable root login

3 Disable password login

Trang 27

Server security - firewalls

Trang 28

nmap

Trang 29

$ nmap YOUR_SERVER_IP

Trang 30

Tales from real life

Trang 37

Server security - iptables

$ sudo iptables -A INPUT -p tcp dport 22 -j ACCEPT

-A append rule

-p protocol (tcp, icmp)

dport destination port

-j jump (DROP, REJECT, ACCEPT, LOG)

Trang 38

Creating iptable rules

Create an iptable rule to block all

outgoing HTTP connections

Trang 39

Creating iptable rules

iptables -A OUTPUT -p tcp dport 80 -j REJECT

Trang 40

Creating iptable rules

Create an iptable rule to only allow icmp connections on port 892 from the IP

address 192.0.0.1

Trang 41

Creating iptable rules

iptables -A INPUT -s 192.0.0.1 -p icmp dport 892 -j ACCEPT

Trang 42

There has to be a better

way!

Trang 43

Server security - ufw

$ sudo ufw allow ssh

$ sudo ufw enable

ufw - uncomplicated firewall

Trang 44

Create ufw rules

Create a ufw rule to block all outgoing

HTTP connections

Trang 45

Creating ufw rules

ufw reject out http

Trang 46

Server security - firewalls

Trang 48

Automatic Updates

Trang 49

Server security - update software

$ sudo apt install unattended-upgrades

Trang 50

Server security - update software

/etc/apt/apt.conf.d/20auto-upgrades

https://wiki.debian.org/UnattendedUpgrades

Trang 51

Server security - update software

/etc/apt/apt.conf.d/50unattended-upgrades

Trang 52

Fail2ban

Trang 53

$ sudo apt install fail2ban

$ sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Copy jail file

$ sudo vi /etc/fail2ban/jail.local

Install fail2ban

Trang 54

If you misconfigure fail2ban, you can

lock yourself out of your server!

WARNING

Trang 56

find search file names

search file contents

Finding things

Trang 57

find directory option file/folder

Finding things

Trang 59

find

Trang 60

Find all log files in /var/log/

$ find /var/log/ -type f -name *.log

Trang 61

Find all empty files in /etc

$ find /etc -type f -empty

Trang 62

Find all directories with the word log

$ find / -type d -name log

Trang 63

Searching contents

grep

grep - global regular expression print

$ grep -i ‘jem’ /var/www

grep options search

expression

directory

$ zgrep FILE search inside gzip file

Trang 64

Find running node processes

ps aux | grep node

Trang 65

Redirection

Trang 67

Write to file

ps aux > foo

Trang 68

What does this do?

Trang 69

foo < bar > baz

Trang 70

Shells

Trang 71

What is a shell?

Trang 72

shell application kernel

$ echo $0 show current shell

Trang 73

Changing shells

Trang 74

Changing shells

$ cat /etc/shells list acceptable shells to

change to

$ chsh -s /bin/sh change shell to ‘sh’

$ su $USERNAME login into new shell to see the

change

$ chsh -s /bin/bash change shell to ‘bash’

Trang 75

Differences between shells

https://en.wikipedia.org/wiki/Comparison_of_command_shells

Trang 76

Shell scripting

Trang 77

- simple

- portable

Why shell scripting

Trang 79

Bash scripting

Trang 80

Shell scripting - bash

$ vi load.sh

#!/bin/sh

cat /proc/loadavg | awk '{print $1"-"$2"-"$3}'

Trang 82

load average

1 minute

5 minute

15 minutes

Trang 83

$ sudo chmod 755 /load.sh Make executable

Trang 84

https://isabelcastillo.com/linux-chmod-permissions-cheat-sheet

Trang 85

Creating a shell script with Node

Trang 86

Node shell scripting - setup

$ mkdir ~/workspace create a workspace folder

$ cd ~/workspace move into workspace folder

$ touch index.js create index.js

Trang 87

Node shell scripting - setup

$ npm init initialize project

$ vi package.json

add reference to script

Trang 88

Node shell scripting

$ vi index.js

#!/usr/bin/node

const exec = require('child_process').exec; const stat = exec(`cat /proc/loadavg | awk '{print $1"-"$2"-"$3}'`);

stat.stdout.on('data', function(data) {

console.log(data);

});

Trang 89

https://frontendmasters.com/courses/bash-vim-regex/

Trang 91

Nginx setup

1 Install nginx

2 Proxy traffic to node server

3 Add domain name

4 Open port 443

Trang 92

Nginx setup - adding domain name

sudo vi /etc/nginx/sites-available/default

server_name jem.party www.jem.party;

Add domain name to nginx conf

Trang 94

https://github.com/diafygi/acme-tiny

Trang 95

https://certbot.eff.org/

Trang 96

$ sudo add-apt-repository ppa:certbot/certbot

$ sudo apt update

$ sudo apt install python-certbot-nginx

Add the certbot repository

Pull in new repository information

Install certbot with nginx plugin

Trang 97

$ sudo certbot nginx Use certbot to get certificate

$ sudo certbot renew dry-run Test auto renew

Trang 99

How to do we run periodic

tasks?

Trang 101

https://crontab.guru/

Trang 103

cron

Trang 106

Nginx - gzip

Trang 107

/etc/nginx/nginx.conf

Trang 108

Nginx - gzip

gzip_comp_level 6 increase compression level

http://nginx.org/en/docs/http/ngx_http_gzip_module.html

/var/etc/nginx/nginx.conf

Trang 109

Expires headers

Trang 110

Nginx - expires headers

Trang 111

location /static/ {

expires 30d;

proxy_pass http://127.0.0.1:3001/static/;}

expire static assets in 30 days

/etc/nginx/sites-available/default

Trang 112

Nginx - expires headers

Trang 113

caching

Trang 114

Nginx - cache

proxy_cache_path /tmp/nginx levels=1:2

keys_zone=slowfile_cache:10m inactive=60m use_temp_path=off;

proxy_cache_key "$request_uri";

/etc/nginx/sites-available/default

Trang 116

websockets

Trang 118

http/2

Trang 119

Nginx - http/2

listen 443 http2 ssl; # managed by Certbot

/etc/nginx/sites-available/default

https://http2.akamai.com/demo

Trang 120

Nginx - http/2

Trang 121

Redirect request to new url

location /help {

return 301 https://developer.mozilla.org/en-US/; }

/etc/nginx/sites-available/default

Trang 122

Part 6

databases

● Database types

● MySQL

Trang 123

Database types

Trang 124

MySQL

Trang 126

Database tips

1 Back up your database

2 Use a strong root password

3 Don’t expose the database outside the

network

4 Sanitize your SQL

5 Back up your database

Trang 127

https://github.com/mysqljs/mysql

Trang 129

Dedicated Server

Trang 130

the cloud

Trang 133

Containers

Trang 135

Installing Postgres on Docker

Trang 136

https://www.linux.com/news/8-open-source-CONTAIN ER-ORCHESTRATION-TOOLS-KNOW

Trang 137

Automating deployments

Trang 139

HOORAY!!

Ngày đăng: 16/11/2019, 21:01

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm