Linux基礎(day66)

19.1 Linux監控平臺介紹

Linux監控平臺介紹

  • 監控存在的緣由
    • 站點出了問題,沒有人知道,等用戶發現了,才提醒供應商;對公司影響很大
  • 常見開源監控軟件
    • cacti、nagios、zabbix、smokeping、open-falcon等等,其中nagios、zabbix流行度很是高
    • cacti、smokeping偏向於基礎監控,成圖很是漂亮,適合監控網絡設備
      • cacti監控網絡的設備
    • cacti、nagios、zabbix服務端監控中心,須要php環境支持(用Apache的php,用nginx的php均可以),其中zabbix和cacti都須要mysql做爲數據存儲,nagios不用存儲歷史數據,注重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而能夠成圖
      • 由於zabbix配置簡單,優點明顯,早起使用nagios的企業,慢慢的轉向使用zabbix
      • nagios,須要更改配置文件,並不支持web界面一鍵執行,nagios和zabbix相比,
        • nagios 更注重的是某一個監控的狀態,不關注歷史;
        • zabbix,則是把每一次監控的數值反饋出來,數值存到數據庫裏面,方便後期數據圖去分析監控整個狀態;
        • nagios不須要mysql的支持,不能成圖,若須要畫圖,得安裝插件之後才支持web界面;
        • ccti 也須要mysql的支持,也能夠成圖,能夠記錄歷史數據
      • zabbix 在web界面下管理得很是完全,能夠增長監控節點,報警預知等等
    • open-falcon爲小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究
      • open-falcon軟件適合大企業使用,小企業能夠去研究它的思想
  • 後續以介紹zabbix爲主

19.2 zabbix監控介紹

zabbix監控介紹

  • C/S架構,基於C++開發,監控中心支持web界面配置和管理
    • zabbix軟件,是C/S架構:有一個服務端,去客戶端抓數據。在客戶端必需要有一個服務啓動運行才能夠抓取數據;數據能夠主動的上報服務端,也可讓服務端去鏈接客戶端獲取(經過抓取數據方式,數據獲取分兩個模式,一個主動模式,一個被動模式),zabbix軟件基於C++開發,監控中心須要一個PHP的web環境,由於要開啓一個web界面配置和管理
  • 單臺server節點(即一臺server),理論上 能夠支持上萬臺客戶端
    • 瓶頸:在於採集數據的量,雖然支持上萬臺,但監控的項目過多,仍是會致使zabbix效率下降;因此,當服務器大到必定規模的時候,就須要對zabbix進行優化
    • 解決方法:能夠增長一些代理點,這些代理點充當server,替代server去採集數據,最終獲得分析結果再彙報給主服務端server
  • 目前zabbix軟件,最新版本3.4,官方文檔
    • 更新快,使用的用戶多
  • zabbix架構裏,包括了5個組件:
    • zabbix-server 監控中心,接收客戶端上報信息,負責配置、統計、操做數據
    • 數據存儲 存放數據,好比mysql
    • web界面 也叫web UI,在web界面下操做配置是zabbix簡單易用的主要緣由(若是沒有web界面,就沒法在瀏覽器上配置它)
    • zabbix-proxy 可選組件,它能夠代替zabbix-server的功能,減輕server的壓力(當機器量不少的時候,可使用zabbix-proxy)
      • 有時候,服務器分佈在多個機房裏,每一個機房的服務器之間都是一個單獨的內網,這時候就能夠在某一個局域網裏搭建一個 zabbix-proxy ,用這臺 proxy 去監控局域網裏的機器
    • zabbix-agent 客戶端軟件(每一臺客戶端都須要安裝agent),負責採集各個監控服務或項目的數據,並上報

監控流程圖:

輸入圖片說明

19.3/19.4/19.6 安裝zabbix

安裝zabbix

  • 官網下載地址
  • wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  • rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  • yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
  • 會連帶安裝httpd和php
  • 若是mysql以前沒有安裝的話,須要根據lamp那一章的mysql安裝方法安裝mysql
  • vim /etc/my.cnf //須要增長配置
