Raspberrypi omv

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

Raspberry pi OMV(Open Media Vault) 내용 정리.

Basic

Facilities

다음의 기능들이 가능해야 한다.

  • RAID 1
  • 내부/외부 NAS 접속
  • 네트워크 드라이브 설정 가능
  • 사용자 단위 디렉토리 지정(Permission 적용)
  • 토렌트 데몬 적용
  • Cron 작업 설정(외부 사이트 백업 작업)
  • 24 hours working

Hardware

다음의 사양으로 NAS를 구성한다. RAID 1 을 사용할 예정이므로 2베이 스토리지를 구했다.

  • Controller : Raspberrypi 3(4GB micro sd card)
  • Storage : 이지넷유비쿼터스 NEXT-702U3 RAID

Storage

장기간 미사용시, 슬립모드가 지원되는 제품을 구매할 예정이었으나, 해당 제품이 슬립모드 이후 다시 작동이 안된다는 리뷰가 있어서 일반 2Bay 스토리지 중 가장 저렴한 제품으로 선택함.

Installation

Download

Raspberry pi NAS 를 위한 배포본이 있다. Open Media Vault. 아래의 링크에서 다운로드가 가능하다.

이미 다른 배포본이 설치된 상태에서 Open Media Vault 를 설치하고 싶다면 아래를 참조하자.

Install

먼저 umount 를 시켜야 한다. <source lang=bash> $ umount /dev/mmcblk0p $ umount /dev/mmcblk0p1 $ umount /dev/mmcblk0p2 $ umount /dev/mmcblk0p3 </source>

파일을 dd 명령어로 입력하면 된다. <source lang=bash> $ sudo dd bs=4M if=omv_2.2.5_rpi2_rpi3.img of=/dev/mmcblk0

$ sudo dd bs=4M if=./omv_3.0.24_beta_rpi2_rpi3.img of=/dev/mmcblk0 status=progress 1740636160 bytes (1.7 GB, 1.6 GiB) copied, 17.0886 s, 102 MB/s </source>

Configurations

Start

OMV 는 웹 인터페이스를 제공한다. 단, Apache 가 아니라 nginx 로 구동된다. <source lang=bash> $ sudo service nginx start </source>

Settings

Remote download backup

sftp download 후, 기존 파일 삭제한다.

이상하게 ssh-copy-id 명령어가 잘 되지 않았다. 때문에 부득이 별도의 패스워드를 입력하는 스크립트를 사용했다<ref>http://stackoverflow.com/questions/5386482/how-to-run-the-sftp-command-with-a-password-from-bash-script</ref>.

#!/bin/sh

export SSHPASS=<your_password>
cd <local_backup_directory>

sshpass -e sftp -oBatchMode=no -b - <username>@<hostname> << EOF
cd <remote_backup_directory>
<sftp commands>
bye
EOF

rsync data backup

본래 RAID1(미러링)으로 백업을 구성할 계획이었다. 하지만.. 결론적으로는 정말 바보같은 생각이었다.

무중단 서비스를 구성하는 것이 아닌이상, 굳이 RAID1 를 선택할 필요가 없었던 것이었다. 한번의 아픈 실패를 겪고, 대안으로 rsync 를 쓰기로 했다.

Plugins

owncloud

설정한 owncloud 로 접속 시도시, 다음과 같은 오류가 나타나는 경우가 있다.

You are accessing the server from an untrusted domain.

Please contact your administrator. 
If you are an administrator of this instance, configure the "trusted_domain" setting in config/config.php. 
An example configuration is provided in config/config.sample.php.

이는 owncloud 설정 중, trusted_domains 항목을 설정하지 않아서인데, omv UI 에서는 설정하는 항목을 찾지 못했다.

직접 파일을 수정해야 한다. 아래의 항목에 있는 파일을 열고, trusted_domains 항목에 원하는 자신(raspberry pi)의 도메인/Ipaddress 를 입력해야 한다.

cat /var/www/owncloud/config/config.php

...
  'trusted_domains' => 
  array (
    0 => 'raspberrypi.local:8443',
    1 => '192.168.100.10:8443',
  ),
...

파일을 수정하기 위해서는 다음과 같은 순서로 수정해야 한다<ref>http://forums.openmediavault.org/index.php/Thread/7045-OMV-owncloud-plugins-can-t-add-trusted-domain/</ref>.

- owncloud 를 enable 한다.
- ssh 로 접속해서 파일을 수정한다.
- nginx 를 재시작한다(/etc/init.d/nginx restart).

transmissionbt

별도의 패키지를 설치해서도 가능하지만, 플러그인으로도 설치/관리가 가능하다.

별도 설치시, 다음의 패키지를 설치하면 된다. 별도로 설치를 하게되면 OMV Web ui 로 관리/설정이 불가능하다. <source lang=bash> $ sudo apt-get install transmission transmission-daemon </source>

Auto remove

토렌트 다운로드 완료 후, 자동 삭제 스크립트<ref>http://goedonthouden.com/2013/04/21/transmission-daemon-auto-remove-torrents/</ref>이다. 별다른 점은 없고, transmission 에 접속해서 다운로드 완료된 토렌트를 찾아 삭제하는 스크립트이다. cron 이나, 다른 별도의 툴을 이용하여 매번 스크립트를 실행해 주어야 한다.

<source lang=bash> $ cat removecompletedtorrents.sh

  1. !/bin/sh

TORRENTLIST=`transmission-remote --auth=user:password --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=' ' --fields=1`

for TORRENTID in $TORRENTLIST do echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"

DL_COMPLETED=`transmission-remote --auth=user:password --torrent $TORRENTID --info | grep "Percent Done: 100%"` if [ "$DL_COMPLETED" != "" ]; then echo "Torrent #$TORRENTID is completed." echo "Removing torrent from list." transmission-remote --auth=user:password --torrent $TORRENTID --remove else echo "Torrent #$TORRENTID is not completed. Ignoring." fi echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *" done </source>

cron job에 추가해주면 된다. 매 1분마다 동작한다.

* * * * * root ../../bin/removecompletedtorrents.sh

혹은 Script to process after torrent finishes 항목에 파일 경로를 입력해주면 된다.

See also

References

<references />