1. 程式人生 > >十五周四次課

十五周四次課

fec listen package face 監控 china 慢慢 default 說明

19.1 Linux監控平臺介紹

監控存在的原因

站點出了問題,沒有人知道,等用戶發現了,才提醒供應商;對公司影響很大

常見開源監控軟件

cacti、nagios、zabbix、smokeping、open-falcon等等 //主流 nagios、zabbix

cacti、smokeping偏向於基礎監控,成圖非常漂亮 //比較適合監控網絡設備

cacti、nagios、zabbix服務端監控中心,需要php環境支持,其中zabbix和cacti都需要mysql作為數據存儲,nagios不用存儲歷史數據,註重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而可以成圖;

因為zabbix配置簡單,優勢明顯,早起使用nagios的企業,慢慢的轉向使用zabbix

nagios,需要更改配置文件,並不支持web界面一鍵執行,nagios和zabbix相比,nagios 更註重的是某一個監控的狀態,不關註歷史;zabbix,則是把每一次監控的數值反饋出來,方便後期數據圖去分析監控整個狀態;nagios不支持mysql,需要安裝插件以後才支持web界面;zabbix 支持mysql,可以成圖,可以記錄歷史數據

zabbix 在web界面下管理得非常徹底,可以增加監控節點,報警預知等等

open-falcon為小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,監控的思想和結構值得研究

後續以介紹zabbix為主

19.2 zabbix監控介紹

C/S架構,基於C++開發,監控中心支持web界面配置和管理

單server節點可以支持上萬臺客戶端

最新版本3.4,官方文檔https://www.zabbix.com/manuals

5個組件

zabbix-server 監控中心,接收客戶端上報信息,負責配置、統計、操作數據

數據存儲 存放數據,比如mysql

web界面 也叫web UI,在web界面下操作配置是zabbix簡單易用的主要原因

zabbix-proxy 可選組件,它可以代替zabbix-server的功能,減輕server的壓力

zabbix-agent 客戶端軟件,負責采集各個監控服務或項目的數據,並上報

最新版本3.4,官方文檔https://www.zabbix.com/manuals 5個組件 zabbix-server 監控中心,接收客戶端上報信息,負責配置、統計、操作數據 數據存儲 存放數據,比如mysql

web界面 也叫web UI,在web界面下操作配置是zabbix簡單易用的主要原因 zabbix-proxy 可選組件,它可以代替zabbix-server的功能,減輕server的壓力 zabbix-agent 客戶端軟件(每一臺客戶端都需要安裝),負責采集各個監控服務或項目的數據,並上報
監控流程圖:
技術分享圖片

19.3 安裝zabbix

安裝之前要準備倆臺機器,一臺服務端,一臺客戶端,這裏我們用zabbix 服務端,test01 客戶端

默認yum安裝的zabbix版本是2.2的太舊,所以選擇安裝官方提供的repo源

wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm

倆臺機器都安裝一下

安裝yum,源

rpm -ivh zabbix-release-3.4-1.el7.noarch.rpm

[root@zabbix ~]# wget repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm
--2018-01-17 15:25:32--  
 正在解析主機 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.4-1.el7.noarch.rpm”100%[==================================================>] 13,392      --.-K/s 用時 0s      

2018-01-17 15:25:34 (100 MB/s) - 
已保存 “zabbix-release-3.4-1.el7.noarch.rpm” [13392/13392])

[root@zabbix ~]# 

[root@zabbix ~]# rpm -ivh zabbix-release-3.4-1.el7.noarch.
rpm警告:zabbix-release-3.4-1.el7.noarch.
rpm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY準備中...                          ################################# [100%]
正在升級/安裝...   1:zabbix-release-3.4-1.el7         ################################# [100%]
[root@zabbix ~]#

客戶端

[root@test01 ~]# wget repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm
--2018-01-17 15:25:38--  
 正在解析主機 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.4-1.el7.noarch.rpm”100%[=============================================================>] 13,392      
 4.18KB/s 用時 3.1s   

2018-01-17 15:25:46 (4.18 KB/s) - 
已保存 “zabbix-release-3.4-1.el7.noarch.rpm” [13392/13392])

[root@test01 ~]# 

