반응형

docker 실행시 컨테이너 내부에서 컨테이너 외부 파일을 연결할수 있는 방법이 있다.

docker run 실행시 -v [호스트경로]:[컨테이너경로] 를 추가해주면 호스트 경로와 컨테이너 경로가 연결되게 된다. 한가지 중요한 점은 호스트 경로의 상태가 컨테이너 경로에 덮어써진다는 것이다. 

➜  docker docker run --name nginx-mounts -d -p 8081:80 -v /Users/Workspaces/docker:/usr/share/nginx/html nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
7d63c13d9b9b: Pull complete 
15641ef07d80: Pull complete 
392f7fc44052: Pull complete 
8765c7b04ad8: Pull complete 
8ddffa52b5c7: Pull complete 
353f1054328a: Pull complete 
Digest: sha256:dfef797ddddfc01645503cef9036369f03ae920cac82d344d58b637ee861fda1
Status: Downloaded newer image for nginx:latest
f1aa047705f563a0db1f76abbadddf74ea2fff7542e55601a84eccf43dc207b4
➜  docker curl localhost:8081                          
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.21.4</center>
</body>
</html>

위에서는 docker를 실행할 때 /Users/Workspaces/docker 경로를 컨테이너 안에 /usr/share/nginx/html 에 바인드 시켰다. 기본적으로 nginx의 /usr/share/nginx/html 경로에는 index.html 파일이 존재하지만 현재 호스트의 /Users/Workspaces/docker 경로에는 아무것도 없는 빈 디렉토리이기 때문에 403 이 나온다.

 

728x90
반응형
반응형

시스템의 mac 주소를 확인할때 사용한다. 

root@myserver-001:~# arp
Address                  HWtype  HWaddress           Flags Mask            Iface
10.32.0.2                ether   e2:be:6b:98:75:27   C                     weave
10.32.0.3                ether   c2:2b:4a:0f:0b:5b   C                     weave
10.36.0.1                ether   02:84:38:18:ac:31   C                     weave
10.36.0.2                ether   8e:21:c9:42:d3:da   C                     weave
10.36.0.3                ether   a2:7f:5e:83:5b:c4   C                     weave
10.44.0.4                ether   2a:54:11:6b:1f:fe   C                     weave
10.44.0.5                ether   b6:bb:2c:98:2b:7b   C                     weave
_gateway                 ether   02:50:56:56:44:52   C                     ens160
192.168.0.2                      (incomplete)                              ens160
myserver-002             ether   00:50:56:99:e5:ba   C                     ens160
10.44.0.1                ether   46:bf:dd:bc:51:8a   C                     weave
192.168.30.18                    (incomplete)                              docker0
10.44.0.2                ether   e6:4a:dc:2d:f4:e7   C                     weave
myserver-003             ether   00:50:56:99:1e:4d   C                     ens160
10.44.0.3                ether   96:38:40:ba:ac:a0   C                     weave

다음과 같이 뒤에 host 명을 붙여주면 해당 host 의 정보만 출력한다.

root@myserver-001:~# arp myserver-002
Address                  HWtype  HWaddress           Flags Mask            Iface
myserver-002             ether   00:50:56:99:e5:ba   C                     ens160

 

728x90
반응형

'Development > Linux' 카테고리의 다른 글

xargs 명령어  (0) 2024.01.17
[리눅스 명령어] nohup  (0) 2021.06.09
[리눅스 명령어] 디스크 관련 명령어  (0) 2021.06.04
파일 찾기, 파일 날짜별 삭제  (0) 2021.05.21
[리눅스 명령어] IP 관련 명령어  (0) 2021.03.08
반응형

1. docker inspect container_id
명령어를 치면 굉장히 많은 정보를 확인할 수 있다. 그래서 grep 으로 조회하면 좀 수월하다.
docker inspect container_id | grep IP

"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "192.168.0.1",
"IPPrefixLen": 16,
"IPv6Gateway": "",
        "IPAMConfig": null,
        "IPAddress": "192.168.0.1",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,

2. docker exec -it container_id /bin/bash
위 명령어를 사용하면 컨테이너 내부로 접속이 가능하다. 내부로 접속을 해서 ip addr 이나 ifconfig, hostname -I 등을 사용해서 확인 가능하다. 

3. docker exec container_id command
exec 만 사용을 하고 후에 명령어를 치면 컨테이너 내부에 명령어를 보내 실행이 가능하다. 

 

728x90
반응형
반응형

간단한(?) Ping 테스트.

- inventory 파일 정보
[workers]
worker1 ansible_host=192.168.0.12 ansible_user=root
worker2 ansible_host=192.168.0.14 ansible_user=root

- ping을 쏴보자. (-m 옵션은 module 이라는 의미)
ansible workers -m ping
당연히 될줄 알았으나 Error 발생

