"데비안 미러 서버를 만드는 방법"의 두 판 사이의 차이

한국 데비안 사용자 모임
둘러보기로 가기 검색하러 가기
457번째 줄: 457번째 줄:
 
==== 미러링 로그 확인 ====
 
==== 미러링 로그 확인 ====
  
아래 명령으로 미러링의 실시간 로그를 확인할 수 있습니다.
+
아래 명령으로 저장소(debian-security)를 미러링하는 실시간 로그를 확인할 수 있습니다.
  
 
<pre>
 
<pre>

2021년 5월 2일 (일) 19:22 판

데비안 공식 문서에서 'ftpsync'를 이용해서 데비안 미러 서버를 만드는 것을 권장하고 있습니다. ftpsync는 데비안 프로젝트에서 만든 프로그램입니다. 이 프로그램을 이용하면 쉽게 미러 서버를 구축할 수 있습니다.

물론 'apt-mirror'를 이용해서 데비안 미러 서버를 만들 수도 있습니다. 데비안 미러 서버를 구축하고자 한다면 ftpsync를 사용하시는 것을 권장합니다.

본문에서는 ftpsync를 이용해서 데비안 미러 서버를 만든 방법을 설명합니다. 이 글의 부제목은 '데비안유저스의 미러 서버 구축기'입니다.


목차

Nginx 설치 및 설정

$ sudo apt install nginx nginx-extras libnginx-mod-http-geoip libnginx-mod-http-fancyindex


nginx에서 디렉터리 목록 나열을 허용하기(fancyindex 이용) [1]

/etc/nginx/sites-available/default 파일에서 ‘location /’ 항목에 아래 초록색 내용을 추가합니다. fancyindex를 이용하면 웹에서 파일과 디렉터리 목록을 예쁘게 볼 수 있습니다.

(.. 생략 ..)
location / { 
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.                           


			#autoindex on;   # 디렉터리 목록을 나열한다.
			#autoindex_exact_size off;
        
+          fancyindex on;   # 디렉터리 목록을 나열한다.(fancyindex 사용)
+          fancyindex_exact_size off;

        try_files $uri $uri/ =404;
    }
(.. 생략 ..)

nginx에서 해외 아이피 차단. 국내 아이피만 접속 허용(geoip 이용)

/etc/nginx/nginx.conf 파일 수정

/etc/nginx/nginx.conf 파일에 아래 초록색으로 표시한 내용을 추가합니다.

user www-data;                                                      
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on; 
}

