Official documentation here.
Install required packages
apt install -y php8.3-{cli,curl,fpm,gd,mbstring,mysql,snmp,xml,zip} acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap python3-dotenv python3-pymysql python3-redis python3-setuptools python3-systemd rrdtool snmp snmpd whois
Add librenms
user
useradd librenms -d /opt/librenms -M -r -s "$(which bash)"
Download LibreNMS to /opt
cd /opt && \
git clone https://github.com/librenms/librenms.git
Set permissions on the new directory
chown -R librenms:librenms /opt/librenms && \
chmod 771 /opt/librenms && \
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ && \
setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
Login as the librenms
user and install the PHP dependencies
su - librenms && \
./scripts/composer_wrapper.php install --no-dev && \
exit
If your server uses a proxy, you will likely need to install Composer manually
wget https://getcomposer.org/composer-stable.phar && \
mv composer-stable.phar /usr/bin/composer && \
chmod +x /usr/bin/composer
Set your server's timezone in these locations
vim /etc/php/8.2/fpm/php.ini /etc/php/8.2/cli/php.ini
Set the system timezone as well
timedatectl set-timezone America/Denver
Edit the MariaDB server configuration
vim /etc/mysql/mariadb.conf.d/50-server.cnf
Under the [mysqld]
section, add
innodb_file_per_table=1
lower_case_table_names=0
Enable and Restart MariaDB
systemctl enable mariadb.service && \
systemctl restart mariadb.service
Login to MariaDB with the root
user.
mysql -u root
Create a new DB.
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create DB librenms
user. Replace ‘user-password’ with something secure.
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'user-password';
Give the new user privileges on the new DB.
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
Flush privileges to apply the changes just made and exit.
FLUSH PRIVILEGES;
exit
Copy FPM www.conf
cp /etc/php/8.3/fpm/pool.d/www.conf /etc/php/8.3/fpm/pool.d/librenms.conf
Modify the librenms.conf
FPM file to fit LibreNMS's required config
[www]
to [librenms]
user
and group
to librenms
listen
to a generic name (not containing the PHP version)sed -i 's/\[www\]/\[librenms\]/' /etc/php/*/fpm/pool.d/librenms.conf && \
sed -i 's/user = www-data/user = librenms/' /etc/php/*/fpm/pool.d/librenms.conf && \
sed -i 's/group = www-data/group = librenms/' /etc/php/*/fpm/pool.d/librenms.conf && \
sed -i 's|listen = /run.*|listen = /run/php-fpm-librenms.sock|'
Create a new vhost file with the following contents. (Modify server_name
to fit your setup)
vim /etc/nginx/sites-enabled/librenms.vhost
bash -c "cat > /etc/nginx/sites-enabled/librenms.conf" <<'EOF'
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;
}
}
EOF
Remove the default Nginx site configuration.
rm /etc/nginx/sites-enabled/default
Restart NGINX and PHP-FPM
systemctl reload nginx && \
systemctl restart php8.3-fpm
Create symbolic link for LNMS to the system PATH.
ln -s /opt/librenms/lnms /usr/bin/lnms
Copy the completion bash file.
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
Copy example config to snmpd working directory.
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
Edit the copied file.
vim /etc/snmp/snmpd.conf
Replace ‘RANDOMSTRINGGOESHERE’ with the SNMP community you are using.
com2sec readonly default [my-community-here]
Download ‘Distro’ which is responsible for OS detection
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
Change the file permissions of ‘distro’
chmod +x /usr/bin/distro
Enable and Restart snmpd
.
systemctl enable snmpd && \
systemctl restart snmpd
Copy cron file to working directory.
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
Copy logrotate file to working directory.
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
In a web browser, navigate to http://librenms.example.com/install
and complete the on-screen instructions.
One very important note, that I learned the hard way - config.php is depreciated! To configure Libre, use the lnms command.
Go into the Global settings in the GUI to see all config parameters. For example, to set the Unix user LibreNMS will run as:
lnms config:set user librenms
To unset a parameter set the parameter without any value
lnms config:set user
Reset user to the default? (yes/no) [no]:
> yes