📜 ⬆️ ⬇️

Home “cloud” server at 10 watts? Completely!

Hello to users of Habr.

Today I want to tell you about a home web server that simultaneously perfectly performs the functions of a home media center (mp3, ip-tv, video, uPnP, etc.).

It all started with the fact that for some time I used the HP MicroServer N36L server with RAID5 for 4 terabytes (3x2GB HDD WD Green + 8 Gb ECC RAM) for internal needs, with virtual machines on the vBox in Oracle, which is not bad in principle, but its the constant buzzing worried family members in the sense of knowingly eating kilowatts per year (if you are interested, I will tell about it in one of the following posts).
In addition, I wanted something more modern, with the possibility of using it as a full-fledged media center with a direct connection to the TV.

After a long search and comparison, I chose the currently relevant device on the RK3188 chipset: K-R42, 4-core CPU, 2GB of RAM and 4GB of flash memory (although 8GB was proudly indicated on the box) graphically by the Mali400 kernel on android 4.2.2.
')
Of course, everything described below is also suitable for other similar devices that are connected via HDMI to the TV, but for me a significant advantage in choosing was the availability of a full-fledged housing for normal heat exchange, an optical SPDIF connector for sound and a modern chipset.

The cost of K-R42 ranges around $ 90-120 (geekbuying.com, aliexpress.com with shipping), which is more expensive than 2 core sticks / boxes, but comparable to many others on the same RK3188 chipset.

It should be noted that as a media center, it works with a bang: the current XBMC 12.2 Frodo is currently installed and started without any problems, the control from the console is quite smooth and there are no special problems with this. Thanks to the external antenna, the wireless connection is very stable, it heats up in the process of work not so much, but it is noticeably warm under load.

1. We put Linux.


What - I didn’t have much difference, but for simplicity I chose Debian wheezy.

Unfortunately, there are no working drivers for the Mali400 in order to get a full-fledged 3D graphics acceleration, so there are no options yet - you need to use the chroot environment instead of reflashing the device completely to Linux (the corresponding manuals are already on the network).
Fortunately for this, under the android there is a wonderful app: Linux Deploy, giving a choice of any of the existing mainstream distributions.

I will not describe in detail, the installation is rather trivial: just run the application, select the desired configuration and press start.
After inserting an 8GB microSD card in the media box, I chose to install the SD card section without a graphical environment (there is of course an option for those who want to get a graphic desktop via VNC), Debian was installed, with SSH autoload and sudo- android user with a password changeme .

Go through SSH for further configuration:

ssh android@<ip-of-the-box>




2. Users and other ...


The android user password is naturally worth changing from changeme to something more recent:

passwd

and also for root, disable the ability to login over SSH in / etc / ssh / sshd_config:

sudo nano /etc/ssh/sshd_config
 PermitRootLogin yes → PermitRootLogin no 


if you need to create your full user, then

sudo adduser username

and do not forget to add it to the groups in which the user “android” is present:

sudo adduser username aid_system aid_radio aid_bluetooth aid_graphics aid_input aid_audio aid_camera aid_log aid_compass aid_mount aid_wifi aid_adb aid_install aid_media aid_dhcp aid_sdcard_rw aid_vpn aid_keystore aid_usb aid_drm aid_available aid_gps aid_media_rw aid_mtp aid_drmrpc aid_nfc aid_sdcard_r aid_shell aid_cache aid_diag aid_net_bt_admin aid_net_bt aid_inet aid_net_raw aid_net_admin aid_net_bw_stats aid_net_bw_acct

Otherwise, your new user may not have access to some devices / Internet, etc.
Necessary groups can always be viewed by

groups android

Now let's update the newly installed system:
 sudo apt-get update sudo apt-get dist-upgrade 


install the task manager:

sudo apt-get install cron

To provide access to our server from the outside, we register on some DynDNS site (dyn.com, noip.com, etc.), and install the client to update our dynamic IP address (I used ddclient):

sudo apt-get install ddclient

Here is an example ddclient configuration:
 # Configuration file for ddclient generated by debconf # # /etc/ddclient.conf protocol=dyndns2 use=web, web=checkip.dyndns.com/, web-skip='IP Address' server=www.dyndns.com login=myserveruser password='mydyndnspassword' myserver.dyndns.org 


On the router, you must allow Port Forwarding from the Internet for ports 22 (SSH), 80 (HTTP), 443 (HTTPS) on the IP of our “micro” server.




3. We put LAMP


Here everything is rather trivial:
 sudo apt-get update sudo apt-get install apache2 mysql-server php5 php5-curl php5-gd php5-mysql php-apc 


For the convenience of further settings, we set the graphic panel (webmin)
 cd /tmp wget http://prdownloads.sourceforge.net/webadmin/webmin_1.660_all.deb sudo dpkg -i webmin_1.660_all.deb sudo apt-get -f install sudo service webmin start 

(In order to save webmin resources, I manually launch all the time only when needed)