worker1 | FAILED! => {
    "msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}
worker2 | FAILED! => {
    "msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}

sshpass 프로그램이 없다고 하길래 sshpass 프로그램을 설치했다.
apt install sshpass.

그리고 다시 시도!. 그리고 다시 Error

worker1 | FAILED! => {
    "changed": false, 
    "module_stderr": "Shared connection to 192.168.0.12 closed.\r\n", 
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 127
}

python 이 없다고 나옴. 생각해보니 master 에 ansible 만 설치했지 다른 노드에는 아무것도 안한 상태였다. 그래서 각각의 노드에 python 을 설치했다. (apt install python)

그리고 나서 다시 했더니 다음과 같은 Error 가 나온다.

worker1 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: root@192.168.0.12: Permission denied (publickey,password).\r\n", 
    "unreachable": true
}
worker2 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: root@192.168.0.14: Permission denied (publickey,password).\r\n", 
    "unreachable": true
}

흠... 패스워드 문제인것 같아서 옵션을 줘보고 실행을 해봤다.

ansible all -m ping -k

-k : 이 옵션은 실행시에 password 를 물어보도록 하는 옵션이다.
이렇게 실행을 했더니 정상적으로 실행이 되었다. 

root@myserver-001:~# ansible all -m ping -k
SSH password: 
worker1 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
worker2 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

 

728x90
반응형

'Development > Ansible' 카테고리의 다른 글

Ansible Inventory 파일  (0) 2021.11.12
반응형

호스트 파일에는 목적지 노드의 정보를 담고 있다. 

1. 파일 위치 : /etc/ansible/hosts (설치위치에 따라 달라질수는 있다.) 
실제로 ansible.cfg 파일을 보면 다음과 같이 default 로 정의되어있다.
# some basic default values...
#inventory      = /etc/ansible/hosts

2. 사용 방법

test test.com

[test]
test.com

[web]
web1.com
web2.com

[db]
db.com

[mail]
mail.com

[workers]
worker1 ansible_host=192.168.0.12 ansible_user=root 
worker2 ansible_host=192.168.0.14 ansible_user=root 

[all_servers:children]
test
web
db
mail

- test test.com : test 는 alias 이며 test.com 이 실제 접속 주소이다.
- [] : [] 으로 표현된 부분은 group 이름이다. 
- ansible_user : 각각의 노드에 user 가 다를 경우 ansible_user 로 정의 해준다.
- [그룹명:children] : 그룹들로 서로 묶을 수 있다.

 

728x90
반응형

'Development > Ansible' 카테고리의 다른 글

Ansible Ping 테스트 해보자.  (0) 2021.11.12
반응형

history 명령어를 통해서 이미지가 어떤 과정을 거쳐 생성되었는지 확인해볼수 있다.

아래와 같이 nginx 의 latest 이미지와 stable 이미지에 대한 내역을 비교해볼수 있다.

