| 1 | = Monitoring Lab Setup = |
| 2 | ---- |
| 3 | |
| 4 | Below are the requirements for running LibreNMS on Ubuntu 18.04: |
| 5 | |
| 6 | * Database Server – We will use MariaDB |
| 7 | * PHP 7.2 |
| 8 | * Web Server – We will use Nginx |
| 9 | |
| 10 | == Install LEMP stack (MariaDB, Nginx, and PHP) == |
| 11 | === Installation of MariaDB === |
| 12 | |
| 13 | LibreNMS is not fully compatible with MySQL strict mode, for now, please disable this after mysql is installed. |
| 14 | |
| 15 | ` sudo vim /etc/mysql/mariadb.cnf ` |
| 16 | |
| 17 | Within the ` [mysqld]` section please add: |
| 18 | {{{ |
| 19 | innodb_file_per_table=1 |
| 20 | sql-mode="" |
| 21 | lower_case_table_names=0 |
| 22 | }}} |
| 23 | |
| 24 | Then restart mysql `sudo systemctl restart mysql` |
| 25 | |
| 26 | Now you need to create a database for LibreNMS. |
| 27 | |
| 28 | {{{ |
| 29 | mysql –u root –p |
| 30 | MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci; |
| 31 | MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'Strongpassword'; |
| 32 | MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; |
| 33 | MariaDB [(none)]> FLUSH PRIVILEGES; |
| 34 | MariaDB [(none)]> exit |
| 35 | }}} |
| 36 | |
| 37 | === Installation of PHP === |
| 38 | |
| 39 | Ubuntu 18.04 has PHP 7.2 in its repositories. Install it by running the commands below on your terminal |
| 40 | |
| 41 | {{{ |
| 42 | sudo apt-get -y install wget php php-pear php-cgi php-common curl php-curl \ |
| 43 | php-mbstring php-gd php-mysql php-gettext php-bcmath \ |
| 44 | php-imap php-json php-xml php-snmp php-fpm php-zip |
| 45 | }}} |
| 46 | |
| 47 | To confirm the php version installed, use the command `php –v` |
| 48 | |
| 49 | it should give you a similar output as below |
| 50 | |
| 51 | {{{ |
| 52 | #php -v |
| 53 | |
| 54 | PHP 7.2.8 (cli) (built: Jul 17 2018 09:50:46) ( NTS ) |
| 55 | Copyright (c) 1997-2018 The PHP Group |
| 56 | Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies |
| 57 | }}} |
| 58 | |
| 59 | Configure and Start PHP-FPM |
| 60 | Ensure date.timezone is set in php.ini to your preferred time zone: |
| 61 | Edit both files: |
| 62 | sudo vim /etc/php/7.2/fpm/php.ini |
| 63 | sudo vim /etc/php/7.2/cli/php.ini |
| 64 | |
| 65 | Change date.timezone under [Date] section: |
| 66 | [Date] |
| 67 | ; Defines the default timezone used by the date functions |
| 68 | ; http://php.net/date.timezone |
| 69 | date.timezone = Asia/Colombo |
| 70 | Restart php fpm: |
| 71 | sudo systemctl restart php7.2-fpm.service |
| 72 | |
| 73 | For this setup, we will use Nginx as a web server for LibreNMS, install it by running: |
| 74 | sudo apt-get install nginx |
| 75 | |
| 76 | Step 2: Download and Install LibreNMS |
| 77 | We will download and install LibreNMS in this step. If you don’t have git, first install it: |
| 78 | $ sudo apt-get install git |
| 79 | |
| 80 | LibreNMS will run under its own user called librenms which we need to add: |
| 81 | sudo useradd -r -M -d /opt/librenms librenms |
| 82 | getent passwd librenms |
| 83 | |
| 84 | |
| 85 | output: |
| 86 | |
| 87 | librenms:x:997:996::/opt/librenms:/bin/sh |
| 88 | Add this user to web user group www-data |
| 89 | sudo usermod -a -G librenms www-data |
| 90 | |
| 91 | When done. proceed to install packages required by LibreNMS |
| 92 | |
| 93 | sudo apt-get update |
| 94 | sudo apt install rrdtool whois fping imagemagick graphviz mtr-tiny \ |
| 95 | nmap python-mysqldb snmp snmpd python-memcache mtr-tiny acl |
| 96 | |
| 97 | Clone LibreNMS source code from github: |
| 98 | git clone https://github.com/librenms/librenms.git librenms |
| 99 | |
| 100 | output: |
| 101 | Cloning into 'librenms'... |
| 102 | remote: Counting objects: 130428, done. |
| 103 | remote: Compressing objects: 100% (27/27), done. |
| 104 | remote: Total 130428 (delta 10), reused 10 (delta 4), pack-reused 130396 |
| 105 | Receiving objects: 100% (130428/130428), 128.54 MiB | 19.52 MiB/s, done. |
| 106 | Resolving deltas: 100% (88754/88754), done. |
| 107 | Checking out files: 100% (8476/8476), done. |
| 108 | |
| 109 | Move the folder librenms to /opt |
| 110 | |
| 111 | sudo mv librenms/ /opt/ |
| 112 | |
| 113 | Change permission of the directory: |
| 114 | sudo chown -R librenms:librenms /opt/librenms/ |
| 115 | sudo chmod -R 775 /opt/librenms/ |
| 116 | |
| 117 | Configure snmpd |
| 118 | sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf |
| 119 | sudo vim /etc/snmp/snmpd.conf |
| 120 | |
| 121 | Edit the text which says RANDOMSTRINGGOESHERE and set your own community string. |
| 122 | |
| 123 | curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro |
| 124 | chmod +x distro |
| 125 | sudo mv distro /usr/bin/distro |
| 126 | |
| 127 | Restart snmpd |
| 128 | |
| 129 | sudo systemctl restart snmpd |
| 130 | |
| 131 | Create LibreNMS Cron job |
| 132 | Run the command below to set cron job: |
| 133 | |
| 134 | sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms |
| 135 | Copy logrotate config |
| 136 | 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: |
| 137 | |
| 138 | sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms |
| 139 | |
| 140 | Fix LibreNMS Permissions |
| 141 | Finally, fix all permissions |
| 142 | sudo chown -R librenms:librenms /opt/librenms |
| 143 | sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ |
| 144 | sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ |
| 145 | |
| 146 | Configure Nginx: |
| 147 | Let’s create the VirtualHost definition for Nginx to be used by LibreNMS. |
| 148 | sudo vim /etc/nginx/conf.d/librenms.conf |
| 149 | |
| 150 | server { |
| 151 | listen 80; |
| 152 | server_name librenms.example.com; |
| 153 | root /opt/librenms/html; |
| 154 | index index.php; |
| 155 | |
| 156 | charset utf-8; |
| 157 | gzip on; |
| 158 | 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; |
| 159 | location / { |
| 160 | try_files $uri $uri/ /index.php?$query_string; |
| 161 | } |
| 162 | location /api/v0 { |
| 163 | try_files $uri $uri/ /api_v0.php?$query_string; |
| 164 | } |
| 165 | location ~ \.php { |
| 166 | include fastcgi.conf; |
| 167 | fastcgi_split_path_info ^(.+\.php)(/.+)$; |
| 168 | fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; |
| 169 | } |
| 170 | location ~ /\.ht { |
| 171 | deny all; |
| 172 | } |
| 173 | } |
| 174 | Check syntax: |
| 175 | |
| 176 | sudo nginx –t |
| 177 | |
| 178 | output: |
| 179 | |
| 180 | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok |
| 181 | nginx: configuration file /etc/nginx/nginx.conf test is successful |
| 182 | |
| 183 | if all is okay, restart nginx: |
| 184 | |
| 185 | sudo systemctl restart nginx |
| 186 | |
| 187 | |
| 188 | Run composer install: |
| 189 | |
| 190 | cd /opt/librenms |
| 191 | ./scripts/composer_wrapper.php install --no-dev |
| 192 | |
| 193 | Now open your web browser and start the installer: |
| 194 | |
| 195 | http://librenms.example.com/install.php |