본문 바로가기

TIL

[TIL-151] 위코드 63일차 : AWS 배포

AWS 배포

더보기

☁  ~  cd Desktop
☁  Desktop  cd WantU
☁  WantU  ssh -i 54.180.151.133
jeonseulgi@54.180.151.133: Permission denied (publickey).
☁  WantU  ssh -i  ubuntu@54.180.151.133
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1060-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Mar 27 05:00:00 UTC 2022

  System load:  0.0               Processes:           97
  Usage of /:   25.7% of 7.69GB   Users logged in:     0
  Memory usage: 28%               IP address for eth0: 프라이빗 IP
  Swap usage:   0%

 * Ubuntu Pro delivers the most comprehensive open source security and
   compliance features.

   https://ubuntu.com/aws/pro

16 updates can be applied immediately.
To see these additional updates run: apt list --upgradable


*** System restart required ***
Last login: Fri Mar 18 13:27:19 2022 from ...
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ip-...:~$ ls
ubuntu@ip-...:~$ pwd
/home/ubuntu
ubuntu@ip-...:~$ git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
ubuntu@ip-...:~$ git clone https://github.com/JUNSEULGI/AWS-practice.git
Cloning into 'AWS-practice'...
remote: Enumerating objects: 67, done.
remote: Counting objects: 100% (67/67), done.
remote: Compressing objects: 100% (61/61), done.
remote: Total 67 (delta 3), reused 67 (delta 3), pack-reused 0
Unpacking objects: 100% (67/67), done.
ubuntu@ip-...:~$ ls
AWS-practice
ubuntu@ip-...:~$ cd AWS-practice/
ubuntu@ip-...:~/AWS-practice$ ls
README.md  package-lock.json  package.json  public  src
ubuntu@ip-...:~/AWS-practice$ npm install

Command 'npm' not found, but can be installed with:

sudo apt install npm

ubuntu@ip-...:~/AWS-practice$ curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -

## Installing the NodeSource Node.js 14.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2490 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Fetched 2742 kB in 1s (2772 kB/s)
Reading package lists... Done

## Confirming "bionic" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_14.x/dists/bionic/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
gpg: WARNING: unsafe ownership on homedir '/home/ubuntu/.gnupg'

## Creating apt sources list file for the NodeSource Node.js 14.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x bionic main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x bionic main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease
Get:4 https://deb.nodesource.com/node_14.x bionic InRelease [4584 B]
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Get:6 https://deb.nodesource.com/node_14.x bionic/main amd64 Packages [769 B]
Fetched 5353 B in 1s (5227 B/s)
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn


ubuntu@ip-...:~/AWS-practice$ sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python
  python-minimal python2.7 python2.7-minimal
Suggested packages:
  python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib nodejs python
  python-minimal python2.7 python2.7-minimal
