zabbix搭建-服务监控报警与自动恢复
Posted xiaochangwei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix搭建-服务监控报警与自动恢复相关的知识,希望对你有一定的参考价值。
#zabbix部署参考 https://www.cnblogs.com/itbox/p/12142066.html #关闭防火墙 systemctl disable firewalld.service #关闭Selinux vim /etc/selinux/config SELINUX=diabled #安装apache yum -y install httpd #启动并设置为自启动 systemctl enable httpd systemctl start httpd #安装好mysql或使用其他地址mysql #安装php环境 yum install -y php php-mysql #安装zabbix #1.下载安装release包,此包用来更新yum仓库 rpm -ivh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm #2.安装Zabbix组件包(注意选择组件,zabbixServer这台机器我不安装agent,另一台机器则只安装agent) yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender #配置数据库 #1.创建数据库并设置编码为utf8 mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | zabbix | +--------------------+ 5 rows in set (0.00 sec) #2.创建zabbix账户并设置密码 mysql> grant all privileges on zabbix.* to zabbix@localhost identified by ‘AbcdefG123!‘; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> grant all privileges on zabbix.* to xiao@% identified by ‘AbcdefG123!‘; #3.刷新权限 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #4.导入数据库初始化脚本 cd /usr/share/doc/zabbix-server-mysql-4.4.4/ gunzip create.sql.gz mysql -uroot -p zabbix <create.sql #5.确认表已经导入 #配置zabbix server数据库信息 vim /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=Zabbix DBPassword=xxxxxx #启动zabbix server并设置为自启动 systemctl start zabbix-server systemctl enable zabbix-server #修改市区为上海 Asia/Shanghai vi /etc/httpd/conf.d/zabbix.conf #重启httpd systemctl restart httpd #登陆并配置数据库账号密码和/etc/zabbix/zabbix_server.conf中的一致 http://IP/zabbix 默认登陆账户Admin(首字母大写) 默认登录密码zabbix #安装agent yum install -y zabbix-agent #1.配置zabbix server所在地址 cd /etc/zabbix/ vi zabbix_agentd.conf Server=127.0.0.1 ServerActive=127.0.0.1 Hostname=Zabbix server #这个需要和配置-主机列表中的名称对应 systemctl start zabbix-agent systemctl enable zabbix-agent #自动监测异常,通知并恢复 先建立模板-应用集-监控项-触发器,最后才是动作 首先要确保agent端开启远程执行命令 sed -i ‘s|# EnableRemoteCommands=0|EnableRemoteCommands=1|g‘ /usr/local/zabbix/etc/zabbix_agentd.conf 动作中配置远程命令时候最前面加上sudo,并在agent上配置zabbix的权限: # visudo #允许zabbix用户在无密码清空下执行所有操作或者部门操作zabbix ALL=(ALL) NOPASSWD:/etc/init.d/nginx restart zabbix ALL=(ALL) NOPASSWD:ALL #Default requiretty #如果此行没注释,请一并注释 #自定义脚本监控 https://www.cnblogs.com/yanjieli/p/10833311.html # vim /etc/zabbix/script/service_status.sh #!/bin/bash #Desc:zabbix 远程执行命令、重启应用 nginx、mysql、php、等 case $1 in Docker) result=`systemctl status docker |grep ‘active (running)‘ |wc -l` echo $result ;; Mysql) result=`pidof mysqld |wc -l` echo $result ;; *) echo "Usage:$0(Docker|Mysql)" ;; esac #在配置文件中配置调用方式和脚本 [root@localhost zabbix]# cat zabbix_agentd.d/service_status.conf UserParameter=myservice.status[*],/etc/zabbix/script/service_status.sh $1 #创建触发器并设定判定异常时候的标准 {checke service status:myservice.status[Docker].last()}=0 #在agent-server端测试能否调通 zabbix_get -s 192.168.1.14 -k "myservice.status[Docker]" #最后配置动作相关 #最后可测试,比如停掉docker服务后会发现docker自动重启了,邮件也会收到异常和恢复的通知 ##########################################问题点########################################## 1.zabbix提示the zone for php is not set解决 https://blog.csdn.net/jing875480512/article/details/79002404
以上是关于zabbix搭建-服务监控报警与自动恢复的主要内容,如果未能解决你的问题,请参考以下文章