ubuntu에 ghost를 올려서 사용해 보니 기능을 변경해야 될 부분들이 보여 이번엔  source를 통해 설치해보도록 하겠습니다.

 

ubuntu를 사용하는 새로운 ec2를 생성하여 작업하도록 하겠습니다.

ghost는 node를 사용하므로 node설치를 먼저 해줍니다. 설치는 이전 포스팅을 참고하세요.

https://sound-story.tistory.com/28

 

[ec2] ubuntu에 node 설치하기

ubuntu 20.04 버전에 node.js를 설치해봅니다. node는 서버 프로그래밍을 위한 js 런타임으로 javaScript로 확장 가능한 백엔드 기능을 개발할 수 있습니다. 1. CURL 설치 node를 설치하기 전 커맨드 라인 툴을

sound-story.tistory.com

 

이번 포스팅은 ghost.org의 아래 가이드를 따라 했습니다.

https://ghost.org/docs/install/source/

 

Ghost Docs

Everything you need to know about working with the Ghost professional publishing platform.

ghost.org

 

가이드에 따르면 yarn 패키지를 사용하므로 yarn을 설치합니다. 이전에 npm을 설치하였기에 sudo npm install -g yarn 명령어로 설치합니다.

$ sudo npm install -g yarn

> yarn@1.22.18 preinstall /usr/local/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.22.18
added 1 package in 2.439s

1. global package 설치

$ yarn global add knex-migrator ember-cli
yarn global v1.22.18
[1/4] Resolving packages...
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request > har-validator@5.1.5: this library is no longer supported
warning ember-cli > broccoli > sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
warning ember-cli > broccoli-babel-transpiler > @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning ember-cli > broccoli-babel-transpiler > @babel/polyfill > core-js@2.6.12: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning ember-cli > broccoli-concat > fast-sourcemap-concat > source-map-url@0.3.0: See https://github.com/lydell/source-map-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[2/4] Fetching packages...
error knex@2.0.0: The engine "node" is incompatible with this module. Expected version ">=12". Got "10.19.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

node 버전 문제로 인해 error가 발생합니다.

12 이상의 node버전이 필요하므로 node update를 먼저 실행하고 진행합니다. (위에서 언급한 node설치 포스팅을 참고하세요.)

global package를 다시 설치해보니 이번엔 잘 됩니다.

$ yarn global add knex-migrator ember-cli
yarn global v1.22.18
[1/4] Resolving packages...
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning knex-migrator > ghost-ignition > bunyan-loggly > node-loggly-bulk > request > har-validator@5.1.5: this library is no longer supported
warning ember-cli > broccoli > sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
warning ember-cli > broccoli-babel-transpiler > @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning ember-cli > broccoli-babel-transpiler > @babel/polyfill > core-js@2.6.12: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning ember-cli > broccoli-concat > fast-sourcemap-concat > source-map-url@0.3.0: See https://github.com/lydell/source-map-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning ember-cli > broccoli > sane > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "knex-migrator@4.2.10" with binaries:
      - knex-migrator
      - knex-migrator-init
      - knex-migrator-health
      - knex-migrator-migrate
      - knex-migrator-reset
      - knex-migrator-rollback
success Installed "ember-cli@4.3.0" with binaries:
      - ember
Done in 37.60s.

 

Ghost와 Ghost-admin repository를 받아옵니다.

$ git clone https://github.com/TryGhost/Ghost.git
Cloning into 'Ghost'...
remote: Enumerating objects: 154171, done.
remote: Counting objects: 100% (1085/1085), done.
remote: Compressing objects: 100% (628/628), done.
remote: Total 154171 (delta 618), reused 854 (delta 452), pack-reused 153086
Receiving objects: 100% (154171/154171), 68.28 MiB | 11.05 MiB/s, done.
Resolving deltas: 100% (104825/104825), done.
$ git clone https://github.com/TryGhost/Admin.git
Cloning into 'Admin'...
remote: Enumerating objects: 119161, done.
remote: Counting objects: 100% (571/571), done.
remote: Compressing objects: 100% (249/249), done.
remote: Total 119161 (delta 356), reused 513 (delta 320), pack-reused 118590
Receiving objects: 100% (119161/119161), 61.51 MiB | 11.27 MiB/s, done.
Resolving deltas: 100% (84280/84280), done.

 

