바뀜

둘러보기로 가기 검색하러 가기
16,101 바이트 추가됨 ,  2021년 5월 9일 (일) 22:37
편집 요약 없음
데비안 공식 문서에서 'ftpsync'를 이용해서 데비안 미러 서버를 만드는 것을 권장하고 있습니다. ftpsync는 데비안 프로젝트에서 만든 프로그램입니다. 이 프로그램을 이용하면 쉽게 미러 서버를 구축할 수 있습니다.
 
물론 'apt-mirror'를 이용해서 데비안 미러 서버를 만들 수도 있습니다. 데비안 미러 서버를 구축하고자 한다면 ftpsync를 사용하시는 것을 권장합니다.
 
본문에서는 ftpsync를 이용해서 [http://mirror.debianusers.or.kr/ 데비안 미러 서버]를 만든 방법을 설명합니다. 이 글의 부제목은 '데비안유저스의 미러 서버 구축기'입니다.
 
 
== Nginx 설치 및 설정 ==
미러링 서비스를 제공할 서버의 웹 서버는 꼭 Nginx로 운영하지 않아도 됩니다. Apache 또는 Lighttpd 등으로 웹 서버를 운영해도 됩니다. 단지 제가 Nginx를 선호하기 때문에 웹 서버를 Nginx로 운영하는 것입니다.
<pre>
=== nginx에서 Nginx에서 디렉터리 목록 나열을 허용하기(fancyindex 이용) <ref>https://marlon.kern.earth/blog/2019-01-14_fancy-index.html</ref> ===
/etc/nginx/sites-available/default 파일에서 ‘location /’ 항목에 아래 초록색 내용을 추가합니다.
fancyindex를 이용하면 웹에서 파일과 디렉터리 목록을 예쁘게 볼 수 있습니다.
</syntaxhighlight>
=== nginx에서 Nginx에서 해외 아이피 차단. 국내 아이피만 접속 허용(geoip 이용) ===저는 제 미러 서버에 국내 아이피만 접속되도록 설정했습니다. 해외 아이피를 가진 사용자가 제 미러 서버에 접속이 차단되도록 설정한 이유는 해외 트래픽 요금이 비싸기 때문입니다. 트래픽 요금에 걱정이 없으신 분은 저처럼 해외 트래픽을 차단할 필요 없습니다.
==== /etc/nginx/nginx.conf 파일 수정 ====
$ sudo systemctl restart nginx
</pre>
 
== rsync 설치 ==
rsync를 설치하는 이유는 미러 서버를 구축할 때 사용하는 ftpsync가 내부적으로 rsync를 이용해서 원격 서버에 있는 파일 또는 디렉터리들을 받아오기 때문입니다.
 
<pre>
$ sudo apt install rsync
</pre>
 == MRTG ==[https://oss.oetiker.ch/mrtg/ MRTG(Multi Router Traffic Grapher)]를 사용하는 목적은 간단하게 네트워크의 트래픽(인바운드, 아웃바운드)을 지켜보기 위해서입니다. 트래픽을 지켜보는 다른 프로그램(Zabbix, Cacti 등)을 사용하고자 한다면 굳이 MRTG를 사용하지 않아도 됩니다. === MRTG 설치 및 설정 <ref>https://www.youtube.com/watch?v=ftutyWqzRCs</ref>===
<pre>
$ sudo apt install snmpd snmp 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 에서 확인할 수 있습니다.
 
<syntaxhighlight lang="diff">
(..생략..)
- 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>
</syntaxhighlight>
 
== 디렉터리(/data) ==
</pre>
 == ftpsync <ref>https://www.debian.org/mirror/ftpmirror#how</ref> <ref>https://salsa.debian.org/mirror-team/archvsync/#usage</ref> <ref>https://manpages.debian.org/testing/ftpsync/ftpsync.conf.5.en.html</ref> <ref>https://manpages.debian.org/testing/ftpsync/ftpsync.1.en.html</ref> ==
=== 사용자 계정(ftpsync) 생성 ===
+ ftpsync
</syntaxhighlight>
 
크론을 다시 시작합니다.
$ sudo systemctl restart cron
</pre>
 
=== ftpsync 다운로드 ===
다운로드 받은 파일을 압축 해제합니다. ftpsync.tar.gz 파일의 압축을 해제하면 distrib 디렉터리가 생깁니다.
 
=== 디렉터리 변경(이동) ===
</pre>
=== 로그 디렉터리(/home/ftpsync/log) 생성 ===
ftpsync에서 작업한 로그가 저장될 디렉터리(/home/ftpsync/log)를 생성합니다.
=== 로그 디렉터리 생성 ===
<pre>
$ id
</pre>
=== 저장소(debian) 미러링 ===
==== /home/ftpsync/etc/ftpsync.conf 파일 생성 및 설정 ==== /home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync.conf 파일을 생성합니다.
<pre>
</pre>
==== /home/ftpsync/etc/ftpsync.conf 파일 설정 ====
ftpsync.conf 파일은 데비안 미러 서버에서 'debian' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian/ 저장소를 만들었습니다.
제가 사용하는 ftpsync.conf는 다음과 같습니다.
+ RSYNC_BW="1024" # (1024KByte/s / 1024) * 8 = 8Mbit/s
</syntaxhighlight>
 
==== 미러링 실행 ====
미러링이 완료된 후에 나중에 미러링을 갱신하려면 아래 명령을 다시 실행하면 됩니다. 아래 명령을 crontab에 등록해서 주기적으로 실행하면 도움이 될 것입니다.
 
<pre>
$ /home/ftpsync/bin/./ftpsync
</pre>
 
==== 미러링 로그 확인 ====
아래 명령으로 저장소(debian)를 미러링하는 실시간 로그를 확인할 수 있습니다.
 
<pre>
$ tail -f /home/ftpsync/log/rsync-ftpsync.log
</pre>
 
=== 저장소(debian-security) 미러링 ===
 
==== /home/ftpsync/etc/ftpsync-security.conf 파일 생성 ====
/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-security.conf 파일을 생성합니다.
 
<pre>
$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-security.conf
</pre>
 
==== /home/ftpsync/etc/ftpsync-security.conf 파일 설정 ====
ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-security' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-security.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-security/ 저장소를 만들었습니다.
제가 사용하는 ftpsync-security.conf는 다음과 같습니다.
 
<syntaxhighlight lang="diff">
########################################################################
########################################################################
## 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
</syntaxhighlight>
 
==== 미러링 실행 ====
미러링이 완료된 후에 나중에 미러링을 갱신하려면 아래 명령을 다시 실행하면 됩니다. 아래 명령을 crontab에 등록해서 주기적으로 실행하면 도움이 될 것입니다.
 
<pre>
$ /home/ftpsync/bin/./ftpsync sync:archive:security
</pre>
 
==== 미러링 로그 확인 ====
 
아래 명령으로 저장소(debian-security)를 미러링하는 실시간 로그를 확인할 수 있습니다.
 
<pre>
$ tail -f /home/ftpsync/log/rsync-ftpsync-security.log
</pre>
 
=== 저장소(debian-cd) 미러링 ===
 
==== /home/ftpsync/etc/ftpsync-cd.conf 파일 생성 ====
/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-cd.conf 파일을 생성합니다.
 
<pre>
$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-cd.conf
</pre>
 
==== /home/ftpsync/etc/ftpsync-cd.conf 파일 설정 ====
ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-cd' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-cd.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-cd/ 저장소를 만들었습니다.
제가 사용하는 ftpsync-cd.conf는 다음과 같습니다.
 
<syntaxhighlight lang="diff">
########################################################################
########################################################################
## 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
</syntaxhighlight>
 
==== 미러링 실행 ====
미러링이 완료된 후에 나중에 미러링을 갱신하려면 아래 명령을 다시 실행하면 됩니다. 아래 명령을 crontab에 등록해서 주기적으로 실행하면 도움이 될 것입니다.
 
<pre>
$ /home/ftpsync/bin/./ftpsync sync:archive:cd
</pre>
 
==== 미러링 로그 확인 ====
아래 명령으로 저장소(debian-cd)를 미러링하는 실시간 로그를 확인할 수 있습니다.
 
<pre>
$ tail -f /home/ftpsync/log/rsync-ftpsync-cd.log
</pre>
 
=== 저장소(debian-multimedia) 미러링 ===
 
==== /home/ftpsync/etc/ftpsync-multimedia.conf 파일 생성 ====
/home/ftpsync/etc/ftpsync.conf.sample 파일을 복사해서 ftpsync-multimedia.conf 파일을 생성합니다.
 
<pre>
$ id
uid=1001(ftpsync) gid=1001(ftpsync) groups=1001(ftpsync)
$ cp /home/ftpsync/etc/ftpsync.conf.sample /home/ftpsync/etc/ftpsync-multimedia.conf
</pre>
 
==== /home/ftpsync/etc/ftpsync-multimedia.conf 파일 설정 ====
ftpsync-security.conf 파일은 데비안 미러 서버에서 'debian-multimedia' 저장소를 다운로드하는 데 사용합니다. 저는 ftpsync-cd.conf 파일을 이용해 http://mirror.debianusers.or.kr/debian-multimedia/ 저장소를 만들었습니다.
제가 사용하는 ftpsync-multimedia.conf는 다음과 같습니다.
 
<syntaxhighlight lang="diff">
########################################################################
########################################################################
## 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
</syntaxhighlight>
 
==== 미러링 실행 ====
미러링이 완료된 후에 나중에 미러링을 갱신하려면 아래 명령을 다시 실행하면 됩니다. 아래 명령을 crontab에 등록해서 주기적으로 실행하면 도움이 될 것입니다.
 
<pre>
$ /home/ftpsync/bin/./ftpsync sync:archive:multimedia
</pre>
 
==== 미러링 로그 확인 ====
아래 명령으로 저장소(debian-multimedia)를 미러링하는 실시간 로그를 확인할 수 있습니다.
 
<pre>
$ tail -f /home/ftpsync/log/rsync-ftpsync-multimedia.log
</pre>
 
 
== /etc/apt/sources.list 파일 수정 ==
 
=== 클라이언트 ===
 
/etc/apt/sources.list 파일을 아래와 같이 수정합니다.
 
<pre>
# 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
</pre>
 
'sudo apt update' 명령을 실행합니다.
<pre>
$ sudo apt update
</pre>
 
=== 미러 서버 ===
직접 셋팅한 미러 서버에서 /etc/apt/sources.list를 local repository로 설정합니다.
 
<pre>
deb file:/data/mirrors/debian/ buster main
deb file:/data/mirrors/debian-security buster/updates main contrib
</pre>
 
'sudo apt update' 명령을 실행합니다.
<pre>
$ sudo apt update
</pre>
 
== 참고 ==

둘러보기 메뉴