free
df
uptime????????????????????????????????监控系统启动时间的信息命令
ifconfig/route/glances/iftop/nethogs
netstat
iostat/iotop
vmstat
?
使用脚本+定时任务来进行
安装zabbix客户端来实现
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
zabbix服务程序软件????????zabbix-server-mysql
zabbix服务web软件:????????zabbix-web-mysql????httpd php
数据库服务软件:????????????mariadb-server
[root@zabbix-server ~] # yum install -y zabbix-server-mysql zabbix-web-mysql httpd php mariadb-server
[root@zabbix-server ~] # vim /etc/zabbix/zabbix_server.conf
91 # DBHost=localhost????????????指定连接的数据库是本地还是远程,如果是远程,指定IP地址
100 DBName=Zabbix????????????????指定数据库的名称
116 DBUser=Zabbix????????????????指定用户名称
125 DBPassword=Zabbix????????????指定密码信息
[root@zabbix-server ~] # systemctl start mariadb.service
[root@zabbix-server ~] # mysql -uzabbix -pzabbix
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1884
Server version: 5.5.64-MariaDB MariaDB Server
?
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
?
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
?
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;????????????创建数据库
?
?
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘;????????创建数据库对用的用户
[root@zabbix-server ~] # zcat /usr/share/doc/zabbix-server-mysql-4.0.15/create.sql.gz|mysql -uzabbix -pzabbix zabbix
[root@zabbix-server ~] # vim /etc/httpd/conf.d/zabbix.conf
20 php_value date.timezone Asia/Shanghai????????????修改时区为你创建zabbix所在的时区
[root@zabbix-server ~] # systemctl start zabbix-server.service httpd mariadb.service
[root@zabbix-server ~] # systemctl enable zabbix-server.service httpd mariadb.service
【zabbix-agent服务的配置】
[root@web01 ~] # yum -y install zabbix-agent
[root@web01 ~] # vim /etc/zabbix/zabbix_agentd.conf
98 Server=172.16.1.71????????????????????指定要哪台服务器可以进行监控我这台服务器
[root@web01 ~] # systemctl restart zabbix-agent.service
[root@web01 ~] # vim /etc/zabbix/zabbix_agentd.conf
?
268 Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@web01 zabbix_agentd.d] # cat user_count.conf
UserParameter=user.count,w | grep -c "pts"????????????????统计当前登录的用户
[root@zabbix-server ~] # yum -y install zabbix-get
[root@zabbix-server ~] # zabbix_get -s 172.16.1.7 -k user.count????????检测成功
1
[root@zabbix-server ~] # zabbix_get -s 172.16.1.7 -k user.count
2
[root@web01 scripts] # cd /etc/zabbix/zabbix_agentd.d/
[root@web01 zabbix_agentd.d] # vim tcp_eleven_status.conf
UserParameter=tcp_eleven.status[*],netstat -an|grep -ic $1
[root@zabbix-server ~] # zabbix_get -s 172.16.1.7 -k tcp_eleven.status[LISTEN]
83
[root@zabbix-server ~] # zabbix_get -s 172.16.1.7 -k tcp_eleven.status[ESTABLISHED]
4
触发器为了解决人为监控看数据,可以通过设定一个值来进行判断,当到达这个阈值的时候就会触发报警
[root@web01 zabbix_agentd.d] # vim /server/scripts/monitor_web.sh
#!/bin/bash
netstat -lntup|grep -w 80 &>/dev/null
if [ $? -ne 0 ]
then
echo 0????????????????????如果返回状态不等于0,则返回0
else
echo 1????????????????????如果返回状态等于0,则返回1
fi
[root@web01 zabbix_agentd.d] # cd /etc/zabbix/zabbix_agentd.d/
[root@web01 zabbix_agentd.d] # cat server.conf
UserParameter=net.tcp.checkweb,/server/scripts/monitor_web.sh
[root@web01 zabbix_agentd.d] #
[root@zabbix-server ~] # zabbix_get -s 172.16.1.7 -k net.tcp.checkweb
1????????????????????????????正常
You have new mail in /var/spool/mail/root
[root@web01 zabbix_agentd.d] # systemctl stop nginx
You have new mail in /var/spool/mail/root
[root@web01 zabbix_agentd.d] #
如果不行,就需要清除下浏览器缓存在看下
<option value="alarm_disaster.mp3" selected="selected">alarm_disaster</option>????????复制出来的内容
[root@zabbix-server ~] # cd /etc/httpd/conf.d/
You have new mail in /var/spool/mail/root
[root@zabbix-server conf.d] # vim zabbix.conf ????????????配置文件所在的目录
#
# Zabbix monitoring system php web frontend
#
?
Alias /zabbix /usr/share/zabbix
?
<Directory "/usr/share/zabbix">????????????????????????Zabbix所在的站点目录
Options FollowSymLinks
AllowOverride None
[root@zabbix-server conf.d] # find /usr/share/zabbix -name "alarm_disaster.mp3"????????????查找
/usr/share/zabbix/audio/alarm_disaster.mp3????????????????查找出来的结果
[root@zabbix-server conf.d] # cd /usr/share/zabbix/audio/????????切换到这个目录下
[root@zabbix-server audio] # ls
alarm_average.mp3 alarm_disaster.mp3 alarm_high.mp3 alarm_information.mp3 alarm_ok.mp3 alarm_warning.mp3 no_sound.mp3????????可以又很多音乐文件,将自己的音乐文件放进去,更换成你要换的名字即可
如果出现不会播放更换自己的音乐,你要自己清除下缓存即可
[root@zabbix-server audio] # vim /etc/zabbix/zabbix_server.conf
508 ### Option: AlertScriptsPath
509 # Full path to location of custom alert scripts.
510 # Default depends on compilation options.
511 # To see the default path run command "zabbix_server --help".
512 #
513 # Mandatory: no
514 # Default:
515 # AlertScriptsPath=${datadir}/zabbix/alertscripts
516
517 AlertScriptsPath=/usr/lib/zabbix/alertscripts????????????????存放脚本的路径
[root@zabbix-server alertscripts] # cat mail_163.py
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_user = ‘460523471@qq.com‘????????????????指定你设置的邮箱
mail_pass = ‘enoncgdkvjhlbjbd‘ ????????????????你的验证密码
?
def send_mail(to_list,subject,content):
me = "zabbix 监控告警平台"+"<"+mail_user+">"
msg = MIMEText(content, ‘plain‘, ‘utf-8‘)
msg[‘Subject‘] = subject
msg[‘From‘] = me
msg[‘to‘] = to_list
try:
s = smtplib.SMTP("smtp.qq.com", 25) ????这儿你的smtp服务器是qq就写qq,是其他就写其他
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
You have new mail in /var/spool/mail/root
[root@web01 zabbix_agentd.d] # systemctl stop nginx
[root@web01 zabbix_agentd.d] #
https://work.weixin.qq.com/wework_admin/loginpage_wx--------登陆进去,注册登陆
[root@zabbix-server alertscripts] # cat ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
?
[install]
trusted-host=mirrors.aliyun.com
You have new mail in /var/spool/mail/root
[root@zabbix-server alertscripts] #
[root@zabbix-server alertscripts] # cat weixin.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#author: yanggd
#date: 2018-04-20
#comment: zabbix接入微信报警脚本
?
import requests
import sys
import os
import json
import logging
?
logging.basicConfig(level = logging.DEBUG, format = ‘%(asctime)s, %(filename)s, %(levelname)s, %(message)s‘,
datefmt = ‘%a, %d %b %Y %H:%M:%S‘,
filename = os.path.join(‘/tmp‘,‘weixin.log‘),
filemode = ‘a‘)
?
corpid=‘ww3ff5e031e93d32d9‘????????????????????写成自己的企业ID
appsecret=‘qG_KF_Ot2yUnevM0K3b8PaoOC7zqZT3IZwx_o9JeHcc‘????????????写成自己的secury
agentid=1000002????????????????????????????写成自己的AgentID
#获取accesstoken
token_url=‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=‘ + corpid + ‘&corpsecret=‘ + appsecret
req=requests.get(token_url)
accesstoken=req.json()[‘access_token‘]
?
#发送消息
msgsend_url=‘https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=‘ + accesstoken
?
touser=sys.argv[1]
subject=sys.argv[2]
#toparty=‘3|4|5|6‘
message=sys.argv[2] + "\n\n" +sys.argv[3]
?
params={
"touser": touser,
# "toparty": toparty,
"msgtype": "text",
"agentid": agentid,
"text": {
"content": message
},
"safe":0
}
req=requests.post(msgsend_url, data=json.dumps(params))
logging.info(‘sendto:‘ + touser + ‘;;subject:‘ + subject + ‘;;message:‘ + message)
[root@zabbix-server alertscripts] # ./weixin.py LiangYuXing test_info "we check nginx"
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
[root@web01 zabbix_agentd.d] # systemctl stop nginx
?
https://user.aiops.com/pages/v2/login?from=oneacaoptcmfhaot--------登录注册
[root@zabbix-server ~] # cd /usr/lib/zabbix/alertscripts/
[root@zabbix-server alertscripts] # wget https://download.aiops.com/ca_agent/zabbix/ca_zabbix_release-2.1.0.tar.gz
[root@zabbix-server alertscripts] # tar -xzf ca_zabbix_release-2.1.0.tar.gz
[root@zabbix-server alertscripts] #
[root@zabbix-server alertscripts] # cd cloudalert/bin
[root@zabbix-server bin] # bash install.sh 72f622ad-9b2c-76ea-41c9-3c5de8be95e5
start to create config file...
Zabbix管理地址: http://10.0.0.71/zabbix/????????????你zabbix的登录地址,不需要加index.php
Zabbix管理员账号: Admin
Zabbix管理员密码(zabbix)????????????????????上面默认不显示
[root@web01 ~] # systemctl stop nginx
[root@web01 ~] #
[root@zabbix-server fonts] # cd /usr/share/zabbix/assets/fonts
[root@zabbix-server fonts] # ll
[root@zabbix-server fonts] # mv graphfont.ttf graphfont.ttf_backup
[root@zabbix-server fonts] # mv msyh.ttc graphfont.ttf
[root@zabbix-server fonts] # ls
graphfont.ttf graphfont.ttf_backup
[root@zabbix-server fonts] #
官方网址链接: https://grafana.com/
告示:只是告诉你们,具体我这里有下载地址
[root@zabbix-server fonts] # wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-6.5.1-1.x86_64.rpm
[root@zabbix-server fonts] # yum localinstall -y grafana-6.5.1-1.x86_64.rpm
[root@zabbix-server ~] # systemctl restart grafana-server.service
[root@zabbix-server ~] # systemctl enable grafana-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
[root@zabbix-server ~] #
账号:admin 密码:admin
[root@zabbix-server ~] # grafana-cli plugins list-remote | grep zabbix
id: alexanderzobnin-zabbix-app version: 3.10.4
You have new mail in /var/spool/mail/root
[root@zabbix-server ~] #
https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/3.10.4/download
[root@zabbix-server ~] # mkdir -p /var/lib/grafana/plugins
[root@zabbix-server plugins] # unzip grafana_zabbix插件.zip
[root@zabbix-server ~] # systemctl restart grafana-server.service
[root@zabbix-server ~] #
[root@zabbix-server ~] # grafana-cli plugins list-remote | grep zabbix
id: alexanderzobnin-zabbix-app version: 3.10.4
You have new mail in /var/spool/mail/root
[root@zabbix-server ~] #
[root@zabbix-server ~] # grafana-cli plugins install alexanderzobnin-zabbix-app
[root@zabbix-server ~] # systemctl restart grafana-server.service
[root@zabbix-server ~] #
配置监控模板,可以少很多重复的工作,可以提高工作效率
原文:https://www.cnblogs.com/liangyuxing/p/12002152.html