zabbix搭建过程,使用ubnutu24.04版本和ZABBIX6.4.21(根据需求可自行更换,建议使用服务器套虚拟机套平台使用)
一、系统配置安装前
设置系统固定地址,并且保证可以上网
使用nmtui命令设置固定地址,设置完毕后,重启网卡
#sudo /etc/init.d/network-manager restart
Restarting network-manager (via systemctl): network-manager.service.
反馈重启成功。
关闭防火墙关闭selinux,也可直接放通端口50001。
#systemctl stop firewalld
#systemctl disable firewalld
#SELINUX=disabled 临时关闭无任何影响
二、下载安装对应的ZABBIX 安装包
首先:安装存储库
root@localhost# wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb
# dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb
# apt update
其次:安装zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agen
# apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent
最后:安装数据库(数据库我是参考的别人的,来源:iksjls)
# apt install mariadb-server -y
# systemctl start mariadb
# systemctl enable mariadb
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none): # 当前root还没有密码,直接回车即可
Set root password? [Y/n] y # 是否要设置root密码,y
New password: # 123(可自定义)
Re-enter new password: # 再次确认一遍密码
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y # 当前有个anonymous用户,是否移除 y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n # 不允许root远程登录, n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y # 是否移除test数据库 y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y # 是否重载权限表 y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB! # 配置完成
三、设置密码,并将下载的数据库同步到自己的数据库当中去
# mysql -uroot -p
这里输入刚刚设置的mariadb数据库的密码
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by '123'; #这里密码123可自定义,下一步填写DB数据库需要用到
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix //这一句原封不动地打上,我就在这里出了错,老是导入不到系统里面去,使用原话就OK了。
导入数据库后禁用log_bin_trust_function_creators
# mysql -uroot -p
这里是mariadb数据库密码
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
四、使用vi编辑配置文件 /etc/zabbix/zabbix_server.conf
将 DBPassword=password 取消注释然后在后面填自己的数据库密码(用到1次)
五、将server和agent进行重启并设置开机启动。
# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2
六、进入网页:http://xxx.xxx.xxx.xxx/zabbix xxx.xxx.xxx.xxx位设置的ubnutu系统地址。
按照默认流程选择中文,填写DB数据库密码(用到2次),使用默认项完成设置。