[컴][웹] Apache, CentOS 7 에서 Let's Encrypt 인증서 설치


Apache, CentOS 7 에서 Certbot 설치

Certbot 이 EPEL (Extra Packages for Enterprise Linux). 형태로 제공된다.

설치

혹시 repository 설정이 안되어 있다면, the EPEL repository 를 설정해야 한다. 보통 기본으로 되어 있긴 한다.(참고)
  • sudo yum install python2-certbot-apache

실행

  • sudo certbot --apache
    • certificate 을 가져오게 된다.
    • cerbot 이 가져온 certificate 에 대해서 apache configuration 을 수정한다.
  • sudo certbot --apache certonly
    • certificate 만 가져온다.
    • 직접 apache configuration 을 수정해야 한다.
  • sudo certbot certonly
    • 서버의 지정없이 certificate 을 가져올 수 있다.
Let's Encrypt's new ACMEv2 server 에서 a wildcard certificate 를 가져오려고 한다면, Certbot's DNS plugins 를 사용해야 한다.
아래는 cloudflare 용 dns plugin (cerbot-dns-cloudflare ) 를 사용하는 command 이다.
  • sudo certbot -a certbot-dns-cloudflare -i apache -d "*.example.com" -d example.com --server https://acme-v02.api.letsencrypt.org/directory
  • 서버 지정없이(아래참고)
    sudo certbot certonly --manual -d "*.example.com" -d example.com  --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory

server 지정없이 하는 방법(certbot certonly)

아래 링크에 자세한 방법이 나와 있다.

server 지정없이 한 경우 결과화면

IMPORTANT NOTES:

 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/certbot renew/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/certbot renew/privkey.pem
   Your cert will expire on 2010-02-01. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:


   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le


apache vhost 설정

SSLCipherSuite 는 Cipher Suites and Enforcing Strong Security 를 참고하자.
 
아래 설정에서 보면 알겠지만, 3개의 file 이 필요하다.
  1. 인증서
  2. 인증서를 만들때 쓰인 privatekey
  3. 인증서Chain
 
<VirtualHost *:443>
    DocumentRoot /home/myserverdomain/public
    ServerName dd.myserverdomain.com
    ServerAlias dd.myserverdomain.com

    SSLCipherSuite          ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
    SSLHonorCipherOrder     on
    SSLOptions +StrictRequire

    SSLEngine on
    SSLCertificateFile "/etc/letsencrypt/live/myserverdomain.com/cert.pem"
    SSLCertificateKeyFile "/etc/letsencrypt/live/myserverdomain.com/privkey.pem"
    SSLCertificateChainFile "/etc/letsencrypt/live/myserverdomain.com/fullchain.pem"
    ...

인증서 갱신

cerbot renew 이용

인증서를 갱신(renew) 하는 방법은 아래와 같다. 이것을 주기적으로 하고 싶다면 cron 이나 systemd timer 에 넣어놓으면 된다. 보통 하루에 2번 수행하는 것을 추천한다. renew 시점이 아니면 아무일도 하지 않아서 계속 돌려도 문제는 없다.[ref. 1]
  • sudo certbot renew --dry-run

cerbot renew 가 안되는 경우

위의 방법을 사용하면, 에러가 발생한다. 아래에서 답을 찾았다.
방법은, 일단 다시 아래처럼 신청하면 새롭게 만들어진다. 물론 DNS 확인도 해야 한다.
  • certbot certonly --manual -d '*.mydomain.com'
인증서를 변경하고 나서는 apache 를 restart 해야 한다. reload 하는 방법도 있는듯 한데 일단 그 부분은 확인이 필요하다.

[root@myserver bin]# certbot certonly --manual -d '*.mydomain.com'
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for mydomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.mydomain.com with the following value:

Rfdklsfjkldsehtdfdsfdsgdgaga4

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mydomain.com-0001/privkey.pem
   Your cert will expire on 2019-04-21. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

인증서 위치

기존에 아래 path 에 인증서가 있는 경우,
  • /etc/letsencrypt/live/mydomain.com
새롭게 만들어지는 것은 아래 path 에 추가로 만들어진다.
  • /etc/letsencrypt/live/mydomain.com-0001
참고로, /etc/letsencrypt/live/mydomain.com 에 있는 것은 link 이다. 실제 file 들은 아래경로에 있다.
  • /etc/letsencrypt/archive/mydomain.com

인증서 삭제

certbot delete --cert-name mydomain.com


문제

httpd: Syntax error on line 23 of /etc/httpd/conf/httpd.conf: Cannot load modules/mod_mpm_event.so into server
httpd 가 yum 에 의해 설치되지 않아서 일까 위의 문제가 발생했다. 그래서 Cerbot 없이 설치하는 법을 택했다.

Cerbot 없이

See Also

  1. DNS 의 TXT 확인 방법

References

  1. Certbot | Apache on CentOS/RHEL 7 


[컴][웹] React Hooks


React Hooks

Hook 은 거창한 것이 아니다. 이미 class component 에서 제공하던 state 를 function component 에서도 가능하게 해주는 function(?) 라고 보면 된다.