[root@test01 ~]# rpm -ivh zabbix-release-3.4-1.el7.noarch.
rpm警告:zabbix-release-3.4-1.el7.noarch.
rpm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY準備中...                          ################################# [100%]
正在升級/安裝...   1:zabbix-release-3.4-1.el7         ################################# [100%]
[root@test01 ~]#

然後可以看到/etc/yum.repos.d 目錄下多了一個 zabbix.repo,這個其實就是剛剛我們安裝的rpm包所安裝的一個文件,有了這個源之後,就可以直接yum 安裝zabbix了。

[root@zabbix ~]# cat /etc/yum.repos.d/CentOS-Base.repo       CentOS-Media.repo      epel-testing.repo
CentOS-CR.repo         CentOS-Sources.repo    zabbix.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo      
CentOS-fasttrack.repo  epel.repo.1            
[root@zabbix ~]# cat /etc/yum.repos.d/zabbix.repo [zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.4/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@zabbix ~]#

yum安裝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界面,zabbix-server-mysql ,web和mysql打交道,安裝一些web和mysql打交道的一些東西

[root@zabbix ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
已安裝:  zabbix-agent.x86_64 0:3.4.10-2.el7                zabbix-get.x86_64 0:3.4.10-2.el7        
  zabbix-server-mysql.x86_64 0:3.4.10-2.el7         zabbix-web.noarch 0:3.4.10-2.el7        
  zabbix-web-mysql.noarch 0:3.4.10-2.el7           作為依賴被安裝:  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                      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      
  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                 
  libXpm.x86_64 0:3.5.12-1.el7                  libtool-ltdl.x86_64 0:2.4.2-22.el7_3       
  libxslt.x86_64 0:1.1.28-5.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-42.el7                 
  php-bcmath.x86_64 0:5.4.16-42.el7             php-cli.x86_64 0:5.4.16-42.el7             
  php-common.x86_64 0:5.4.16-42.el7             php-gd.x86_64 0:5.4.16-42.el7              
  php-ldap.x86_64 0:5.4.16-42.el7               php-mbstring.x86_64 0:5.4.16-42.el7        
  php-mysql.x86_64 0:5.4.16-42.el7              php-pdo.x86_64 0:5.4.16-42.el7             
  php-xml.x86_64 0:5.4.16-42.el7                t1lib.x86_64 0:5.1.2-14.el7                
  unixODBC.x86_64 0:2.3.1-11.el7               完畢![root@zabbix ~]#

如果mysql之前沒有安裝的話,需要根據lamp那一章的mysql安裝方法安裝mysql,也可以直接yum安裝mysql

因為我們之前已經安裝過mysql,這裏就省略了

先看下mysql有沒有啟動起來,沒有就要啟動

[root@zabbix ~]# ps aux |grep mysql
root       1181  0.0  0.1 115392  1684 ?        S    21:49   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zabbix.pid
mysql      1700  0.1 45.5 1300844 455476 ?      Sl   21:50   0:05 /usr/local/mysql/bin/mysqd --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/zabbix.err --pid-file=/data/mysql/zabbix.pid --socket=/tmp/mysql.sock
root       2922  0.0  0.0 112680   980 pts/0    R+   23:20   0:00 grep --color=auto mysql
[root@zabbix ~]#

接下來還需要編輯下mysql的配置文件,設定一個默認的字符集

vim /etc/my.cnf //需要增加配置 character_set_server = utf8

如果不設置中文的話,到時候web界面中文顯示就會有問題

[root@zabbix ~]# vi /etc/my.cnf[mysqld]
character_set_server = utf8
datadir=/data/mysqlsocket=/tmp/mysql.sock
server-id=131
log_bin=zabbixlinux1
# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in 
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
## include all files from the config directory
##!includedir /etc/my.cnf.d:wq
[root@zabbix ~]# vi /etc/my.cnf
[root@zabbix ~]#

然後重啟下mysql

[root@zabbix ~]# systemctl restart mysql
[root@zabbix ~]#

然後進入mysql命令行,創建zabbix庫 create database zabbix character set utf8;

再創建用戶 grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘zabbix-zabbix‘;

[root@zabbix ~]# mysql -uroot -pzabbixlinux
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 1Server 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> 

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 ‘zabbix-zabbix‘; 
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@zabbix ~]#

導入數據