Now you can go to https: // <ip-of-the-box>: 10,000 with android user and customize everything your heart desires.

If this is not done yet, restart the web server to activate all the modules we have installed:

sudo service apache2 restart




4. Autoload


In order for our daemon services to automatically load in the chroot environment when our box starts, the script /etc/init.d/myscrypt is provided in Linux Deploy

My looks like this:
 #!/bin/sh case "$1" in start) /bin/mount -a /etc/init.d/mysql start /etc/init.d/apache2 start /etc/init.d/ddclient start /etc/init.d/cron start ;; stop) /etc/init.d/apache2 stop /etc/init.d/mysql stop /etc/init.d/ddclient stop /etc/init.d/cron stop /bin/umount /mnt/usb ;; *) echo "Usage: $0 {start|stop}" ;; esac 


When the media player is “turned off” from the console, the device instead of completely shutting down goes into standby mode (many people in the network consider this feature a disadvantage, but in our case is an undeniable advantage!), While all the running services continue to work. The processor load is about 5%, and only one core out of 4!




5. Install ownCloud


The fifth stable version of this cloud service can already be quite comfortable to use. The owncloud installation is described in great detail on the official page ( http://doc.owncloud.org/server/5.0/admin_manual/ ), here I will give the main steps regarding our installation:


 sudo echo 'deb http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_7.0/ /' >> /etc/apt/sources.list.d/owncloud.list sudo apt-get update sudo apt-get install owncloud 


Now we go in the browser on

http: // <ip-of-the-box> / owncloud /

and finish customizing your owncloud: enter MySQL database data.

In case the installer complains about the inability to use .htaccess,
change the / etc / apache2 / sites-enabled / 000-default AllowOverride file to All:

sudo nano /etc/apache2/sites-enabled/000-default
  <Directory /var/www/> … AllowOverride None → AllowOverride All … </Directory> 

as well as in the / etc / apache2 / sites-enabled / default-ssl file, if you intend to use owncloud with SSL:

sudo nano /etc/apache2/sites-enabled/default-ssl
 <Directory /var/www/> … AllowOverride None → AllowOverride All … </Directory> 


and restart the webserver:

sudo service apache2 restart

Further customization of owncloud usually causes no problems and is described in detail in the administrator’s manual.

5.1 If there is not enough space

The size of the “cloud” storage with the described installation is limited by the free space on the SD card. A convenient way to increase the amount of available space is to transfer your owncloud / data folder to an external USB-HDD.

To do this, format any external USB drive (for example, its first partition) as ext4, and specify its mount point in / etc / fstab:
 sudo mkdir /mnt/usb_hdd sudo chmod a+rwx /mnt/usb_hdd sudo nano /etc/fstab 

 … /dev/block/sda1 /mnt/usb_hdd ext4 noatime,acl,user_xattr 1 1 … 


Mount disk

mount /mnt/usb_hdd

and transfer owncloud / data to it:
 sudo mv /var/www/owncloud/data /mnt/usb_hdd/ sudo ln -s /mnt/usb_hdd/data /var/www/owncloud/data 


Now our storage capacity is limited only by free space on an external USB drive.




6. Backup by plan


Easily and quickly, with the help of duplicity, a regular backup is organized on an external server, if desired, also with encryption.
If the main file server is located on the same network as me and supports wake-on-lan, then this process can be fully automated (including the start of the file server).

sudo apt-get install wakeonlan duplicity

We will create a folder for backups (for example / media / backup / owncloud) on the file server 192.168.0.2 with the MAC address 33: d0: ab: dd: 11: c1,
for which the local user user1 has write access.

Setting up passwordless access for the root user via SSH to the file server:
 sudo su ssh-keygen -t rsa (  ,   ) ssh-copy-id -i .ssh/id_rsa.pub user1@192.168.0.2 exit 


now we make tasks for the task manager in the crontab:

sudo crontab -e
 49 23 * * * /usr/bin/wakeonlan 33:d0:ab:dd:11:c1 0 0 * * sun /usr/bin/duplicity full --no-encryption --volsize 100 --exclude /tmp --exclude /proc --exclude /sys / rsync://user1@192.168.0.2//media/backup/owncloud 0 0 * * 1-6 /usr/bin/duplicity --no-encryption --volsize 100 --exclude /tmp --exclude /proc --exclude /sys / rsync://user1@192.168.0.2//media/backup/owncloud 0 1 * * sun /usr/bin/duplicity remove-all-but-n-full 2 --force rsync://user1@192.168.0.2//media/backup/owncloud 


According to this plan, we will back up our entire chroot environment, complete on Sundays, incremental on other days, with the removal of old records. If the file server is sleeping, it will be woken up in advance over the network (of course, if it supports this feature).




Well, we have both a working media center and a web server with cloud storage.
Constructive criticism and suggestions are welcome.

Source: https://habr.com/ru/post/198492/


All Articles