http {
+    # 우리나라를 제외한 해외 아이피를 모두 차단함. 
+    geoip_country /usr/share/GeoIP/GeoIP.dat;
+    map $geoip_country_code $allowed_country {
+        default no; 
+        KR yes;
+    }   

    ##  
    # Basic Settings
    ##  

    sendfile on;
 (..생략..)

/etc/nginx/sites-available/default 파일 수정

(..생략..)
location / { 
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.

        fancyindex on; 
        fancyindex_exact_size off;

+       if ($allowed_country = no) {
+            return 444;
+       }            
+        try_files $uri $uri/ /index.html; 

-        #try_files $uri $uri/ =404;
    }
(..생략..)

Nginx 재시작

$ sudo systemctl restart nginx


rsync 설치

rsync를 설치하는 이유는 미러 서버를 구축할 때 사용하는 ftpsync가 내부적으로 rsync를 이용해서 원격 서버에 있는 파일 또는 디렉터리들을 받아오기 때문입니다.

$ sudo apt install rsync


MRTG

MRTG(Multi Router Traffic Grapher)를 사용하는 목적은 간단하게 네트워크의 트래픽(인바운드, 아웃바운드)을 지켜보기 위해서입니다. 트래픽을 지켜보는 다른 프로그램(Zabbix, Cacti 등)을 사용하고자 한다면 굳이 MRTG를 사용하지 않아도 됩니다.

MRTG 설치 및 설정 [2]

$ sudo apt install snmpd snmp mrtg


/etc/snmp/snmpd.conf 파일을 아래처럼 수정합니다.

(..생략..)
-#rocommunity public  localhost
+rocommunity public  localhost
(..생략..)


snmpd를 재시작합니다.

$ systemctl restart snmpd


mrtg 디렉터리를 생성합니다.

$ sudo mkdir /data/mrtg


mrtg.cfg 파일을 백업합니다.

$ sudo cp /etc/mrtg.cfg /etc/mrtg.cfg.bak


/etc/mrtg 파일을 편집합니다.

(..생략..)
- #WorkDir: /var/www/mrtg
+ WorkDir: /data/mrtg
(..생략..)
+ #  to get bits instead of bytes and graphs growing to the right
+ Options[_]: growright, bits
(..생략..)


cfgmaker public@localhost > /etc/mrtg.cfg


MRTG의 index.html 파일을 생성합니다.

indexmaker /etc/mrtg.cfg > /data/mrtg/index.html


MRTG 데이터는 /data/mrtg에 저장됩니다. 이 데이터를 웹에서 보여주고자 /var/www/mrtg로 심볼릭링크를 걸었습니다.

$ ln -s /data/mrtg/ /var/www/mrtg

이제 MRTG의 인덱스 페이지를 볼 수 있습니다. 저의 경우는 http://mirror.debianusers.or.kr/mrtg/ 에서 MRTG의 인덱스 페이지를 확인할 수 있습니다.


MRTG 추가 설정

/etc/mrtg.cfg을 아래와 같이 설정합니다. 저의 경우 아래 /etc/mrtg.cfg 파일에서 설정한 내용을 http://mirror.debianusers.or.kr/mrtg/debianusers-mirror_3.html 에서 확인할 수 있습니다.

(..생략..)
- Target[localhost_3]: 3:public@localhost:
+ Target[debianusers-mirror_3]: 3:public@localhost:
- SetEnv[localhost_3]: MRTG_INT_IP="121.78.112.223" MRTG_INT_DESCR="No-Description"
+ SetEnv[debianusers-mirror_3]: MRTG_INT_IP="121.78.112.223" MRTG_INT_DESCR="No-Description"
- MaxBytes[localhost_3]: 125000000
+ MaxBytes[debianusers-mirror_3]: 1250000
- Title[localhost_3]: Traffic Analysis for 3 -- debianusers-mirror
+ Title[debianusers-mirror_3]: Traffic Analysis for 3 -- debianusers-mirror
- PageTop[localhost_3]: <h1>Traffic Analysis for 3 -- debianusers-mirror</h1>
+ PageTop[debianusers-mirror_3]: <h1>Traffic Analysis for 3 -- debianusers-mirror</h1>
        <div id="sysdetails">
            <table>
                <tr>
                    <td>System:</td>
                    <td>debianusers-mirror in Sitting on the Dock of the Bay</td>
                </tr>
                <tr>
                    <td>Maintainer:</td>
-                    <td>Me &lt;me@example.org&gt;</td>
+                    <td>Hyun-gwan Seo&lt;westporch@debianusers.or.kr&gt;</td>
                </tr>
                <tr>
                    <td>Description:</td>
                    <td>No-Description  </td>
                </tr>
                <tr>
                    <td>ifType:</td>
                    <td>ethernetCsmacd (6)</td>
                </tr>
                <tr>
                    <td>ifName:</td>
                    <td>enp5s0f1</td>
                </tr>
                <tr>
                    <td>Max Speed:</td>
-                    <td>125.0 MBytes/s</td>
+                    <td>1.25 MBytes/s</td>
                </tr>
                <tr>
                    <td>Ip:</td>
                    <td>121.78.112.223 (debianusers-mirror)</td>
                </tr>
            </table>
        </div>


디렉터리(/data)

디렉터리(/data)의 퍼미션 변경

$ sudo chmod 757 data

미러용 디렉터리(/data/mirrors) 생성

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ mkdir /data/mirrors


ftpsync [3] [4] [5] [6]

사용자 계정(ftpsync) 생성

$ sudo adduser ftpsync

crontab을 사용할 수 있는 사용자 설정

/etc/cron.allow 파일에 'ftpsync'를 추가한 후 저장합니다.

root
westporch
+ ftpsync

크론을 다시 시작합니다.

$ sudo systemctl restart cron

ftpsync 다운로드

아래 명령어로 ftpsync를 내려받습니다.

$ wget https://ftp-master.debian.org/ftpsync.tar.gz -P /home/ftpsync

다운로드 받은 파일을 압축 해제합니다. ftpsync.tar.gz 파일의 압축을 해제하면 distrib 디렉터리가 생깁니다.

디렉터리 변경(이동)

$ mv /home/ftpsync/distrib/bin /home/ftpsync/
$ mv /home/ftpsync/distrib/etc /home/ftpsync/

로그 디렉터리(/home/ftpsync/log) 생성

ftpsync에서 작업한 로그가 저장될 디렉터리(/home/ftpsync/log)를 생성합니다.

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ mkdir /home/ftpsync/log

저장소(debian) 미러링

/home/ftpsync/etc/ftpsync.conf 파일 생성

/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync.conf 파일을 생성합니다.

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync.conf

/home/ftpsync/etc/ftpsync.conf 파일 설정

ftpsync.conf 파일은 데비안 미러 서버에서 'debian' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian/ 저장소를 만들었습니다. 제가 사용하는 ftpsync.conf는 다음과 같습니다.

########################################################################
########################################################################
## This is a sample configuration file for the ftpsync mirror script. ##
## Only options most users may need are included.  For documentation  ##
## and all available options see ftpsync.conf(5).                     ##
########################################################################
########################################################################

- # MIRRORNAME=`hostname -f`
+ MIRRORNAME=`hostname -f`
- # TO="/srv/mirrors/debian/"
+ TO="/data/mirrors/debian/"
# MAILTO="$LOGNAME"
# HUB=false

########################################################################
## Connection options
########################################################################

- RSYNC_HOST=
+ RSYNC_HOST= "ftp.kaist.ac.kr"
RSYNC_PATH="debian"
# RSYNC_USER=
# RSYNC_PASSWORD=

########################################################################
## Mirror information options
########################################################################

# INFO_MAINTAINER="Admins <admins@example.com>, Person <person@example.com>"
# INFO_SPONSOR="Example <https://example.com>"
# INFO_COUNTRY=DE
# INFO_LOCATION="Example"
# INFO_THROUGHPUT=10Gb

########################################################################
## Include and exclude options
########################################################################

- # ARCH_INCLUDE=
+ #ARCH_INCLUDE="all amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el s390x"
+ ARCH_INCLUDE="amd64 i386 source"
# ARCH_EXCLUDE=

########################################################################
## Log option
########################################################################

- # LOGDIR=
+ LOGDIR="/home/ftpsync/log"

+ ## limit I/O bandwidth. Value is KBytes per second, unset or 0 means unlimited
+ RSYNC_BW="1024"  # (1024KByte/s / 1024) * 8 = 8Mbit/s

미러링 실행

$ /home/ftpsync/bin/./ftpsync

미러링 로그 확인

아래 명령으로 미러링의 실시간 로그를 확인할 수 있습니다.

$ tail -f /home/ftpsync/log/rsync-ftpsync.log

저장소(debian-security) 미러링

/home/ftpsync/etc/ftpsync-security.conf 파일 생성

/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-security.conf 파일을 생성합니다.

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-security.conf

/home/ftpsync/etc/ftpsync-security.conf 파일 설정

ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-security' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-security.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-security/ 저장소를 만들었습니다. 제가 사용하는 ftpsync-security.conf는 다음과 같습니다.

########################################################################
########################################################################
## This is a sample configuration file for the ftpsync mirror script. ##
## Only options most users may need are included.  For documentation  ##
## and all available options see ftpsync.conf(5).                     ##
########################################################################
########################################################################

- # MIRRORNAME=`hostname -f`
+ MIRRORNAME=`hostname -f`
- # TO="/srv/mirrors/debian/"
+ TO="/data/mirrors/debian-security/"
# MAILTO="$LOGNAME"
# HUB=false

########################################################################
## Connection options
########################################################################

- RSYNC_HOST=
+ RSYNC_HOST="ftp.kaist.ac.kr"
- RSYNC_PATH="debian"
+ RSYNC_PATH="debian-security"
# RSYNC_USER=
# RSYNC_PASSWORD=

########################################################################
## Mirror information options
########################################################################

# INFO_MAINTAINER="Admins <admins@example.com>, Person <person@example.com>"
# INFO_SPONSOR="Example <https://example.com>"
# INFO_COUNTRY=DE
# INFO_LOCATION="Example"
# INFO_THROUGHPUT=10Gb

########################################################################
## Include and exclude options
########################################################################

- # ARCH_INCLUDE=
+ #ARCH_INCLUDE="all amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el s390x"
+ ARCH_INCLUDE="amd64 i386 source"
# ARCH_EXCLUDE=

########################################################################
## Log option
########################################################################

- # LOGDIR=
+ LOGDIR="/home/ftpsync/log"

+ ## limit I/O bandwidth. Value is KBytes per second, unset or 0 means unlimited
+ RSYNC_BW="1024"  # (1024KByte/s / 1024) * 8 = 8Mbit/s

미러링 실행

$ /home/ftpsync/bin/./ftpsync sync:archive:security

미러링 로그 확인

아래 명령으로 저장소(debian-security)를 미러링하는 실시간 로그를 확인할 수 있습니다.

$ tail -f /home/ftpsync/log/rsync-ftpsync-security.log

저장소(debian-cd) 미러링

/home/ftpsync/etc/ftpsync-cd.conf 파일 생성

/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-cd.conf 파일을 생성합니다.

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-cd.conf

/home/ftpsync/etc/ftpsync-cd.conf 파일 설정

ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-cd' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-cd.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-cd/ 저장소를 만들었습니다. 제가 사용하는 ftpsync-cd.conf는 다음과 같습니다.

########################################################################
########################################################################
## This is a sample configuration file for the ftpsync mirror script. ##
## Only options most users may need are included.  For documentation  ##
## and all available options see ftpsync.conf(5).                     ##
########################################################################
########################################################################

- # MIRRORNAME=`hostname -f`
+ MIRRORNAME=`hostname -f`
- # TO="/srv/mirrors/debian/"
+ TO="/data/mirrors/debian-cd/"
# MAILTO="$LOGNAME"
# HUB=false

########################################################################
## Connection options
########################################################################

- RSYNC_HOST=
+ RSYNC_HOST="ftp.kaist.ac.kr"
- RSYNC_PATH="debian"
+ RSYNC_PATH="debian-cd"
# RSYNC_USER=
# RSYNC_PASSWORD=

########################################################################
## Mirror information options
########################################################################

# INFO_MAINTAINER="Admins <admins@example.com>, Person <person@example.com>"
# INFO_SPONSOR="Example <https://example.com>"
# INFO_COUNTRY=DE
# INFO_LOCATION="Example"
# INFO_THROUGHPUT=10Gb

########################################################################
## Include and exclude options
########################################################################

- # ARCH_INCLUDE=
+ #ARCH_INCLUDE="all amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el s390x"
+ ARCH_INCLUDE="amd64 i386"
# ARCH_EXCLUDE=

########################################################################
## Log option
########################################################################

- # LOGDIR=
+ LOGDIR="/home/ftpsync/log"

+ ## limit I/O bandwidth. Value is KBytes per second, unset or 0 means unlimited
+ RSYNC_BW="1024"  # (1024KByte/s / 1024) * 8 = 8Mbit/s

미러링 실행

$ /home/ftpsync/bin/./ftpsync sync:archive:cd

미러링 로그 확인

아래 명령으로 미러링의 실시간 로그를 확인할 수 있습니다.

$ tail -f /home/ftpsync/log/rsync-ftpsync-cd.log

저장소(debian-multimedia) 미러링

/home/ftpsync/etc/ftpsync-multimedia.conf 파일 생성

/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-multimedia.conf 파일을 생성합니다.

$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-multimedia.conf

/home/ftpsync/etc/ftpsync-multimedia.conf 파일 설정

ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-multimedia' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-cd.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-multimedia/ 저장소를 만들었습니다. 제가 사용하는 ftpsync-multimedia.conf는 다음과 같습니다.

########################################################################
########################################################################
## This is a sample configuration file for the ftpsync mirror script. ##
## Only options most users may need are included.  For documentation  ##
## and all available options see ftpsync.conf(5).                     ##
########################################################################
########################################################################

- # MIRRORNAME=`hostname -f`
+ MIRRORNAME=`hostname -f`
- # TO="/srv/mirrors/debian/"
+ TO="/data/mirrors/debian-multimedia/"
# MAILTO="$LOGNAME"
# HUB=false

########################################################################
## Connection options
########################################################################

- RSYNC_HOST=
+ RSYNC_HOST="ftp.kaist.ac.kr"
- RSYNC_PATH="debian"
+ RSYNC_PATH="debian-multimedia"
# RSYNC_USER=
# RSYNC_PASSWORD=

########################################################################
## Mirror information options
########################################################################

# INFO_MAINTAINER="Admins <admins@example.com>, Person <person@example.com>"
# INFO_SPONSOR="Example <https://example.com>"
# INFO_COUNTRY=DE
# INFO_LOCATION="Example"
# INFO_THROUGHPUT=10Gb

########################################################################
## Include and exclude options
########################################################################

- # ARCH_INCLUDE=
+ #ARCH_INCLUDE="all amd64 arm64 armel armhf i386 mips mips64el mipsel ppc64el s390x"
+ ARCH_INCLUDE="amd64 i386 source"
# ARCH_EXCLUDE=

########################################################################
## Log option
########################################################################

- # LOGDIR=
+ LOGDIR="/home/ftpsync/log"

+ ## limit I/O bandwidth. Value is KBytes per second, unset or 0 means unlimited
+ RSYNC_BW="1024"  # (1024KByte/s / 1024) * 8 = 8Mbit/s

미러링 실행

$ /home/ftpsync/bin/./ftpsync sync:archive:multimedia

미러링 로그 확인

아래 명령으로 미러링의 실시간 로그를 확인할 수 있습니다.

$ tail -f /home/ftpsync/log/rsync-ftpsync-multimedia.log

/etc/apt/sources.list 파일 수정

클라이언트

/etc/apt/sources.list 파일을 아래와 같이 수정합니다.

# debianusers-mirror [데비안10(buster)를 사용할 경우]
deb http://mirror.debianusers.or.kr/debian/ buster main
deb-src http://mirror.debianusers.or.kr/debian/ buster main

deb http://mirror.debianusers.or.kr/debian-security buster/updates main
deb-src http://mirror.debianusers.or.kr/debian-security buster/updates main

deb http://mirror.debianusers.or.kr/debian/ buster-updates main
deb-src http://mirror.debianusers.or.kr/debian/ buster-updates main

'sudo apt update' 명령을 실행합니다.

$ sudo apt update

미러 서버

직접 셋팅한 미러 서버에서 /etc/apt/sources.list를 local repository로 설정합니다.

deb file:/data/mirrors/debian/ buster main
deb file:/data/mirrors/debian-security buster/updates main contrib

'sudo apt update' 명령을 실행합니다.

$ sudo apt update


미러 서버의 대역폭 설정(wondershaper 이용)

wondershaper 설치

$ sudo apt install wondershaper


시스템 재시작 시에도 wondershaper 설정이 되도록 하기 [7]

wondershaper로 이더넷 장치에 대역폭을 설정해도, 리부팅하면 설정이 초기화됩니다. 따라서 부팅할 때 마다 wondershaper를 적용하도록 해야합니다.

/etc/systemd/wondershaper.conf에 아래 내용을 추가한다.

+ [wondershaper]
+ # Adapter
+ IFACE="eth0"
+ 
+ # Download rate in Kbps
+ DSPEED="10240"
+ 
+ # Upload rate in Kbps
+ USPEED="10240"

/usr/lib/systemd/system/wondershaper.service에 아래 내용을 추가합니다.

+ [Unit]
+ Description=Bandwidth shaper/Network rate limiter
+ After=network.target
+ Wants=network.target
+ 
+ [Service]
+ Type=oneshot
+ RemainAfterExit=yes
+ EnvironmentFile=/etc/systemd/wondershaper.conf
+ ExecStart=/usr/sbin/wondershaper $IFACE $DSPEED $USPEED
+ ExecStop=/usr/sbin/wondershaper clear $IFACE
+
+ [Install]
+ WantedBy=multi-user.target

wondershaper.service 서비스를 시작합니다.

$ sudo systemctl start wondershaper.service

부팅할 때 wondershaper.service를 시작하도록 설정합니다.

$ sudo systemctl enable wondershaper.service
Created symlink /etc/systemd/system/multi-user.target.wants/wondershaper.service → /lib/systemd/system/wondershaper.service.

참고