1.统计分析
1.1 如何监控
系统层:cpu,负载,内存,磁盘,网络,系统 zabbix自带模板
应用层:nginx/lvs/haproxy/php-fpm/mysql/pgsql/tomcat/nfs/glusterfs… 模板监控
业务层:网站访问速度,用户访问量pv\uv\ip,用户活跃度 日活,周活,月活 订单量,利润
<a name="Rv6A6"></a>
## 1.2 第三方平台统计用户访问量
使用第三方统计平台 (百度统计)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1581532/1613381298314-6063fd08-0b79-4ef5-b15c-d900d04a68e9.png#align=left&display=inline&height=372&margin=%5Bobject%20Object%5D&name=image.png&originHeight=744&originWidth=921&size=90974&status=done&style=stroke&width=460.5)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1581532/1613381327552-ae05e13d-c791-4fcd-a1ba-4a5dff2cd04f.png#align=left&display=inline&height=384&margin=%5Bobject%20Object%5D&name=image.png&originHeight=767&originWidth=1140&size=339883&status=done&style=stroke&width=570)
> 将统计分析的js代码添加到网站模板
![image.png](https://cdn.nlark.com/yuque/0/2021/png/1581532/1613381380288-3bfb32b3-568d-45ff-9ddd-fdfb5f9332f2.png#align=left&display=inline&height=338&margin=%5Bobject%20Object%5D&name=image.png&originHeight=676&originWidth=546&size=124306&status=done&style=stroke&width=273)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1581532/1613381393334-a6ddb47b-7cfa-43eb-bd6c-fe7cef4b3169.png#align=left&display=inline&height=314&margin=%5Bobject%20Object%5D&name=image.png&originHeight=628&originWidth=1285&size=306755&status=done&style=stroke&width=642.5)
<a name="RxKbs"></a>
## 1.3 自建统计分析平台
自建统计平台 <br />使用开源的统计平台piwik<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1581532/1613381425677-263d5a53-bf99-4fac-9ff7-22a58fe52f4f.png#align=left&display=inline&height=383&margin=%5Bobject%20Object%5D&name=image.png&originHeight=766&originWidth=1291&size=381811&status=done&style=none&width=645.5)
<a name="aQIK2"></a>
# 2.MYSQL监控
<a name="vqZ7j"></a>
# 2.1 使用percona插件监控mysql
```javascript
1.准备mysql环境
略
2.yum安装的mysql监控:
#导入模板(兼容性)
#把zabbix的取值配置文件,放入到指定目录/etc/zabbix/zabbix_agentd.d/
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
cd /var/lib/zabbix/percona/templates/
cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agent2.d/
systemctl restart zabbix-agent2.service
yum install php-cli php-mysqlnd -y 或者php72w-cli php72w-mysqlnd
vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
数据库账号密码
#zabbix-get调试取值
zabbix_get -s 10.0.0.8 -k MySQL.Open-files
#在目标主机链接刚导入的模板
#验证,查看最新数据
其他方式安装的mysql监控:
#导入模板(兼容性)
#把zabbix的取值配置文件,放入到指定目录/etc/zabbix/zabbix_agentd.d/
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
cd /var/lib/zabbix/percona/templates/
cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agent2.d/
systemctl restart zabbix-agent2.service
yum install php-cli -y 或者php72w-cli
vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '123456';
$mysql_socket = '/tmp/mysql.sock';
#zabbix-get调试取值
zabbix_get -s 10.0.0.8 -k MySQL.Open-files
#在目标主机链接刚导入的模板
#验证,查看最新数据
3.自动发现
3.1 zabbix自动发现和自动注册(主动)
自动发现
自动发现规则
添加主机的规则
自定注册:
agent配置:
vim /etc/zabbix/zabbix_agent2.conf
Server=10.0.0.71
ServerActive=10.0.0.71
Hostname=10.0.0.8
HostMetadata=web
验证:
systemctl restart zabbix-agent2.service
agent配置
[root@web02 templates]# vim
/etc/zabbix/zabbix_agentd.conf
验证:
systemctl restart zabbix-agent.service
Ps : ansible实现自动注册
[root@zabbix-server ~]# tail -3 /etc/ansible/hosts
[agent]
10.0.0.7 ansible_ssh_user='root' ansible_ssh_pass='123456' HostMetadata=db
10.0.0.8 ansible_ssh_user='root' ansible_ssh_pass='123456' HostMetadata=web
[root@zabbix-server ~]# grep -Ev '^$|#' zabbix_agentd.conf.j2
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server={{ zabbix_server_ip }}
ServerActive={{ zabbix_server_ip }}
Hostname={{ ansible_default_ipv4.address }}
HostMetadata={{ HostMetadata }}
Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@zabbix-server ~]# cat zabbix_agent.yml
- hosts: agent
vars:
- zabbix_server_ip: 10.0.0.71
tasks:
- name: Install Zabbix Agent
yum:
name: https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.7-1.el7.x86_64.rpm
state: present
- name: Configure Zabbix Agent
template: src=zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf
notify: Restart Zabbix Agent
- name: Start Zabbix Agent
service: name=zabbix-agent state=started enabled=yes
handlers:
- name: Restart Zabbix Agent
service: name=zabbix-agent state=restarted
4. 其他
4.1 zabbix的主动模式 & 被动模式
#被动:
如果有100个监控项,zabbix-server对agent进行100次取值
#主动:
如果有100个监控项,agent主动向zabbix-server索要任务清单,根据清单采集所有监控项,一次性发送给zabbix-server
4.2 snmp协议监控window和Linux
#不能安装zabbix-agent的设备,都可以使用snmp监控
snmp协议: simple network manager protocol
OID:监控标准都有一个唯一的id,object id
总内存oid: .1.3.6.1.4.1.2021.4.5.0
MIB:存储所有oid信息
snmp协议版本
v1
v2c -c commuity 密码,口令
v3
安装snmp服务端
yum install net-snmp -y
vim /etc/snmp/snmpd.conf
#第41行修改为
com2sec notConfigUser default oldboy
view systemview included .1
systemctl start snmpd.service
安装snmp客户端,测试取值
yum install net-snmp-utils.x86_64 -y
#snmpget 每次只能取一个值
#snmpwalk 范围性的取值
[root@zabbix-server yum.repos.d]# snmpwalk -v 2c -c oldboy 10.0.0.8 .1.3.6.1.2.1.25.2.2.0
HOST-RESOURCES-MIB::hrMemorySize.0 = INTEGER: 995896 KBytes
4.3 zabbix故障预处理和报警升级
资料: 故障预处理.pdf
4.3 Zabbix-ipmi监控服务器硬件
5. 版本升级
5.1 升级注意事项:
zabbix版本: 2.2 -->3.0 -->4.0 -->5.0
php版本: php5.3 php5.4 php5.4 php7.2
zabbix-server 升级zabbix-release,yum install zabbix-server-mysql -y,systemctl restart zabbix-server
zabbix-web 升级php版本
yum remove php-* -y
yum install php72w-fpm php72w-gd.x86_64 php72w-bcmath.x86_64 php72w-xml.x86_64 php72w-mbstring.x86_64 php72w-ldap.x86_64 php72w-mysqlnd.x86_64 -y
升级其他注意事项 请参考zabbix官网