포스트

홈서버 (재)구축하기 - 2. 유틸 설치 및 웹서버 구성 준비

서버 관리에 필요한 기본적인 유틸과 nginx 설치하기

홈서버 (재)구축하기 - 2. 유틸 설치 및 웹서버 구성 준비

유틸 설치와 사용

서버의 상태를 체크하는데 필요한 기본적인 유틸을 설치해보자. 우선 SSD/HDD의 상태와 하드웨어의 온도를 체크하는 유틸을 설치할 계획이다.

특히 smartctl는 전편에서 언급했듯 유용하게 썼다. SSD는 교체했지만, HDD도 있으니 배드섹터 색출하기 위해서라면 계속 사용하게 될 유틸.

smartctl

smartctl는 디스크의 S.M.A.R.T.(Self-Monitoring, Analysis and Reporting Technology)가 분석한 데이터를 확인할 수 있는 툴이다.

설치

1
2
$ sudo apt update
$ sudo apt install smartmontools

사용

  1. S.M.A.R.T. 활성화 확인
    1
    
     $ sudo smartctl -i /dev/sdX
    
  2. 디스크의 건강 상태 확인
    1
    
     $ sudo smartctl -H /dev/sdX
    
  3. 디스크의 여러 속성 조회
    1
    
     $ sudo smartctl -A /dev/sdX
    
  4. 디스크 상태 테스트
    1
    2
    3
    
     $ sudo smartctl -t short /dev/sdX   # 짧은 테스트
     $ sudo smartctl -t long /dev/sdX    # 긴 테스트
     $ sudo smartctl -c /dev/sdX         # 테스트 진행 상태 확인
    
  5. 디스크의 오류 로그 확인
    1
    
     $ sudo smartctl -l error /dev/sdX
    

더 자세한 정보는 smartmontools 공식 웹사이트에서 확인 가능하다.

lm-sensors

lm-sensors는 Linux 시스템에서 하드웨어 센서를 모니터링하기 위한 도구로, CPU 온도, 팬 속도, 전압 등을 확인할 수 있다.

설치

1
2
$ sudo apt update
$ sudo apt install lm-sensors

사용

  1. 센서 감지
    1
    
     $ sudo sensors-detect --auto
    
  2. 온도 확인
    1
    2
    
     $ sudo sensors
     $ sudo watch -n 2 sensors  # 실시간 확인, 2초 간격으로 업데이트
    

웹서버 구성 - nginx

nginx는 HTTP 및 역방향/메일/TCP/UDP 프록시 서버로 사용되는 오픈 소스 소프트웨어다.

Caddy 등 다른 대체제가 있지만, 설정이 좀 귀찮더라도 대단한 서비스를 하는 건 아니라도 홈서버의 제한된 리소스를 효율적으로 사용하는 nginx를 택했다. 홈서버를 처음 다룰 때 선택해서 익숙하기도 하고 다양한 모듈이 있는 것도 장점. 사실… 그냥 익숙한 게 최고다.

설치

기본 APT 저장소에 있는 nginx 패키지는 업데이트가 조금 밀리는 편으로, 바로 sudo apt install nginx를 사용하지 않고 저장소 설정 후 설치하기로 한다. nginx 공식 웹사이트에 있는 설치 방법을 따라 설치했다.

  1. 저장소 설정을 위한 필수 요소 설치
    1
    
     $ sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
    
  2. nginx 공식 저장소에서 GPG Key 받기
    1
    
     $ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
    
  3. 받은 Key가 올바른지 웹사이트에 공개된 fingerprint와 비교
    1
    
    $ gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
    
  4. APT 저장소에 nginx 공식 패키지 링크 설정
    1
    
    $ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
    
  5. 설정한 링크를 먼저 받도록 우선 순위 설정
    1
    
    $ echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
    
  6. nginx 설치
    1
    2
    
    $ sudo apt update
    $ sudo apt install nginx
    
  • 설치 완료 Welcome to nginx! Hello World!

    설치 후에 nginx가 서비스로 등록되어 자동으로 실행된다.

기본 명령어

  • 설정 테스트
    1
    
      $ sudo nginx -t
    
  • 상태 확인
    1
    
      $ sudo service nginx status
    
  • 재시작
    1
    
    $ sudo service nginx restart
    

    설정에 문법 오류가 있을 경우 시작되지 않는다. 즉, downtime이 발생한다.

  • 설정 다시 불러오기
    1
    
    $ sudo servcie nginx reload
    

    설정에 문법 오류가 있을 경우 에러 메세지를 표시하고, nginx는 이전 설정으로 정상 작동한다.

설정

nginx의 설정은 /etc/nginx/nginx.conf에서 확인할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice; # 에러 메세지의 경로와 기록 레벨
pid        /var/run/nginx.pid;              # nginx의 프로세스 ID가 저장되는 경로


events {
    worker_connections  1024;               # Worker Process가 처리할 수 있는 동접자의 수
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    # 로깅 문서: https://docs.nginx.com/nginx/admin-guide/monitoring/logging/
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;  # 접속 로그의 경로

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;             # 디렉토리에 있는 conf 파일 전부 포함
}

지금은 우선 기본 설정을 그대로 놔두고, 나중에 /etc/nginx/conf.d에 파일을 추가해 작업을 진행 할 것이다.

이 글은 저작권자의 CC BY 4.0 라이센스를 따릅니다.