Linux監控平臺搭建(一)--介紹

一 Linux監控平臺介紹

常見開源監控軟件php

  1. cacti、nagios、zabbix、smokeping、open-falcon等等
  2. cacti、smokeping偏向於基礎監控,成圖很是漂亮
    這兩種適合於監控網絡設備
  3. cacti、nagios、zabbix服務端監控中心,須要php環境支持,其中zabbix和cacti都須要mysql做爲數據存儲,nagios不用存儲歷史數據,注重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而能夠成圖
  4. open-falcon爲小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究
  5. 後續以介紹zabbix爲主

二 zabbix監控軟件介紹

  1. C/S架構,基於C++開發,監控中心支持web界面配置和管理
    須要agent,意思是在客戶端必須要有一個服務啓動,這個服務是負責採集數據的,這個數據會主動地上報服務端,也可讓服務端去鏈接客戶端抓取這個數據,所以這裏就須要分兩種模式:主動模式和被動模式
  2. 單server節點能夠支持上萬臺客戶端
    瓶頸在於採集數據的量,當服務器規模大到必定程度時就須要作一些優化了,好比說能夠增長一些代理點proxy來充當server的角色,替代server去採集數據,而後他獲得分析結果再彙報給server
  3. 最新版本3.4,官方文檔https://www.zabbix.com/manuals
  4. 5個組件
  5. zabbix-server 監控中心,接收客戶端上報信息,負責配置、統計、操做數據
  6. 數據存儲 存放數據,好比mysql
  7. web界面 也叫web UI,在web界面下操做配置是zabbix簡單易用的主要緣由
  8. zabbix-proxy 可選組件,它能夠代替zabbix-server的功能,減輕server的壓力
  9. zabbix-agent 客戶端軟件,負責採集各個監控服務或項目的數據,並上報

zabbix監控流程圖

輸入圖片說明

三 安裝zabbix

  1. 官網下載地址 www.zabbix.com/download
  2. wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  3. rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm 實際上咱們能夠看到,安裝這個包就是安裝了一個yum源
[root@lijie-01 src]# ls !$ 
ls /etc/yum.repos.d/
CentOS7-Base-163.repo  CentOS-fasttrack.repo  CentOS-Vault.repo  zabbix.repo
CentOS-CR.repo         CentOS-Media.repo      epel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel-testing.repo
[root@lijie-01 src]# 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
[root@lijie-01 src]#
  1. 安裝zabbix服務器,前端,代理
# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql

其中zabbix-agent是客戶端軟件,zabbix-get是服務端上用的一個工具,這個工具是能夠經過命令行的形式得到客戶端上某些監控項目的數據,zabbix-server-mysql是安裝一些跟mysql相關的文件,zabbix-web是web UI,zabbix-web-mysql是安裝web和mysql相關的一些文件前端

  1. 會連帶安裝httpd和php
做爲依賴被安裝:
  OpenIPMI-libs.x86_64 0:2.0.19-15.el7          OpenIPMI-modalias.x86_64 0:2.0.19-15.el7    
  apr.x86_64 0:1.4.8-3.el7_4.1                  apr-util.x86_64 0:1.5.2-6.el7               
  dejavu-fonts-common.noarch 0:2.33-6.el7       dejavu-sans-fonts.noarch 0:2.33-6.el7       
  fontpackages-filesystem.noarch 0:1.44-8.el7   fping.x86_64 0:3.10-4.el7                   
  httpd.x86_64 0:2.4.6-67.el7.centos.6          httpd-tools.x86_64 0:2.4.6-67.el7.centos.6  
  iksemel.x86_64 0:1.4-6.el7                    libX11.x86_64 0:1.6.5-1.el7                 
  libX11-common.noarch 0:1.6.5-1.el7            libXau.x86_64 0:1.0.8-2.1.el7               
  libXpm.x86_64 0:3.5.12-1.el7                  libxcb.x86_64 0:1.12-1.el7                  
  libzip.x86_64 0:0.10.1-8.el7                  mailcap.noarch 0:2.1.41-2.el7               
  php.x86_64 0:5.4.16-43.el7_4.1                php-bcmath.x86_64 0:5.4.16-43.el7_4.1       
  php-cli.x86_64 0:5.4.16-43.el7_4.1            php-common.x86_64 0:5.4.16-43.el7_4.1       
  php-gd.x86_64 0:5.4.16-43.el7_4.1             php-ldap.x86_64 0:5.4.16-43.el7_4.1         
  php-mbstring.x86_64 0:5.4.16-43.el7_4.1       php-mysql.x86_64 0:5.4.16-43.el7_4.1        
  php-pdo.x86_64 0:5.4.16-43.el7_4.1            php-xml.x86_64 0:5.4.16-43.el7_4.1          
  t1lib.x86_64 0:5.1.2-14.el7                   unixODBC.x86_64 0:2.3.1-11.el7              