기존의 function component 에서는 state를 사용할 수 없었다.
이 React Hooks 는 아직 정식으로 release 되지 않았다.

Hook 사용시 규칙

Hooks 는 use 로 시작한다. 그리고 facebook 에서도 custom Hook 에 대해서도 이 convention 을 지켜달라고 한다.[ref. 2]

참고로, ref. 3 에 보면 왜 이름을 createState 가 아니라 useState 로 지었는지 이야기가 나온다.
아래 링크를 참고하자.

Hooks FAQ

Hooks 가 어떻게 동작하는가?
How does React associate Hook calls with components?

React keeps track of the currently rendering component. Thanks to the Rules of Hooks, we know that Hooks are only called from React components (or custom Hooks — which are also only called from React components).

There is an internal list of “memory cells” associated with each component. They’re just JavaScript objects where we can put some data. When you call a Hook like useState(), it reads the current cell (or initializes it during the first render), and then moves the pointer to the next one. This is how multiple useState() calls each get independent local state.

References

  1. Introducing Hooks – React
  2. Writing Custom Hooks – React
  3. Using the State Hook – React

[컴][go] golang 의 interface{}(interface type) 의 itable 이 어떻게 생성될까.

golang itable  / how to generate itable in go / go virtual function table /

Go의 itable 의 생성

interface{}(interface type) 에 대한 itable 이 어떻게 생성되는지에 대한 설명이다.

Go 의 dynamic type conversion 들은 compiler 또는 linker 가 미리 모든 가능한 itable 들을 미리계산하는 것이 합리적이지 않다는 뜻이다.

너무 많은 (interface type, concrete type) pair 들이 존재한다. 그리고 대다수는 필요하지 않을 것이다. 대신에, 컴파일러는 위의 예제의 Binary, int 또는 func(map[int]string) 같은 각 concrete type 에 대해서 type description structure 를 생성한다.

비슷하게, 컴파일러는 interface type 에 대해 다른 type description structure 를 하나 생성한다. 그것 또한 method list 를 갖고 있다. interface runtime 은 interface type 의 method table 에 있는 모든 method를 concrete type의 method table 에서 찾아서 itable 을 계산한다.

runtime 은 itable 을 생성한 후에, 이것을 caching 한다. 그래서 이 것은 한번의 계산만 필요하다.


Computing the Itable

Now we know what the itables look like, but where do they come from? Go's dynamic type conversions mean that it isn't reasonable for the compiler or linker to precompute all possible itables: there are too many (interface type, concrete type) pairs, and most won't be needed. Instead, the compiler generates a type description structure for each concrete type like Binary or int or func(map[int]string). Among other metadata, the type description structure contains a list of the methods implemented by that type. Similarly, the compiler generates a (different) type description structure for each interface type like Stringer; it too contains a method list. The interface runtime computes the itable by looking for each method listed in the interface type's method table in the concrete type's method table. The runtime caches the itable after generating it, so that this correspondence need only be computed once. [ref. 1]

References

  1. research!rsc: Go Data Structures: Interfaces
  2. How to use interfaces in Go by jordan orelli

[컴] 윈도우즈10 에 OpenSSH 설치하기

wondows 10 install open ssh


updated, 2020-04-19

  1. Installation of OpenSSH For Windows Server 2019 and Windows 10 | Ms docs, 2019-09-27
위 링크에서 powershell 을 이용해서 바로 windows 에서 제공하는 OpenSSH 를 설치할 수 있다.
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0



윈도우즈10 에 OpenSSH 설치하기

아래 link 에 설명이 나와 있다. 여기서는 Windows 10 version 1803 이전버전에 대한 설치를 진행한다.

설치하기

admin 계정으로 다음 작업들을 한다.

c:\a\apps\oepnssh\win64>powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
[SC] SetServiceObjectSecurity 성공
[SC] ChangeServiceConfig2 성공
[SC] ChangeServiceConfig2 성공
sshd and ssh-agent services successfully installed

c:\a\apps\oepnssh\win64>

그러면 아래처럼 service 가 설치된다.



port 22 열어주기

기본적으로 windows firewall 이 막고 있다. 이것을 열어주자.
powershell 로는 아래처럼 하면 된다.
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22


See Also

  1. Installation of OpenSSH For Windows Server 2019 and Windows 10 | Ms docs, 2019-09-27






[컴][앱][웹] 공유 문서를 local server 에 설치해 보자.

구글독스 / 구글닥스 / google docs in local computer / local server / 로컬서버에서 구글 독스


Etherpad

local server 에서 공동으로 편집이 가능한 editor 이다. 쉽게 생각하면 구글 독스 같은 것을 로컬 서버에 설치해서 사용할 수 있다.





[컴] cpu가 그래픽처리를 위해 GPU를 사용하는 과정



그래픽카드와 함께 CPU 가 좋아야 하는 이유

내용에 틀린부분이 있을 수 있다. 그러니 의심이 가면 관련 부분을 찾아보기 바란다.

