'2020/03'에 해당되는 글 24건

  1. 2020.03.31 [Docker] Ubuntu 에 Docker & Docker Compose 설치 하기
  2. 2020.03.31 [Docker] Amazon Linux 에 Docker & Compose 설치 하기.
  3. 2020.03.30 [Docker] Docker Compose 에서 volume 사용 하기
  4. 2020.03.30 [Docker] Image 다운로드 및 로컬 설치 하기
  5. 2020.03.27 [Elasticsearch] Single node 실행
  6. 2020.03.27 [Docker] Docker Registry 구성 키워드
  7. 2020.03.26 [AWS] Spring Cloud Config S3 Backend 사용하기
  8. 2020.03.25 [Ubuntu] add-apt-repository: command not found 발생 시
  9. 2020.03.23 [Certificate] 확장자에 따른 인증서 종류
  10. 2020.03.23 [AWS] IGW vs NAT GW

[Docker] Ubuntu 에 Docker & Docker Compose 설치 하기

Cloud&Container 2020. 3. 31. 15:59

ubuntu 18.04 에 docker & docker compose 설치)

 

# ubuntu user 로 설치
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
$ sudo apt-get remove docker docker-engine docker.io containerd runc
$ sudo apt-get update
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ apt-cache madison docker-ce
5:19.03.8~3-0~ubuntu-bionic

$ sudo apt-get install docker-ce=5:19.03.8~3-0~ubuntu-bionic docker-ce-cli=5:19.03.8~3-0~ubuntu-bionic containerd.io
$ sudo docker run hello-world

# https://docs.docker.com/compose/install/
# https://github.com/docker/compose 에서 latest version 을 확인 합니다.
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ docker-compose --version

$ docker-compose up
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
$ sudo usermod -aG docker ubuntu
$ newgrp docker
:

[Docker] Amazon Linux 에 Docker & Compose 설치 하기.

Cloud&Container/IaC 2020. 3. 31. 14:06

Amazon linux docker & docker-compose 설치)

$ sudo yum update
$ sudo yum install docker
$ docker version
...중략...
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
$ sudo service docker start
$ docker version
Got permission denied while trying to connect to the Docker daemon socket at 
unix:///var/run/docker.sock: 
Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: 
connect: permission denied
$ sudo docker version
$ sudo usermod -a -G docker ec2-user

# https://github.com/docker/compose 에서 latest version 을 확인 합니다.
$ sudo curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

$ docker-compose up
Couldn't connect to Docker daemon at http+docker://localhost - is it running?

$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ newgrp docker 

$ docker-compose up
:

[Docker] Docker Compose 에서 volume 사용 하기

Cloud&Container 2020. 3. 30. 14:40

기본 문서는 아래 링크 참고 하시면 됩니다.

 

Reference)

https://docs.docker.com/compose/compose-file/#volumes
https://docs.docker.com/compose/compose-file/#volume-configuration-reference

 

두 가지의 syntax 를 제공 하고 있습니다.

  1. Short Syntax
  2. Long Syntax

1. Short Syntax 

https://docs.docker.com/compose/compose-file/#short-syntax-3

valumes:
  - ${SOURCE-PATH}:${DESTINATION-PATH}:${MODE}

${SOURCE-PATH} 에는 Host의 Path 또는 Volume Name 을 사용 할 수 있습니다.

 

Case 1) bind mount 형식으로 volume 생성이 됩니다.

services:
...중략...
  volumes:
    - /mount/data:/usr/share/elasticsearch/mnt:rw
    
    
$ docker inspect ${SERVICE-NAME}
...중략...
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mount/data",
                "Destination": "/usr/share/elasticsearch/mnt",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ]
...중략...

 

Case 2) volume 형식으로 volume 생성이 됩니다.

- volume 사용 시 주의 사항은 Container 내부에 이미 생성 되어 있는 File System 을 사용

services:
...중략...
  volumes:
    - mount01:/usr/share/elasticsearch/data:rw
...중략...

volumes:
  mount01:
    driver: local      

$ docker volume ls --format "{{.Name}} : {{.Mountpoint}}"
megatoi-monitor-elasticsearch_mount01 : /var/lib/docker/volumes/megatoi-monitor-elasticsearch_mount01/_data