0 upgraded, 8 newly installed, 0 to remove and 17 not upgraded.
Need to get 29.5 MB of archives.
After this operation, 140 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython2.7-minimal amd64 2.7.17-1~18.04ubuntu1.6 [335 kB]
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python2.7-minimal amd64 2.7.17-1~18.04ubuntu1.6 [1291 kB]
Get:3 https://deb.nodesource.com/node_14.x bionic/main amd64 nodejs amd64 14.19.1-1nodesource1 [25.5 MB]
Get:4 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 python-minimal amd64 2.7.15~rc1-1 [28.1 kB]
Get:5 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython2.7-stdlib amd64 2.7.17-1~18.04ubuntu1.6 [1917 kB]
Get:6 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python2.7 amd64 2.7.17-1~18.04ubuntu1.6 [248 kB]
Get:7 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 libpython-stdlib amd64 2.7.15~rc1-1 [7620 B]
Get:8 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 python amd64 2.7.15~rc1-1 [140 kB]
Fetched 29.5 MB in 1s (55.4 MB/s)
Selecting previously unselected package libpython2.7-minimal:amd64.
(Reading database ... 113840 files and directories currently installed.)
Preparing to unpack .../0-libpython2.7-minimal_2.7.17-1~18.04ubuntu1.6_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.17-1~18.04ubuntu1.6) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../1-python2.7-minimal_2.7.17-1~18.04ubuntu1.6_amd64.deb ...
Unpacking python2.7-minimal (2.7.17-1~18.04ubuntu1.6) ...
Selecting previously unselected package python-minimal.
Preparing to unpack .../2-python-minimal_2.7.15~rc1-1_amd64.deb ...
Unpacking python-minimal (2.7.15~rc1-1) ...
Selecting previously unselected package libpython2.7-stdlib:amd64.
Preparing to unpack .../3-libpython2.7-stdlib_2.7.17-1~18.04ubuntu1.6_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.17-1~18.04ubuntu1.6) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../4-python2.7_2.7.17-1~18.04ubuntu1.6_amd64.deb ...
Unpacking python2.7 (2.7.17-1~18.04ubuntu1.6) ...
Selecting previously unselected package libpython-stdlib:amd64.
Preparing to unpack .../5-libpython-stdlib_2.7.15~rc1-1_amd64.deb ...
Unpacking libpython-stdlib:amd64 (2.7.15~rc1-1) ...
Setting up libpython2.7-minimal:amd64 (2.7.17-1~18.04ubuntu1.6) ...
Setting up python2.7-minimal (2.7.17-1~18.04ubuntu1.6) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python-minimal (2.7.15~rc1-1) ...
Selecting previously unselected package python.
(Reading database ... 114588 files and directories currently installed.)
Preparing to unpack .../python_2.7.15~rc1-1_amd64.deb ...
Unpacking python (2.7.15~rc1-1) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_14.19.1-1nodesource1_amd64.deb ...
Unpacking nodejs (14.19.1-1nodesource1) ...
Setting up nodejs (14.19.1-1nodesource1) ...
Setting up libpython2.7-stdlib:amd64 (2.7.17-1~18.04ubuntu1.6) ...
Setting up python2.7 (2.7.17-1~18.04ubuntu1.6) ...
Setting up libpython-stdlib:amd64 (2.7.15~rc1-1) ...
Setting up python (2.7.15~rc1-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
ubuntu@ip-...:~/AWS-practice$ node -v
v14.19.1
ubuntu@ip-...:~/AWS-practice$ npm -v
6.14.16
ubuntu@ip-...:~/AWS-practice$ npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> core-js@3.21.1 postinstall /home/ubuntu/AWS-practice/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js:
https://opencollective.com/core-js
https://patreon.com/zloirock
https://paypal.me/zloirock
> bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.21.1 postinstall /home/ubuntu/AWS-practice/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1412 packages from 678 contributors and audited 1413 packages in 40.459s

169 packages are looking for funding
  run `npm fund` for details

found 15 vulnerabilities (2 moderate, 13 high)
  run `npm audit fix` to fix them, or `npm audit` for details
ubuntu@ip-172-31-3-135:~/AWS-practice$ npm run build

> wantu-project@0.1.0 build /home/ubuntu/AWS-practice
> react-scripts build

Creating an optimized production build...
Compiled with warnings.

src/pages/Job/Job.js
  Line 35:6:  React Hook useEffect has missing dependencies: 'id' and 'token'. Either include them or remove the dependency array                                                                                                                           react-hooks/exhaustive-deps
  Line 45:6:  React Hook useEffect has a missing dependency: 'applier'. Either include it or remove the dependency array. You can also do a functional update 'setApplier(a => ...)' if you only need 'applier' in the 'setApplier' call                    react-hooks/exhaustive-deps
  Line 78:6:  React Hook useEffect has missing dependencies: 'token' and 'userData'. Either include them or remove the dependency array. You can also do a functional update 'setUserData(u => ...)' if you only need 'userData' in the 'setUserData' call  react-hooks/exhaustive-deps

src/pages/Main/Main.js
  Line 23:6:  React Hook useEffect has a missing dependency: 'getToken'. Either include it or remove the dependency array                               react-hooks/exhaustive-deps
  Line 45:6:  React Hook useEffect has missing dependencies: 'area', 'category', 'sort', and 'tag'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

src/pages/Mypage/Mypage.js
  Line 24:6:  React Hook useEffect has missing dependencies: 'fileLoad' and 'token'. Either include them or remove the dependency array  react-hooks/exhaustive-deps
  Line 46:6:  React Hook useEffect has missing dependencies: 'fileLoad' and 'token'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

File sizes after gzip:

  52.64 kB  build/static/js/main.c6e490f5.js
  3.65 kB   build/static/css/main.08655662.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment

ubuntu@ip-...:~/AWS-practice$ ls
README.md  build  node_modules  package-lock.json  package.json  public  src

~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"server.js" [New File]                                        0,0-1         All
const http = require("http");
ubuntu@ip-...:~/AWS-practice$ npm install express --save
npm WARN fork-ts-checker-webpack-plugin@6.5.0 requires a peer of typescript@>= 2.7 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ express@4.17.3
updated 1 package and audited 1414 packages in 12.074s

167 packages are looking for funding
  run `npm fund` for details

found 15 vulnerabilities (2 moderate, 13 high)
  run `npm audit fix` to fix them, or `npm audit` for details
ubuntu@ip-...:~/AWS-practice$ ls
README.md  build  node_modules  package-lock.json  package.json  public  src
ubuntu@ip-...:~/AWS-practice$ vi server.js
ubuntu@ip-...:~/AWS-practice$ ls
README.md  node_modules       package.json  server.js
build      package-lock.json  public        src
ubuntu@ip-...:~/AWS-practice$ node server.js
app listening at 8000
^C
ubuntu@ip-...:~/AWS-practice$ node server.js &
[1] 564
ubuntu@ip-...:~/AWS-practice$ app listening at 8000

  1. AWS에서 EC2 서버를 생성한다.
    1. 인스턴스 생성.
    2. 키를 잘 보관한다.
  2. 생성한 우분투 서버를 연다.
    1. ssh -i ${key 이름} ubuntu@${퍼블릭 IP}
    2. key 이름은 터미널에서 현재 위치가 키가 위치한 곳이 아니라면 경로까지 붙여줘야 한다.
    3. 프라이빗 IP도 있는데 퍼블릭 IP를 써야 하고, 앞에 ubuntu@를 붙여야 한다.
  3. 배포할 repository를 클론한다.
    1. "git"이라고 명령어를 입력해보면, git은 사용할 수 있는 상태다.
  4. 코드가 동작하기 위해 필요한 환경을 만든다.
    1. nodejs 설치
    2. npm install
  5. nodejs로 프론트 코드 돌릴 서버를 만든다.
    1. express 설치
    2. vi로 server.js 파일 만들어 코드 작성
      1. 포트는 8000번을 허용
      2. 모든 루트에 대해 index.html을 응답함
  6. 빌드하여 서버를 돌린다.
    1. npm start는 개발자 모드였던 것. 실제로 배포할 때는 이렇게 소스 코드가 전부 노출되어서는 안 됨.
    2. npm run build 하면 product mode.
    3. 만들어둔 서버 파일을 실행한다. node server.js