1稀拐、搭建zabbix服務(wù)啸澡,實(shí)現(xiàn)監(jiān)控linux和windows的內(nèi)存拐邪,cpu慰毅,磁盤,網(wǎng)絡(luò)等基礎(chǔ)指標(biāo)
-
zabbix部署網(wǎng)絡(luò)拓?fù)鋱D
環(huán)境說明
操作系統(tǒng):Centos7
安裝zabbix-release
node1:10.193.116.98 安裝zabbix-server模塊
node2:10.193.116.97 安裝zabbix數(shù)據(jù)庫模塊
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通過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é)果
將node5添加監(jiān)控
配置--->主機(jī)-->填寫主機(jī)名稱-->選擇群組-->填寫接口IP-->選擇proxy-->添加模板-->更新
查看node5監(jiān)控?cái)?shù)據(jù)
監(jiān)測(cè)-->最新數(shù)據(jù)-->選擇主機(jī)-->選擇應(yīng)用集
windows服務(wù)器監(jiān)控(10.193.116.93)
- 網(wǎng)管下載Windows版本的zabbix-agent
地址:https://www.zabbix.com/cn/download_agents#tab:40LTS
-
解析安裝包至Windows本地C盤
-
安裝
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"
或者通過服務(wù)管理啟動(dòng):
-
測(cè)試是否獲取數(shù)據(jù)
-
zabbix-web 添加Windows主機(jī)扎阶,并查看數(shù)據(jù)
2汹胃、搭建zabbix服務(wù),監(jiān)控nginx status
- node5 安裝nginx东臀,添加開啟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; }
- 編寫監(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頁面添加nginx_status告警items
配置Nginx_requests來進(jìn)行說明
首先配置監(jiān)控項(xiàng)
配置-->模板-->監(jiān)控項(xiàng)
接著進(jìn)入進(jìn)程配置頁面
-
添加告警
配置-->模板-->觸發(fā)器
名稱:Nginx每秒請(qǐng)求超過100
表達(dá)式:
{Centos7-Nginx:nginx.statu[requests].last(#1)}>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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者- 文/潘曉璐 我一進(jìn)店門挪拟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人枝冀,你說我怎么就攤上這事舞丛。” “怎么了果漾?”我有些...
- 文/不壞的土叔 我叫張陵球切,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我绒障,道長(zhǎng)吨凑,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮鸵钝,結(jié)果婚禮上糙臼,老公的妹妹穿的比我還像新娘。我一直安慰自己恩商,他們只是感情好变逃,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著怠堪,像睡著了一般揽乱。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上粟矿,一...
- 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼哗讥!你這毒婦竟也來了嚷那?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬榮一對(duì)情侶失蹤杆煞,失蹤者是張志新(化名)和其女友劉穎魏宽,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體决乎,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡队询,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了构诚。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蚌斩。...
- 正文 年R本政府宣布叠聋,位于F島的核電站,受9級(jí)特大地震影響受裹,放射性物質(zhì)發(fā)生泄漏碌补。R本人自食惡果不足惜虏束,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望厦章。 院中可真熱鬧镇匀,春花似錦、人聲如沸袜啃。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽群发。三九已至晃择,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間也物,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓抵栈,卻偏偏與公主長(zhǎng)得像告材,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子古劲,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 一斥赋、架構(gòu)設(shè)計(jì)及環(huán)境規(guī)劃: 架構(gòu)設(shè)計(jì)圖: 架構(gòu)設(shè)計(jì)說明: 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í)的開源解決方案产艾。 ...
- 1.寫在前面 本文主要介紹的是zabbix的編譯安裝過程疤剑,包含它的基礎(chǔ)環(huán)境LNMP,雖然zabbix官方一般推薦的...
- 本文詳細(xì)介紹新哥zabbix安裝過程及出現(xiàn)的問題闷堡,讀完后可直接上手安裝隘膘。內(nèi)容較長(zhǎng)建議收藏后在電腦打開閱讀安裝...