/dev/urandom

/dev/urandom

Pseudorandom thoughts generator.

I'm Niccolò Maggioni.
Student, geek and developer.

NodeJS, MongoDB and Redis on NTC's C.H.I.P.

Not so long ago I tried setting up on my C.H.I.P. a small stack that included NodeJS, MongoDB and Redis.

The requirements were nothing special, as I just needed a simple portable environment to test a project I’m working on. I thought that C.H.I.P.’s ARMv8 1GHz CPU, 4GB Flash and 512MB RAM would suffice for the task, so I begun to dig in the ARM realm.

At first I remember having given up almost instantly, as nothing came pre-packaged and compiling from source just wouldn’t finish right. I eventually resorted to using other hardware for that project, a cluster of 6 old machines (microservices ftw) powered by AMD Athlon processors - they lacked the SSE2 instruction set, so that had me watching over multi-day compilations (IIRC the total sum of compiling times was somewhat over 48 hours). But that’s a story I might write about in the future.

In the past days I had to set up another test environment for the same project, but that cluster had already been devoted to another cause - this reminds me I need a proper homelab for toying with virtualization… - so I shook the Box-of-Embedded-Boards-that-I-sweared-I’d-have-used-properly-one-day™ three times and the C.H.I.P. surfaced.

Not wanting to mess with the will of the holy BOEBTISIHUPOD™, I picked up the board and started searching.

It seems that things just got easier since a couple of months ago!

MeAfter having looked around a bit

NodeSource’s NodeJS repos now include ARMv6 and up builds, MongoDB started issuing official builds with working WiredTiger support, and Redis… Well, it compiles fine but some tests still don’t want to pass. For a temporary sandbox environment, though, I’ll just pretend I never saw those failing tests and that everything will be fine. I can’t tell if such failed tests can indicate a potential failure for the whole Redis instance or if they are minor nuisances. By the looks of it, all the most important tests seem to be ok, but don’t go about running crazy loads on ARM-backed Redis instances until you’ve made all tests pass!

Remember that you are in mostly uncharted waters here…


NodeJS

Installing the language and its tools on ARM processors (v6 and up) is now pretty straightforward.

If you are on a Debian-based build you can rely on NodeSource’s repos:

1
2
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y build-essentials nodejs

If you want to install a different version (6.x is the LTS at the moment of writing) you should refer to the downloads page and its package manager section.

Test the installation with this one-liner:

1
echo -e "NodeJS version:\t$(node -v)\nNPM version:\t$(npm -v)"

MongoDB

A not-so-recent version is readily available in the repos:

1
2
apt-cache show mongodb | grep Version
# Version: 1:2.4.10-5

You may obtain v2.6.12 by adding Debian’s unstable (sid) repos, that may even have newer versions for the armhf arch. Be sure to properly configure APT’s priorities of you’ll find yourself with an hybrid stable-testing-unstable distro.

If the unstable/testing repos are fine to you, you can try to obtain the said version of MongoDB:

1
sudo apt-get -t testing install mongodb

If you absolutely need the newest version, things will begin to get ugly. And very, very time consuming - a build can take up to 10 hours, and most probably you will need two or three tries before getting the build flags right along with all the dependencies. Be sure to get your ARM version right as well where needed.

Remember that working on 32-bits platforms is unsupported and introduces significant drawbacks for MongoDB.

Anyhow, start and enable the service:

1
2
3
sudo systemctl start mongodb
sudo systemctl enable mongodb
sudo systemctl status mongodb

Redis

As I wrote before, Redis should be fairly easy to compile and run:

1
2
3
4
5
6
sudo apt-get install build-essentials tcl
wget http://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
make test

As stated before some tests could fail, if you are ok with that and your Redis binaries seem to be working (src/redis-server & src/redis-cli), proceed with:

1
2
3
4
5
6
7
8
9
10
sudo make install
sudo mkdir /etc/redis
sudo cp ~/redis-stable/redis.conf /etc/redis
sudo sed -i 's/^supervised no/supervised systemd/' /etc/redis/redis.conf
sudo sed -i 's/^dir \.\//dir \/var\/lib\/redis/' /etc/redis/redis.conf
echo -e '[Unit]\nDescription=Redis In-Memory Data Store\nAfter=network.target\n\n[Service]\nUser=redis\nGroup=redis\nExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf\nExecStop=/usr/local/bin/redis-cli shutdown\nRestart=always\n\n[Install]\nWantedBy=multi-user.target' | sudo tee /etc/systemd/system/redis.service
sudo adduser --system --group --no-create-home redis
sudo mkdir /var/lib/redis
sudo chown -R redis:redis /var/lib/redis
sudo chmod -R 770 /var/lib/redis

Complete the job by starting and enabling Redis’ service:

1
2
3
sudo systemctl start redis
sudo systemctl enable redis
sudo systemctl status redis

If you’re a perfectionist, don’t forget about testing the connection:

1
2
3
redis-cli
127.0.0.1:6379> ping
# PONG

Found this article useful? Crypto makes for an excellent tip!

1LZto1zhrzHgFssZRbgG4WB9oW1RfbSc7F
0x3587C66f56C6C696A031b50451Ae68fE34993405
GBA3DXBLWF4WN32XANZWU65WIYJJIV7FKXO4VDYLMEQ7HTPZJMVV4733

Share this