다운로드한 Ghost로 이동하여 실행합니다.

~/Ghost$ yarn start
yarn run v1.22.18
warning ghost@4.46.0: The engine "cli" appears to be invalid.
$ node index
[2022-05-18 05:50:53] INFO Ghost is running in development...
[2022-05-18 05:50:53] INFO Listening on: 127.0.0.1:2368
[2022-05-18 05:50:53] INFO Url configured as: http://localhost:2368/
[2022-05-18 05:50:53] INFO Ctrl+C to shut down
[2022-05-18 05:50:53] INFO Ghost server started in 2.136s
[2022-05-18 05:50:54] INFO Database is in a ready state.
[2022-05-18 05:50:54] INFO Ghost database ready in 2.726s
[2022-05-18 05:50:59] INFO Stripe not configured - skipping migrations
[2022-05-18 05:50:59] INFO Ghost URL Service Ready in 8.238s
[2022-05-18 05:50:59] INFO Ghost booted in 8.417s
[2022-05-18 05:50:59] INFO Adding offloaded job to the queue
[2022-05-18 05:50:59] INFO Scheduling job update-check at 2 53 15 * * *. Next run on: Wed May 18 2022 15:53:02 GMT+0000 (Coordinated Universal Time)

접속해 보니 정상적으로 뜨는 것을 확인할 수 있습니다.

728x90
반응형

지난번 docker를 설치한 ubuntu서버에 ghost를 올려보도록 하겠습니다.

https://sound-story.tistory.com/26

 

[Ubuntu] docker 및 docker compose 설치하기

AWS EC2에 만든 ubuntu서버에 docker 및 docker compose를 설치해보겠습니다. 먼저 생성한 ec2에 연결합니다. > ssh -i "***.pem" ubuntu@ec2-***.ap-northeast-2.compute.amazonaws.com The authenticity of host..

sound-story.tistory.com

 

설치는 ghost.org의 가이드에 따라 실행하였습니다.

https://ghost.org/docs/install/ubuntu/

 

How to install & setup Ghost on Ubuntu 16.04, 18.04 and 20.04

A full production install guide for how to install the Ghost professional publishing platform on a production server running Ubuntu 16.04, 18.04 or 20.04.

ghost.org

1. nginx 설치

Ghost는 nginx 서버를 이용합니다. 따라서 nginx를 설치합니다.

$ sudo apt-get install nginx

http와 https 연결을 위해 방화벽을 허용해 줍니다.

$ sudo ufw allow 'Nginx Full'
Rules updated
Rules updated (v6)

 

2. MySQL 설치

MySQL을 사용하므로 설치합니다.

$ sudo apt-get install mysql-server

 

MySQL을 실행하여 root의 password를 설정합니다.

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.29-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '비밀번호';
Query OK, 0 rows affected (0.01 sec)

mysql을 빠져나옵니다.

mysql> quit
Bye

 

3. Node.js 설치

다음으로 node를 설치합니다.

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash
$ sudo apt-get install -y nodejs

 

4. Ghost-CLI 설치

Ghost-CLI는 Ghost를 빠르고 쉽게 사용하기 위한 commandline 툴입니다. npm 또는 yarn을 이용하여 설치할 수 있습니다.

$ sudo npm install ghost-cli@latest -g

 

5. Ghost 설치

생성할 sitename으로 디렉터리를 생성합니다.

sudo mkdir -p /var/www/'sitename'

ghost-admin 사용자를 추가합니다.