$ docker inspect ${SERVICE-NAME}
...중략...
        "Mounts": [
            {
                "Type": "volume",
                "Name": "megatoi-monitor-elasticsearch_mount01",
                "Source": "/var/lib/docker/volumes/megatoi-monitor-elasticsearch_mount01/_data",
                "Destination": "/usr/share/elasticsearch/data",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            }
        ],
...중략...

 

2. Long Syntax

https://docs.docker.com/compose/compose-file/#long-syntax-3

기본 옵션만 살펴 보겠습니다.

자세한건 위 문서를 참고하세요.

  • type
    • volume
      • Volume 선언 시 Source 는 volumes: syntax 에서 named volume 선언이 되어 있어야 합니다.
    • bind
      • Source File System 이 만들어져 있어야 합니다.
  • source
    • Host File System  을 작성 합니다. 
    • Short Syntax 에서 처럼 Host 의 Path 또는 Volume Name 을 사용 할 수 있습니다.
  • target
    • Container File System 을 작성 합니다.

Case 1) bind mount 형식으로 volume 생성이 됩니다.

services:
...중략...
    volumes:
        - type: bind
          source: /mount/data
          target: /usr/share/elasticsearch/mnt
...중략...


$ docker inspect ${SERVICE-NAME}
...중략...
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mount/data",
                "Destination": "/usr/share/elasticsearch/mnt",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
...중략...

 

Case 2) volume 형식으로 volume 생성이 됩니다.

- volume 사용 시 주의 사항은 Container 내부에 이미 생성 되어 있는 File System 을 사용

services:
...중략...
    volumes:
        - type: volume
          source: mount01
          target: /usr/share/elasticsearch/data
...중략...
volumes:
  mount01:
    driver: local
...중략...


$ docker inspect ${SERVICE-NAME}
...중략...
        "Mounts": [
            {
                "Type": "volume",
                "Name": "megatoi-monitor-elasticsearch_mount01",
                "Source": "/var/lib/docker/volumes/megatoi-monitor-elasticsearch_mount01/_data",
                "Destination": "/usr/share/elasticsearch/data",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],
...중략...

hort Syntax 의 Case 2) 와 같이 사용도 가능 합니다.

:

[Docker] Image 다운로드 및 로컬 설치 하기

Cloud&Container/IaC 2020. 3. 30. 08:41

인터넷이 안되는 환경에서 설치를 해야 할 경우가 있을 수도 있어서 이미지를 다운로드 받아 설치 하는 명령어를 작성해 보았습니다.

찾아 보면 다 나와 있는 거라서 그냥 기억력을 돕는 차원에서 간단하게 작성 합니다.

 

- root 로 안할 경우 누락 되는 파일이 있을 수 있음.
- save : load
- export : import

 

로컬로 다운로드 받기)

$ sudo docker save [옵션] <파일명> [이미지명]
$ sudo docker save -o elasticsearch.tar docker.elastic.co/elasticsearch/elasticsearch:7.6.1

# docker-compose.yml 파일 안에 
# image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1


이미지 올리기)

$ sudo docker load -i tar파일명
$ sudo docker load -i elasticsearch.tar


컨테이너 자체를 파일로 내리기)

$ sudo docker export <컨테이너명 or 컨테이너ID> > xxx.tar


컨테이너 올리기)

$ sudo docker import <파일 or URL> - [image name[:tag name]]

 

:

[Elasticsearch] Single node 실행

Elastic/Elasticsearch 2020. 3. 27. 16:05

Elasticsearch 버전이 올라 가면서 master node 를 최소 쿼럼 구성으로 해야 하는데요.

아마 잘 아시겠지만 Single node 구성을 원하시는 분은 아래 설정을 통해서 실행 하시면 됩니다.

 

[Single node 설정]

discovery.type=single-node

 

이 설정은 아래 설정이 포함되어 있을 경우 충돌이 납니다.

cluster.initial_master_nodes

 

본 설정을 주석 처리 하거나 삭제 하신 후 실행 시키면 정상 동작 합니다.

 

Elastic 공식 문서에 자세한 설명이 나와 있으니 참고 하시면 좋습니다.

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery-settings.html#modules-discovery-settings

:

[Docker] Docker Registry 구성 키워드

Cloud&Container/IaC 2020. 3. 27. 10:50
  • Nexus3
  • Harbor
  • S3

 

참고문서)

