19.1 Linux監控平臺介紹
cacti,nagios和zabiix都是c/s架構,需要安裝一個服務端,被監控的客戶端上安裝客戶端。
都需要有LAMP的支持Nagios不需要數據庫,cacti,zabiix都需要mysql支持,用來存儲數據。
cacti擅長監控網絡流量,成圖專業。
Nagios監控某個指標並不返回具體的數值,而是隻返回一個狀態,告訴我們該指標正常或者不正常。發現指標不正常,直接報警。
zabiix可以存儲數據,很方便的畫圖,而且支持查詢歷史數據。可以方便的自定義監控項目,可以定製化監控業務的某個指標,這個監聽項目不可能在zabiix的自帶模板中找到,所以只能自定義。還提供了易用的二次開發接口,方便擴展。
19.2 zabiix監控介紹
單個服務節點可以支持上萬臺客戶端。官網爲http://www.zabiix.com/ 最新版本3.4. 官網文檔:http://www.zabiix.com/ manuals 主流版本文檔 (1.4,1.6,1.8,2.0,2.2,)
zabiix組件
zabiix-server是整個監控體系最核心的組件,它負責接收客戶端發送的報告信息,所有的配置,統計數據及操作數據都由它組織。
數據存儲
web界面
在web界面中配置,管理各個客戶端,需要php環境支持。
zabiix-proxy
zabiix-proxy爲可選組件,用於監控節點非常多的分佈式環境中,它可以代理zabiix-server的功能,減輕zabbix-server的壓力。
zabbix-agent
zabbix-agent爲部署在各客戶端的組件,用於採集各監控項目的數據,並把採集的數據傳輸給zabiix-proxy,zabiix-server
zabbix結構
zabbix監控安裝和部署
zabbix官網下載地址http://www.zabbix.com/download,版本3.2 安裝zabbix的yum擴展源,然後利用yum安裝zabbix即可。
[root@aminglinux-128 ~]# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm --2018-09-10 17:41:40-- http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm 正在解析主機 repo.zabbix.com (repo.zabbix.com)... 162.243.159.138 正在連接 repo.zabbix.com (repo.zabbix.com)|162.243.159.138|:80... 已連接。 已發出 HTTP 請求,正在等待迴應... 200 OK 長度:13392 (13K) [application/x-redhat-package-manager] 正在保存至: “zabbix-release-3.2-1.el7.noarch.rpm” 100%[==============================================================================================>] 13,392 --.-K/s 用時 0.001s 2018-09-10 17:41:41 (12.5 MB/s) - 已保存 “zabbix-release-3.2-1.el7.noarch.rpm” [13392/13392])
[root@aminglinux-128 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm 警告:zabbix-release-3.2-1.el7.noarch.rpm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY 準備中... ################################# [100%] 正在升級/安裝... 1:zabbix-release-3.2-1.el7 ################################# [100%]
[root@aminglinux-128 ~]# yum list |grep zabbix zabbix-release.noarch 3.2-1.el7 installed iksemel.x86_64 1.4-2.el7.centos zabbix-non-supported iksemel-devel.x86_64 1.4-2.el7.centos zabbix-non-supported iksemel-utils.x86_64 1.4-2.el7.centos zabbix-non-supported pcp-export-pcp2zabbix.x86_64 3.12.2-5.el7 base pcp-export-zabbix-agent.x86_64 3.12.2-5.el7 base python-pyzabbix.noarch 0.7.3-2.el7 epel uwsgi-stats-pusher-zabbix.x86_64 2.0.16-1.el7 epel
安裝所有的包
[root@aminglinux-128 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
連帶安裝httpd和php,讓httpd監聽8080端口,讓nginx去代理httpd。
配置nginx
[root@aminglinux-128 ~]# systemctl start httpd
[root@aminglinux-128 ~]# vim /etc/httpd/conf/httpd.conf
[root@aminglinux-128 ~]# netstat -lnpt |grep httpd tcp6 0 0 :::8080 :::* LISTEN 6869/httpd [root@aminglinux-128 ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
上例爲使其加入開機啓動
創建nginx的虛擬主機配置文件:
vim /etc/local/nginx/conf/vhost/zabbix.conf
server { listen 80; server_name 192.68.193.128:// location / { proxy_pass http://192.168.193.128:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } # /usr/local/nginx/sbin/nginx -t #/usr/local/nginx/sbin/nginx -s reload
配置mysql
[root@aminglinux-128 ~]# vim /etc/my.cnf
在【mysqld】模塊下面修改或增加如下內容
character_set-server =utf8
重啓mysql服務
/etc/init.d/mysqld restart
[root@localhost ~]# /etc/init.d/mysqld restart ERROR! MySQL server PID file could not be found! Starting MySQL........ SUCCESS!
[root@aminglinux-128 ~]# mysql -u'user1' -p'123456' -h'127.0.0.1'
創建zabbix庫,字符集爲UTF-8
mysql> create database zabbix character set utf8
創建zabbix用戶
mysql> grant all on zabbix.* to 'zabbix@'127.0.0.1' identied by '123456'; '> quit
導入zabbix相關的數據:
進入zabbix-server-mysql目錄 :
[root@aminglinux-128 ~]# ls /usr/share/doc/zabbix-server-mysql-3.2.11/ AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@aminglinux-128 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
解壓當前目錄下create.sql.gz壓縮包 :
[root@aminglinux-128 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
把解壓的create.sql文件內容,導入到zabbix庫裏 :
[root@aminglinux-128 zabbix-server-mysql-3.2.11]# mysql -uroot -phaomima zabbix < create.sql Warning: Using a password on the command line interface can be insecure.
使其開機啓動
[root@aminglinux-128 zabbix-server-mysql-3.2.11]# systemctl enable httpd
修改zbbix-server的配置文件,並啓動zabbix-server服務:
增加如下內容
DBHost=127.0.0.1
DBPassword=haomima-zabbix
啓動zabbix-server服務
開機啓動
[root@aminglinux-128 zabbix-server-mysql-3.2.11]# systemctl start zabbix-server [root@aminglinux-128 zabbix-server-mysql-3.2.11]# enable start zabbix-server -bash: enable: start: 不是shell內建 -bash: enable: zabbix-server: 不是shell內建 [root@aminglinux-128 zabbix-server-mysql-3.2.11]# systemctl enable zabbix-server Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service
zabbix-server監聽10051端口
配置web界面
在瀏覽器輸入http://192.168.193.149.
點擊下一步提示date.timezone的警告,
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
在裏面添加上面的內容
忘記admin密碼
進入mysql命令行,選擇zabbix庫:
[root@aminglinux-128 ~]# mysql -uroot -phaomima zabbix Warning: Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3255 Server version: 5.6.39-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update zabbix.users set passwd=md5('aminglinux') where alias='Admin'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>