$ sudo adduser ghost-admin
Adding user `ghost-admin' ...
Adding new group `ghost-admin' (1001) ...
Adding new user `ghost-admin' (1001) with group `ghost-admin' ...
Creating home directory `/home/ghost-admin' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for ghost-admin
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n]

추가한 사용자에 superuser gorup을 부여합니다.

$ sudo usermod -aG sudo ghost-admin

위에서 생성한 폴더에 소유자를 변경합니다.

$ sudo chown ghost-admin:ghost-admin /var/www/'sitename'
[sudo] password for ghost-admin:

ll 명령어로 소유자가 변경됐음을 확인합니다.

$ ll
total 16
drwxr-xr-x  4 root        root        4096 May 16 06:17 ./
drwxr-xr-x 14 root        root        4096 May 16 05:54 ../
drwxr-xr-x  2 ghost-admin ghost-admin 4096 May 16 06:17 sitename/
drwxr-xr-x  2 root        root        4096 May 16 05:54 html/

755로 권한을 변경합니다.

$ sudo chmod 775 /var/www/sitename

생성한 폴더로 이동합니다.

cd /var/www/sitename

설치 프로세스를 시작합니다.

ghost install

다운로드 및 설치에 약간의 시간이 소요됩니다.

 

ghost 서비스가 올라오고 http://localhost:2368/ghost로 접속하니 잘 되네요.

 

728x90
반응형

AWS EC2에 만든 ubuntu서버에 docker 및 docker compose를 설치해보겠습니다.

 

먼저 생성한 ec2에 연결합니다.

> ssh -i "***.pem" ubuntu@ec2-***.ap-northeast-2.compute.amazonaws.com
The authenticity of host '***.ap-northeast-2.compute.amazonaws.com (xx.xxx.x.xxx)' can't be established.
ECDSA key fingerprint is SHA256:PcvcASLF420AQzOU5mzhCdy6D8OMMORUd29bpT6w0a8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-***.ap-northeast-2.compute.amazonaws.com,xx.xxx.x.xxx' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-1004-aws x86_64)

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

  System information as of Mon May 16 05:03:46 UTC 2022

  System load:  0.146484375       Processes:             105
  Usage of /:   5.0% of 28.90GB   Users logged in:       0
  Memory usage: 20%               IPv4 address for eth0: xxx.xx.xx.xxx
  Swap usage:   0%

0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ip-:~$

yes를 입력하여 접속하니, ec2를 처음 생성하여 위와 같이 뜹니다.

sudo apt-get update를 실행합니다.

ubuntu@ip-:~$  sudo apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:4 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Get:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [5109 B]
Hit:6 http://security.ubuntu.com/ubuntu jammy-security InRelease
Fetched 54.0 kB in 0s (114 kB/s)
Reading package lists... Done

 

apt 패키지 index를 업데이트하고 https를 통해 repository를 이용하기 위해 다음과 같이 설치합니다.

ubuntu@ip-:~$ sudo apt-get install -y ca-certificates \
    curl \
    software-properties-common \
    apt-transport-https \
    gnupg \
    lsb-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package
curl: (6) Could not resolve host: software-properties-common
curl: (6) Could not resolve host: apt-transport-https
curl: (6) Could not resolve host: gnupg
curl: (6) Could not resolve host: lsb-release

 

docker의 official GPG key를 등록합니다.

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

stable repository를 등록합니다.

ubuntu@ip-:~$  echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

 

sudo apt-get install docker-ce docker-ce-cli containerd.io 명령어로 docker Engine을 설치합니다.

ubuntu@ip-:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin libltdl7 libslirp0 pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libltdl7 libslirp0 pigz
  slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 28 not upgraded.
Need to get 102 MB of archives.
After this operation, 422 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy/main amd64 libltdl7 amd64 2.4.6-15build2 [39.6 kB]
Get:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61.5 kB]
Get:4 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB]
Get:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.6.4-1 [28.1 MB]
Get:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:20.10.16~3-0~ubuntu-jammy [40.6 MB]
Get:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:20.10.16~3-0~ubuntu-jammy [21.0 MB]
Get:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:20.10.16~3-0~ubuntu-jammy [8167 kB]
Get:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-jammy [3521 kB]
Fetched 102 MB in 3s (32.3 MB/s)
Selecting previously unselected package pigz.
(Reading database ... 63599 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.6-1_amd64.deb ...
Unpacking pigz (2.6-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.6.4-1_amd64.deb ...
Unpacking containerd.io (1.6.4-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.16~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.16~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.16~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce (5:20.10.16~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.16~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.16~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.17.0~ubuntu-jammy_amd64.deb ...
Unpacking docker-scan-plugin (0.17.0~ubuntu-jammy) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../6-libltdl7_2.4.6-15build2_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-15build2) ...
Selecting previously unselected package libslirp0:amd64.
Preparing to unpack .../7-libslirp0_4.6.1-1build1_amd64.deb ...
Unpacking libslirp0:amd64 (4.6.1-1build1) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../8-slirp4netns_1.0.1-2_amd64.deb ...
Unpacking slirp4netns (1.0.1-2) ...
Setting up docker-scan-plugin (0.17.0~ubuntu-jammy) ...
Setting up containerd.io (1.6.4-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up libltdl7:amd64 (2.4.6-15build2) ...
Setting up docker-ce-cli (5:20.10.16~3-0~ubuntu-jammy) ...
Setting up libslirp0:amd64 (4.6.1-1build1) ...
Setting up pigz (2.6-1) ...
Setting up docker-ce-rootless-extras (5:20.10.16~3-0~ubuntu-jammy) ...
Setting up slirp4netns (1.0.1-2) ...
Setting up docker-ce (5:20.10.16~3-0~ubuntu-jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

 

설치 완료docker --version으로 버전을 확인합니다.

ubuntu@ip-:~$ docker --version
Docker version 20.10.16, build aa7e414

 

다음으로 docker compose를 설치합니다.

docker compose는 docker설치 시 함께 설치되지 않으므로 별도로 설치해주어야 하며, 여러 개의 도커 애플리케이션 컨테이너들을 정의하고 실행할 수 있도록 해줍니다. yaml파일을 사용하여 서비스를 설정하고 하나의 커맨드만으로 여러 개의 도커 컨테이너들을 사용할 수 있습니다.

ubuntu@ip-:~$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 12.1M  100 12.1M    0     0  14.7M      0 --:--:-- --:--:-- --:--:-- 44.4M

 

실행 권한을 부여합니다.

ubuntu@ip-:~$ sudo chmod +x /usr/local/bin/docker-compose

 

docker compose 또한 docker-compse --version 명령을 통해 잘 설치되었는지 확인해봅니다.

ubuntu@ip-:~$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c

 

728x90
반응형

로그인 후에 Access Token을 발급하여 쿠키에 저장하는 것까지 구현해 보았습니다.

https://sound-story.tistory.com/19

 

[NestJS] Auth Token을 쿠키에 저장하기

email, password를 통해 로그인하여 access token을 생성하고, 생성된 access token으로 사용자 정보를 조회해 보는 것을 해보았어요. 이어서 token을 쿠키에 저장하는 로직을 구현해 보려고 합니다. 1. cookie-p

sound-story.tistory.com

오늘은 Refresh Token을 구현하기에 앞서 인증의 개념에 대해서 정리하고 시작해 보려고 합니다.

먼저 저희가 acces token발급 시 사용했던 JWT에 관한 얘기입니다.

로그인하면 제일 많이 들어본 거 같아요. 많이 쓰이기 때문에 많이 들어봤겠죠.

 

JWT란?

JSON Web Token의 약어로, 마이크로 서비스의 인증, 인가에 사용할 수 있는 JSON입니다.

서버와 클라이언트 간 정보를 주고받을 때 HTTP Request Header에 JSON토큰을 넣은 후 서버는 별도의 인증과정 없이 헤더에 포함되어 있는 JWT 정보를 통해 인증하게 됩니다.

이렇게 사용되는 JSON 데이터는 URL로 이용할 수 있는 문자 만으로 구성되게 됩니다.

 

JWT는 header, payload, signature로 구성되어 있고, 각 요소는  '.'으로 구분되어 있습니다.

jwt 구성 요소 ( jwt 구조)

실제로 저희가 구현해서 발급했던 토큰을 살펴보니 3개의 구성이 눈에 보입니다.

jwt token

이 토큰을 가지고 공식 홈페이지에서 Decoded를 해보았습니다.

https://jwt.io/

 

JWT.IO

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

jwt.io

 

 

Encoded에 토큰을 입력하니 Decoded 되어 Header, Payload, Verify Signature 정보가 보입니다.

1. Header : 어떤 알고리즘이 사용되었는지에 대한 "alg"와 JWT의 유형 정보를 가진 "typ"이 있습니다.

  • "alg" : 토큰을 암호화하는 알고리즘 정보입니다. 저는 "HS256"으로 토큰을 암호화했다는 뜻입니다. 알고리즘은 "HS256"외에도 "HS512"(HMAC), "SHA256", "RSA" 등이 있습니다.
  • "typ" : 토큰의 유형 정보입니다. 저는 JWT를 사용했습니다.

 

2. Payload : 클레임(claim) 정보가 저장됩니다. 클레임은 정보 '조각'이라는 의미로, 토큰 또는 사용자에 대한 property를 <key : value>의 형태로 저장할 수 있습니다. 저는 사용자의 id와 이름, 토큰 발급 시간, 토큰 만료 시간을 payload로 사용했는데요. jwt.io에서 보면 registered, public, private claim 3가지가 있습니다.

  • Registered claims : 필수 사항은 아니지만 권장되는 claim입니다. iss(발급자), expiration(유효기간), subject(제목), aud(청취자) 등 이 있습니다. 자세한 정보는 https://datatracker.ietf.org/doc/html/rfc7519#section-4.1에서 확인할 수 있습니다.
  • Public claims : 원하는 대로 정의할 수 있는 claim으로 충돌을 피하려면 IANA JSON Web 토큰 레지스트리에서 정의하거나 충돌 방지 네임스페이스를 포함하는 URI로 정의해야 합니다.
  • Private claims : 사용에 동의한 당사자 간에 정보를 공유하기 위해 작성된 custom claim입니다.

3. Signature : 암호화가 되어 있기 때문에 구조를 보여줍니다. 암호화된 헤더, 암호화된 페이로드, 시크릿(사용자가 정한 시크릿 키), 알고리즘으로 되어 있어요. 저희는 HMAC SHA256 알고리즘을 사용하였네요.

jwt 구성 요소 ( jwt 구조)

JWT 인증과정

그렇다면 발급된 token은 어떻게 쓰일까요?

1. 애플리케이션, 사용자가 인증서버에 인증을 요청합니다. 

2. 인증에 성공하면 인증서버는 액세스 토큰을 반환합니다.

3. 애플리케이션 또는 사용자는 발급된 액세스 토큰으로 API 서버에 접속할 수 있게 됩니다.

jwt process / jwt 프로세스 (https://jwt.io/introduction)

 

JWT 왜 쓸까요?

그렇다면 어떠한 이유에서 JWT를 사용할까요.

JWT의 장단점에 대해 생각해보겠습니다.

 

JSON은 XML보다 장황하지 않기 때문에 암호화 시 사이즈가 작아져 JWT가 SAML보다 콤팩트합니다. 때문에 HTML 및 HTTP 환경에서 JWT를 사용하는 것이 효율적입니다.

보안상 SWT는 HMAC 알고리즘을 사용하여 공유 비밀에 의해서만 대칭적으로 서명할 수 있습니다. 단, JWT 토큰과 SAML 토큰은 X.509 증명서 형식으로 공개 키와 개인 키 쌍을 서명에 사용할 수 있습니다. 불분명한 보안 취약점을 도입하지 않고 XML 디지털 서명을 사용하여 XML에 서명하는 것은 JSON의 간단한 서명에 비해 매우 어렵습니다.

JSON 파서는 오브젝트에 직접 매핑되기 때문에 대부분의 프로그래밍 언어에서 일반적입니다. 반대로 XML에는 문서와 객체의 자연스러운 매핑이 없습니다. 이를 통해 SAML 어설션보다 JWT를 사용하는 것이 쉬워집니다.

이용에 관해서는 JWT를 인터넷 규모로 사용하고 있습니다. 이를 통해 여러 플랫폼(특히 모바일)에서 클라이언트 측 JSON Web 토큰을 쉽게 처리할 수 있습니다.

 

하지만, JWT에도 한계는 있습니다. 개발자의 학습영역? 범위가 끝이 없는 이유는 100% 완벽하다고 끝내기가 없어서이지 않을까 싶습니다.

구현하고 decode를 하면서 든 의문입니다.

저희가 payload에 저장하였던 email과 이름은 민감정보가 아닐까요? 이를 오픈해도 될까요?

token을 발급하고 만약 payload에 저장된 정보가 변경되었다면, payload에서 decode 한 정보와 현재 정보는 일치하지 않네요?

JWT는 토큰의 상태를 저장하지 않습니다. Stateless 이 특성 때문에 한번 만들어진 토큰을 제어할 수 없다는 단점이 있어요. 임의로 삭제할 수 없으니 만료시간이 중요한데, 이를 길게 하면 데이터나 보안이 취약해지고, 짧게 하자니 로그인을 자주 해야 하는 문제가 발생합니다. 이에 대한 대안으로 refresh token, sliding session이 많이 사용되고 있는데요.

 

JWT의 대안

1. Refresh token

JWT를 발급할 때 Access Token과 함께 Refresh Token을 함께 발급하여 Access Token의 짧은 만료시간의 문제를 해결하는 방법입니다. Access Token은 1분, 3분의 짧은 시간을 부여하고 Refresh Token에는 일주일, 2주의 비교적 긴 만료시간을 부여하여 Access Token을 보장해주는 방법입니다. Access Token이 만료되면 Refresh Token으로 서버에게 새로운 Access Token을 발급하도록 합니다.

 

2. Sliding Session

sliding session은 서비스를 사용 중인 유저에 대해서 만료시간을 연장시켜 주는 방법입니다.

쇼핑몰에 접속하여 계속 쇼핑을 하고 있으면 만료시간을 연장하여 쇼핑, 결제 등의 서비스를 지속적으로 이용 가능하도록 하는 방법입니다. 

 

앞으로는 refresh token에 대해서 구현해 보도록 하겠습니다.

 

728x90
반응형

회사에서 모니터를 32인치로 바꿔주었어요. 이제 노트북 화면은 볼일이 없어지고, 모니터를 나눠서 사용하려고 하는데, 왼쪽은 더 크게 하고 싶었습니다.

삼성에 찾아보니 "Easy Setting Box"라는 프로그램을 이용해서 가능하더군요.

 

1. 분할 프로그램 "Easy Setting Box" 설치하기

https://www.samsung.com/sec/consumer/learningresources/monitor/EasySettingBox/EasySettingBox/

 

Easy Setting Box 프로그램 설치

Easy Setting Box 프로그램 설치

www.samsung.com

 

PC 사양에 맞는 설치 파일을 다운로드합니다. 아쉽게도 window만 지원하네요.

 

2. 분할 프로그램 "Easy Setting Box" 실행 및 설정

프로그램을 화면이에요. 저는 1번이 노트북, 2번이 모니터입니다.

노트북은 그대로 두고 2번 모니터에 적용할 [화면 분할 방식]을 선택하고 [영역 조절]을 클릭합니다.

빨간색으로 영역이 보이고 이를 드래그하여 조절해줍니다.

저는 왼쪽에는 코딩 화면, 오른쪽엔 도큐먼트나 메모장을 주로 열어서 이렇게 세팅하였어요.

[나가기]를 누르면 분할 설정이 완료됩니다.

사용 방법은 창을 이동하면 상단에 어느 분할화면에 위치시킬지 창이 뜹니다.

왼쪽에 위치해 볼께요.

원하는 위치에 놓으면 창크기 조절 완료!

 

아주 편리합니다.

그럼 오늘도 즐거운 개발되세요.

 

 

+ 일부 프로그램에서 적용되지 않을 수 있다더니...

vscode는 되지 않네요ㅠㅠ

728x90
반응형

구글 검색에 등록하고 나니 네이버에서는 안될까 라는 생각이 들었습니다.

그래서 네이버도 서치 콘솔도 찾아보았어요.

네이버에서는 '서치 어드바이저'라고 부르네요.

 

먼저 네이버로 서치어드바이저로 들어가 주세요.

https://searchadvisor.naver.com/

 

네이버 서치어드바이저

네이버 서치어드바이저와 함께 당신의 웹사이트를 성장시켜보세요

searchadvisor.naver.com

 

 

로그인이 완료되면 [웹마스터 도구]로 들어갑니다.

티스토리 주소를 입력하면 사이트 소유확인 페이지로 넘어갑니다.

저희는 구글에서 했던 방법과 동일하게 HTML 태그로 인증하도록 하겠습니다.

<meta~로 시작하는 태그를 복사해 주세요.

음 아쉽게도 네이버는 자동 복사 버튼이나 기능이 없어서 태그를 선택해서 복사합니다.

 

다음은 블로그 관리 홈으로 들어가 주세요.

메뉴 중 [꾸미기] - [스킨 편집] - [html 편집]을 선택해 줍니다.

이번엔 구글 서치 아래쪽에 네이버 서치 어드바이저를 붙여볼게요.

구글 서치 등록되어 있는 거 보이시죠?

아래에 복사한 <meta 태그 붙여 넣기 후 적용하면 됩니다.

 

그럼 다시 네이버 서치 어드바이저로 돌아와서 [소유확인]을 클릭해주면 

자동 등록 방지 보안 문자 입력 후 확인하여 등록을 완료합니다.

 

728x90
반응형

블로그를 시작하고 글을 올리면 자동으로 구글에 검색되는 줄 알았어요;;;

but!!! 구글 서치 콘솔(Google Search Console)에 인증을 받아야 검색이 되는 거였습니다.

 

방법은 5분도 안 걸릴 만큼 간단해요!! 

https://search.google.com/search-console/about

 

Google Search Console

Search Console 도구와 보고서를 사용하면 사이트의 검색 트래픽 및 실적을 측정하고, 문제를 해결하며, Google 검색결과에서 사이트가 돋보이게 할 수 있습니다.

search.google.com

 

구글 서치콘솔로 들어가 주세요.

 

시작하기로 들어가면 도메인과 URL 접두어 선택하도록 나와요.

저희는 xxx.tistory.com로 URL을 사용하고 있으므로 URL 접두어를 선택해주고,

"https://xxx.tistory.com" 형태로 본인의 블로그 주소를 입력하면 됩니다.

입력 후 계속!!

 

그럼 소유권 확인이라는 창이 뜰 거예요.

권장 확인 방법, 다른 확인 방법 중 저희는 다른 확인 방법에 있는 HTML 태그를 이용해 보겠습니다.

 

<meta~ 로 시작하는 태그를 복사해 주세요.

 

다음은 블로그 관리 홈으로 들어가 주세요.

메뉴 중 [꾸미기] - [스킨 편집] - [html 편집]을 선택해 줍니다.

아래의 화면이 나오게 돼요.

그럼 아까 복사해둔 <meta~로 시작하는 태그를

<head> 영역에 붙여 넣고 적용!

 

다음으로 다시 구글 서치 콘솔로 돌아와 [확인] 버튼을 클릭해주세요.

그럼 인증 확인 후에

 

위와 같이 완료됩니다!

 

구글 검색창에서 제 블로그를 볼 수 있는 날까지! 열심히 포스팅해볼게요.

728x90
반응형

git 생성 후 확인해보니 내 이름이 이상하게 뜬다;;;

LAPTOP-XXXXXX\PC사용자명 형태로 말이다. 이를 바꿔보자.

먼저 git관련 설정을 확인해보자.

 git config --list

user.name이 LAPTOP-XXX로 설정되어 있는 것을 볼 수 있다. 아마도 다른 설정을 안 하면 기본적으로 이렇게 설정되는 것 같다.

이를 상콤하게 "sound"로 변경한다.

git config --global user.name "sound"

후에 "git config --list" 명령어로 확인하니 변경되었다.

앞으로는 sound로 push push 하겠어요!

728x90
반응형

+ Recent posts