Install Node.js on Ubuntu 16.04
Introduction
Node.js is part of the next generation web servers that is small; fast and super efficient.
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
-
The reason we are interested in Node.js is because it supports Websocket. Websocket is a reasonably new technology that is supported by the latest versions of all the major browsers which allows you to display data in real-time.
-
We will make use of Socket.IO as a wrapper to Websocket which runs on Node.js to read the log file and debug output of FreeRADIUS in real-time.
-
So to summarise : Node.js→Websocket→Soket.IO→Client.
Install Node.js and dependencies
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm -g install tail
sudo npm -g install socket.io@0.9.x
sudo npm -g install connect
sudo npm -g install mysql
sudo npm -g install forever
Add start-up script
Everything is now installed that we will need to enable us to serve the FreeRADIUS log file in real-time using Node.js, Websocket and Socet.IO.
We need to install a start-up file, start the Node.js server up and confirm that it works.
#The systemd startup file
sudo cp /usr/share/nginx/html/cake2/rd_cake/Setup/Node.js/nodejs-socket-io.service /lib/systemd/system/
# add a sym link to node
sudo ln -s /usr/bin/nodejs /usr/bin/node
#Enable it
sudo systemctl enable nodejs-socket-io.service
#Start it
sudo systemctl start nodejs-socket-io.service
Test the Node.js server
sudo cat /var/log/nodejs-socket-io.log
#Result in....
info: socket.io started
Up and running on port 8000
Things to remember about Websocket
Websocket is not supported in
IE version 9 and below.
Remember that this is running on port 8000 and some firewalls may block it.
You are welcome to alter the port on which Node.js serve by editing the /rd_cake/Setup/Node.js/Logfile.node.js file.
The start-up script calls Logfile.node.js during start-up. Depending on the web server you run; the absolute path of this script will change accordingly. Be sure to update this script as well if you change servers (Nginx VS Apache).
Although this Node.js server serves the FreeRADIUS log file; it will only be visible if the requester provides the token belonging to root. All other users will not be allowed to see this log file through the Node.js server.
Next steps