LibreNMS是一个功能强大的开源网络监控系统,支持多种网络设备和操作系统,包括Cisco、Linux、FreeBSD、Juniper、HP等。以下是在Debian 10上安装LibreNMS的详细步骤。
步骤1: 更新系统
首先,确保您的Debian 10系统是最新的:
sudo apt update
步骤2: 安装必需的软件包
安装LibreNMS所需的一些软件包和依赖项:
sudo apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nmap python-memcache python-mysqldb rrdtool snmp snmpd whois python3-pymysql python3-dotenv python3-redis python3-setuptools
步骤3: 安装 LEMP 堆栈
在继续之前,请确保您的Debian 10服务器上已经安装了LEMP(Linux、Nginx、MySQL、PHP)堆栈。如果您还没有安装它,可以参考相关教程进行安装。
步骤4: 下载 LibreNMS
创建一个LibreNMS系统用户,以及下载和配置LibreNMS:
sudo useradd librenms -d /opt/librenms -M -r sudo usermod -a -G librenms www-data cd /opt sudo -u librenms git clone https://github.com/librenms/librenms.git sudo chown -R librenms:librenms /opt/librenms sudo chmod 770 /opt/librenms sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
步骤5: 配置 MariaDB
配置MariaDB数据库以供LibreNMS使用:
mysql -u root -p
登录后创建数据库和用户,并为其分配权限:
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; FLUSH PRIVILEGES; EXIT;
编辑MariaDB配置文件以启用必需的选项:
sudo 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
步骤6: 配置 Nginx
创建Nginx虚拟主机配置文件以为LibreNMS配置Web服务器:
sudo rm /etc/nginx/sites-enabled/default sudo nano /etc/nginx/sites-available/librenms.vhost
在文件中添加以下Nginx配置,确保替换server_name
为您的域名或IP地址:
server { listen 80; server_name librenms.yourdomain.com; # 替换成您的域名或 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; proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; 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.3-fpm.sock; # 使用适当的 PHP 版本 } location ~ /\.ht { deny all; } }
启用虚拟主机配置并重新加载Nginx:
sudo ln -s /etc/nginx/sites-available/librenms.vhost /etc/nginx/sites-enabled/librenms.vhost sudo systemctl restart nginx
步骤7: 配置 SNMP
复制LibreNMS提供的SNMP配置示例文件,并编辑以设置您的SNMP社区字符串:
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf sudo chmod 600 /etc/snmp/snmpd.conf sudo nano /etc/snmp/snmpd.conf
将文件中的RANDOMSTRINGGOESHERE
替换为您的SNMP社区字符串。然后重启SNMP服务:
sudo service snmpd restart
步骤8: 配置 UFW 防火墙
如果您使用UFW防火墙,确保允许必需的端口(SSH、HTTP、HTTPS和SNMP):
sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw allow 161/udp sudo ufw enable
步骤9: 访问 LibreNMS
使用浏览器访问LibreNMS的Web界面:
http://your-server-ip/
您将被引导到LibreNMS的登录页面,使用之前设置的LibreNMS系统用户登录。
恭喜!您已成功在Debian 10上安装LibreNMS,现在可以开始监控您的网络设备和服务器。
暂无评论内容