cd /usr/share/doc/zabbix-server-mysql-3.4.7

給他解壓一下 gzip -d create.sql.gz

導入數據

mysql -uroot -pxxx zabbix < create.sql

[root@zabbix ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.10/
[root@zabbix zabbix-server-mysql-3.4.10]# 
[root@zabbix zabbix-server-mysql-3.4.10]# lsAUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README

[root@zabbix zabbix-server-mysql-3.4.10]# gzip -d create.sql.gz 
[root@zabbix zabbix-server-mysql-3.4.10]# lsAUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@zabbix zabbix-server-mysql-3.4.10]# mysql -uroot -pzabbixlinux zabbix < create.sql 
Warning: Using a password on the command line interface can be insecure.
[root@zabbix zabbix-server-mysql-3.4.10]#

啟動zabbix 服務

[root@zabbix ~]# systemctl start zabbix-server[root@zabbix ~]#

還要啟動httpd服務,但是在啟動之前要檢查下,系統裏面有沒有啟動nginx服務,如果啟動了nginx說明監聽80端口 ,如果nginx服務啟動了就要把它給關閉

[root@zabbix ~]# ps aux |grep nginx
root       1095  0.0  0.1  45992  1180 ?        Ss   21:49   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody     1097  0.0  0.3  48480  3796 ?        S    21:49   0:00 nginx: worker process
nobody     1098  0.0  0.3  48480  3808 ?        S    21:49   0:00 nginx: worker process
root       3200  0.0  0.0 112680   980 pts/0    R+   23:34   0:00 grep --color=auto nginx
[root@zabbix ~]# 
[root@zabbix ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl):                            [  確定  ]
[root@zabbix ~]# 
[root@zabbix ~]# !psps aux |grep nginx
root       3222  0.0  0.0 112680   980 pts/0    R+   23:35   0:00 grep --color=auto nginx
[root@zabbix ~]# netstat -lntpActive 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      1136/rpc.mountd     
tcp        0      0 0.0.0.0:50995           0.0.0.0:*               LISTEN      991/rpc.statd       
tcp        0      0 0.0.0.0:46261           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1065/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1792/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      3132/mysqld         
tcp6       0      0 :::40463                :::*                    LISTEN      991/rpc.statd       
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::20048                :::*                    LISTEN      1136/rpc.mountd     
tcp6       0      0 :::39446                :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1065/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1792/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
[root@zabbix ~]#

看下有沒有監聽80端口,沒有監聽80端口就可以順利的把httpd 服務啟動起來,再來看有沒有監聽80端口

[root@zabbix ~]# systemctl start httpd
[root@zabbix ~]# !netnetstat -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      1136/rpc.mountd     
tcp        0      0 0.0.0.0:50995           0.0.0.0:*               LISTEN      991/rpc.statd       
tcp        0      0 0.0.0.0:46261           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1065/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1792/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      3132/mysqld         
tcp6       0      0 :::40463                :::*                    LISTEN      991/rpc.statd       
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::80                   :::*                    LISTEN      3230/httpd          
tcp6       0      0 :::20048                :::*                    LISTEN      1136/rpc.mountd     
tcp6       0      0 :::39446                :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1065/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1792/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
[root@zabbix ~]#

那麽如果以後想要httpd開機啟動,還有zabbix-server 還需要把它加入到服務的啟動列表裏面去

[root@zabbix ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.
target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix ~]# 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.
[root@zabbix ~]#

還不要忘記把nginx給它停掉

[root@zabbix ~]# systemctl disable nginx
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx off
[root@zabbix ~]# 
[root@zabbix ~]# chkconfig nginx off
[root@zabbix ~]#

那服務端,咱們啟動了起來了 看一看進程

[root@zabbix ~]# ps aux |grep zabbix
zabbix     3197  0.0  0.3 256076  3448 ?        S    23:33   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root       3365  0.0  0.0 112680   980 pts/0    R+   23:40   0:00 grep --color=auto zabbix
[root@zabbix ~]#

還要看看zabbix有沒有監聽端口

[root@zabbix ~]# !netnetstat -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      1136/rpc.mountd     
tcp        0      0 0.0.0.0:50995           0.0.0.0:*               LISTEN      991/rpc.statd       
tcp        0      0 0.0.0.0:46261           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1065/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1792/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      3132/mysqld         
tcp6       0      0 :::40463                :::*                    LISTEN      991/rpc.statd       
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::80                   :::*                    LISTEN      3230/httpd          
tcp6       0      0 :::20048                :::*                    LISTEN      1136/rpc.mountd     
tcp6       0      0 :::39446                :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1065/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1792/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
[root@zabbix ~]#

進程還在,但是沒有看到zabbix的監聽的端口,說明有問題,下節來看下問題出在哪裏

[root@zabbix ~]# !psps aux |grep zabbix
zabbix     3197  0.0  0.3 256076  3448 ?        S    23:33   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root       3369  0.0  0.0 112680   980 pts/0    R+   23:42   0:00 grep --color=auto zabbix
[root@zabbix ~]#

19.4 安裝zabbix

接著上面的問題,沒有查到zabbix 監聽的端口,可以查看下它的日誌,

[root@zabbix ~]# less /var/log/zabbix/zabbix_server.log
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)econnecting in 10 seconds
to database ‘zabbix‘ failed: [2002] Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)~
~

