Tag Archives: rrd

Using RPi-Monitor with your own webserver (Nginx)

As I recently moved this site to a RPI for hosting purposes, I though it would be a good idea to have a nice web page to monitor the current status of the box. Some googling later and I found the excellent RPi-Monitor.

By default it has it’s own webserver, and it is not recommended to use anything other then that, but running a second webserver seemed a little bit untidy to my thinking so I set it to run on Nginx instead.

The actual changes were quite simple, with one or two gotcha’s.

RPi-Monitor stores the webpage in /usr/share/rpimonitor/web by default. Rather then play with that I just created a symbolic link between the root of the webserver and that point:

ln -s /usr/share/rpimonitor/web /var/www/rpimonitor

and that is sorted.

Next up is the configuration change to the rpimonitor daemon – config file located in /etc/rpimonitor/daemon.conf. We need to set it into no-server mode and also change the user, as I’ve disabled the default ‘pi’ account on this box.

# daemon.noserver=1
# Define that rpimonitor shouldn't start web server (default:0)
# Note: A symbolic link from /var/lib/rpimonitor/stat to
# /usr/share/rpimonitor/stat may be required
daemon.noserver=1

# Define user used to run the server process (default:pi)
# Note: If user is not existing, process will run with uid=1000
daemon.user=rpi-monitor
#
# daemon.group=pi
# Define group used to run the server process (default:pi)
# Note: If group is not existing, process will run with gid=1000
daemon.group=rpi-monitor
#

Restart the service, and you should be able to access it from http://my-website.com/rpi-monitor

$ sudo service rpimonitor restart

RPI-Monitor StatusHowever there is a slight issue in that the datastore is inaccessible to the webserver, so statistics are unavailable with error “File stat/uptime.rrd is not a valid RRD archive”. To resolve this we need to go back to the daemon.conf file and move the datastore to somewhere under the root directory of the website

# daemon.datastore=/var/lib/rpimonitor
# Define the data storage directory (Default:/var/lib/rpimonitor)
daemon.datastore=/var/www/rpimonitor

Restart the service again and all is worky.

$ sudo service rpimonitor restart

RPI-Monitor StatisticsNote: you could also just move the webroot in the same way, rather then using the symbolic link.

Migrating WordPress Tiny EC2 Instance to Raspberry Pi

Having hosted this blog on a tiny AWS EC2 instance for some time, mostly to gain exposure to EC2, I decided to migrate it to a spare Raspberry Pi and use my home network connection. For the most part this was a fairly seamless transition.

Raspberry Pi Preparation

Basic setup was updating and locking down the RPI. The next step was to install a webserver. Rather then Apache2, I decided to install nginx instead as it is supposed to be a little lighter on resources.

sudo apt-get install nginx php5-fpm
sudo service nginx restart

Try to connect to http://$SERVER_IP and you should see a “Welcome to NGINX” page. If not then something has gone wrong and you need to look at /var/log/nginx/error.log

Next up is to install MySQL and the PHP connection API

sudo apt-get install mysql-server php5-mysql

Be sure to set a strong MySQL root password

At this point I suggest switching your MySQL config with the my-small.cnf as we are working on a relatively low memory device

sudo cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
sudo service mysql restart

Prepare the WordPress MySQL Account

mysql -u root -p
CREATE DATABASE `wordpressdb`;
GRANT ALL PRIVILEGES ON `wordpressdb`.* TO 'wordpress'@'localhost' IDENTIFIED BY 'long_complicated_wordpress_password';
FLUSH PRIVILEGES;
EXIT

At this point I configured nginx to allow PHP to be executed by editing /etc/nginx/sites-enabled/default in two areas:

server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

root /var/www;
index index.html index.htm index.php;

...

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

WordPress Migration

For this I made use of the excellent XCloner Plugin to backup my existing server, then used the manual method to restore the entire wordpress installation on the new server. No issues…

Some Performance Improvements

First some caching helpers:

sudo apt-get install memcached php5-memcache php-apc
sudo /etc/init.d/php5-fpm restart

To take advantage in WordPress install the following plugins:

  • nginx Compatibility
  • W3 Total Cache

From the W3 Total Cache settings page

  • enable Page Cache with memcached
  • enable Object Cache with APC

Moving the RRD

First up, install rrdtool on the RPI:

sudo apt-get install rrdtool

Then dump the old RRD from the original server. This is required as the database itself is very platform specific, and cannot be just copied between architectures.

rrdtool dump ./database.rrd > database.xml

On the new server, import it into a shiny new RRD:

rrdtool restore ./database.xml ./database.rrd

DNS Changes

Since this is hosted on a home connection, which has a public IP, we cannot guarantee that the IP address will stay the same. Like most tech-savy people I use Dynamic DNS to ensure I can access my home network.

In this case, I make a CNAME record for flat-planet.net, pointing towards my dynamic DNS record, and we are done.