如何在Ubuntu 20.04 LTS系统服务器上安装LibreNMS
在本文中我们将向您介绍如何在香港服务器的Ubuntu 20.04 LTS系统上安装LibreNMS。LibreNMS是一个用于服务器和网络硬件的开源自动发现网络监视工具。它支持广泛的网络硬件,例如Cisco,Juniper,Brocade,Foundry,HP,以及包括Linux和Windows在内的操作系统。LibraNMS是在GPLv3下发布的网络监视工具“ Observium ”的基于社区的分支。
步骤1.首先,通过apt在终端中运行以下以下命令,确保所有系统软件包都是最新的。
sudo apt update
sudo apt upgrade
步骤2.安装LEMP堆栈。
这里需要Ubuntu 20.04 LEMP服务器。如果您尚未安装LEMP,请先安装。
步骤3.在Ubuntu 20.04上安装LibreNMS。
让我们安装LibreNMS所需的软件包:
sudo install apt install curl composer fping git graphviz imagemagick rrdtool snmp snmpd whois unzip python python3-pip
现在,我们将从GitHub存储库中获取LibreNMS源代码:
cd /opt
git clone https://github.com/librenms/librenms.git
接下来,创建一个将管理LibreNMS的用户,并将Nginx添加到LibreNMS组:
useradd librenms -d /opt/librenms -M -r
usermod -a -G librenms www-data
我们将需要更改一些文件夹权限:
chown -R librenms:librenms /opt/librenms
chmod 770 /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/
之后,我们提供了一个PHP脚本,它将安装作曲家的依赖项。要执行该操作,我们将使用以下命令。要执行此脚本,我们需要切换到LibreNMS用户:
su - librenms
cd /opt/librenms
./scripts/composer_wrapper.php install --no-dev
exit
步骤4.为LibreNMS配置MariaDB。
默认情况下,不会对MariaDB进行加固。您可以使用mysql_secure_installation脚本保护MariaDB 。您应该仔细阅读每个步骤,并在每个步骤下面仔细进行操作,这将设置root密码,删除匿名用户,禁止远程root登录以及删除测试数据库并访问安全的MariaDB:
mysql_secure_installation
像这样配置它:
- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
接下来,我们将需要登录到MariaDB控制台并为LibreNMS创建数据库。运行以下命令:
mysql -u root -p
这将提示您输入密码,因此输入您的MariaDB根密码,然后按Enter。登录数据库服务器后,您需要为LibreNMS安装创建数据库:
MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> CREATE USER ‘librenms’@‘localhost’ IDENTIFIED BY ‘YOUR-PASSWD’;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO ‘librenms’@‘localhost’;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
完成后,打开MariaDB配置文件,在[mysqld]部分添加以下行。
nano /etc/mysql/mariadb.conf.d/50-server.cnf
在[mysqld]部分中,请添加:
innodb_file_per_table=1
lower_case_table_names=0
然后,重新启动MariaDB,以使更改生效:
sudo systemctl restart mariadb
步骤5.为LibreNMS配置Nginx。
让我们为LibreNMS使用的Nginx创建VirtualHost定义:
nano /etc/nginx/conf.d/librenms.conf
将以下内容添加到配置文件中:
server {
listen 80;
server_name www.a5idc.net;
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
u
r
i
/
/
i
n
d
e
x
.
p
h
p
?
uri/ /index.php?
uri//index.php?query_string;
}
location /api/v0 {
try_files $uri
u
r
i
/
/
a
p
i
v
0.
p
h
p
?
uri/ /api_v0.php?
uri//apiv0.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;
}
}
现在,我们可以重新启动Nginx Web服务器,以便进行更改:
sudo systemctl restart nginx
步骤6.配置防火墙。
允许Nginx通过防火墙,以便用户能够从外部计算机访问LibreNMS门户:
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
步骤7.访问LibreNMS Web界面,
LibreNMS默认使用HTTP端口80。打开您浏览器并访问 你的域名或者ip,按照要求完成所需的步骤来完成安装。
至此,您已成功安装LibreNMS,希望本文对您有所帮助。