1、搭建zabbix服務(wù),實(shí)現(xiàn)監(jiān)控linux和windows的內(nèi)存,cpu,磁盤(pán),網(wǎng)絡(luò)等基礎(chǔ)指標(biāo)
-
zabbix部署網(wǎng)絡(luò)拓?fù)鋱D
zabbix部署網(wǎng)絡(luò)拓?fù)?/div>環(huán)境說(shuō)明
操作系統(tǒng):Centos7
安裝zabbix-release
node1:10.193.116.98 安裝zabbix-server模塊
node2:10.193.116.97 安裝zabbix數(shù)據(jù)庫(kù)模塊
node3:10.193.116.96 安裝zabbix-web模塊
node4:10.193.116.95 安裝zabbix-proxy模塊
node5:10.193.116.94 安裝zabbix-agent模塊
A機(jī)房:zabbix-agent直接連接zabbix-server
B機(jī)房:zabbix-agent直接連接zabbix-proxy通過(guò)ansible進(jìn)行部署
- 創(chuàng)建roles和hosts文件
mkdir -pv {zabbix-server,zabbix-agent,zabbix-web,zabbix-proxy,zabbix-mariadb}/{tasks,vars,templates,files,meta,defaults,handlers} hosts文件 [node1-zabbix-server] 10.193.116.98 [node2-zabbix-mariadb] 10.193.116.97 [node3-zabbix-web] 10.193.116.96 [node4-zabbix-proxy] 10.193.116.95 [all-zabbix-agent] 10.193.116.[94:97]- zabbix-mariadb 角色
[root@ansible zabbix-mariadb]# tree . |-- defaults |-- files | |-- create.sql.gz | `-- my.cnf |-- handlers |-- meta |-- tasks | `-- main.yml |-- templates `-- vars main.yml內(nèi)容 - name: install mariadb-server yum: name={{ item }} with_items: - mariadb-server - MySQL-python - name: copy conf copy: src=my.cnf dest=/etc/my.cnf backup=yes - name: start service service: name=mariadb state=started enabled=yes - name: create zabbix databases mysql_db: login_user=root name={{ db_name }} encoding=utf8 - name: mariadb conf mysql_user: login_user=root name={{ zabbix_name}} host={{ zabbix_hosts }} password={{ zabbix_passwd }} priv='{{ db_name }}.*:ALL' state=present tags: db playbook內(nèi)容段 - hosts: node2-zabbix-mariadb remote_user: root vars: - db_name: zabbix - zabbix_name: zabbix - zabbix_hosts: 10.193.116.% - zabbix_passwd: zabbix roles: - zabbix-mariadb- zabbix-server 角色
[root@ansible zabbix-server]# tree . |-- defaults |-- files |-- handlers |-- meta |-- tasks | `-- main.yml |-- templates | `-- zabbix_server.conf.j2 `-- vars main.yml內(nèi)容 - name: install zabbix-server-mysql zabbix-get yum: name={{ item }} with_items: - zabbix-server-mysql - zabbix-get - mariadb - zabbix-agent - name: install conf template: src=zabbix_server.conf.j2 dest=/etc/zabbix/zabbix_server.conf - name: init zabbix_db shell: zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h{{ DBHost }} -u{{ DBUser }} -p{{ DBPassword }} {{ DBName }} ignore_errors: yes - name: start service service: name=zabbix-server state=started enabled=yes - name: start agent service: name=zabbix-agent state=started enabled=yes zabbix_server.conf.j2中變量如下 DBHost={{ DBHost }} DBName={{ DBName }} DBUser={{ DBUser }} DBPassword={{ DBPassword }} playbook內(nèi)容段 - hosts: node1-zabbix-server remote_user: root vars: - DBHost: 10.193.116.97 - DBName: zabbix - DBUser: zabbix - DBPassword: zabbix roles: - zabbix-server- zabbix-web 角色
[root@ansible zabbix-web]# tree . |-- defaults |-- files | `-- zabbix.conf |-- handlers |-- meta |-- tasks | `-- main.yml |-- templates `-- vars main.yml內(nèi)容 - name: install zabbix-server-web yum: name={{ item }} with_items: - zabbix-web-mysql - mariadb - name: httpd conf copy: src=zabbix.conf dest=/etc/httpd/conf.d/ - name: start service service: name=httpd state=started enabled=yes playbook內(nèi)容段 - hosts: node3-zabbix-web remote_user: root roles: - zabbix-web- zabbix-proxy 角色
[root@ansible zabbix-proxy]# tree . |-- defaults |-- files | `-- my.cnf |-- handlers |-- meta |-- tasks | `-- main.yml |-- templates | `-- zabbix_proxy.conf.j2 `-- vars main.yml內(nèi)容 - name: install mariadb-server yum: name={{ item }} with_items: - mariadb-server - zabbix-proxy-mysql - zabbix-get - MySQL-python - name: copy conf copy: src=my.cnf dest=/etc/my.cnf backup=yes - name: start service service: name=mariadb state=started enabled=yes - name: create zabbix databases mysql_db: login_user=root name={{ DBName }} encoding=utf8 - name: mariadb conf mysql_user: login_user=root name={{ DBUser }} host={{ DBHost }} password={{ DBPassword }} priv='{{ DBName }}.*:ALL' state=present tags: db - name: init proxy_db shell: zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -h{{ DBHost }} -u{{ DBUser }} -p{{ DBPassword }} {{ DBName }} ignore_errors: yes - name: copy zabbix-proxy template: src=zabbix_proxy.conf.j2 dest=/etc/zabbix/zabbix_proxy.conf - name: start zabbix-proxy service: name=zabbix-proxy state=started enabled=yes zabbix_proxy.conf.j2中變量 Server={{ Server }} DBName={{ DBName }} DBUser={{ DBUser }} DBPassword={{ DBPassword }} playbook內(nèi)容段 - hosts: node4-zabbix-proxy remote_user: root vars: - Server: 10.193.116.98 - DBHost: localhost - DBName: zabbix_proxy - DBUser: zabbix - DBPassword: zabbix roles: - zabbix-proxy- zabbix-agent 角色
[root@ansible zabbix-agent]# tree . |-- defaults |-- files |-- handlers |-- meta |-- tasks | `-- main.yml |-- templates | `-- zabbix_agentd.conf.j2 `-- vars main.yml內(nèi)容 - name: install zabbix-agent yum: name={{ item }} with_items: - zabbix-agent - name: agent conf template: src=zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf - name: start service service: name=zabbix-agent state=started enabled=yes zabbix_agentd.conf.j2中變量 Server={{ Server }} ServerActive={{ ServerActive }} Hostname={{ ansible_default_ipv4.address }} playbook內(nèi)容段 - hosts: all-zabbix-agent remote_user: root vars: - ServerActive: 10.193.116.98 - Server: 10.193.116.98 roles: - zabbix-agent- playbook
[root@ansible ansible]# vim zabbix.yaml - hosts: node2-zabbix-mariadb remote_user: root vars: - db_name: zabbix - zabbix_name: zabbix - zabbix_hosts: 10.193.116.% - zabbix_passwd: zabbix roles: - zabbix-mariadb - hosts: node1-zabbix-server remote_user: root vars: - DBHost: 10.193.116.97 - DBName: zabbix - DBUser: zabbix - DBPassword: zabbix roles: - zabbix-server - hosts: node3-zabbix-web remote_user: root roles: - zabbix-web - hosts: node4-zabbix-proxy remote_user: root vars: - Server: 10.193.116.98 - DBHost: localhost - DBName: zabbix_proxy - DBUser: zabbix - DBPassword: zabbix roles: - zabbix-proxy - hosts: all-zabbix-agent remote_user: root vars: - ServerActive: 10.193.116.98 - Server: 10.193.116.98 roles: - zabbix-agent-
運(yùn)行結(jié)果
運(yùn)行結(jié)果
將node5添加監(jiān)控
配置--->主機(jī)-->填寫(xiě)主機(jī)名稱(chēng)-->選擇群組-->填寫(xiě)接口IP-->選擇proxy-->添加模板-->更新
主機(jī)添加過(guò)程查看node5監(jiān)控?cái)?shù)據(jù)
監(jiān)測(cè)-->最新數(shù)據(jù)-->選擇主機(jī)-->選擇應(yīng)用集
查看node5內(nèi)存監(jiān)控?cái)?shù)據(jù)windows服務(wù)器監(jiān)控(10.193.116.93)
- 網(wǎng)管下載Windows版本的zabbix-agent
地址:https://www.zabbix.com/cn/download_agents#tab:40LTS
下載Windows版本zabbix-agent -
解析安裝包至Windows本地C盤(pán)
解壓至本地C盤(pán) -
安裝
cd "C:\zabbix_agents-4.0.7-win-amd64\bin"
zabbix_agentd.exe -i -c "C:\zabbix_agents-4.0.7-win-amd64\conf\zabbix_agentd.conf"
安裝
啟動(dòng)
命令行啟動(dòng):
zabbix_agentd.exe -s -c "C:\zabbix_agents-4.0.7-win-amd64\conf\zabbix_agentd.conf"
啟動(dòng)命令或者通過(guò)服務(wù)管理啟動(dòng):
zabbix agent 啟動(dòng)管理-
測(cè)試是否獲取數(shù)據(jù)
測(cè)試獲取angent狀態(tài) -
zabbix-web 添加Windows主機(jī),并查看數(shù)據(jù)
Windows主機(jī)狀態(tài)
Windows host監(jiān)控?cái)?shù)據(jù)
2、搭建zabbix服務(wù),監(jiān)控nginx status
- node5 安裝nginx,添加開(kāi)啟nginx狀態(tài)監(jiān)控
location /nginx_status { # Turn on nginx stats stub_status on; # I do not need logs for stats access_log off; # Security: Only allow access from 192.168.1.100 IP # allow 127.0.0.1/8; deny all; }- 編寫(xiě)監(jiān)控腳本
[root@node5 ~]# vim /usr/bin/nginx_status.sh #!/bin/bash # host='127.0.0.1' port='80' statusurl='nginx_status' active(){ curl -s http://${host}:${port}/${statusurl} |awk '/^Active/{print $3}' } accepts(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $1}' } handled(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $2}' } requests(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==3{print $3}' } reading(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $2}' } writing(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $4}' } waiting(){ curl -s http://${host}:${port}/${statusurl} |awk 'NR==4{print $6}' } case "$1" in active) active ;; accepts) accepts ;; handled) handled ;; requests) requests ;; reading) reading ;; writing) writing ;; waiting) waiting ;; *) echo $"Usage: $0 {active|accepts|handled|requests|reading|writing|waiting}" exit 1 esac- zabbix-agent 自定義key
[root@node5 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf UserParameter=nginx.statu[*],/usr/bin/nginx_status.sh $1 重啟zabbix-agent [root@node5 ~]# systemctl restart zabbix-agent-
zabbix-web頁(yè)面添加nginx_status告警items
nginx_status告警items
配置Nginx_requests來(lái)進(jìn)行說(shuō)明
首先配置監(jiān)控項(xiàng)
配置-->模板-->監(jiān)控項(xiàng)
監(jiān)控項(xiàng)頁(yè)面配置
接著進(jìn)入進(jìn)程配置頁(yè)面
設(shè)置為每秒更改 -
添加告警
配置-->模板-->觸發(fā)器
名稱(chēng):Nginx每秒請(qǐng)求超過(guò)100
表達(dá)式:
{Centos7-Nginx:nginx.statu[requests].last(#1)}>100
Nginx每秒請(qǐng)求超過(guò)100 壓測(cè)觸發(fā)告警
安裝ab壓測(cè)工具 [root@node5 ~]# yum -y install httpd-tools [root@node5 ~]# ab -n 5000 -c 20 http://127.0.0.1/nginx_status告警觸發(fā)
采集Nginx_requests數(shù)據(jù)?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。相關(guān)閱讀更多精彩內(nèi)容
- 一、架構(gòu)設(shè)計(jì)及環(huán)境規(guī)劃: 架構(gòu)設(shè)計(jì)圖: 架構(gòu)設(shè)計(jì)說(shuō)明: 1. 基礎(chǔ)架構(gòu)為L(zhǎng)AMP環(huán)境,采用keepalived實(shí)現(xiàn)...
- 轉(zhuǎn)載:http://www.cnblogs.com/yaoyaojcy/p/8182067.html 自學(xué)Zabb...
- zabbix(音同 z?bix)是一個(gè)基于WEB界面的提供分布式系統(tǒng)監(jiān)視以及網(wǎng)絡(luò)監(jiān)視功能的企業(yè)級(jí)的開(kāi)源解決方案。 ...
- 1.寫(xiě)在前面 本文主要介紹的是zabbix的編譯安裝過(guò)程,包含它的基礎(chǔ)環(huán)境LNMP,雖然zabbix官方一般推薦的...
- 本文詳細(xì)介紹新哥zabbix安裝過(guò)程及出現(xiàn)的問(wèn)題,讀完后可直接上手安裝。內(nèi)容較長(zhǎng)建議收藏后在電腦打開(kāi)閱讀安裝...

















