Ubuntu24.04安装Librenms

1 安装所需的软件包

apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd unzip python3-command-runner python3-pymysql python3-dotenv python3-redis python3-setuptools python3-psutil python3-systemd python3-pip whois traceroute
 
 

2 添加用户

useradd librenms -d /opt/librenms -M -r -s "$(which bash)"
 
 

3 下载LibreNMS

cd /opt
git clone https://github.com/librenms/librenms.git
 
 

4 设置权限

chown -R librenms:librenms /opt/librenms
chmod 771 /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/
 
 

5 安装PHP相关

su - librenms
./scripts/composer_wrapper.php install --no-dev
exit
 
 

手动模式

wget https://getcomposer.org/composer-stable.phar
mv composer-stable.phar /usr/bin/composer
chmod +x /usr/bin/composer
 
 

6 设置时区

vi /etc/php/8.3/fpm/php.ini
vi /etc/php/8.3/cli/php.ini
 
 

示例: "Asia/Shanghai", "Australia/Brisbane"

同时修改系统时区

timedatectl set-timezone Asia/Shanghai
 
 

7 设置MariaDB

vi /etc/mysql/mariadb.conf.d/50-server.cnf
 
 

在 [mysql]区块添加:

innodb_file_per_table=1
lower_case_table_names=0
 
 

然后重启MariaDB

systemctl enable mariadb
systemctl restart mariadb
 
 

登入到数据库:

mysql -u root
创
 
 

建数据库:

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';
exit
 
 

8 配置PHP-FPM

cp /etc/php/8.3/fpm/pool.d/www.conf /etc/php/8.3/fpm/pool.d/librenms.conf
vi /etc/php/8.3/fpm/pool.d/librenms.conf
 
 

将[www]改成[librenms]:

[librenms]
 
 

将 user 和 group 改成 "librenms":

user = librenms
group = librenms
 
 

将listen改成:

listen = /run/php-fpm-librenms.sock
 
 

9 配置Web Server

vi /etc/nginx/conf.d/librenms.conf
 
 

添加如下配置,编辑server_name成实际的域名或者IP:

server {
   
 listen      80;
 server_name librenms.example.com;
 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 ~ [^/]\.php(/|$) {
   
  fastcgi_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
   
  deny all;
 }
}
 
 
rm /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default
systemctl restart nginx
systemctl restart php8.3-fpm
 
 

10 Selinux和Firewall

均设置成默认关闭

11 启用lnms命令补全

ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
 
 

12 配置snmpd

cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
vi /etc/snmp/snmpd.conf
 
 

将文件中RANDOMSTRINGGOESHERE替换成所需的团体字

curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
systemctl enable snmpd
systemctl restart snmpd
 
 

13 Cron job

cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
 
 

14 开启调度程序

cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/

systemctl enable librenms-scheduler.timer
systemctl start librenms-scheduler.timer
 
 

15 日志配置

cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
 
 

16 网页安装程序

访问http://librenms.example.com/install进行安装

chown librenms:librenms /opt/librenms/config.php
 
 

17 最后

通过http://librenms.example.com/访问、设置、使用

posted @   东绕城  阅读(73)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示