~
~
(END)

說明不能連接mysql ,所以還需要去改下配置文件

vim /etc/zabbix/zabbix_server.conf //修改或增加

DBHost=127.0.0.1 //在DBName=zabbix上面增加 ,搜索DBHost

DBPassword=zabbix-zabbix //在DBuser下面增加

### Option: DBHost
#       Database host name.
If set to localhost, socket is used for MySQL.
#       If set to empty string, socket is used for PostgreSQL.
## Mandatory: no# Default:
# DBHost=localhostDBHost=127.0.0.1
### Option: DBName-- 插入 --

這裏的ip寫多少127.0.0.1 ,也可以寫localhost

因為mysql和zabbix裝在同一臺機器上,這裏可以寫localhost或者127.0.0.1;如果是在生產環境上,有時候為了提升zabbix的性能,可能會把MySQL裝在其他機器上,這是的DBHost,就需要寫上mysql的ip

DBUser=zabbix
DBPassword=zabbix-zabbix
### Option: DBPassword
#       Database password. Ignored for SQLite.
#       Comment this line if no password is used.-- 插入 -- 

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf
root@zabbix ~]#

這個地方的DBPassword=zabbix-zabbix 是指的咱們授權的時候用的密碼

更改完這幾項就可以啟動服務了,之前啟動過,這裏重啟一下就ok

