2018/04/03

How to install LibreNMS on Ubuntu Server 16.04

System update and install package
sudo su
apt install software-properties-common
add-apt-repository ppa:ondrej/php
apt update
apt install -y apache2 composer fping git graphviz imagemagick libapache2-mod-php7.2 mariadb-client mariadb-server mtr-tiny nmap php7.2-cli php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-mcrypt php7.2-mysql php7.2-snmp php7.2-xml php7.2-zip python-memcache python-mysqldb rrdtool snmp snmpd whois sendmail

Configure DB
mysql -uroot -p
CREATE DATABASE librenmsdb;
CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'librenmspwd';
GRANT ALL PRIVILEGES ON librenmsdb.* TO 'librenmsuser'@'localhost';
exit

nano /etc/mysql/mariadb.conf.d/50-server.cnf
innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0

/lib/systemd/systemd-sysv-install enable mysql
systemctl restart mysql

Configure Web and LibreNMS
nano /etc/php/7.2/apache2/php.ini and /etc/php/7.2/cli/php.ini
date.timezone = Asia/Taipei

useradd librenms -d /opt/librenms -M -r
usermod -a -G librenms www-data
cd /opt
git clone https://github.com/librenms/librenms.git librenms
cd /opt/librenms
chmod 775 rrd
chown -R librenms:librenms /opt/librenms

nano /etc/apache2/sites-available/librenms.conf
<VirtualHost *:80>
  DocumentRoot /opt/librenms/html/
  ServerName localhost
  CustomLog /opt/librenms/logs/access_log combined
  ErrorLog /opt/librenms/logs/error_log
  AllowEncodedSlashes NoDecode
  <Directory "/opt/librenms/html/">
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>
</VirtualHost>

a2dissite 000-default
a2ensite librenms.conf
a2enmod rewrite
systemctl restart apache2
/lib/systemd/systemd-sysv-install enable apache2
./scripts/composer_wrapper.php install --no-dev

Open Browser to open http://localhost web page
Finished 6/6 installation steps

Post setup
nano /opt/librenms/config.php

<?php
## Have a look in defaults.inc.php for examples of settings you can set here. DO NOT EDIT defaults.inc.php!

### Database config
$config['db_host'] = 'localhost';
$config['db_port'] = '3306';
$config['db_user'] = 'librenmsuser';
$config['db_pass'] = 'librenmspassword';
$config['db_name'] = 'librenmsdb';
$config['db_socket'] = '';

// This is the user LibreNMS will run as
//Please ensure this user is created and has the correct permissions to your install
$config['user'] = 'librenms';

### Locations - it is recommended to keep the default
#$config['install_dir']  = "/opt/librenms";

### This should *only* be set if you want to *force* a particular hostname/port
### It will prevent the web interface being usable form any other hostname
#$config['base_url']        = "http://librenms.company.com";

### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir
### and that your web server has permission to talk to rrdcached.
#$config['rrdcached']    = "unix:/var/run/rrdcached.sock";

### Default community
$config['snmp']['community'] = array("public");

### Authentication Model
$config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth
#$config['http_auth_guest'] = "guest"; # remember to configure this user if you use http-auth

### List of RFC1918 networks to allow scanning-based discovery
#$config['nets'][] = "10.0.0.0/8";
#$config['nets'][] = "172.16.0.0/12";
#$config['nets'][] = "192.168.0.0/16";

# Update configuration
#$config['update_channel'] = 'release';  # uncomment to follow the monthly release channel
#$config['update'] = 0;  # uncomment to completely disable updates
$config['fping'] = "/usr/sbin/fping";

cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
chown -R librenms:librenms /opt/librenms
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
chmod -R ug=rwX /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
echo 'ALTER DATABASE librenmsdb CHARACTER SET utf8 COLLATE utf8_unicode_ci;' | mysql -p -u librenmsuser
./validate.php

Ubuntu Client setup
apt install snmpd
cd /etc/snmp
mv snmpd.conf snmpd.conf.bak
nano /etc/snmp/snmpd.conf
# Change "libre" to your preferred SNMP community string

com2sec readonly default libre

group MyROGroup v2c readonly

view all included .1 80

access MyROGroup "" any noauth exact all none none

# Update your location here

syslocation Taiepi, Taiwan
syscontact IT Admin <12345@it.com>

# Distro Detection

extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro

#  Listen for connections from the local system only
agentAddress  udp:161

# rocommunity public  default    -V systemonly
rocommunity public "Monitor Server IP"

curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
systemctl restart snmpd
/lib/systemd/systemd-sysv-install enable snmpd
netstat -anp | grep :161

Open Browser to open http://localhost web page
Find Devices > Add Device
Hostname = Domain name or IP address
SNMP Version = v2c/161/udp
Community = public

沒有留言:

張貼留言