I won a Raspberry Pi at the IBM booth at DevOps Enterprise Summit 2014!
Raspberry Pi is awesome and delicious. What's not to love about a $35 computer the size of a deck of cards?
I've been using a Pi for some time now connected to an external drive that acts as my backup server. I use duplicity to SSH files to the Pi storage. Simple, easy and effective. It's been working great for years, but lately I've been wanting something more modern, something that I can use to both store files and retrieve them easily, from computers and phones. You know, like Dropbox.
I've been hearing good things about ownCloud recently, on podcasts and in articles. It's a self-managed file storage system (meaning you manage it, not someone else), and has some nice integrations for photos, music and documents (and other things too). It's open source. It's free to use. It has multiple Android apps that can integrate with it. So I thought I'd give it a try.
Why not put it on a Pi?
Maybe win a raffle or something.
The Pi doesn't come with any storage at all. It's designed to use and SD card as a hard drive, so you'll need one. Any cheap SD card will do; I recommend 8GB in just about any class you can find.
This is a file server, right?
I'm all Fedora-ed up on my laptops, so even though I've been running Raspbian on my old Pi, I wanted to give Pidora a shot.
Download it from here.
On a Fedora computer that can read/write an SD card,
yum install fedora-arm-installer
Run fedora-arm-installer and put the image on the SD card.
Insert the SD card in the Pi. Turn it on and finish Fedora setup.
- I assume you can run an installer
- I assume you can handle your IP business
- I set startup to be console, not GUI; your choice
Check out the OwnCloud website.
Set up the repository and install ownCloud like this.
cd /etc/yum.repos.d/
wget http://download.opensuse.org/repositories/isv:ownCloud:community/Fedora_20/isv:ownCloud:community.repo
yum install owncloud
Also you need to install a missed dependency.
yum install php-gd
We're going to enable HTTPS, obviously.
yum install mod_ssl
You're setting up a file server, so you're going to need more storage than your little SD card provides. I have an external drive mounted at /mnt/iosafe. OwnCloud has a 'data' directory that holds all the things, and it should live on this external drive.
mkdir -p /mnt/iosafe/owncloud/data
mv /var/www/html/owncloud/data /var/www/html/owncloud/data.bak
ln -s /mnt/iosafe/owncloud/data /var/www/html/owncloud/data
chown apache:apache /mnt/iosafe/owncloud/data
chmod 0770 /mnt/iosafe/owncloud/data
rsync -av /var/www/html/owncloud/data.bak/ /var/www/html/owncloud/data
Start and enable httpd
systemctl start httpd.service
systemctl enable httpd.service
Your ownCloud instance should be up at https://i.p.address/owncloud.
I want to be able to access my ownCloud from out in the world, so I'll need a hostname that can roll with my IP address changing every so often. I decided to use no-ip.com as my dynamic DNS service. It's free and has a linux client.
Set up an account.
Download the linux client to the Pi and explode it.
In the exploded dir
$ make
$ sudo make install
The package contains a Red Hat init script. Let's use it.
cp redhat.noip.sh /etc/init.d/noip
chmod +x /etc/init.d/noip
systemctl start noip.service
systemctl enable noip.service
Go see your owncloud at https://your.fancy.fqdn/owncloud/
Enable 'Enforce HTTPS' on the admin page: https://your.fancy.fqdn/owncloud/index.php/settings/admin.
I used this as a reference.
yum install php-apc
vim /etc/cron.d/owncloud
*/15 * * * * apache /usr/bin/php -f /var/www/html/owncloud/cron.php
Then configure cron in the UI at https://your.fancy.fqdn/owncloud/index.php/settings/admin.
And add this line to /var/www/html/owncloud/config/config.php
'overwritewebroot' => '/owncloud',
yum install mod_xsendfile
And add these lines to /etc/httpd/conf.d/owncloud.conf
SetEnv MOD_X_SENDFILE_ENABLED 1
XSendFile On
XSendFilePath /tmp/oc-noclean
Also, ntpd should be running.
yum install ntp
systemctl start ntpd.service
systemctl enable ntpd.service
I used this as a reference.
Install sendmail-cf so you can configure sendmail
yum install sendmail-cf
First, go to Gmail and create an app-specific password. This is the password you'll use below.
mkdir -m 700 /etc/mail/authinfo/
cd /etc/mail/authinfo/
vim gmail-auth
gmail-auth:
AuthInfo: "U:root" "I:YOUR GMAIL EMAIL ADDRESS" "P:YOUR APP-SPECIFIC PASSWORD"
makemap hash gmail-auth < gmail-auth
cd /etc/mail
vim sendmail.mc
Right before the first MAILER define, put this:
define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl
make -C /etc/mail
systemctl unmask sendmail.service
systemctl start sendmail.service
systemctl enable sendmail.service
Then go into the admin page: https://your.fancy.fqdn/owncloud/index.php/settings/admin
and configure Email Server Send Mode to be 'sendmail'.
vim /boot/config.txt
arm_freq=900
sdram_freq=500
At this point you should have a performant (well, for a Pi), secure, and full-featured ownCloud install. Go install the app on your phone to have photos and videos automatically upload, and to be able to access calendars, contacts, notes, password databases, photos, and a ton more things. So far I'm really pleased with the result. I hope you will be too.
This is beautiful. I would use some caution on that last bit about overclocking though. Unless your SD Card is at the very least a Class 10, the risk of data corruption is extremely likely. Awesome job dude!