바뀜

둘러보기로 가기 검색하러 가기
1,332 바이트 추가됨 ,  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
== MRTG ==
[https://oss.oetiker.ch/mrtg/ MRTG(Multi Router Traffic Grapher)]를 사용하는 목적은 간단하게 네트워크의 트래픽(인바운드, 아웃바운드)을 지켜보기 위해서입니다. 트래픽을 지켜보는 다른 프로그램(Zabbix, Cacti 등)을 사용하고자 한다면 굳이 MRTG를 사용하지 않아도 됩니다.
=== MRTG 설치 및 설정 <ref>https://www.youtube.com/watch?v=ftutyWqzRCs</ref> ===
=== MRTG 추가 설정 ===
/etc/mrtg.cfg을 아래와 같이 설정합니다. 저의 경우 아래 /etc/mrtg.cfg 파일에서 설정한 내용은 내용을 http://mirror.debianusers.or.kr/mrtg/debianusers-mirror_3.html 에서 확인할 수 있습니다.
<syntaxhighlight lang="diff">
$ mkdir /data/mirrors
</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
</syntaxhighlight>
 
크론을 다시 시작합니다.
$ sudo systemctl restart cron
</pre>
 
=== ftpsync 다운로드 ===
다운로드 받은 파일을 압축 해제합니다. ftpsync.tar.gz 파일의 압축을 해제하면 distrib 디렉터리가 생깁니다.
 
=== 디렉터리 변경(이동) ===
</pre>
=== 로그 디렉터리(/home/ftpsync/log) 생성 ===
ftpsync에서 작업한 로그가 저장될 디렉터리(/home/ftpsync/log)를 생성합니다.
=== 로그 디렉터리 생성 ===
<pre>
$ id
$ mkdir /home/ftpsync/log
</pre>
 
=== 저장소(debian) 미러링 ===
+ 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) 미러링 ===
+ 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) 미러링 ===
+ 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) 미러링 ===
+ 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 파일 수정 ==
</pre>
 
== 미러 서버의 대역폭 설정(wondershaper 이용)==
 
=== wondershaper 설치 ===
 
<pre>
$ sudo apt install wondershaper
</pre>
 
 
=== 시스템 재시작 시에도 wondershaper 설정이 되도록 하기 <ref>https://documentation.online.net/en/dedicated-server/tutorials/network/configure-wondershaper#launch_wondershaper_automatically_on_boot_with_systemd</ref> ===
wondershaper로 이더넷 장치에 대역폭을 설정해도, 리부팅하면 설정이 초기화됩니다. 따라서 부팅할 때 마다 wondershaper를 적용하도록 해야합니다.
 
/etc/systemd/wondershaper.conf에 아래 내용을 추가한다.
 
<syntaxhighlight lang="diff">
+ [wondershaper]
+ # Adapter
+ IFACE="eth0"
+
+ # Download rate in Kbps
+ DSPEED="10240"
+
+ # Upload rate in Kbps
+ USPEED="10240"
</syntaxhighlight>
 
/usr/lib/systemd/system/wondershaper.service에 아래 내용을 추가합니다.
 
<syntaxhighlight lang="diff">
+ [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
</syntaxhighlight>
 
wondershaper.service 서비스를 시작합니다.
 
<pre>
$ sudo systemctl start wondershaper.service
</pre>
 
부팅할 때 wondershaper.service를 시작하도록 설정합니다.
 
<pre>
$ sudo systemctl enable wondershaper.service
Created symlink /etc/systemd/system/multi-user.target.wants/wondershaper.service → /lib/systemd/system/wondershaper.service.
</pre>
== 참고 ==

둘러보기 메뉴