https://velog.io/@king/%EC%82%AC%EB%82%B4-Docker-Registry-%EB%A7%8C%EB%93%A4%EA%B8%B0-Nexus3-%EA%B8%B0%EB%B0%98-e9k69evm4a

https://engineering.linecorp.com/ko/blog/harbor-for-private-docker-registry/

https://goharbor.io/

 

:

[AWS] Spring Cloud Config S3 Backend 사용하기

Cloud&Container/AWS 2020. 3. 26. 10:57

Spring Cloud Config Server 설정)

 

[S3 설정]
- S3 버킷 생성
- 접근권한 부여

[ConfigApplication.java]

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
  public static void main(String[] args) {
	SpringApplication.run(ConfigApplication.class, args);
  }
}


[build.gradle]

compile 'com.amazonaws:aws-java-sdk-s3'


[application.yml]

server:
port: 8888

spring:
  profiles:
    active: awss3
  cloud:
    config:
      server:
        awss3:
          region: ap-northeast-2
          bucket: s3config


[Config Server 접근 URL]

http://localhost:8888/${S3-FILE-NAME}/${PROFILE-NAME}

- 생성한 버킷 하위로 설정 파일 목록이 존재 해야 합니다.
- ${S3-FILE-NAME} 는 생성한 Bucket 아래 만든 설정 파일명 입니다.
- backoffice
- ${PROFILE-NAME} 은 설정 파일에 대한 프로필명 입니다.
- app1, app2

예제)
Config Server URL : 
http://localhost:8888/backoffice/app1

S3 :
megatoidiscons3config/backoffice-app1.yml
or
megatoidiscons3config/backoffice-app1.properties


[backoffice-app1.yml]

project.app1="backoffice-app1"


[backoffice-app2.yml]

project.app2="backoffice-app2"

 

Spring Cloud Config Client 설정)

[application.yml]

spring:
  cloud:
    config:
      name: backoffice
      uri: http://localhost:8888
      profile: app1,app2


[HelloController.java]

@RestController
public class HelloController {

  @Value ("${project.app1}")
  String projectApp1;

  @Value ("${project.app2}")
  String projectApp2;

  @RequestMapping("/app1")
  public String helloApp1() {
    return projectApp1;
  }

  @RequestMapping("/app2")
  public String helloApp2() {
    return projectApp2;
  }
}

 

git 사용 하는 건 문서들이 많이 나와 있어서 s3 로 정리해 봤습니다.

:

[Ubuntu] add-apt-repository: command not found 발생 시

ITWeb/개발일반 2020. 3. 25. 18:32

# add-apt-repository: command not found 에러가 발생 하면 아래와 같이 설치 하시면 됩니다.
$ sudo apt-get install software-properties-common

:

[Certificate] 확장자에 따른 인증서 종류

ITWeb/개발일반 2020. 3. 23. 10:56

원본 글)

https://www.securesign.kr/guides/kb/54

 

SSL 인증서 파일 포맷 종류 - crt, cer, csr, pem, der, pfx, p12, jks, key - SecureSign

SSL 인증서 파일 포맷 종류 - crt, cer, csr, pem, der, pfx, p12, jks, key - SecureSign

www.securesign.kr

.pem
PEM (Privacy Enhanced Mail)은 Base64 인코딩된 ASCII 텍스트 이다. 파일 구분 확장자로 .pem 을 주로 사용한다.  노트패드에서 열기/수정도 가능하다. 개인키, 서버인증서, 루트인증서, 체인인증서 및  SSL 발급 요청시 생성하는 CSR 등에 사용되는 포맷이며, 가장 광범위하고 거의 99% 대부분의 시스템에 호환되는 산업 표준 포맷이다. (대부분 텍스트 파일)

.crt
거의 대부분 PEM 포맷이며, 주로 유닉스/리눅스 기반 시스템에서 인증서 파일임을 구분하기 위해서 사용되는 확장자 이다. 다른 확장자로 .cer 도 사용된다. 파일을 노트패드 등으로 바로 열어 보면 PEM 포맷인지 바이너리 포맷인지 알수 있지만 99% 는 Base64 PEM 포맷이라고 봐도 무방하다. (대부분 텍스트 파일)

