This article aims to comprehensively introduce the entire process of building a cloud storage service, allowing those without a Linux background to avoid detours. Therefore, there are many details elaborated, which experienced users may ignore. Recently, many cloud storage services in China have collapsed one after another, and it is believed that many people do not want to endure the speed limits imposed by certain services. The demand for private clouds is increasing. The simplest and most reliable solution is to purchase high-performance, multifunctional NAS devices like Synology, but the price of thousands of yuan makes many people hesitate. There are various private cloud software available in the market, such as KodExplorer, Nextcloud/ownCloud, and Seafile. Here, IT Home will introduce how to build private cloud storage using a Raspberry Pi 3B development board.
First, let’s introduce the main character of this article—KodExplorer.
KodExplorer, originally named Mango Cloud, is a private cloud and online document management solution based on web technology, with the following features:
-
Lightweight and easy to deploy.
-
Strong applicability and multiple application scenarios.
-
High aesthetics and customizable.
After experiencing various cloud storage services, I chose KodExplorer mainly because I was attracted by its Windows-like interface at first glance. KodExplorer does not require a database, is lightweight enough, and is simple to set up, considering the limited capabilities of the small Raspberry Pi. Compared to ownCloud, KodExplorer performs much better on Raspberry Pi. However, it also has some shortcomings, such as lack of mobile client support, inconvenient synchronization, and some issues with the mobile web version.
aria2
aria2 is regarded as a download artifact by many netizens, and many friends have come into contact with it. It is an open-source, free, cross-platform (Windows, Mac, Linux) multi-threaded download software that is not speed-limited. It features fast speed, small size, and strong performance. aria2 supports downloading files from HTTP / FTP / BT / Magnet links, etc.
Preparation
-
Raspberry Pi 3B
-
Memory card
-
Hard disk
-
Public IP
-
Domain name
Install the operating system on the Raspberry Pi and log in
First, go to the Raspberry Pi official website to download the system image.
Click Download Zip to download the compressed package. After the download is complete, unzip it to obtain the img image file.
Download the imaging tool Win32DiskImager v0.9.zip and install it.
Use a card reader to connect the memory card to the computer, and run Win32diskimager.
Select the img file just downloaded for the image file, select the memory card drive letter for the device, then choose Write to start installing the system. Once the installation is complete, a completion dialog will pop up. After installation, seeing only 74MB on the memory card in Windows is normal, as Windows cannot see the Linux partition.
Then create a blank file named ssh (with no file extension) in the root directory of the memory card to enable SSH service for logging into the Raspberry Pi.
Insert the memory card into the Raspberry Pi, connect the Raspberry Pi’s Ethernet port to the router’s LAN port with a network cable, and then connect the power supply. The Raspberry Pi will boot up!
Log in to the router’s background to check the internal IP of the Raspberry Pi.
You can see that the IP address obtained by the Raspberry Pi is 192.168.2.6. Remember this address.
Download and install PuTTY, and run PuTTY after installation.
Make sure the computer and Raspberry Pi are in the same local area network. Enter 192.168.2.6 in the hostname field, and keep the default port 22, then click open. A security warning will pop up; click yes. Then enter the username: pi; password: raspberry (the password is not visible while typing) to successfully log in to the Raspberry Pi.
Domain Name
You can register a domain name you like at Alibaba Cloud; some domain names cost only a few yuan a year. With that, the preparation work is complete.
Build KodExplorer
After logging in with PuTTY, set a password for the root user by entering (right-click to paste in PuTTY):
sudo passwd root
It will prompt you to enter a password, then confirm it (the password is not visible while typing).
Enter the following command to switch to the root user:
su
First, we need to remove the restriction on direct login for the root user on the Raspberry Pi by editing the sshd_config file:
sudo nano /etc/ssh/sshd_config
Press Ctrl+W to search for PermitRootLogin, remove the # in front, and change without-password to yes:
PermitRootLogin yes
Press Ctrl+O to save the file, Ctrl + X to exit the editor, and then reboot the Raspberry Pi:
reboot
Install Apache + PHP
Log in as the root user and update the installation source first:
sudo apt-get update
Install apache2 and PHP:
sudo apt-get install apache2 php7.0 php7.0-curl php7.0-mbstring php7.0-gd
At this point, accessing the Raspberry Pi’s IP will show the default page of apache2.
Mount the Hard Disk
The Raspberry Pi mounts NTFS hard disks as a read-only file system by default. We can achieve this through other tools by installing ntfs-3g:
sudo apt-get install ntfs-3gmodprobe fuse
Next, we create a mount point; I chose the mount point in the /media/pi/mo folder:
sudo mkdir /media/pi/mo
Check the currently mounted hard disk:
fdisk -l
We will see the following information at the bottom:
Device Boot Start End Sectors Size Id Type/dev/mmcblk0p1 8192 93236 85045 41.5M c W95 FAT32 (LBA)/dev/mmcblk0p2 94208 62521343 62427136 29.8G 83 LinuxDisk /dev/sda: 464.8 GiB, 3899024998 bytes, 937766584 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xa7cf32d1Device Boot Start End Sectors Size Id Type/dev/sda1 2048 334438655 937766584 464.8G 7 HPFS/NTFS/exFAT
Among them, /dev/sda1 is the partition information for this hard disk. Below, we will mount the hard disk with the default user www-data of Apache, and enter the following command to check the user identity:
sudo -u www-data id
The displayed information is as follows:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Then let the hard disk auto-mount by editing /etc/fstab:
sudo nano /etc/fstab
Add the following content to the last line of the file:
/dev/sda1 /media/pi/mo ntfs uid=33,gid=33,noexec,umask=007 0 0
Here, uid and gid represent the user and group, which are the information we checked above; umask indicates the denied permissions, where the first number is 0, indicating no permissions are denied, which means readable, writable, and executable. The second and third numbers represent the user group and other users. Press Ctrl+O to save the file, then Ctrl + X to exit the editor, and reboot to take effect:
reboot
Configure KodExplorer
Download and unzip KodExplorer:
cd /media/pi/mo/kod
wget http://static.kodcloud.com/update/download/kodexplorer4.25.zip
unzip kodexplorer4.25.zip
chmod -Rf 777 ./*
Configure Apache:
nano /etc/apache2/sites-available/kod.conf
Paste the following content:
<VirtualHost *:80>ServerName kod.wumo.com
ServerAdmin [email protected]
DocumentRoot /media/pi/mo/kod<Directory "/media/pi/mo/kod/"> Options FollowSymLinks
AllowOverride All
Require all granted</Directory>
Note: Here, replace kod.wumo.com with your own domain name used to access the cloud disk. Restart apache2:
sudo service apache2 restart
Resolve the Domain Name
First, we need to configure port forwarding on the router. Enter the router management background, find the port forwarding/port mapping option. Taking my router as an example, the service name can be anything; I fill in the port range as 58080 (the one on the figure is 80, ignore it). This port can be any port, which is used when we access the web service on the Raspberry Pi through the domain name. You can use other ports but try to avoid 80, 443, and 8080, as ISPs may block these default web service ports; internal IP: the internal IP of the Raspberry Pi; local port: 80; this way, we transfer access to port 58080 of the router to port 80 of the Raspberry Pi. Here, we also configure a forwarding rule for aria2: forward port 6800 of the router to port 6800 of the Raspberry Pi.
Home broadband IP changes frequently, so we need dynamic domain name resolution. Most routers have dynamic domain name functionality. If you don’t know how to do it, you can refer to this article to upload softether (extraction code: uqgx) to the root directory of the Raspberry Pi using WinScp and unzip it:
tar -zxvf softether-vpnserver-v4.25-9656-rtm-2018.01.15-linux-arm_eabi-32bit.tar.gz
cd /vpnserver
./.install.sh
./vpnserver start–Simplified Chinese
Then set the password:
./vpncmd
Enter 1, and press enter three times, then input:
ServerPasswordSet
Follow the prompts to set the password, then download and install the Windows management tool (in the above cloud link), click “New Settings” to add a connection file. Fill in the internal IP of the Raspberry Pi in the hostname, port: 443, password: the password you just set.
After confirming, select “Remote Access vpnserver” and click OK all the way, and you will see the dynamically assigned domain name.
Remember this domain name; my domain name is registered with Alibaba Cloud. Go to the Alibaba Cloud console > My Resources > Cloud Resolution DNS > Your Domain, and choose to add resolution.
Record type: CNAME; host record: the domain name you filled in when configuring Apache (I filled in kod above); record value: the domain name assigned by dynamic DNS.
Now our private cloud is complete! You can access http://your domain name: the port number forwarded to the Raspberry Pi to see the cloud disk we built. The effect is as follows:
This article was written using the built-in MD editor of KodExplorer.
Configure Aria2
Here, the configuration of aria2 refers to this article.
Install Aria2
sudo apt-get install aria2
Configure Aria2 by creating an aria2 directory in the /etc directory to store configuration files:
sudo mkdir /etc/aria2
Create an empty aria2.session file:
sudo touch /etc/aria2/aria2.session
Create the configuration file:
sudo nano /etc/aria2/aria2.conf
Enter the following content in the file:
# File save path (can use absolute or relative path), default: current startup location
dir=/media/pi/mo/kod/data/User/admin/home/download
# Enable disk cache, 0 to disable cache, requires version 1.16 or above, default: 16M
disk-cache=32M
# File pre-allocation method, can effectively reduce disk fragmentation, default: prealloc
# falloc and trunc require file system and kernel support
# NTFS recommends using falloc, EXT3/4 recommends trunc, MAC needs to comment this item
file-allocation=none
# Resume download
continue=true
## Download connection related ### Maximum concurrent download tasks, can be modified at runtime, default: 5
max-concurrent-downloads=10
# Number of connections per server, can specify when adding, default: 1
max-connection-per-server=5
# Minimum file segment size, can specify when adding, range 1M - 1024M, default: 20M
# Assuming size=10M, if the file is 20MiB, then two sources will be used to download; if the file is 15MiB, then one source will be used
min-split-size=10M
# Maximum threads per task, can specify when adding, default: 5
split=10
# Overall download speed limit, can modify at runtime, default: 0
#max-overall-download-limit=0
# Single task download speed limit, default: 0
#max-download-limit=0
# Overall upload speed limit, can modify at runtime, default: 0
#max-overall-upload-limit=0
# Single task upload speed limit, default: 0
#max-upload-limit=0
# Disable IPv6, default: false
disable-ipv6=true
## Progress save related ### Timed save session, 0 to save only when exiting, requires version 1.16.1 or above, default: 0
#save-session-interval=60
## RPC related settings ### Enable RPC, default: false
enable-rpc=true
# Allow all sources, default: false
rpc-allow-origin-all=true
# Allow non-external access, default: false
rpc-listen-all=true
# Event polling method, values: [epoll, kqueue, port, poll, select], different systems have different defaults
#event-poll=select
# RPC listening port, can modify when port is occupied, default: 6800
#rpc-listen-port=6800
# Set RPC authorization token, added in v1.18.4, replaces --rpc-user and --rpc-passwd options
rpc-secret=123456789
# Set RPC access username, this option has been deprecated in the new version, it is recommended to use --rpc-secret option
#rpc-user=
# Set RPC access password, this option has been deprecated in the new version, it is recommended to use --rpc-secret option
#rpc-passwd=
## BT/PT download related ### When downloading a torrent (ending with .torrent), automatically start the BT task, default: true
#follow-torrent=true
# BT listening port, use when the port is blocked, default: 6881-6999
listen-port=51413
# Maximum connections per seed, default: 55
#bt-max-peers=55
# Enable DHT function, PT needs to be disabled, default: true
enable-dht=true
# Enable IPv6 DHT function, PT needs to be disabled
#enable-dht6=false
# DHT network listening port, default: 6881-6999
#dht-listen-port=6881-6999
# Local node discovery, PT needs to be disabled, default: false
#bt-enable-lpd=true
# Seed exchange, PT needs to be disabled, default: true
enable-peer-exchange=true
# Speed limit per seed, useful for few seeds, default: 50K
#bt-request-peer-speed-limit=50K
# Client masquerade, PT needs peer-id-prefix=-TR2770-user-agent=Transmission/2.77
# When the seed's share ratio reaches this number, automatically stop seeding, 0 means always seeding, default: 1.0
seed-ratio=0.1
# Force save session, even if the task is completed, default: false
# After enabling newer versions, it will still retain .aria2 files after the task is completed
#force-save=false
# BT verification related, default: true
#bt-hash-check-seed=true
# When continuing previous BT tasks, no need to verify again, default: false
bt-seed-unverified=true
# Save magnet link metadata as torrent files (.torrent files), default: false
bt-save-metadata=false
Note 1: Change rpc-secret=123456789 to your own password;
Note 2: The default download directory of aria2 is placed in the download folder of the KodExplorer administrator file directory, and after the download is complete, you can see it in KodExplorer.
Start aria2
Here, we will run aria2 using the www-data user. First, grant executable permissions to the configuration directory:
sudo chown -R www-data:www-data /etc/aria2
Run aria2 as www-data user:
sudo -u www-data aria2c --conf-path=/etc/aria2/aria2.conf
If no error messages are prompted, press Ctrl+C to stop the above command and run it as a daemon in the background:
sudo -u www-data aria2c --conf-path=/etc/aria2/aria2.conf -D
Make it a system service:
sudo nano /etc/init.d/aria2c
Paste the following content:
#!/bin/sh### BEGIN INIT INFO# Provides: aria2# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Aria2 Downloader### END INIT INFO case "$1" instart) echo "Starting aria2c ..." sudo -u www-data aria2c --conf-path=/etc/aria2/aria2.conf -D;;stop) echo "Shutting down aria2c ..." killall aria2c;;restart) killall aria2c
sleep 3 sudo -u www-data aria2c --conf-path=/etc/aria2/aria2.conf -D;;esacexit
Then set the permissions for this file:
sudo chmod 755 /etc/init.d/aria2c
Test if the service can start:
sudo service aria2c start
Add aria2c service to run automatically:
sudo update-rc.d aria2c defaults
Install the web management interface for aria, and we choose aria2-NG as the web management interface. Create a directory:
mkdir /var/www/html/aria2
Download and unzip aria2-NG:
cd /var/www/html/aria2 && wget https://github.com/mayswind/AriaNg/releases/download/0.3.0/aria-ng-0.3.0.zip
unzip aria-ng-0.3.0.zip
Configure Apache:
nano /etc/apache2/sites-available/aria2.conf
Enter the following content:
<VirtualHost *:80>ServerName aria2.wumo.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/aria2<Directory "/var/www/html/aria2/"> Options FollowSymLinks
AllowOverride All
Require all granted</Directory>ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>
Note: Just like above, replace aria2.wumo.com with the domain name you use to access the aria2 management interface.
ln -s /etc/apache2/sites-available/aria2.conf /etc/apache2/sites-enabled/aria2.conf
Restart apache2:
sudo service apache2 restart
Then go to Alibaba Cloud and resolve the CNAME record of the domain name you use to access the aria2 management interface to the dynamic domain name. Enter http://the domain name used to access the aria2 management interface: external port (I used 58080 above) in the browser to access your aria2. Here, an authentication error will be displayed:
Go to AriaNG settings > RPC > Aria2RPC key and enter the password you set above, then reload the page:
Here it will show that it is connected.
Thus, we have successfully completed the setup~
– END –
Selected Hot Articles from the Academy:
Select the right computer configuration in 10 minutes
Graphics card knowledge popularization
Flashing Android system on Lumia phones
Installing “Almost” Chrome OS on PC
Using Chrome plugins on Android phones
Finally understanding the files in Android phones
What’s inside the APK installation package for Android?
Learn to shut down Windows 10 in 10 seconds
Make a “private cloud disk” with an old computer
After complaining about Baidu for years, do you really know how to search?

Learn more about fresh technology by clicking to read the original text on IT Home.