[root@zabbix ~]# systemctl restart zabbix-server
[root@zabbix ~]# !psps aux |grep zabbix
zabbix     3407  3.1  0.4 256256  4136 ?        S    16:20   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix     3410  0.0  0.2 256256  2468 ?        S    16:20   0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
zabbix     3411  0.0  0.2 256256  2680 ?        S    16:20   0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.012940 sec, idle 60 sec]
zabbix     3412  0.5  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: poller 
#1 [got 0 values in 0.000004 sec, idle 5 sec]zabbix     3413  0.4  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: poller 
#2 [got 0 values in 0.000005 sec, idle 5 sec]zabbix     3414  0.5  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: poller 
#3 [got 0 values in 0.000006 sec, idle 5 sec]zabbix     3415  0.5  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: poller 
#4 [got 0 values in 0.000007 sec, idle 5 sec]zabbix     3416  0.5  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: poller 
#5 [got 0 values in 0.000005 sec, idle 5 sec]zabbix     3417  0.4  0.5 363204  5200 ?        S    16:20   0:00 /usr/sbin/zabbix_server: unreachable poller 
#1 [got 0 values in 0.000005 sec, idle 5 sec]zabbix     3418  0.0  0.3 256256  3584 ?        S    16:20   0:00 /usr/sbin/zabbix_server: trapper 
#1 [processed data in 0.000000 sec, waiting for connection]zabbix     3419  0.0  0.3 256256  3584 ?        S    16:20   0:00 /usr/sbin/zabbix_server: trapper 
#2 [processed data in 0.000000 sec, waiting for connection]zabbix     3420  0.0  0.3 256256  3584 ?        S    16:20   0:00 /usr/sbin/zabbix_server: trapper 
#3 [processed data in 0.000000 sec, waiting for connection]zabbix     3422  0.0  0.3 256256  3584 ?        S    16:20   0:00 /usr/sbin/zabbix_server: trapper 
#4 [processed data in 0.000000 sec, waiting for connection]zabbix     3424  0.0  0.3 256256  3584 ?        S    16:20   0:00 /usr/sbin/zabbix_server: trapper 
#5 [processed data in 0.000000 sec, waiting for connection]zabbix     3426  0.0  0.2 258832  2620 ?        S    16:20   0:00 /usr/sbin/zabbix_server: icmp pinger 
#1 [got 0 values in 0.000006 sec, idle 5 sec]zabbix     3427  0.0  0.2 256256  2688 ?        S    16:20   0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.110521 sec, idle 30 sec]
zabbix     3428  0.0  0.2 256256  2468 ?        S    16:20   0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix     3429  0.0  0.2 256256  2688 ?        S    16:20   0:00 /usr/sbin/zabbix_server: timer 
#1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 15 sec]zabbix     3430  0.0  0.2 256256  2840 ?        S    16:20   0:00 /usr/sbin/zabbix_server: http poller 
#1 [got 0 values in 0.001036 sec, idle 5 sec]zabbix     3431  0.2  0.5 360620  5040 ?        S    16:20   0:00 /usr/sbin/zabbix_server: discoverer 
#1 [processed 0 rules in 0.066387 sec, idle 60 sec]zabbix     3432  0.0  0.2 256256  2828 ?        S    16:20   0:00 /usr/sbin/zabbix_server: history syncer 
#1 [synced 0 items in 0.000001 sec, idle 1 sec]zabbix     3433  0.0  0.2 256256  2828 ?        S    16:20   0:00 /usr/sbin/zabbix_server: history syncer 
#2 [synced 0 items in 0.000003 sec, idle 1 sec]zabbix     3434  0.0  0.2 256256  2828 ?        S    16:20   0:00 /usr/sbin/zabbix_server: history syncer 
#3 [synced 0 items in 0.000002 sec, idle 1 sec]zabbix     3441  0.0  0.2 256256  2828 ?        S    16:20   0:00 /usr/sbin/zabbix_server: history syncer 
#4 [synced 0 items in 0.000003 sec, idle 1 sec]zabbix     3442  0.0  0.3 256256  3764 ?        S    16:20   0:00 /usr/sbin/zabbix_server: escalator 
#1 [processed 0 escalations in 0.001375 sec, idle 3 sec]zabbix     3443  0.0  0.3 256256  3760 ?        S    16:20   0:00 /usr/sbin/zabbix_server: proxy poller
#1 [exchanged data with 0 proxies in 0.000005 sec, idle 5 sec]zabbix     3444  0.0  0.2 256256  2588 ?        S    16:20   0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000007 sec, idle 1 sec]
zabbix     3445  0.0  0.2 256256  2812 ?        S    16:20   0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.001277 sec, idle 5 sec]
root       3458  0.0  0.0 112680   980 pts/0    R+   16:20   0:00 grep --color=auto zabbix
[root@zabbix ~]#

再來看下監聽的端口,zabbix 應該監聽10051端口

[root@zabbix ~]# !netnetstat -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      1136/rpc.mountd     
tcp        0      0 0.0.0.0:50995           0.0.0.0:*               LISTEN      991/rpc.statd       
tcp        0      0 0.0.0.0:46261           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1065/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1792/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      3407/zabbix_server  
tcp6       0      0 :::3306                 :::*                    LISTEN      3132/mysqld         
tcp6       0      0 :::40463                :::*                    LISTEN      991/rpc.statd       
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::80                   :::*                    LISTEN      3230/httpd          
tcp6       0      0 :::20048                :::*                    LISTEN      1136/rpc.mountd     
tcp6       0      0 :::39446                :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1065/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1792/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
tcp6       0      0 :::10051                :::*                    LISTEN      3407/zabbix_server  
[root@zabbix ~]#

接下來需要配置web界面了,打開瀏覽器

輸入你的ip地址也就是你的監控中心的ip地址 172.16.22.233/zabbix

技術分享圖片

進入到這個安裝界面點next step 就可以了

技術分享圖片

如果出現以下錯誤:

錯誤: 此處有錯誤提示,意識是PHP無法識別“data.timezone”(時區)。
技術分享圖片

vim /etc/php.ini