character_set_server = utf8
  • 重啓mysqld服務後,進入mysql命令行,建立zabbix庫
    • create database zabbix character set utf8;
  • 再建立用戶
    • grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'aming-zabbix';
  • 導入數據
  • cd /usr/share/doc/zabbix-server-mysql-3.2.7
  • gzip -d create.sql.gz
  • mysql -uroot -pxxx zabbix < create.sql
  • systemctl start httpd; systemctl enable httpd
  • vim /etc/zabbix/zabbix_server.conf //修改或增長
DBHost=127.0.0.1 //在DBName=zabbix上面增長
DBPassword=aming-zabbix //在DBuser下面增長
  • systemctl start zabbix-server
  • systemctl enable zabbix-server
  • netstat -lntp |grep zabbix //查看監聽端口
  • 瀏覽器訪問http://ip/zabbix/ web界面下面配置zabbix
  • 用戶名Admin 密碼zabbix
  • 進入後臺第一件事情就是修改密碼

安裝zabbix

  • 準備工做
    • 兩臺機器,一臺做爲服務端(監控中心),另一臺做爲它的客戶端
  • 背景
    • zabbix,能夠直接yum安裝,但須要安裝epel擴展源,在epel擴展源裏面安裝的zabbix的版本,最高是2.2版本,比較舊,因此使用官方提供的repo源
  • 這裏實驗使用的zabbix3.2版本
  1. 首先訪問官網下載地址,選擇對應的版本,並提供對應的發行版,而後選擇download,跳轉到一個界面,找到這個rpm包(包含release),也就是說yum源在這個裏面,下圖所示,複製該連接

輸入圖片說明

  1. 在兩臺機器都須要下載它