.cer
거의 대부분 PEM 포맷이며, 주로 Windows 기반에서 인증서 파일임을 구분하기 위해서 사용되는 확장자 이다. crt 확장자와 거의 동일한 의미이며, cer 이나 crt 확장자 모두 윈도우에서는 기본 인식되는 확장자이다. 저장할때 어떤 포맷으로 했는지에 따라 다르며, 이름 붙이기 나름이다.

.csr
Certificate Signing Request 의 약자이며 거의 대부분 PEM 포맷이다. SSL 발급 신청을 위해서 본 파일 내용을 인증기관 CA 에 제출하는 요청서 파일임을 구분하기 위해서 붙이는 확장자 이다. (대부분 텍스트 파일)

.der
Distinguished Encoding Representation (DER) 의 약자이며, 바이너리 포맷이다. 노트패드등으로 열어 봐서는 알아 볼수 없다.  바이너리 인코딩 포맷을 읽을수 있는 인증서 라이브러리를 통해서만 내용 확인이 가능하다.  사설 또는 금융등 특수 분야 및 아주 오래된 구형 시스템을 제외하고는, 최근 웹서버 SSL 작동 시스템 에서는 흔히 사용되는 포맷은 아니다. (바이너리 이진 파일)

.pfx / .p12
PKCS#12 바이너리 포맷이며, Personal Information Exchange Format 를 의미한다. 주로 Windows IIS 기반에서  인증서 적용/이동시 활용된다. 주요 장점으로는 개인키,서버인증서,루트인증서,체인인증서를 모두 담을수 있어서 SSL 인증서 적용이나 또는 이전시 상당히 유용하고 편리하다. Tomcat 등 요즘에는 pfx 설정을 지원하는 서버가 많아지고 있다.  (바이너리 이진 파일)

.key
주로 openssl 및 java 에서 개인키 파일임을 구분하기 위해서 사용되는 확장자이다. PEM 포맷일수도 있고 DER 바이너리 포맷일수도 있으며, 파일을 열어봐야 어떤 포맷인지 알수가 있다. 저장할때 어떤 포맷으로 했는지에 따라 다르며, 확장자는 이름 붙이기 나름이다.

.jks
Java Key Store 의 약자이며, Java 기반의 독자 인증서 바이너리 포맷이다. pfx 와 마찮가지로 개인키,서버인증서,루트인증서,체인인증서를 모두 담을수 있어서 SSL 인증서 파일 관리시 유용하다. Tomcat 에서 SSL 적용시 가장 많이 사용되는 포맷이다. (바이너리 이진 파일)

:

[AWS] IGW vs NAT GW

Cloud&Container/AWS 2020. 3. 23. 10:43

VPC 를 구성 하면서 외부 통신을 위해서는 IGW 가 꼭 필요 합니다.

만약 외부 통신이 필요 하지 않은 VPC 라면 IGW 를 구성 하지 않아도 되겠죠.

 

NAT GW 는 VPC 구성 후 Private Subnet 에 있는 리소스가 외부와 Internet 통신을 하기 위해 필요한 서비스 입니다.

이 과정에서 Elastic IP 가 필요 합니다.

 

이 두 GW 의 차이점이 더 궁금하신 분은 아래 문서 참고 하세요.

 

https://medium.com/awesome-cloud/aws-vpc-difference-between-internet-gateway-and-nat-gateway-c9177e710af6

Internet Gateway

An Internet Gateway (IGW) is a logical connection between an Amazon VPC and the Internet. It is not a physical device. Only one can be associated with each VPC. It does not limit the bandwidth of Internet connectivity. (The only limitation on bandwidth is the size of the Amazon EC2 instance, and it applies to all traffic — internal to the VPC and out to the Internet.)

If a VPC does not have an Internet Gateway, then the resources in the VPC cannot be accessed from the Internet (unless the traffic flows via a corporate network and VPN/Direct Connect).

An Internet Gateway allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say — an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A subnet is deemed to be a Public Subnet if it has a Route Table that directs traffic to the Internet Gateway.


NAT Gateway

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, OS patch, etc)
  2. It only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

AWS introduced a NAT Gateway Service that can take the place of a NAT Instance. The benefits of using a NAT Gateway service are:

  • It is a fully-managed service — just create it and it works automatically, including fail-over
  • It can burst up to 10 Gbps (a NAT Instance is limited to the bandwidth associated with the EC2 instance type)

However:

  • Security Groups cannot be associated with a NAT Gateway
  • You’ll need one in each AZ since they only operate in a single AZ
: