Install LibreNMS
Note
This assumes the Ubuntu initial configurations have been perfomed as found here.
Note
Installation instructions sourced from LibreNMS' official documentation.
Install required packages
sudo apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip whois traceroute
Add LibreNMS User
Download LibreNMS
Set Permissions
sudo chown -R librenms:librenms /opt/librenms
sudo chmod 771 /opt/librenms
sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
Install PHP Dependencies
Set Timezone
Set timezone in both of the php ini files. In my case, it is America/New_York. You can look up the correct timezone here.
Configure MariaDB
Within the [mysqld] section add:
Enable MariaDB at boot and restart:
Start MariaDB client:
Run the following query on the db, changing the password to something secure:
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit
Configure PHP-FPM
Duplicate the default config file:
Modify the config file:
- Change [www] to [librenms]
- Change user and group to librenms
- Change listen to /run/php-fpm-librenms.sock
Since I will not run any other PHP web applications on this server, delete the www.conf file:
Configure Web Server
Add the following configuration, editing the server_name:
server {
listen 80;
server_name librenms.example.com;
root /opt/librenms/html;
index index.php;
charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/run/php-fpm-librenms.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi.conf;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Remove the default site:
Restart nginx:
Restart php:
Enable LNMS Command Completion
This feature grants you the opportunity to use tab for completion on lnms commands as you would for normal linux commands.
sudo ln -s /opt/librenms/lnms /usr/bin/lnms
sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
Configure SNMPD
Make a copy the example file:
Edit the config file:
- Edit the text which says RANDOMSTRINGGOESHERE and set your own community string.
Download the distro information file:
sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
sudo chmod +x /usr/bin/distro
Enable and restart the snmpd service:
Add Cron Job
Enable the Scheduler
sudo cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
sudo systemctl enable librenms-scheduler.timer
sudo systemctl start librenms-scheduler.timer
Copy logrotate Config
LibreNMS keeps logs in /opt/librenms/logs. Over time these can become large and be rotated out. To rotate out the old logs you can use the provided logrotate config file:
Web Installer
Now head to the web installer and follow the on-screen instructions.
http://ipaddress/install
The web installer might prompt you to create a config.php file in your librenms install location manually, copying the content displayed on-screen to the file. If you have to do this, please remember to set the permissions on config.php after you copied the on-screen contents to the file. Run:
Add Devices
You can now add devices from the web interface by clicking on Devices > Add Device. Provided the instructions found here were followed, you can add an Ubuntu host using:
- Hostname or IP: ipaddress
- SNMP: ON
- SNMP Version: v2c 161 udp
- Port Association Mode: ifIndex
- Community: use the snmp configured on the server
- Force add: OFF