25.Zabbix入门必备

Zabbix入门必备

1.配置zabbix源

[root@zabbix ~]# cat /etc/yum.repos.d/zabbix.repo 
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/3.5/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch 
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0

2.安装软件【服务端】

[root@zabbix ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server -y

3.客户端只需安装Zabbix-agent即可

[root@web01 ~]# yum localinstall https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm

4.安装初始化数据库

 1.启动数据库,创建数据库,配置数据库连接信息。
[root@zabbix ~]# systemctl start mariadb
[root@zabbix ~]# systemctl enable mariadb
[root@zabbix ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

2.导入数据
[root@zabbix ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.0
[root@zabbix zabbix-server-mysql-4.0.0]# zcat create.sql.gz |mysql -uroot zabbix

3.在zabbix_server.conf中编辑数据库配置
[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf 
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix    ##添加数据库密码zabbix
 
4.启动Zabbix Server进程
[root@zabbix ~]# systemctl start zabbix-server
[root@zabbix ~]# systemctl enable zabbix-server

5.检查端口10051是否开启

[root@zabbix ~]# netstat -lntp 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      2154/zabbix_server  

6.修改Zabbix前端的PHP配置

[root@zabbix ~]# vim /etc/httpd/conf.d/zabbix.conf
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
         php_value date.timezone Asia/Shanghai

7.启动httpd服务,并加入开机自启

[root@zabbix ~]# systemctl start httpd
[root@zabbix ~]# systemctl enable httpd
[root@zabbix ~]# netstat -lntp |grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      2290/httpd     

8.通过浏览器验证

Zabbix前端可以在浏览器中通过 http://zabbix-frontend-hostname/zabbix 进行访问。默认的用户名/密码为 Admin/zabbix。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.客户端操作:

1.监控一台主机
2.需要安装Agent

1.安装
[root@web01 ~]# yum localinstall https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm

2.配置
[root@web01 ~]# vim /etc/zabbix/zabbix_agentd.conf 
Server=172.16.1.71		#Zabbix-Server的IP地址

3.启动
[root@web01 ~]# systemctl start zabbix-agent
[root@web01 ~]# systemctl enable zabbix-agent

4.检查agent端口
[root@web01 ~]# netstat -lntp |grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1604/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      1604/zabbix_agentd  

3.打开zabbix-server Web管理界面添加主机

在这里插入图片描述
在这里插入图片描述
agent-------监控系统相关信息(应用程序等等)
SNMP-----监控交换机、路由器、防火墙
JMX-------监控JVM----》Tomcat
IPMI------监控硬件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.排查错误:

  • 1.检查IP和端口
  • 2.检查firewalld和Selinux
  • 3.检查配置文件
  • 4.重载服务
  • 5.查看日志

5.架构了解

zabbix-agent(数据采集)-->zabbix-server(数据分析|报警)--> 数据库(数据存储) <--zabbix web(数据展示)

6.拆分数据库

1.准备一台172.16.1.51的数据库,安装mysql(版本一致)

yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb

2.创建zabbix数据库,授权(网络授权)

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

3.在旧数据库上备份库,然后恢复到新的数据库。

[root@zabbix ~]# mysqldump -uroot --databases zabbix  --single-transaction > `date +%F%H`-zabbix.sql

4.远程导入数据

[root@zabbix ~]# cat 2019-10-1717-zabbix.sql |mysql -h172.16.1.51 -uzabbix -pzabbix zabbix

5.停止服务端MySQL服务【数据库错误】

在这里插入图片描述

6.修改Zabbix-Server配置文件指向数据库的IP

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf 
DBHost=172.16.1.51
[root@zabbix ~]# systemctl restart zabbix-server

7.修改Zabbix-Web配置文件指向数据库的IP

[root@zabbix ~]# vim /etc/zabbix/web/zabbix.conf.php 
$DB['SERVER']   = '172.16.1.51';
[root@zabbix ~]# systemctl restart httpd

8.Web恢复正常界面》

在这里插入图片描述

原文地址:https://www.cnblogs.com/yinwu/p/11741515.html