Zabbix监控接入
1、环境
实验机器:
118.31.158.83(zabbix server)
172.17.6.11(zabbix proxy)
172.17.6.11(zabbix agent)
2、安装zabbix server
2.1、添加zabbix软件仓库
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-13.el7.noarch.rpm
2.2、安装zabbix部署包
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
2.3、安装mysql 并创建数据库
yum -y install mariadb mariadb-server
systemctl enable mariadb
systemctl start mariadb
2.4、创建zabbix数据库
create database zabbix character set utf8 collate utf8_bin;
2.5、在数据库中新建用户
mysql -uroot -p
>create user 'zabbix'@'localhost' identified by 'zabbix';
#mysql创建用户报错,ERROR 1396 (HY000): Operation CREATE USER failed for 'zabbix'@'localhost'
这是一个官方bug,解决方法
>drop user zabbix@localhost;
>flush privileges;
>create user zabbix@localhost identified by 'zabbix';
2.6、对zabbix server授权访问
>grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
>flush privileges; #更新权限
>select user,host from mysql.user; #查看
2.7、导入数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
2.8、为 zabbix server配置数据库
编辑 zabbix_server.conf文件以使用已创建的数据库 #vi /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix LogFile=/tmp/zabbix_server.log Timeout=4 LogSlowQueries=3000
2.9、设置开机自启并启动 zabbix server进程
systemctl enable zabbix-server systemctl zabbix-server start
2.10、编辑zabbix前端php配置
Zabbix前端的Apache配置文件位于 /etc/httpd/conf.d/zabbix.conf
vi /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 always_populate_raw_post_data -1 php_value date.timezone Asia/Shanghai
2.11、启动apache服务
systemctl enable httpd systemctl restart httpd
启动 httpd时候 zabbix-server.service failed. ~ 未关闭防火墙
永久关闭selinux防火墙 # vim /etc/sysconfig/selinux SELINUX=disabled setenforce 0
3、安装配置zabbix proxy代理服务
centos6系统
1、配置mysql和proxy源 rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.1/MySQL-shared-community-5.1.72-1.rhel5.x86_64.rpm rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/6/x86_64/zabbix-proxy-mysql-4.0.15-1.el6.x86_64.rpm rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/6/x86_64/zabbix-agent-4.0.15-1.el6.x86_64.rpm 2、更新源 yum clean all &&yum makecache 3、安装proxy、agent、mysql yum install -y zabbix-proxy-mysql zabbix-agent yum -y install mysql mysql-server 4、centos6关闭防火墙 service iptables stop 5、centos6设置开机启动 chkconfig mysqld on chkconfig zabbix-proxy on chkconfig zabbix-agent on 6、进入mysql的/etc/my.cnf文件,设置最大连接数为10000;启动mysql max_connections=10000 service mysqld start 7、登录mysql数据库,新建一个zabbix_proxy库和zabbix用户,对zabbix用户授权 mysql -uroot -p >create database zabbix_proxy character set utf8 collate utf8_bin; >create user 'zabbix'@'localhost' identified by 'zabbix'; >grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'zabbix'; >flush privileges; #更新权限 >select user,host from mysql.user; #查看 8、导入zabbix数据到mysql的zabbix_proxy库 zcat /usr/share/doc/zabbix-proxy-mysql-4.0.15/schema.sql.gz |mysql -uzabbix -pzabbix zabbix_proxy
3.2、zabbix_proxy.conf配置文件如下:
ProxyMode=0 Server=118.31.158.83 #指向server端ip ServerPort=10051 Hostname=ajidou #agent代理监测程序的名字 LogFile=/data01/log/zabbix/zabbix_proxy.log LogFileSize=0 DebugLevel=3 PidFile=/var/run/zabbix/zabbix_proxy.pid DBHost=localhost DBName=zabbix_proxy DBUser=zabbix DBPassword=zabbix DBPort=3306 ProxyMode=0 ProxyLocalBuffer=0
3.3、zabbix_agent.conf配置文件如下
PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/data01/log/zabbix/zabbix_agentd.log LogFileSize=0 Hostname=172.17.6.11 Include=/etc/zabbix/zabbix_agentd.d/*.conf ListenPort=10050 Server=172.17.6.11 # 指向proxy代理服务器ip #ServerActive=127.0.0.1:10051 Timeout=10
3.4 、启动proxy和agent
service zabbix-proxy start service zabbix-agent start
4、配置zabbix客户端agentd.conf文件(win系统)
LogFile=c:\Program Files (x86)\zabbix_agent4\zabbix_agentd.log
LogFileSize=1
StartAgents=1 #被动模式
Server=172.17.6.11。 #指向proxy代理服务器ip
#ServerActive=118.31.158.83
Hostname=172.23.50.31。 #本机ip
#Include=c:\zabbix\zabbix_agentd.conf.d\
ListenPort=30050