date.timezone寫 亞洲上海,或者亞洲北京、重慶 date.timezone = Asia/Shanghai

[root@zabbix ~]# vi /etc/php.ini

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[CLI Server]
; Whether the CLI web server uses ANSI color coding in its terminal output.
cli_server.color = On

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezonedate.timezone = Asia/Shanghai

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667; http://php.net/date.default-longitude
;date.default_longitude = 35.2333; http://php.net/date.sunrise-zenith
-- INSERT --

[root@zabbix ~]# vi /etc/php.ini
[root@zabbix ~]#

定義完之後,重新httpd服務,然後再去瀏覽器刷新

[root@zabbix ~]# systemctl restart httpd

技術分享圖片

恭喜你已經成功安裝了zabbix前端

然後點幾finish 登錄

默認的用戶名 admin 密碼 zabbix
技術分享圖片

登錄進去之後首先要去更改密碼,因為這個密碼大家都知道,是默認的密碼,如果以後線上的密碼不更改,那就很危險,很有可能被別人那道權限,
技術分享圖片
技術分享圖片
進去點change password
技術分享圖片

技術分享圖片
這時候密碼改了,還沒有變成中文,需要刷新下

我們退出來重進下
技術分享圖片

這個就是咱麽的zabbix web界面了,這個時候因為你還麽有加入任何的監控主機,所以也沒有什麽數據。

19.6 安裝zabbix

Zabbix客戶端安裝

在客戶端上也需要下載zabbix的yum源

wget repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm

rpm -ivh zabbix-release-3.4-1.el7.noarch.rpm

yum install -y zabbix-agent

vim /etc/zabbix/zabbix_agentd.conf //修改如下配置

Server=127.0.0.1修改為Server=192.168.133.130 //定義服務端的ip(被動模式)

ServerActive=127.0.0.1修改為ServerActive=192.168.133.130 //定義服務端的ip(主動模式)

Hostname=Zabbix server修改為Hostname=zabbix-123 //這是自定義的主機名,一會還需要在web界面下設置同樣的主機名

systemctl start zabbix-agent

systemctl enable zabbix-agent

由於我們之前已經下載 、安裝了zabbix yum源

接下來直接yum 安裝 zabbix-agent 組件

[root@test01 ~]# yum install -y zabbix-agent
已加載插件:fastestmirror
base                                                                            | 3.6 kB  00:00:00     
extras                                                                          | 3.4 kB  00:00:00     
updates                                                                         | 3.4 kB  00:00:00     
zabbix                                                                          | 2.9 kB  00:00:00     
zabbix-non-supported                                                            |  951 B  00:00:00     
(1/3): extras/7/x86_64/primary_db                                               | 130 kB  00:00:00     
(2/3): zabbix/x86_64/primary_db                                                 |  82 kB  00:00:02     
(3/3): updates/7/x86_64/primary_db                                              | 3.6 MB  00:00:08     
zabbix-non-supported/x86_64/primary                                             | 1.6 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
zabbix-non-supported          

4/4正在解決依賴關系--> 正在檢查事務---> 軟件包
zabbix-agent.x86_64.0.3.4.10-2.el7 將被 安裝-->
解決依賴關系完成依賴關系解決

=======================================================================================================
 Package                    架構                 版本                       源                    大小
 =======================================================================================================
 正在安裝: zabbix-agent               x86_64               3.4.10-2.el7               zabbix               347 k
 事務概要=======================================================================================================安裝  1 
 軟件包總下載量:347 k安裝大小:1.3 M
Downloading packages:警告:/var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-3.4.10-2.el7.x86_64.
rpm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY
zabbix-agent-3.4.10-2.el7.x86_64.rpm 的公鑰尚未安裝zabbix-agent-3.4.10-2.el7.x86_64.rpm                                            
| 347 kB  00:00:13     
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 檢索密鑰導入 GPG key 0xA14FE591: 
用戶ID     : "Zabbix LLC <[email protected]>" 
指紋       : a184 8f53 52d0 22b9 471d 83d0 082a b56b a14f e591 
軟件包     : zabbix-release-3.4-1.el7.noarch (installed) 
來自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 數據庫已被非 yum 程序修改。  
正在安裝    : zabbix-agent-3.4.10-2.el7.x86_64                                                   
1/1   驗證中      : zabbix-agent-3.4.10-2.el7.x86_64                                                   
1/1 已安裝:  zabbix-agent.x86_64 0:3.4.10-2.el7                                                                   
完畢!
[root@test01 ~]#