完畢!
  1. 若是mysql以前沒有安裝的話,須要根據lamp那一章的mysql安裝方法安裝mysql,而後啓動mysql
# systemctl start mysql
  1. 編輯mysql配置文件vim /etc/my.cnf設置字符集爲utf8 輸入圖片說明
  2. 重啓mysqld服務後,登錄進入mysql命令行,建立zabbix庫,同時指定字符集
[root@lijie-01 src]# mysql -uroot -p112233
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 6
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> create database zabbix character set utf8;
Query OK, 1 row affected (0.01 sec)
mysql>
  1. 再建立用戶,這個用戶是讓web代碼鏈接mysql數據庫的,zabbix服務啓動的前提也是須要可以鏈接數據庫的
mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '112233';
Query OK, 0 rows affected (0.11 sec)
mysql>
  1. 導入zabbix自帶的數據
[root@lijie-01 src]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/       切換到自帶數據所在目錄
[root@lijie-01 zabbix-server-mysql-3.2.11]# ls    能夠看到數據壓縮包
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@lijie-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz    解壓
[root@lijie-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@lijie-01 zabbix-server-mysql-3.2.11]# mysql -uroot -p112233 zabbix < create.sql  恢復數據到zabbix庫
Warning: Using a password on the command line interface can be insecure.
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start zabbix-server  啓動zabbix服務
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start httpd^C
  1. 啓動httpd服務
[root@lijie-01 zabbix-server-mysql-3.2.11]# ps aux |grep nginx   查看nginx是否佔用80端口
root      6716  0.0  0.0 112676   984 pts/0    S+   17:15   0:00 grep --color=auto nginx
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start httpd  啓動httpd服務      
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl enable httpd     
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@lijie-01 zabbix-server-mysql-3.2.11]#
  1. 修改配置文件vim /etc/zabbix/zabbix_server.conf 配置鏈接數據庫主機的帳號密碼
    DBHost=127.0.0.1 //在DBName=zabbix上面增長
    DBName=zabbix
    DBUser=zabbix
    DBPassword=112233 //在DBuser下面增長
  2. netstat -lntp |grep zabbix //查看監聽端口