root@myserver-001:~# docker history nginx:stable
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
c8d03f6b8b91   4 weeks ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  ENTRYPOINT ["/docker-entr…   0B        
<missing>      4 weeks ago   /bin/sh -c #(nop) COPY file:09a214a3e07c919a…   4.61kB    
<missing>      4 weeks ago   /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7…   1.04kB    
<missing>      4 weeks ago   /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0…   1.96kB    
<missing>      4 weeks ago   /bin/sh -c #(nop) COPY file:65504f71f5855ca0…   1.2kB     
<missing>      4 weeks ago   /bin/sh -c set -x     && addgroup --system -…   63.9MB    
<missing>      4 weeks ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.5.3        0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.20.1     0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B        
<missing>      4 weeks ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      4 weeks ago   /bin/sh -c #(nop) ADD file:910392427fdf089bc…   69.3MB    

root@myserver-001:~# docker history nginx:latest
IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
04661cdce581   45 hours ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  ENTRYPOINT ["/docker-entr…   0B        
<missing>      45 hours ago   /bin/sh -c #(nop) COPY file:09a214a3e07c919a…   4.61kB    
<missing>      45 hours ago   /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7…   1.04kB    
<missing>      45 hours ago   /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0…   1.96kB    
<missing>      45 hours ago   /bin/sh -c #(nop) COPY file:65504f71f5855ca0…   1.2kB     
<missing>      45 hours ago   /bin/sh -c set -x     && addgroup --system -…   61.1MB    
<missing>      45 hours ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~bullseye   0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.7.0        0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.21.4     0B        
<missing>      45 hours ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B        
<missing>      4 weeks ago    /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      4 weeks ago    /bin/sh -c #(nop) ADD file:16dc2c6d1932194ed…   80.4MB

 

728x90
반응형
반응형

kubectl drain 노드명

- drain 명령어를 사용하게 되면 해당 노드의 pod 를 다른 노드로 옮긴다.
- 실제로는 pod 를 옮기는게 아니라 다른 노드에 재 생성한다.
- 데몬셋을 무시하고 진행할 경우에는 --ignore-daemonsets 옵션을 사용한다.

아래와 같이 myserver-002와 myserver-003 에 pod 가 각각 deploy 되어있다.

root@myserver-001:~# kubectl get po -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP          NODE           NOMINATED NODE   READINESS GATES
rollout-nginx-74695fdcd-5trw5   1/1     Running   0          3m55s   10.32.0.2   myserver-002   <none>           <none>
rollout-nginx-74695fdcd-jkw2d   1/1     Running   0          3m55s   10.47.0.2   myserver-003   <none>           <none>
rollout-nginx-74695fdcd-tp75z   1/1     Running   0          3m55s   10.47.0.1   myserver-003   <none>           <none>

이 상황에서 myserver-003 을 drain 을 시켜보면 다음과 같이 변경된다.

root@myserver-001:~# kubectl get nodes
NAME           STATUS                     ROLES                  AGE     VERSION
myserver-001   Ready                      control-plane,master   2d8h    v1.22.3
myserver-002   Ready                      <none>                 2d8h    v1.22.3
myserver-003   Ready,SchedulingDisabled   <none>                 4h23m   v1.22.3

 

root@myserver-001:~# kubectl get po -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP          NODE           NOMINATED NODE   READINESS GATES
rollout-nginx-74695fdcd-5trw5   1/1     Running   0          4m45s   10.32.0.2   myserver-002   <none>           <none>
rollout-nginx-74695fdcd-8c55f   1/1     Running   0          11s     10.32.0.3   myserver-002   <none>           <none>
rollout-nginx-74695fdcd-h6txz   1/1     Running   0          11s     10.32.0.4   myserver-002   <none>           <none>

기존에 있던 rollout-nginx-74695fdcd-5trw5 파드를 제외하고 나머지 pod 는 이름을 보면 새로 만들어진것이다. Age 도 11s 로 나온다. 따라서 위에서 말한것처럼 drain 을 했을 경우 pod 를 옮기는게 아니라 삭제하고 새로 만들게 된다. 

 

728x90
반응형
반응형
  • cordon
    • 지정한 노드에 Pod 를 스케줄링 하지 않는다.
  • taint
    • 지정한 노드에 Pod를 스케줄링 하지 않지만 tolerations 설정을 통해 스케줄링이 가능하다.

 

728x90
반응형
반응형

암호학(cryptograph)

생활코딩 암호학 영상을 보고 요약한 정리 입니다. 

https://www.youtube.com/playlist?list=PLuHgQVnccGMD-9lk4xmb6EG1XK1OmwC3u

  • 암호화의 특징
    • 기밀성 (Confidentiality) : 암호화된것을 알수 없어야함.
    • 무결성 (Integrity) : 내용이 원본과 같다는걸 유지해야함.
    • 인증 (Authentication) : 권한이 있는 사람만 접근 가능해야함.
  • 암호법의 구분
    • 양방향 암호화 : 정보를 감추는 기밀성에 초점이 맞춰짐
      • 대칭키 : 암,복호화시 같은 키 사용
      • 비대칭키 : 암,복호화시 다른 키 사용
    • 단방향 암호화 : 무결성에 초점을 맞춤
  • 단반향 암호화
    • 다른말로 HASH
    • MD5, SHA-256, SHA-512등등
    • 무결성체크, 전자서명, 파일식별자, 패스워드 저장, 블록체인, 가상화패
  • 양방향 암호화
    • 대칭키 방식
      • Twofish, Serpent, AES, DES....
      • 대칭키를 사용할 경우에는 키가 노출될수 있다.
    • 비대칭키 (공개키) 방식
      • 공개키 (public key)
      • 비공개키 (private key)
      • 평문을 공개키로 암호화 (공개키로 복호화 불가능, 비공개키로만 복호화 가능)
      • 평문을 비공개키로 암호화(비공개키로 복호화 불가능, 공개키로만 복호화 가능)
      • 암호화 절처
        • A는 공개키와 비공개키를 생성후 공개키를 노출 시킨다.
        • B는 A가 노출시킨 공개키로 암호문을 만들어 A에게 전달한다.
        • A는 B에게 전달받은 암호문을 자신이 만든 비공개키로 복호화 한다.
      • 전자서명
        • A는 공개키와 비공개키를 생성후 공개키를 노출 시킨다.
        • A는 문서 뒤에 A의 비공개키로 암호화한 text를 추가한다. (이게 전자서명이다)
        • 그걸 B 에게 전달한다
728x90
반응형

+ Recent posts