安裝好後,修改配置文件

vim /etc/zabbix/zabbix_agentd.conf

修改三個地方

1.在客戶端指定一個白名單
Hostname=test01 //方便服務中心識別客戶端機器

  1. Server=172.16.22.233 //ip為監控中心的IP

  2. ServerActive=172.16.22.233//這個涉及到一個主動和被動模式;如果這裏不填寫服務中心的IP,那麽就只能使用被動模式;這個IP是主動模式時候用的

    [root@test01 ~]# vim /etc/zabbix/zabbix_agentd.conf

    Mandatory: no# Default:

    Hostname=

    Hostname=zabbix-02

    Option: HostnameItem

    # Mandatory: no
    # Default:
    # Server=Server=172.16.22.233
    # Mandatory: no
    # Default:
    # ServerActive=
    ServerActive=172.16.22.233
    :wq

    [root@test01 ~]# vim /etc/zabbix/zabbix_agentd.conf
    [root@test01 ~]#

配置完成,啟動服務,查看進程

[root@test01 ~]# systemctl start zabbix-agent
[root@test01 ~]# ps aux |grep zabbix
zabbix     2377  0.0  0.1  80608  1256 ?        S    20:27   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix     2378  0.0  0.1  80608  1288 ?        S    20:27   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix     2379  0.0  0.1  80608  1836 ?        S    20:27   0:00 /usr/sbin/zabbix_agentd: listener #1 
[waiting for connection]zabbix     
2380  0.0  0.1  80608  1836 ?        
S    20:27   0:00 /usr/sbin/zabbix_agentd: listener 
2 [waiting for connection]zabbix     2381  0.0  0.1  80608  1836 ?        S    20:27   0:00 /usr/sbin/zabbix_agentd: listener #3 
[waiting for connection]zabbix     
2382  0.0  0.2  80608  2180 ?        S    20:27   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]root 
2384  0.0  0.0 112680   980 pts/0    R+   20:28   0:00 grep --color=auto zabbix
[root@test01 ~]#

查看下監聽的端口,這個端口是10050,客戶端, 服務端端口是10051

[root@test01 ~]# 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:22              0.0.0.0:*               LISTEN      1742/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2065/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2377/zabbix_agentd  
tcp6       0      0 :::3306                 :::*                    LISTEN      2002/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1742/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2065/master         
tcp6       0      0 :::10050                :::*                    LISTEN      2377/zabbix_agentd  
[root@test01 ~]#

到這裏zabbix 客戶端就安裝結束了

19.5 忘記Admin密碼如何做

進入mysql的

mysql -uroot -pzabbixlinux;

進入zabbix庫

use zabbix;

查看所有表

show tables

[root@zabbix ~]# mysql -uroot -pzabbixlinux
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 36
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> 

mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| groups                     |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| httpstep                   |
| httpstepitem               |
| httptest                   |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| items                      |
| items_applications         |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_url         |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| task                       |
| task_close_problem         |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
+----------------------------+
127 rows in set (0.00 sec)

mysql>

以後監控的服務器,監控的主機很多的話,這些表會越來越大,所有需要指定合適的監控規則、策略,比如數據量需要保留多長時間,那麽在定義這個監控項目的時候就該想到,比如要保留1個月、還是1年,還是其他時間;可能,監控的站點服務量很大的話,一天就要漲好幾個G,那麽你的服務器磁盤能支持保存多長時間;

密碼默認存放的表是users裏面

查看表

desc users;

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.00 sec)

mysql>

我們需要修改的就是passwd的表

修改密碼

 update users set passwd=md5(‘zabbixlinux‘) where alias=‘Admin‘;

mysql> update users set passwd=md5(‘lishiming1‘) where alias=‘Admin‘;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>

查看表的情況

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 | 148308853a00bdc6ed461689d4c72649 |     |         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)

mysql>

這個時候就可以去使用新的密碼(lishiming1)瀏覽器登錄zabbix

這就是怎麽樣去重置你的zabbix管理員密碼

十五周四次課