vendredi 8 avril 2016

Setup a raspberry seed box from scratch

Setup a raspberry torrent box from scratch
with transmission - samba (optimized for speed)- nginx for ssl access to transmission webgui :

!!! ScRaTcH !!! (buy raspberry, SD card, USB key, power supply, download install raspbian on SD, etc...)

Update your PI


sudo raspi-config
    do_what_you_want (server name!)

sudo apt-get update
sudo apt-get upgrade

Prepare folders


sudo mkdir /media/key
sudo mkdir /media/key/complete
sudo mkdir /media/key/incomplete
sudo mkdir /media/key/watch
sudo chmod 775 -R /media/key
sudo fdisk -l
sudo mount -t auto /dev/sda1 /media/key
sudo nano /etc/fstab

   /dev/sda1       /media/key      auto    noatime         0       0


Setup users


sudo useradd nas -m -G users
sudo passwd nas

Install Samba


sudo apt-get install samba
sudo smbpasswd -a nas
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.old
sudo nano /etc/samba/smb.conf
   [global]
       security = user
       workgroup = WORKGROUP
       server string = %h server
       netbios name = your_server_name

        socket options = IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072 TCP_NODELAY
        min receivefile size = 2048
        use sendfile = true
        aio read size = 2048
        aio write size = 2048
        write cache size = 1024000
        read raw = yes
        write raw = yes
        getwd cache = yes
        oplocks = yes
        max xmit = 32768
        dead time = 15
        large readwrite = yes

   [NAS]
       comment = NAS
       path = /media/key
       valid users =@users
       force group = users
       create mask = 0660
       directory mask = 0771
       read only = no

sudo /etc/init.d/samba start
sudo apt-get install transmission-daemon
sudo service transmission-daemon stop
sudo usermod -a -G debian-transmission nas
sudo chgrp -R debian-transmission /media/key
sudo chmod -R 775 /media/key
sudo mv /etc/transmission-daemon/settings.json /etc/transmission-daemon/settings.json.old
sudo nano /etc/transmission-daemon/settings.json
        "download-dir": "/media/key/complete",
        "incomplete-dir": "/media/key/incomplete",
        "rpc-username": "WHAT_YOU_WANT",
        "rpc-password": "WHAT_YOU_WANT",

sudo service transmission-daemon start

Install nginx


sudo apt-get install nginx
sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

sudo nano /etc/nginx/sites-available/default

server {
       listen 80;
       server_name xxx;
       return 301 https://$host$request_uri;
}

server {
       listen 443 ssl;
       server_name xxx;
       access_log off;

       ssl_certificate /etc/nginx/ssl/nginx.crt;
       ssl_certificate_key /etc/nginx/ssl/nginx.key;

       location / {
               proxy_pass http://127.0.0.1:9091/transmission/web/;
               proxy_set_header Connection "";
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_pass_header X-Transmission-Session-Id;
       }

       location /rpc {
               proxy_pass http://127.0.0.1:9091/transmission/rpc;
               proxy_set_header Connection "";
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_pass_header X-Transmission-Session-Id;
       }
}

Or with http redirection to https:

server {
       listen 80;
       access_log off;
       server_name xxx;
       return 301 https://$host$request_uri;
}

server {
        listen 443 ssl;
        server_name xxx;
        access_log off;
        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;
        location / {
               proxy_pass http://127.0.0.1:9091/transmission/web/;
               proxy_set_header Connection "";
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_pass_header X-Transmission-Session-Id;
               }
        location /rpc {
               proxy_pass http://127.0.0.1:9091/transmission/rpc;
               proxy_set_header Connection "";
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_pass_header X-Transmission-Session-Id;
               }
        }

Build SSL keys


sudo mkdir -p /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 36500 -newkey rsa:4096 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
sudo service nginx restart


Fix IP address


Optionl

Use fixed ip address

sudo nano /etc/dhcpcd.conf

# at the bottom of the file....
 interface eth0
 static ip_address=192.168.1.100/24
 static routers=192.168.1.254
 static domain_name_servers=8.8.8.8



Aucun commentaire:

Enregistrer un commentaire