Linux監控平臺介紹
常見開源監控軟件:cacti、nagios、zabbix、smokeping、open-falcon等等,其中cacti、smokeping偏向於基礎監控,成圖非常漂亮。cacti、nagios、zabbix服務端監控中心,需要php環境支持,其中zabbix和cacti都需要mysql作爲數據存儲,nagios不用存儲歷史數據,注重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而可以成圖。open-falcon爲小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究。
zabbix監控介紹
Zabbix不僅適合中小型企業,也適合大型企業,它是C/S架構,分爲服務隊端與客戶端,基於C++開發,監控中心支持web界面配置和管理。單server節點可以支持上萬臺客戶端。最新版本3.4,官方文檔 https://www.zabbix.com/manuals
Zabbix的5個組件:
1.zabbix-server
zabbix-server是整個監控體系中最核心的組件,它負責接收客戶端發送的報告信息,負責所有配置、統計數據及操作數據都由它組織。
2.數據存儲
所有的收集信息都存儲在這裏,比如mysql。
3.web界面
web界面也叫web UI,這是Zabbix監控簡單易用的原因之一,因爲我們可以在web界面中配置、管理各個肇端 ,運行Web界面需要有php環境支持。
4.zabbix-proxy
zabbix-proxy爲可選組件,用於監控節點非常多的分佈式環境中,它可以代替zabbix-server的功能,減輕server的壓力。
5.zabbix-agent
zabbix-agent爲部署在各客戶端的組件,用於採集各監控項目的數據,並把採集的數據傳輸給zabbix-proxy或者zabbix-server。
Zabbix架構流程圖
安裝zabbix
1.官網下載地址
地址:www.zabbix.com/download
2.下載安裝包,實驗準備兩臺機器,兩臺都要下載。
[root@garytao-01 ~]# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
3.使用rpm安裝包(兩臺機器)
#官網有安裝教程
[root@garytao-01 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
#查看安裝的zabbix的yum源
[root@garytao-01 ~]# cat /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo.1 zabbix.repo
[root@garytao-01 ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
4.安裝zabbix的一些包
[root@garytao-01 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
#會連帶安裝httpd和php
#如果mysql之前沒有安裝的話,需要根據lamp那一章的mysql安裝方法安裝mysql
#啓動mysql
[root@garytao-01 ~]# /etc/init.d/mysqld start
5.配置/etc/my.cnf
[root@garytao-01 ~]# vi /etc/my.cnf
增加如下配置內容:
character_set_server = utf8
6.重啓mysql服務後,進入mysql命令行,創建zabbix庫。
#查看服務進程
[root@garytao-01 mysql]# ss -tnl
#假設如果mysql無法重啓,可以查看進程,使用命令殺死假死進程。
[root@garytao-01 mysql]# killall mysqld
#重啓成功
[root@garytao-01 ~]# systemctl restart mysql
[root@garytao-01 ~]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
#創建zabbix庫
[root@garytao-01 ~]# mysql -uroot -pszyino-123
#創建庫
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
#創建用戶
mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'admin-zabbix';
Query OK, 0 rows affected (0.01 sec)
mysql>
7.導入數據
#進入目錄
[root@garytao-01 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@garytao-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
#解壓壓縮包
[root@garytao-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
[root@garytao-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS ChangeLog COPYING create.sql NEWS README
#導入數據
[root@garytao-01 zabbix-server-mysql-3.2.11]# mysql -uroot -pszyino-123 zabbix < create.sql
Warning: Using a password on the command line interface can be insecure.
[root@garytao-01 zabbix-server-mysql-3.2.11]# cd
8.啓動 zabbix-server服務
#啓動zabbix
[root@garytao-01 ~]# systemctl start zabbix-server
#啓動httpd,先檢查看nginx服務有沒啓動,啓動了關掉。
[root@garytao-01 ~]# ps aux |grep nginx
root 830 0.0 0.2 46860 2276 ? Ss 1月29 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 10890 0.0 0.3 48784 3780 ? S 00:00 0:00 nginx: worker process
nobody 10891 0.0 0.3 48784 3780 ? S 00:00 0:00 nginx: worker process
root 14512 0.0 0.0 112680 976 pts/0 R+ 14:19 0:00 grep --color=auto nginx
[root@garytao-01 ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl): [ 確定 ]
[root@garytao-01 ~]# systemctl start httpd
[root@garytao-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 896/rpc.mountd
tcp 0 0 0.0.0.0:38964 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 822/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1596/master
tcp 0 0 0.0.0.0:38329 0.0.0.0:* LISTEN 795/rpc.statd
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp6 0 0 :::3306 :::* LISTEN 14401/mysqld
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 14538/httpd
tcp6 0 0 :::20048 :::* LISTEN 896/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 822/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1596/master
tcp6 0 0 :::2049 :::* LISTEN -
tcp6 0 0 :::38115 :::* LISTEN -
tcp6 0 0 :::47721 :::* LISTEN 795/rpc.statd
9.加入服務,設置開機啓動
[root@garytao-01 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@garytao-01 ~]# 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.
#如果有安裝nginx,需要關閉開機啓動
[root@garytao-01 ~]# systemctl disable nginx
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx off
[root@garytao-01 ~]# chkconfig nginx off
#查看監聽端口,發現沒有監聽端口
[root@garytao-01 ~]# ps aux |grep zabbix
zabbix 14507 0.0 0.3 256080 3452 ? S 14:18 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root 14677 0.0 0.0 112680 976 pts/0 R+ 14:38 0:00 grep --color=auto zabbix
[root@garytao-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 896/rpc.mountd
tcp 0 0 0.0.0.0:38964 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 822/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1596/master
tcp 0 0 0.0.0.0:38329 0.0.0.0:* LISTEN 795/rpc.statd
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp6 0 0 :::3306 :::* LISTEN 14401/mysqld
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 14538/httpd
tcp6 0 0 :::20048 :::* LISTEN 896/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 822/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1596/master
tcp6 0 0 :::2049 :::* LISTEN -
tcp6 0 0 :::38115 :::* LISTEN -
tcp6 0 0 :::47721 :::* LISTEN 795/rpc.statd
查看日誌
[root@garytao-01 ~]# less /var/log/zabbix/zabbix_server.log
無法連接mysql,如下圖:
修改配置文件:
[root@garytao-01 ~]# vim /etc/zabbix/zabbix_server.conf
增加如下配置:
DBHost=127.0.0.1 //在DBName=zabbix上面增加
DBPassword=admin-zabbix //在DBuser下面增加
編輯配置文件之後,需要重啓服務,重新加載配置文件。
#重啓
[root@garytao-01 ~]# systemctl restart zabbix-server
#查看啓動服務,正常需要啓動如下服務
[root@garytao-01 ~]# ps aux |grep zabbix
zabbix 14777 1.1 0.4 256260 4120 ? S 15:12 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix 14780 0.0 0.2 256260 2468 ? S 15:12 0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
zabbix 14781 0.0 0.2 256260 2676 ? S 15:12 0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.033642 sec, idle 60 sec]
zabbix 14782 0.3 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000003 sec, idle 5 sec]
zabbix 14783 0.3 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix 14784 0.4 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix 14785 0.3 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 14786 0.3 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000006 sec, idle 5 sec]
zabbix 14787 0.3 0.5 363204 5188 ? S 15:12 0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 14788 0.0 0.3 256260 3584 ? S 15:12 0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix 14789 0.0 0.3 256260 3584 ? S 15:12 0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix 14790 0.0 0.3 256260 3584 ? S 15:12 0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix 14791 0.0 0.3 256260 3584 ? S 15:12 0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix 14794 0.0 0.3 256260 3584 ? S 15:12 0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix 14796 0.0 0.2 258832 2616 ? S 15:12 0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 14797 0.0 0.2 256260 2684 ? S 15:12 0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.005679 sec, idle 30 sec]
zabbix 14799 0.0 0.2 256260 2464 ? S 15:12 0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix 14800 0.0 0.2 256332 2904 ? S 15:12 0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000256 sec, 0 maintenances in 0.000000 sec, idle 30 sec]
zabbix 14801 0.0 0.2 256260 2832 ? S 15:12 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000844 sec, idle 5 sec]
zabbix 14802 0.2 0.5 360624 5028 ? S 15:12 0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.003493 sec, idle 60 sec]
zabbix 14805 0.0 0.2 256260 2816 ? S 15:12 0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix 14812 0.0 0.2 256260 2816 ? S 15:12 0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix 14815 0.0 0.2 256260 2816 ? S 15:12 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix 14817 0.0 0.2 256260 2816 ? S 15:12 0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000004 sec, idle 1 sec]
zabbix 14818 0.0 0.3 256260 3760 ? S 15:12 0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.000721 sec, idle 3 sec]
zabbix 14820 0.0 0.3 256260 3756 ? S 15:12 0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000010 sec, idle 5 sec]
zabbix 14821 0.0 0.2 256260 2584 ? S 15:12 0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000003 sec, idle 1 sec]
zabbix 14822 0.0 0.2 256260 2804 ? S 15:12 0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000936 sec, idle 5 sec]
root 14828 0.0 0.0 112680 976 pts/0 R+ 15:12 0:00 grep --color=auto zabbix
#查看監聽端口
[root@garytao-01 ~]# netstat -lntp |grep zabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 14777/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 14777/zabbix_server
10.web界面下面配置zabbix
- 瀏覽器訪問:172.16.111.100/zabbix
ok說明正常,Fail是有問題的,需要到配置文件裏配置一下.
#修改配置文件,設置時區
[root@garytao-01 ~]# vi /etc/php.ini
#編輯完成文件後,重啓httpd
[root@garytao-01 ~]# systemctl restart httpd
配置圖:
刷新瀏覽器
Database port默認是0就是mysql的3306端口,密碼就是我們創建zabbix用戶時的密碼
安裝成功
- 登錄後臺配置
使用默認用戶名admin 密碼zabbix登錄
進入後臺第一件事情就是修改密碼
備註:修改完成密碼後,設置成中文顯示,保存後刷新瀏覽器。
zabbix客戶端安裝
1.下載zabbix的yum源
#下載yum源
[root@garytao-02 ~]# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
#安裝yum源
[root@garytao-02 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
#安裝
[root@garytao-02 ~]# yum install -y zabbix-agent
2.編輯配置文件
[root@garytao-02 ~]# vi /etc/zabbix/zabbix_agentd.conf
修改如下內容:
Server=127.0.0.1修改爲Server=172.16.111.100 //定義服務端的ip(被動模式)
ServerActive=127.0.0.1修改爲ServerActive=172.16.111.100 //定義服務端的ip(主動模式)
Hostname=Zabbix server修改爲Hostname=admin-123 //這是自定義的主機名,一會還需要在web界面下設置同樣的主機名
3.啓動服務,設置開機啓動
[root@garytao-02 ~]# systemctl start zabbix-agent
[root@garytao-02 ~]# ps aux |grep zabbix
zabbix 7400 0.0 0.1 80604 1256 ? S 16:29 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix 7401 0.0 0.1 80604 1292 ? S 16:29 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 7402 0.0 0.1 80604 1836 ? S 16:29 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix 7403 0.0 0.1 80604 1836 ? S 16:29 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix 7404 0.0 0.1 80604 1836 ? S 16:29 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix 7405 0.0 0.2 80604 2176 ? S 16:29 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root 7413 0.0 0.0 112676 976 pts/0 R+ 16:30 0:00 grep --color=auto zabbix
[root@garytao-02 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3893/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 758/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1221/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 7400/zabbix_agentd
tcp6 0 0 :::3306 :::* LISTEN 1126/mysqld
tcp6 0 0 :::22 :::* LISTEN 758/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1221/master
tcp6 0 0 :::10050 :::* LISTEN 7400/zabbix_agentd
#設置開機啓動:
[root@garytao-02 ~]# systemctl enable zabbix-agent
忘記Admin密碼如何做
1.進入mysql命令行,選擇zabbix庫
[root@garytao-01 ~]# mysql -uroot -pszyino-123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 585
Server version: 5.6.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> desc users;
+----------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+
| userid | bigint(20) unsigned | NO | PRI | NULL | |
| alias | varchar(100) | NO | UNI | | |
| name | varchar(100) | NO | | | |
| surname | varchar(100) | NO | | | |
| passwd | char(32) | NO | | | |
| url | varchar(255) | NO | | | |
| autologin | int(11) | NO | | 0 | |
| autologout | int(11) | NO | | 900 | |
| lang | varchar(5) | NO | | en_GB | |
| refresh | int(11) | NO | | 30 | |
| type | int(11) | NO | | 1 | |
| theme | varchar(128) | NO | | default | |
| attempt_failed | int(11) | NO | | 0 | |
| attempt_ip | varchar(39) | NO | | | |
| attempt_clock | int(11) | NO | | 0 | |
| rows_per_page | int(11) | NO | | 50 | |
+----------------+---------------------+------+-----+---------+-------+
16 rows in set (0.01 sec)
mysql>
2.修改密碼
mysql> update users set passwd=md5('szyino-123') where alias='Admin';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from users;
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
| userid | alias | name | surname | passwd | url | autologin | autologout | lang | refresh | type | theme | attempt_failed | attempt_ip | attempt_clock | rows_per_page |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
| 1 | Admin | Zabbix | Administrator | 251fa94c65a7c8ab5760dd6398159841 | | 1 | 0 | zh_CN | 30 | 3 | default | 0 | | 0 | 50 |
| 2 | guest | | | d41d8cd98f00b204e9800998ecf8427e | | 0 | 900 | en_GB | 30 | 1 | default | 0 | | 0 | 50 |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
2 rows in set (0.00 sec)
#更改完成後使用新密碼登錄zabbix驗證。