项目场景:
使用Zabbix对网络中主要设备进行监控.
phpipam 是一个开源的 Web IP 地址管理应用程序 (IPAM)。 其目标是提供轻量级、现代和有用的 IP 地址管理。它是基于 php 的应用程序,带有 MySQL 数据库后端,使用 jQuery 库、ajax 和 HTML5/CSS3 功能。
phpipam-agent
用于将phpipam服务器部署到远程服务器的扫描代理
GitHub - phpipam/phpipam-agent: phpipam scan agent
安装Ubuntu
Ubuntu 24.04 Server安装流程-CSDN博客
安装后准备工作
-
设置ntp时间服务器
修改NTP配置文件
vi /etc/systemd/timesyncd.conf
timesyncd.conf内容
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file (or a copy of it placed in
# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in
# the /etc/systemd/timesyncd.conf.d/ directory. The latter is generally
# recommended. Defaults can be restored by simply deleting the main
# configuration file and all drop-ins located in /etc/.
#
# Use 'systemd-analyze cat-config systemd/timesyncd.conf' to display the full config.
#
# See timesyncd.conf(5) for details.[Time]
NTP=ntp.aliyun.com
FallbackNTP=ntp.ubuntu.com
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048
ConnectionRetrySec=30
SaveIntervalSec=60
设置时区
timedatectl set-timezone "Asia/Shanghai"
启用网络时间同步
timedatectl set-ntp true
查看时间服务状态
timedatectl set-ntp true
-
设置中文环境
apt install language-pack-zh-hans
localectl set-locale LANG=zh_CN.utf8
reboot
-
安装mysql
apt-get install mysql-server #安装mysql
service mysql start #启动mysql
#################################
#启动和关闭mysql的命令如下:
#启动: sudo service mysql start
#重启: sudo service mysql restart
#关闭: sudo service mysql stop
#################################
#修改mysql的连接方式和数据库密码
mysql -uroot -p #登录mysql数据库
use mysql; #更换数据
update user set host='%' where user='root';#开启远程连接
flush privileges; #修改了之后刷新以下权限
mysql>ALTER USER 'root'@'%' identified with mysql_native_password BY '123456';#修改数据库密码.
flush privileges; #修改了之后刷新以下权限
quit;#退出数据库
#解决Navicat连接不上数据库的问题
vi /etc/mysql/mysql.conf.d/mysqld.cnf;#修改服务配置文件
#################################
#bind-address = 127.0.0.1 修改为
#bind-address = 0.0.0.0
#################################
service mysql restart #重启数据库
重启mysql进程
启动mysql进程,并为它们设置开机自启:
# systemctl restart mysql
# systemctl enable mysql
安装Zabbix
# wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu24.04_all.deb
# dpkg -i zabbix-release_7.0-2+ubuntu24.04_all.deb
# apt update
安装Zabbix server,Web前端,agent
apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent
创建初始数据库
# mysql -uroot -p
Enter password:
mysql>create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.04 sec)
mysql>create user zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)
mysql>grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql>set global log_bin_trust_function_creators = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>quit;
Bye
导入初始架构和数据,系统将提示您输入新创建的密码。
# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
刷新数据
# mysql -uroot -p
Enter password:
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
为Zabbix server配置数据库
编辑配置文件
vi /etc/zabbix/zabbix_server.conf
### Option: DBPassword
# Database password.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=zabbix
DBPassword=password
启动Zabbix server和agent进程
# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2
配置Zabbix信息
使用浏览器登陆Zabbix页面
Zabbix安装完成!!
安装{php}IPAM
PHP设置
安装PHP扩展库
安装pear --- pear是PHP的扩展和应用程序库
安装GMP --- php-gmp是一个用于处理大整数和高精度浮点数计算的数学库,它提供了一系列的函数和类,使得PHP能够进行任意精度的整数运算和浮点数运算。
apt-get install php-pear php-gmp
设置PHP时区设置
查看php时区设置
grep timezone /etc/php/8.3/apache2/php.ini
设置php时区
vi /etc/php/8.3/apache2/php.ini
[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone =Asia/Shanghai
安装{PHP}IPAM
下载库文件
git clone https://github.com/phpipam/phpipam.git /var/www/phpipam
切换目录
cd /var/www/phpipam
检出库
git checkout 1.6
安装其他模块
git submodule update --init --recursive
修改配置文件
cp config.dist.php config.php
vi config.php
/**
* database connection details
******************************/
$db['host'] = '127.0.0.1';
$db['user'] = 'phpipam';
$db['pass'] = 'phpipamadmin';
$db['name'] = 'phpipam';
$db['port'] = 3306;
/**
/**
* Path to access phpipam in site URL, http:/url/BASE/
*
* BASE definition should end with a trailing slash "/"
* BASE will be set automatically if not defined. Examples...
*
* If you access the login page at http://phpipam.local/ = define('BASE', "/");
* If you access the login page at http://company.website/phpipam/ = define('BASE', "/phpipam/");
* If you access the login page at http://company.website/ipam/ = define('BASE', "/ipam/");
*
******************************/
if(!defined('BASE'))
define('BASE', "/phpipam/");
apache2设置
设置虚拟目录
修改apache配置文件
vi /etc/apache2/apache2.conf
插入虚拟目录配置
Alias /phpipam /var/www/phpipam
<Directory /var/www/phpipam>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
启用 rewrite模块
a2enmod rewrite
重启apache
systemctl restart apache2
创建初始数据库
连接数据库
mysql -u root -p
Enter password:(数据库root密码)
创建数据库
mysql> CREATE DATABASE `phpipam`;
创建数据库用户
mysql> CREATE USER 'phpipam'@'localhost' IDENTIFIED BY 'phpipamadmin';
添加用户权限
mysql> GRANT ALL ON phpipam.* TO 'phpipam'@'localhost';
刷新数据权限
mysql> FLUSH PRIVILEGES;
退出数据库连接
mysql> quit;
导入数据库数据
cd cd /var/www/phpipam/
mysql -u root -p phpipam < db/SCHEMA.sql
登录应用页面
现在使用 Admin/ipamadmin 登录到网页。
修改密码
修改中文界面
完成!