A機器
[root@hf-01 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

B機器
[root@hf-02 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 下載完以後,安裝rpm包(實際上就是安裝了一個yum源倉庫)
A機器安裝rpm包
[root@hf-01 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm

B機器安裝rpm包
[root@hf-02 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  1. 查看/etc/yum.repos.d/目錄下面會看到增長了一個zabbix.repo
[root@hf-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo  zabbix.repo
CentOS-CR.repo         CentOS-Media.repo      epel.repo.1
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel-testing.repo
[root@hf-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
[root@hf-01 ~]#
  1. 再有了這個zabbix.repo源以後,就能夠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 //webUI ,web界面
    • zabbix-web-mysql //web和mysql相關組件
  • PS:在服務端是須要安裝這些全部的包,而在客戶端僅僅須要安裝 zabbix-agent 包便可
A機器
[root@hf-01 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql

B機器
[root@hf-02 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
  1. zabbix 是基於php環境的,也就是說用的是php 的代碼編寫的web界面,也就說這個zabbix 至關於一個站點
  2. 安裝mysql,若是mysql以前沒有安裝的話,須要根據lamp那一章的mysql安裝方法安裝mysql
  • 固然yum安裝mysql、或mariadb也能夠
  • 安裝mysql
A機器(由於以前安裝過mysql)
[root@hf-01 ~]# !ps
ps aux| grep mysql
root      1203  0.0  0.1 115388  1684 ?        S    01:22   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/hf-01.pid
mysql     1498  0.1 45.3 973552 458376 ?       Sl   01:22   0:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/hf-01.err --pid-file=/data/mysql/hf-01.pid
root      2586  0.0  0.0 112676   980 pts/1    R+   02:10   0:00 grep --color=auto mysql
[root@hf-01 ~]#
  1. 修改mysql的配置文件,修改/etc/my.cnf文件,設定默認的字符集
A機器
[root@hf-01 ~]# vim /etc/my.cnf
在[mysqld]下添加字符集

character_set_server = utf8
保存退出
  • 若是不設置字符集,那麼zabbix的web界面,設置成中文的話,可能就會出現亂碼
  1. 修改完mysql的配置文件後,重啓mysql服務
  • /etc/init.d/mysqld restart
A機器
[root@hf-01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@hf-01 ~]#
  1. 重啓mysqld服務後,進入mysql命令行(第一次進入mysql命令行),建立zabbix庫,並指定編碼爲utf8
    • create database zabbix character set utf8;
A機器
[root@hf-01 ~]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@hf-01 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 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> create database zabbix character set utf8;        //建立zabbix庫,並指定編碼爲utf8
Query OK, 1 row affected (0.00 sec)

mysql>
  1. 再建立用戶,這個用戶是須要讓web(php)代碼鏈接mysql的,監控中心zabbix mysql服務,啓動的前提就是要鏈接mysql;客戶端採集了數據,須要把這些數據傳遞給服務端,那麼服務端怎麼把這些數據寫入到MySQL去,這時就涉及到了mysql 的用戶,涉及到了mysql 的數據庫;用哪個用戶,去寫入那一個庫。
  • grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'hanfeng-zabbix';
mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'hanfeng-zabbix';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@hf-01 ~]#
  1. 退出mysql的命令行後,導入原始的數據,若缺乏這些數據,zabbix就沒有辦法工做,就沒有辦法在web界面下展示給咱們
  • zabbix-server-mysql-3.2.11 這塊用tab鍵補全,有可能版本號不一樣
A機器
[root@hf-01 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 在/usr/share/doc/zabbix-server-mysql-3.2.11/目錄下有一個create.sql.gz壓縮包,將它解壓,解壓完以後生成了一個.sql的文件
A機器
[root@hf-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@hf-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
[root@hf-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 而後拿到create.sql文件,將它導入到zabbix庫裏面去
A機器
[root@hf-01 zabbix-server-mysql-3.2.11]# mysql -uroot -phanfeng zabbix < create.sql 
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 啓動zabbix服務,啓動zabbix報錯
  • systemctl start zabbix-server
[root@hf-01 ~]# systemctl start zabbix-server
[root@hf-01 ~]#
  1. 啓動httpd服務,在啓動http服務以前,先查看nginx服務是否啓動,若啓動了nginx,就監聽了80端口,就須要去停掉nginx服務,再去啓動httpd服務
[root@hf-01 ~]# ps aux |grep nginx
root      2866  0.0  0.0 112676   984 pts/1    R+   03:06   0:00 grep --color=auto nginx
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]# systemctl start httpd
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      2874/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]#
  • 這時就發現httpd服務監聽了80端口
  1. 若須要開機啓動httpd服務和zabbix服務,則須要將它加入到服務的列表中去
  • systemctl enable httpd
  • systemctl enable zabbix-server
A機器
[root@hf-01 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@hf-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.
[root@hf-01 ~]#
  • 若nginx設置了開機啓動,則須要取消開機啓動
    • systemctl disable nginx
    • chkconfig nginx off
  1. 查看zabbix服務進程
[root@hf-01 ~]# ps aux |grep zabbix
zabbix    2863  0.0  0.3 251752  3332 ?        S    03:04   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root      2926  0.0  0.0 112676   984 pts/1    R+   03:15   0:00 grep --color=auto zabbix
[root@hf-01 ~]#
  1. 查看zabbix監聽的端口
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      2874/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]#
  • 錯誤:
    • 這裏看到服務啓動了,但並無zabbix監聽的端口
  1. 查看zabbix並無監聽端口後,首先檢查zabbix的錯誤日誌,錯誤日誌路徑/var/log/zabbix/zabbix_server.log
[root@hf-01 ~]# tail /var/log/zabbix/zabbix_server.log
  2863:20180103:033242.719 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033242.719 database is down: reconnecting in 10 seconds
  2863:20180103:033252.720 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033252.720 database is down: reconnecting in 10 seconds
  2863:20180103:033302.721 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033302.721 database is down: reconnecting in 10 seconds
  2863:20180103:033312.722 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033312.723 database is down: reconnecting in 10 seconds
  2863:20180103:033322.724 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033322.724 database is down: reconnecting in 10 seconds
[root@hf-01 ~]#
  • 雖然zabbix服務有進程,但沒有完全的起來,說明不可以鏈接mysql,因此還須要更改zabbix的配置文件
  1. 更改zabbix的配置文件,配置文件爲/etc/zabbix/zabbix_server.conf
A機器
[root@hf-01 ~]# vim /etc/zabbix/zabbix_server.conf

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

在DBuser下面增長
DBPassword=hanfeng-zabbix

保存退出
  • 由於mysql和zabbix裝在同一臺機器上,這裏的 DBHost能夠寫localhost 或者127.0.0.1;若是是在生產環境上,有時候爲了提高zabbix的性能,可能會把MySQL裝在其餘機器上,這是的DBHost,就須要寫上mysql的ip
  1. 更改完zabbix配置文件,就能夠啓動zabbix服務了,由於以前啓動了zabbix服務,這裏只需restart重啓下便可
A機器
[root@hf-01 ~]# systemctl restart zabbix-server
[root@hf-01 ~]#
  1. 這時再來查看下zabbix進程,有29個(正常狀況下,都是這麼多進程)
A機器
[root@hf-01 ~]# ps aux |grep zabbix |wc -l
29
[root@hf-01 ~]#
  1. 查看監聽的端口,zabbix監聽的端口爲10051端口
A機器
[root@hf-01 ~]# netstat -lntp |grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      3303/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      3303/zabbix_server  
[root@hf-01 ~]#
  1. 接下來就是配置web界面了(須要關閉防火牆和規則,不然瀏覽器沒法訪問)
  • 在瀏覽器輸入IP地址(即監控中心的IP地址),如192.168.74.129/zabbix 去訪問

輸入圖片說明

  • 不少人會有疑問,僅僅啓動了httpd 服務,沒有去作任何的配置,由於yum安裝zabbix,它默認安裝httpd 及它的配置文件,一切都會幫你配置好了
  1. 再打開zabbix界面後,點擊 Next step ,會出現一個提示,出現OK的都不用管,會看到提示須要去設置php的timezone時區,以下圖

輸入圖片說明

  1. 設置php的timezone時區,在php的配置文件中設置,默認php的配置文件在/etc/php.ini 裏面
A機器
[root@hf-01 ~]# vim /etc/php.ini

搜索 /timezone
將 ;date.timezone 改成以下

date.timezone = Asia/Shanghai
保存退出
  1. 在定義完php的配置文件,還須要重啓apache
[root@hf-01 ~]# systemctl restart httpd
[root@hf-01 ~]#

29.這時再來刷新瀏覽器,會發現都變成OK了php

輸入圖片說明

30.這時再來 Next step ,來配置數據庫相關信息mysql

  • host :MySQL所在機器IP
  • port:0爲默認端口3306,若是有改動就修改
  • name:庫的名字
  • user:庫的用戶
  • password:用戶的密碼

輸入圖片說明

  1. 而後再選擇Next step ,配置站點名字相關

輸入圖片說明

  • host:站點主機名
  • port:端口,若是有改動就改,沒改動,默認就是10051
  • name:站點的名字,你喜歡就好
  1. 配置完成後會有一個信息顯示,若是配置錯誤,能夠back返回上一步從新修改

輸入圖片說明

  1. 安裝成功後,會有提示界面,以下圖

輸入圖片說明

  1. 登陸管理頁,默認的帳號是Admin,密碼爲zabbixlinux

  2. 在登陸進zabbix以後,首先須要去更改密碼(由於默認的密碼你們都知道的),如果在線上環境不更改密碼,很容易被別人拿到後臺權限ios

  • 更改密碼,先選擇 Administration ,而後選擇 Users

輸入圖片說明

  • 而後找到Admin,並點進去,選擇 Change password 修改密碼和選擇語言(支持中文),而後保存退出

輸入圖片說明

  • 這時候密碼改了,但看到界面仍是英文版,刷新瀏覽器便可,會看到變成中文版

輸入圖片說明

  • 這時在退出zabbix,再從新進入下,使用新的密碼,會看到從新進入了,這就是zabbix的web界面了

客戶端安裝zabbix(B機器)

  • 在客戶端上也須要下載zabbix的yum源
  • wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  • rpm -ivh zabbix-release-3.2-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=aming-123 //這是自定義的主機名,一會還須要在web界面下設置一樣的主機名
  • systemctl start zabbix-agent
  • systemctl enable zabbix-agent
  1. 首先客戶端下載
B機器
[root@hf-02 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 下載完以後,安裝rpm包(實際上就是安裝了一個yum源倉庫)
B機器
[root@hf-02 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  1. 客戶端,編輯zabbix的配置文件,文件爲/etc/zabbix/zabbix_agentd.conf
B機器
[root@hf-02 ~]# vi /etc/zabbix/zabbix_agentd.conf

Server=192.168.202.130
# 定義服務端的ip(被動模式)

ServerActive=192.168.133.130    
#定義服務端的ip(主動模式)
#這個涉及到一個主動和被動模式;若是這裏不填寫服務中心的IP,那麼就只能使用被動模式;這個IP是主動模式時候用的

Hostname=Zabbix server修改成Hostname=hf-02 
#這是自定義的主機名,一會還須要在web界面下設置一樣的主機名

保存退出
  1. 啓動zabbix服務
[root@hf-02 ~]# systemctl start zabbix-agent
[root@hf-02 ~]#
  1. 客戶端查看zabbix服務,監聽的端口,客戶端監聽的端口是10050
[root@hf-02 ~]# ps aux |grep zabbix
zabbix    2566  0.0  0.1  80592  1280 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    2567  0.0  0.1  80592  1296 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    2568  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    2569  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    2570  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    2571  0.0  0.2  80720  2180 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      2573  0.0  0.0 112664   972 pts/0    R+   13:17   0:00 grep --color=auto zabbix
[root@hf-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:22              0.0.0.0:*               LISTEN      1301/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1997/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2566/zabbix_agentd  
tcp6       0      0 :::22                   :::*                    LISTEN      1301/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1997/master         
tcp6       0      0 :::10050                :::*                    LISTEN      2566/zabbix_agentd  
[root@hf-02 ~]#
  1. 將zabbix加入到啓動列表裏面,讓它開機啓動
  • systemctl enable zabbix-agent
[root@hf-02 ~]# 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@hf-02 ~]#
  1. 這樣客戶端的zabbix就配置完成

19.5 忘記Admin密碼如何作

忘記Admin密碼如何作

  • 進入mysql命令行,選擇zabbix庫
  • mysql -uroot -p zabbix
  • update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;
  • 這樣就更改了Admin用戶的密碼

忘記zabbix密碼

  • 有時由於時間長了,zabbix管理員帳號密碼給忘記了
  • 解決辦法:
    • 重置zabbix密碼,就是直接更改數據庫裏的數據便可
  1. 首先進入到mysql命令行裏面
A機器
[root@hf-01 ~]# mysql -uroot -phanfeng
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 342
Server version: 5.6.35 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>
  1. 使用zabbix庫
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. 查看zabbix相關的表,之後服務器監控的主機越多,那麼這些表會愈來愈大,因此須要去指定合適的監控策略
  • 好比說:數據量須要保存多長時間,那麼在定義這個監控項目的時候就該想到,要保留1個月仍是1年,仍是其餘時間;
  • 好比,監控的站點服務量很大的話,一天就要漲好幾個G,那麼你的服務器磁盤能支持保存多長時間;
show tables;
  1. zabbix的密碼,默認存放的表是users裏面
  2. 查看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.01 sec)

mysql>
  • 須要修改的就是passwd的表
  1. 修改密碼
  • update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;
mysql> update users set passwd=md5('aminglinux') where alias='Admin';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>
  1. 查看錶的狀況
  • select * from users\G;
mysql> select * from users\G;
*************************** 1. row ***************************
        userid: 1
         alias: Admin
          name: Zabbix
       surname: Administrator
        passwd: 683cb8e76a8889fdc5161e3fa7e51f2d
           url: 
     autologin: 1
    autologout: 0
          lang: zh_CN
       refresh: 30
          type: 3
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
*************************** 2. row ***************************
        userid: 2
         alias: guest
          name: 
       surname: 
        passwd: d41d8cd98f00b204e9800998ecf8427e
           url: 
     autologin: 0
    autologout: 900
          lang: en_GB
       refresh: 30
          type: 1
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
2 rows in set (0.00 sec)

ERROR: 
No query specified

mysql>
  1. 修改之後就能夠去嘗試用新密碼登陸zabbix了,這就是充值zabbix管理員密碼
相關文章
相關標籤/搜索