Ads Atas

Install LibreNMS pada Linux Ubuntu 20.04

librenms

Assalamu'alaikum wr wb

Alhamdulillah kali ini saya bisa kembali membuat artikel terkait dunia jaringan internet. Kali ini saya akan sharing tentang salah satu NMS yang menurut saya sangat membantu dalam monitoring jaringan, yakni LibreNMS. LibreNMS itu sendiri adalah suatu perangkat lunak yang berfungsi sebagai aplikasi yang memonitoring kondisi suatu device ataupun status jaringan dengan menggunakan protocol SNMP yang akan membaca secara terperinci pada suatu device yang kita monitoring. Pada situs resminya LibreNMS memiliki tagline "a fully featured network monitoring system that provides a wealth of features and device support"

Baik langsung saja kita masuk pada poin instalasi LibreNMS.

  1. Terlebih dahulu server sudah diinstall operating system linux, disini saya menggunakan Ubuntu 20.04 bisa juga menggunakan linux lain.

  2. Set timezone pada ubuntu server yang masih baru dengan cara : 
    sudo timedatectl set-timezone Asia/Jakarta
  3. Instal php dan php extension yang diperlukan LibreNMS :
    sudo apt install software-properties-common
    sudo add-apt-repository universe
    sudo add-apt-repository ppa:ondrej/php
    sudo apt update
    sudo apt upgrade
    sudo apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools
  4. Konfigurasi PHP :
    sudo nano /etc/php/7.4/cli/php.ini
    Cari parameter cgi.fix_pathinfo lalu uncomment kemudian rubah nilainya seperti ini :
    cgi.fix_pathinfo=0
    Save dan close

  5. Edit file /etc/php/7.4/fpm/php.ini :
    nano /etc/php/7.4/fpm/php.ini
    Uncomment dan isi zone waktu servernya :
    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = Asia/Jakarta
    Save dan close

  6. Edit file /etc/php/7.4/cli/php.ini :
    nano /etc/php/7.4/cli/php.ini
    Uncomment dan isi zone waktu servernya :
    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = Asia/Jakarta
    Save dan close

  7. Restart service php
    sudo systemctl restart php7.4-fpm
  8. Instal database MariaDB :
    sudo apt-get -y install mariadb-client mariadb-server
  9. Mengamankan database dengan memberikan password :
    sudo mysql_secure_installation
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
                 SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):
    OK, successfully used password, moving on...

    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.

    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Password updated successfully!
    Reloading privilege tables..
    ... Success!

    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.

    Remove anonymous users? [Y/n] y
     ... Success!

    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? [Y/n] y
    ... Success!

    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.

    Remove test database and access to it? [Y/n] y
    - Dropping test database...
    ... Success!
    - Removing privileges on test database...
    ... Success!

    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.

    Reload privilege tables now? [Y/n] y
    ... Success!

    Cleaning up...

    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.

    Thanks for using MariaDB!
  10. Instal web server, disini kita menggunakan NGINX :
    sudo apt-get -y install nginx-full
  11. Menambahkan user baru LibreNMS :
    sudo useradd librenms -d /opt/librenms -M -r
    sudo usermod -a -G librenms www-data
  12. Membuat database LibreNMS :
    sudo mysql -u root -p
    Membuat database beserta user dan password keamanan :
    CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'librenms';
    GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
    FLUSH PRIVILEGES;
    exit
  13. Edit nama file 50-server.cnf :
    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
    Di dalam bagian [mysqld], tambahkan parameter di bawah ini:
    innodb_file_per_table=1
    sql-mode=""
    lower_case_table_names=0
    Save dan close

  14. Restart service MariaDB :
    sudo systemctl restart mysql
  15. Download LibreNMS :
    sudo git clone https://github.com/librenms/librenms.git librenms
  16. Mengkonfigurasi Nginx ubntuk membuat file konfigurasi librenms di dalam nginx agar antarmuka webnya dapat diakses :
    sudo nano /etc/nginx/sites-available/librenms.conf
    Tambahkan parameter di bawah ini dan pastikan mengganti your_server_name_or_ip dengan alamat domain milik kita :
    server {
     listen      80;
     server_name your_server_name_or_ip;
     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 dan close
  17. Sekarang perlu membuat tautan ke file librenms.conf seperti di bawah ini :
    sudo ln -s /etc/nginx/sites-available/librenms.conf /etc/nginx/sites-enabled/
    sudo unlink /etc/nginx/sites-enabled/default
  18. Restart service nginx dan php untuk update perubahan konfigurasi :
    sudo systemctl restart nginx
    sudo systemctl restart php7.4-fpm
  19. Mengkonfigurasi SNMPD, ketik perintah berikut untuk mengkonfigurasi snmp untuk digunakan dengan librenms :
    sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
    sudo nano /etc/snmp/snmpd.conf
  20. Ganti teks yang mengatakan RANDOMSTRINGGOESHERE dan atur string community kita sendiri seperti di bawah ini :
    com2sec readonly  default         public
    Save dan close
  21. Download distro dari librenms :
    sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
    sudo chmod +x /usr/bin/distro
    sudo systemctl restart snmpd
  22. Tambahkan Cronjob untuk log rotate:
    sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
    sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
  23. Merubah permission file/folder librenms :
    sudo chown -R librenms:librenms /opt/librenms
    sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs
    sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs
  24. Menjalankan composer wrapper :
    sudo su - librenms
    /opt/librenms/scripts/composer_wrapper.php install --no-dev


    Lalu exit untuk keluar

  25. Menambahkan rule firewall pada linux :
    sudo ufw allow ssh
    sudo ufw allow http
    sudo ufw allow https
    sudo ufw allow 161/udp
    sudo ufw enable

    Untuk melihat status firewall :
    sudo ufw status
  26. LibreNMS install webserver :
    buka halaman url server dengan cara buka browser lalu ketik dengan http://your_server_name or http://your_server_ip, jika sudah maka akan diarahkan ke install.php pada stage 0 seperti berikut :


  27. Next stage maka akan diarahkan pada pengaturan database LibreNMS pada stage 1, seperti contoh berikut :


  28. Next stage jika sudah mengkoneksikan database maka selanjutnya proses import database librenms pada stage 2, seperti contoh berikut :


  29. Dengan menekan tombol Goto add user akan diarahkan pada stage 3 untuk membuat password admin, seperti contoh berikut :


  30. Setelah sudah mengisi password dan email pada stage 3 maka kita diarahkan untuk klik add user agar ke tahap selanjutnya :


  31. Pada stage 4 kita harus generate config untuk melanjutkan stage ke 5, seperti contoh berikut :


  32. Copy file stage 5 lalu kembali ke ubuntu terminal untuk mengkonfigurasi config.php, seperti berikut :
    sudo nano /opt/librenms/config.php
    paste script tersebut lalu save dan close
  33. Update permission LibreNMS :
    sudo chown -R librenms:librenms /opt/librenms
  34. Jalankan validasi pada librenms :
    sudo /opt/librenms/validate.php
  35. Lalu jalankan command tambahan sebagai berikut jika mengalami kendala error :
    sudo chown -R librenms:librenms '/opt/librenms'
    sudo setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
    sudo chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
    semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/bootstrap/cache(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/storage(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/rrd(/.*)?'
    restorecon -RFv /opt/librenms
    sudo ln -s /opt/librenms/lnms /usr/bin/lnms
    sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
    mysql -u root -p
    ./scripts/github-remove
  36. Selanjutkan bisa cek kembali di browser maka akan muncul halaman login librenms :



    Sekian semoga tutorial kali ini bermanfaat, jangan lupa like dan share
    Nantikan tutorial selanjutnya jangan lupa cek update. Sampai jumpa 😊

Post a Comment

0 Comments