일단 단순하게 표현하면, 던전으로 들어가기 전과 후의 장면은 크게 달라진다. 그런데 캐릭터가 던전으로 들어갔는지, 아니면 그 앞까지 왔는지를 결정하는 것은 graphic 부분이 아닌 다른 code 부분이다. GPU 가 graphic 부분의 일을 처리하겠지만, 그 이외의 logic 을 계산하는 것은 cpu 이다. 그러므로 cpu 가 느리다면, 결국 gpu 가 아무리 빨라도 끊김(흔히 버벅임)을 방지하기는 어렵다.


cpu가 그래픽처리를 위해 GPU를 사용하는 과정

The_CUDA_Handbook.pdf 에서 좋은 설명을 확인할 수 있다. 여기선 일부를 정리해 놓았다.

cpu 와 bus



현재까지, 보드의 south bridge가 대부분의 주변기기들을 담당하고, north bridge 가 memory controller 를 가지고 있다. 그래서 이 north bridge 의 memory controller 를 이용해서 cpu 는 memory 와 통신한다.(이 통신이 이뤄지는 interface 가 front-side bus 이다.)

그리고 north bridge 는 gpu 와 PCI Express interface 를 이용해서 통신한다.(물론 pci express 이전에는 AGP 같은 것이 있었다.)

gpu 안에는 gpu memory controller 가 들어가 있다. 그래서 이 memory controller 를 통해 gpu memory 와 통신한다.

Memory controller 가 CPU 안으로

이러다가 cpu 가 memory controller 를 내장했다.(AMD의 Opteron 과 Intel의 Nehalem (i7) ) 그래서 north bridge 없이 바로 memory 와 통신하게 된다.

그리고 I/O Hub 를 통해 PCI express interface 를 사용해서 GPU 에 접근한다.

HyperTransport (HT) / QuickPath Interconnect (QPI) interface

이 상황에서 cpu 를 여러개 사용하기 위해 cpu 간의 통신이 필요했다.(Multiple CPUs (NUMA)) 그래서 생긴것이 HyperTransport (HT) / QuickPath Interconnect (QPI) 이다. 이 interface 로 cpu core 끼리의 통신과 cpu 와 I/O hub 와의 통신을 하게 된다.

  • cpu core <---> cpu core
  • cpu <---> I/O hub

I/O hub 가 CPU 안으로

인텔의 Sandy Bridge 부터 I/O hub 를 cpu 안에 내장하게 된다.




CPU/GPU 연동

The_CUDA_Handbook.pdf 의 2.5 부분의 내용이다.

GPU 는 직접적으로 page-lock 된 CPU memory 에 DMA 를 통해 접근할 수 있다.

Page-locking 은 주변 하드웨어가 CPU Memory 에 직접적으로 접근할 수 있도록 해주기 위해 OS가 사용하는 기능이다.

locked page 들은 OS 에 의해 퇴출(eviction) 에 적합하지 않다고 표시된 상태이다. 그래서 device driver들은 이 주변기기들이 메모리에 직접적으로 접근하기 위해 페이지들의 물리적인 주소들을 이용하라고 프로그램할 수 있다.

CPU 는 여전히 불확실한 상태에서 memory 에 접근할 수 있다. 그러나 메모리는 옮겨지거나, disk 로 paged out 되지 않는다.

DMA 는 GPU 가 CPU memory 를 "cpu 의 실행"에 대해 독립적으로 그리고 병력적으로 read/write 할 수 있게 해줬다. 다만 여기선 race condition 들을 피하기 위해 CPU 와 GPU 사이의 싱크를 맞추는 것을 고려해야 한다.
  • Pinned host memory(pinned buffer): GPU 가 직접 접근할 수 있는 CPU memory 부분
  • Command buffers: GPU 실행을 통제하기 위해 CUDA driver 에 의해 write되고, GPU에 의해 read 되는 buffer. 

pinned buffer

pinned buffer 는 direct access 를 위해 GUP 에 의해 mapping 된다. CUDA 에서는 API cudaMallocHost() 를 통해 allocate 할 수 있다.

pinned buffer 가 주로 사용되는 방법중 하나는 GPU 에 command 를 보내는 용도이다. CPU 가 command 를 buffer 에 write 하고, 동시에 이것을 GPU 가 이전에 write된 command 를 read 하고 execute 한다.

이 buffer 의 앞부분(leading edge) 에 CPU 가 command 를 write 한다. 그래서 GPU 가 이때는 이 녀석을 읽을 수 없다.

GPU 는 buffer 의 끝부분(trailing edge) 에서부터 command 를 읽어드려서 실행한다.

이 command buffer 는 circular queue 라고 보면 된다. 그래서 한번 command 처리를 다한 부분은 다시 CPU 가 command 를 write 하기 위해 사용된다.

cpu-bound / gpu-bound

이 상황에서 2가지 case 가 있는데 CPU-bound 와 GPU-bound 다. bound 는 "경계" 의 뜻이니, CPU bound 는 CPU 가 경계가 되는 경우라고 보면 되고, GPU-bound 는 GPU 가 경계가 되는 것으로 보면 된다.
  • 하나는 CPU 의 command 를 write  < GPU 의 처리 속도(CPU-bound)
  • 하나는 CPU 의 command 를 write  > GPU 의 처리 속도(GPU-bound)


References