[root@lijie-01 ~]# systemctl start zabbix-server
[root@lijie-01 ~]# systemctl enable zabbix-server
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl disable nginx   禁止nginx啓動
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx off
[root@lijie-01 zabbix-server-mysql-3.2.11]# chkconfig nginx off
[root@lijie-01 ~]# ps aux |grep zabbix   
zabbix    7388  2.0  0.2 254760  4168 ?        S    00:16   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix    7391  0.0  0.1 254760  2520 ?        S    00:16   0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
zabbix    7392  0.0  0.1 254760  2732 ?        S    00:16   0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.004178 sec, idle 60 sec]
zabbix    7393  0.8  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000009 sec, idle 5 sec]
zabbix    7394  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000010 sec, idle 5 sec]
zabbix    7395  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7396  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000247 sec, idle 5 sec]
zabbix    7397  1.0  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7398  1.4  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7399  0.3  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix    7400  0.1  0.1 254760  3624 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix    7401  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix    7402  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix    7403  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix    7407  0.0  0.1 257336  2660 ?        S    00:16   0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix    7408  0.0  0.1 254760  2736 ?        S    00:16   0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.004105 sec, idle 30 sec]
zabbix    7410  0.0  0.1 254760  2516 ?        S    00:16   0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix    7411  0.0  0.1 254760  2736 ?        S    00:16   0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 21 sec]
zabbix    7413  0.1  0.1 254760  2876 ?        S    00:16   0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.001905 sec, idle 5 sec]
zabbix    7414  1.4  0.2 359120  5032 ?        S    00:16   0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.009963 sec, idle 60 sec]
zabbix    7416  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix    7418  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000003 sec, idle 1 sec]
zabbix    7420  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix    7422  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix    7424  0.2  0.2 254760  3808 ?        S    00:16   0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.004486 sec, idle 3 sec]
zabbix    7425  0.1  0.2 254760  3808 ?        S    00:16   0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000006 sec, idle 5 sec]
zabbix    7426  0.0  0.1 254760  2628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000009 sec, idle 1 sec]
zabbix    7428  0.0  0.1 254760  2852 ?        S    00:16   0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.003621 sec, idle 5 sec]
root      7439  0.0  0.0 112680   984 pts/1    S+   00:16   0:00 grep --color=auto zabbix
[root@lijie-01 ~]# netstat -lntp |grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      7388/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      7388/zabbix_server  
[root@lijie-01 ~]#
  1. 配置web界面 打開瀏覽器訪問http://192.168.75.136/zabbix/ web界面下面配置zabbix 輸入圖片說明
    點擊下一步,進入如下頁面,OK的選項咱們不用管,能夠看到有一個fail項,timezone時區fail, 輸入圖片說明 這時咱們須要去php的配置文件/etc/php.ini中找到timezone,設置date.timezone=Asia/shanghai 或者 chongqin,配置完成後須要重啓apache服務,重啓後再來刷新剛纔的頁面,能夠看到時區已經OK 輸入圖片說明 而後點擊下一步,這裏咱們就須要填寫mysql相關的信息 輸入圖片說明 點擊下一步 輸入圖片說明 再下一步 輸入圖片說明 下一步 輸入圖片說明
  2. 登陸 點擊完成,進入登陸界面,填寫登陸信息 輸入圖片說明
    使用默認用戶名Admin 密碼zabbix登陸後,進入首頁以下 輸入圖片說明
  3. 進入後臺第一件事情就是修改密碼 按照下圖順序進入admin用戶我的信息中心 輸入圖片說明 進入後,點擊修改密碼,填寫兩次新密碼,同時能夠將語言修改成中文 輸入圖片說明 修改完成後點擊下方的update更新設置,而後刷新一下,界面就變成中文了 輸入圖片說明

四 忘記Admin密碼怎麼辦

忘記密碼咱們能夠直接進入mysql的zabbix庫users表中修改數據庫數據就能夠了mysql

  1. 進入mysql命令行,選擇zabbix庫
[root@lijie-01 ~]# mysql -uroot -p112233
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 464
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
  1. 更改密碼
mysql> update users set passwd=md5('112233') where alias='Admin';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

這樣就更改了Admin用戶的密碼ios

五 zabbix客戶端安裝

  1. 在客戶端上也須要下載zabbix的yum源
# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 安裝yum源
# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  1. 安裝客戶端
# yum install -y zabbix-agent
  1. vim /etc/zabbix/zabbix_agentd.conf //修改以下配置
    Server=127.0.0.1修改成Server=192.168.75.136 //定義服務端的ip(被動模式) ServerActive=127.0.0.1修改成ServerActive=192.168.75.136 //定義服務端的ip(主動模式)
    Hostname=Zabbix server修改成Hostname=lijie-01 //這是自定義的主機名,一會還須要在web界面下設置一樣的主機名
  2. systemctl start zabbix-agent
[root@lijie-02 src]# systemctl start zabbix-agent
[root@lijie-02 src]# ps aux |grep zabbix
zabbix   50606  0.0  0.0  82964  1272 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix   50607  0.0  0.0  82964  1432 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix   50608  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix   50609  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix   50610  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix   50611  0.0  0.1  83096  2208 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root     50621  0.0  0.0 112680   980 pts/1    S+   01:46   0:00 grep --color=auto zabbi
[root@lijie-02 src]# netstat -lntp |grep zabbix    能夠看到監控的端口爲10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      50606/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      50606/zabbix_agentd
  1. systemctl enable zabbix-agent
[root@lijie-02 src]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@lijie-02 src]#
相關文章
相關標籤/搜索