Category: Linux

  • GPS dongle을 이용한 NTP 구축

    자체 NTP 서버를 구축해보려고 GPS dongle을 하나 구입했다. GPS 동글이 PPS를 지원해 주면 좀 더 정확한 시간 동기화 및 NTP 시간 제공이 가능하다고 하지만, 일단 동글만 이용해 보기로 한다. 인터넷에서 찾은 여러 기사들을 종합하고 실제로 적용해 보았다.

    다음의 패키지들을 설치한다.

    sudo apt -y install gpsd gpsd-clients chrony

    gpsd 환경 설정 파일을 수정한다. GPS 동글은 ACM0으로 연결되어 있다고 가정하고 있다.

    nano /etc/default/gpsd
    
    START_DAEMON="true"
    DEVICES="/dev/ttyACM0"
    GPSD_OPTIONS="-n"
    USBAUTO="true"

    chrony.conf 파일에 다음 내용을 추가한다.

    refclock SHM 0 offset 0.5 delay 0.2 refid NMEA

    gpsd와 chronyd 를 재시작하거나 편하게 시스템 재부팅을 한다.

    그런데 회사 유리창이 아무리봐도 전자파차폐유리인 것 같다. 창문을 닫으면 GPS 신호 수신이 안된다. 미약한 신호라도 받기 시작하면 적어도 시각은 이용할 수 있다. 그럴 경우 gpsd 파일에서 다음을 추가하여 준다.

    GPSD_OPTIONS="-n -r"

    PPS가 지원이 되지 않기 때문에 오차가 크게 제공되는 편이다. 따라서 인터넷 연결이 끊겼을 때는 이용할 수 있으나, 그렇지 않은 경우에는 인터넷을 통한 NTP 동기화를 이용하게 된다.

  • chrony에서 logging 하기

    리눅스 시스템에서 시간 동기화에 이용하는 서비스 중 하나인 chrony 가 제대로 동작하고 있는지 log를 기록하는 방법이다. 인터넷 검색을 해보면 chrony.conf 파일에서 다음의 문구를 추가해주는 것을 알려준다.

    log measurements statistics tracking

    이렇게 하면 /var/log/chrony에 3개의 로그 파일이 만들어진다. 그 중에서 현재 동기화된 서버와의 관계를 보여주는 것은 tracking.log 인 것 같다. 이 파일에 기록되는 항목은 다음과 같은 의미가 있다고 한다.

    The columns are as follows (the quantities in square brackets are the values from the example line above) :

    1. Date [2017-08-22]
    2. Hour:Minute:Second. Note that the date-time pair is expressed in UTC, not the local time zone. [13:22:36]
    3. The IP address of the server or peer to which the local system is synchronised. [203.0.113.15]
    4. The stratum of the local system. [2]
    5. The local system frequency (in ppm, positive means the local system runs fast of UTC). [-3.541]
    6. The error bounds on the frequency (in ppm). [0.075]
    7. The estimated local offset at the epoch, which is normally corrected by slewing the local clock (in seconds, positive indicates the clock is fast of UTC). [-8.621e-06]
    8. Leap status (N means normal, + means that the last minute of this month has 61 seconds,  means that the last minute of the month has 59 seconds, ? means the clock is not currently synchronised.) [N]
    9. The number of combined sources. [2]
    10. The estimated standard deviation of the combined offset (in seconds). [2.940e-03]
    11. The remaining offset correction from the previous update (in seconds, positive means the system clock is slow of UTC). [-2.084e-04]
    12. The total of the network path delays to the reference clock to which the local clock is ultimately synchronised (in seconds). [1.534e-02]
    13. The total dispersion accumulated through all the servers back to the reference clock to which the local clock is ultimately synchronised (in seconds). [3.472e-04]
    14. The maximum estimated error of the system clock in the interval since the previous update (in seconds). It includes the offset, remaining offset correction, root delay, and dispersion from the previous update with the dispersion which accumulated in the interval. [8.304e-03]

    주의할 점은 기록되는 tracking.log 같은 파일을 삭제하면 다시 생성이 되지 않는 것 같다. 매일마다 기록이 필요할 경우는 해당 파일을 복사한 후 파일은 유지하면서, 내용을 삭제하는 방법으로 하는 것이 좋을 것 같다.

    echo '' > /var/log/chrony/tracking.log 

    NTP를 이용하겠다는 사람은 당연히 알고 있어야 하는 것으로 NTP의 기준 시각은 UTC이다. 로그를 해석할 때 실수하지 않도록 하자.

    나는 tracking 만을 이용할 것이기 때문에 다음 옵션만을 이용했다.

    log tracking
  • 노트북 화면 끄기

    노트북(laptop)에서 리눅스 서버를 운영해야 할 경우에 이용할 수 있다. 백라이트를 포함해서 화면을 확실하게 끌 수 있는 방법으로 보인다.

    원격 접속으로 할 때를 기준으로 다음과 같이 하면 끄고 켤 수 있다.

    끌 때

    setterm --blank force --term linux </dev/tty1

    켤 때

    setterm --blank poke --term linux </dev/tty1
  • NGINX 개인 인증서

    LAN에서 사용할 것이면 꼭 인증서를 설치해야 할 필요는 없다. 다만, 요즘 웹 브라우저는 워낙 인증서 우선인지라 인증서 예외 등록하는게 더 편하기 때문에 개인 인증서라도 사용하는 것을 고려해 볼 수는 있다. 다음의 웹 사이트 내용을 참고했다. 다만, 여기서 설명하는 암호화 방식이 너무 구식인지 IE에서도 제대로 인식을 못하기 때문에 암호화 방식을 많이 이용하는 RSA 2048로 했다.

    $ openssl genrsa -out rootca.key 2048
    $ openssl req -new -sha256 -key rootca.key -out rootca.csr
    $openssl x509 -req -sha256 -days 999999 -in rootca.csr -signkey rootca.key -out rootca.crt
    
    $ openssl genrsa -out server.key 2048
    $ openssl req -new -sha256 -key server.key -out server.csr
    $ openssl x509 -req -sha256 -days 999999 -in server.csr -CA rootca.crt -CAkey rootca.key -CAcreateserial -out server.crt
    $ cat server.crt rootca.crt > server.pem

    이렇게 파일을 만들고 server.pem 과 server.key 파일 2개를 이용해서 NGINX 에서 인증서 설정을 하면 된다.