Install LibreNMS Monitoring Tool with Nginx on Ubuntu 20.04 Rumi, March 30, 2021March 30, 2021 First, it is recommended to update your system packages to the latest version. You can do it with the following command: apt-get update -y After updating all packages, install all the dependencies required for LibreNMS with the following command: apt-get install rrdtool whois fping imagemagick graphviz mtr-tiny nmap python3-mysqldb snmp snmpd python3-pip python3-memcache mtr-tiny acl unzip git curl wget -y Once all the dependencies are installed, you can proceed to the next step. Install LEMP Server Next, you will need to install Nginx web server, MariaDB server, PHP and other PHP extensions in your server. You can install all of them by running the following command: apt-get install nginx mariadb-server php php-pear php-cgi php-common php-curl php-mbstring php-gd php-mysql php-bcmath php-imap php-json php-xml php-snmp php-fpm php-zip -y After installing all the packages, you will need to set timezone in your php.ini file. First, find your system timezone with the following command: cat /etc/timezone You should see the following output: Etc/UTC Next, edit both php.ini file with the following command: nano /etc/php/7.4/fpm/php.ini nano /etc/php/7.4/cli/php.ini Define your system timezone as shown below: date.timezone = Dhaka/Asia Save and close the file when you are finished. Then, restart the PHP-FPM service to apply the changes: systemctl restart php7.4-fpm Once you are finished, you can proceed to the next step. Configure MariaDB Database Next, you will need to create a database and user for LibreNMS. First, log in to MariaDB shell with the following command: mysql Once login, create a database and user with the following command: MariaDB [(none)]> create database librenmsdb CHARACTER SET utf8 COLLATE utf8_unicode_ci; MariaDB [(none)]> grant all privileges on librenmsdb.* to librenms@localhost IDENTIFIED by "password"; Next, flush the privileges and exit from the MariaDB shell with the following command: MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit; Next, edit the MariaDB configuration file and add some desired settings: nano /etc/mysql/mariadb.conf.d/50-server.cnf Add the following lines inside [mysqld] section: innodb_file_per_table=1 sql-mode="" lower_case_table_names=0 Save and close the file then restart the MariaDB service to apply the changes: systemctl restart mariadb At this point, your MariaDB is configured. You can now proceed to the next step. Install and Configure LibreNMS First, you will need to create a separate user to run LibreNMS. You can add it with the following command: useradd -r -M -d /opt/librenms librenms Next, add the librenms user to the www-data group with the following command: usermod -a -G librenms www-data Next, change the directory to the /opt and download the latest version of LibreNMS with the following command: cd /opt git clone https://github.com/librenms/librenms.git librenms Next, create a log file for LibreNMS with the following command:Advertisement touch /opt/librenms/logs/librenms.log Next, copy the SNMP sample configuration file with the following command: cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf Next, edit the snmpd.conf file: nano /etc/snmp/snmpd.conf Find the following line: com2sec readonly default RANDOMSTRINGGOESHERE And, replaced it with the following line: com2sec readonly default mysnmpserverkey Save and close the file then download the SNMP distro binary and copy it to the desired location: curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro chmod +x distro mv distro /usr/bin/distro Next, restart the SNMP service to apply the changes: systemctl restart snmpd Next, you will also need to copy LibreNMS cron and logrotate file to the desired location. You can copy them with the following command: cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms Next, change the directory to the librenms and install required depemdencies using the following command: cd /opt/librenms ./scripts/composer_wrapper.php install --no-dev Once all the dependencies are installed, chaneg the ownership of librenms directory and give necessary permissions with the following command: chown -R www-data:librenms /opt/librenms chmod -R 775 /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/ Once you are finished, you can proceed to the next step. Configure Nginx for LibreNMS Next, you will need to create an Nginx virtual host configuration file for LibreNMS. You can create it with the following command: nano /etc/nginx/conf.d/librenms.conf Add the following lines: 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 /api/v0 { try_files $uri $uri/ /api_v0.php?$query_string; } location ~ \.php { include fastcgi.conf; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; } location ~ /\.ht { deny all; } } Save and close the file then check the Nginx for any syntax error with the following command: nginx -t You should see the following output: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful Next, restart the Nginx service to apply the changes: systemctl restart nginx You can also verify the Nginx service status using the following command: systemctl status nginx You should get the following output: nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-09-05 06:15:20 UTC; 4min 5s ago Docs: man:nginx(8) Process: 28239 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 28250 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 28253 (nginx) Tasks: 3 (limit: 2353) Memory: 3.4M CGroup: /system.slice/nginx.service ??28253 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ??28254 nginx: worker process ??28255 nginx: worker process Sep 05 06:15:20 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server... Sep 05 06:15:20 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server. Once you are finished, you can proceed to the next step. Access LibreNMS Web Interface Now, open your web browser and access the LibreNMS using the URL http://librenms.example.com. You will be redirected to the Pre-install check page: Make sure all the required extensions are installed then click on the Database settings. You should see the following page: Provide your database username, database name, password and click on the Check Credentials button. Once its successful, you should see the following page: Now, click on the Build Database button. You should see the following page: Next, click on the Admin user creation button. You should see the following page: Provide your admin username, email, password and click on the Add User button. You should see the following page: Next, click on the Finish installation button. You should see the following page: Next, click on the “validate your install”. You should see the LibreNMS login page: Provide your LibreNMS admin username, password and click on the Login button. You should see the LibreNMS dashboard: Troubelshoot: If you ever have issues with your install, run validate.php: sudo su - librenms cd /opt/lbrenms/ ./validate.php Ref: https://www.howtoforge.com/tutorial/how-to-setup-librenms-monitoring-tool-with-nginx-on-ubuntu-2004/ https://docs.librenms.org/Installation/Install-LibreNMS/ Administrations Configurations (Linux) LibreNMSUbuntu 20