本文介绍在Ubuntu 18.04系统上使用MariaDB数据库、PHP和Nginx服务器来安装LibreNMS监控工具。
一、安装LEMP stack(MariaDB,Nginx和PHP) 请参考在Ubuntu 18.04 Server中安装LEMP的方法[Nginx、MariaDB、PHP7.2]。 LibreNMS与MySQL严格模式不完全兼容,目前,请在安装mysql后禁用它: sudo vim /etc/mysql/mariadb.cnf 在[mysqld]部分中,请添加: innodb_file_per_table=1 sql-mode="" lower_case_table_names=0 然后重启mysql: sudo systemctl restart mysql 安装并配置数据库服务器后,需要为LibreNMS创建数据库: create database librenms; grant all privileges on librenms.* to librenms@localhost IDENTIFIED by "StrongPassword"; flush privileges; quit Ubuntu 18.04在其存储库中有PHP 7.2,通过在终端上运行以下命令来安装它: sudo apt-get -y install wget php php-pear php-cgi php-common php-curl \ php-mbstring php-gd php-mysql php-gettext php-bcmath \ php-imap php-json php-xml php-snmp php-fpm php-zip 要确认安装的php版本,请使用命令php -v查看,要想安装PHP 7.3版本请参考在Ubuntu 18.04或CentOS 7系统上安装PHP 7.3一文。 然后配置并启动PHP-FPM。 确保在php.ini中将date.timezone设置为你的首选时区。 编辑两个文件: sudo vim /etc/php/7.2/fpm/php.ini sudo vim /etc/php/7.2/cli/php.ini 在[Date]部分下更改date.timezone: [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Shanghai 重启php fpm: sudo systemctl restart php7.2-fpm.service 对于此设置,我们将使用Nginx作为LibreNMS的Web服务器,通过运行以下命令安装它: $ sudo apt-get install nginx
二、下载并安装LibreNMS 我们将在此步骤中下载并安装LibreNMS,如果你没有git,请先安装它: $ sudo apt-get install git LibreNMS将在我们需要添加的名为librenms的用户下运行: $ sudo useradd -r -M -d /opt/librenms librenms $ getent passwd librenms librenms:x:997:996::/opt/librenms:/bin/sh 将此用户添加到Web用户组www-data: sudo usermod -a -G librenms www-data 完成后,继续安装LibreNMS所需的软件包: sudo apt-get update sudo apt install rrdtool whois fping imagemagick graphviz mtr-tiny \ nmap python-mysqldb snmp snmpd python-memcache mtr-tiny acl 从Clone LibreNMS源代码: $ git clone https://github.com/librenms/librenms.git librenms Cloning into 'librenms'... remote: Counting objects: 130428, done. remote: Compressing objects: 100% (27/27), done. remote: Total 130428 (delta 10), reused 10 (delta 4), pack-reused 130396 Receiving objects: 100% (130428/130428), 128.54 MiB | 19.52 MiB/s, done. Resolving deltas: 100% (88754/88754), done. Checking out files: 100% (8476/8476), done. 将文件夹librenms移动到/opt: sudo mv librenms/ /opt/ 更改目录的权限: sudo chown -R librenms:librenms /opt/librenms/ sudo chmod -R 775 /opt/librenms/ 配置snmpd: sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf sudo vim /etc/snmp/snmpd.conf 编辑出RANDOMSTRINGGOESHERE的文本并设置你自己的社区字符串: curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro chmod +x distro sudo mv distro /usr/bin/distro 重启snmpd: sudo systemctl restart snmpd 创建LibreNMS Cron作业,运行以下命令以设置cron作业: sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms 复制logrotate配置,LibreNMS将日志保存在/opt/librenms/logs中,要处理旧日志,你可以使用提供的logrotate配置文件: sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms 修复LibreNMS权限: sudo chown -R librenms:librenms /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/
三、配置Nginx 让我们为LibreNMS使用的Nginx创建VirtualHost定义: 运行:$ sudo vim /etc/nginx/conf.d/librenms.conf 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 /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.2-fpm.sock; } location ~ /\.ht { deny all; } } 检查syntax: $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful 如果一切正常,请重新启动nginx: $ sudo systemctl restart nginx
四、在Web UI上配置LibreNMS 运行composer安装: cd /opt/librenms ./scripts/composer_wrapper.php install --no-dev 现在打开Web浏览器并启动安装程序,地址是http://librenms.example.com/install.php(请改为自己配置的地址):
继续配置数据库连接,并添加管理员用户:
Web安装程序可能会提示您手动在librenms安装位置创建config.php文件,将屏幕上显示的内容复制到该文件中: sudo vim /opt/librenms/config.php
如果必须这样做,请记住在将屏幕内容复制到文件后设置config.php的权限: sudo chown librenms:librenms /opt/librenms/config.php 你有一个现成的LibreNMS监控工具,通过单击“validate your install and fix any issues”链接或使用以下命令来验证安装: # cd /opt/librenms # ./validate.php
登录LibreNMS管理员中心并开始配置网络监控:
到这里,在Ubuntu 18.04系统下安装和配置LibreNMS算是全部完成了。
相关主题 |