cacti、nagios、zabbix、smokeping、open-falcon等等。
cacti、smokeping偏向於基礎監控,成圖漂亮。
cacti、nagios、zabbix服務端監控中心,須要php環境支持,其中zabbix和cacti都須要mysql做爲數據存儲,nagios不用存儲歷史數據,注重服務或者監控項的狀態;zabbix會獲取服務或者監控項目的數據從而能夠成圖,zabbix把數據記錄到數據庫裏,支持歷史數據查詢,並且zabbix能夠很是方便的自定義監控項目。
open-falcon爲小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究。
本節學習以zabbix爲例。php
zabbix基於C++開發,是C/S(client/server)架構,即分爲客戶端和服務端,單個服務端節點能夠支持上萬臺客戶端,監控中心支持web UI(web界面)配置和管理。
查看zabbix官方文檔:https://www.zabbix.com/manuals 是學習zabbix的最好途徑。html
zabbix整個體系架構中有如下5個主要角色:mysql
兩臺機器:一臺做爲server(IP:192.168.230.135),一臺做爲client(IP:192.168.230.145),均安裝zabbix,server上安裝數據庫(安裝方法見:https://my.oschina.net/u/3497124/blog/1488479 )。linux
可使用yum安裝zabbix,版本是3.2。在此使用zabbix官方提供的對應版本的yum源安裝較新版本的zabbix。ios
安裝zabbix以前須要先安裝其yum源倉庫。 下載zabbix的yum源倉庫: [root@cham002 ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm [root@cham002 ~]# 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@cham002 ~]# cat /etc/yum.repos.d/ CentOS-Base.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 安裝yum源倉庫: [root@cham002 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm 警告:zabbix-release-3.2-1.el7.noarch.rpm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY 準備中... ################################# [100%] 正在升級/安裝... 1:zabbix-release-3.2-1.el7 ################################# [100%] 安裝zabbix及其組件: [root@cham002 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql #zabbix-agent:客戶端程序 #zabbix-get:服務端上命令行獲取客戶端檢測項目的工具 #zabbix-server-mysql:zabbix-server MySQL版 #zabbix-web:web界面 #zabbix-web-mysql:web界面MySQL相關 注:該過程會連帶安裝PHP和http。
•若是mysql以前沒有安裝的話,須要根據lamp那一章的mysql安裝方法安裝mysqlnginx
檢測mysql有沒有啓動,沒有的話啓動 [root@cham002 ~]# ps aux |grep mysql root 3512 0.0 0.1 113268 1496 ? S 1月24 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/cham002.pid mysql 3672 0.1 44.5 1189812 448836 ? Sl 1月24 1:30 /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/cham002.err --pid-file=/data/mysql/cham002.pid --socket=/tmp/mysql.sock root 51627 0.0 0.0 112684 976 pts/2 S+ 01:27 0:00 grep --color=auto mysql
配置mysql:web
[root@cham002 ~]# vim /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] character_set_server = utf8 #增長這一行,#設置默認字符集--目的是輔助web界面中文顯示 datadir=/data/mysql socket=/tmp/mysql.sock server-id=135 log_bin=chamlinux1 # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES :wq 重啓mysql [root@cham002 ~]# /etc/init.d/mysqld restart Shutting down MySQL.... SUCCESS!
建立數據庫: sql
[root@cham002 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 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> 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 '123456'; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
向zabbix數據庫中導入原始數據: 數據庫
[root@cham002 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/ [root@cham002 zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog COPYING create.sql.gz NEWS README [root@cham002 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz [root@cham002 zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog COPYING create.sql NEWS README [root@cham002 zabbix-server-mysql-3.2.11]# mysql -uroot -pchampin zabbix < create.sql Warning: Using a password on the command line interface can be insecure. #可能數據量比較大,須要等待 [root@cham002 zabbix-server-mysql-3.2.11]#
啓動zabbix服務: vim
[root@cham002 zabbix-server-mysql-3.2.11]# cd [root@cham002 ~]# systemctl start zabbix-server [root@cham002 ~]# start httpd^C 先檢查nginx [root@cham002 ~]# 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 1995/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2173/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2492/master tcp 0 0 0.0.0.0:43998 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:51879 0.0.0.0:* LISTEN 1226/rpc.statd tcp6 0 0 :::3306 :::* LISTEN 51877/mysqld tcp6 0 0 :::33324 :::* LISTEN 1226/rpc.statd tcp6 0 0 :::37486 :::* LISTEN - tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::20048 :::* LISTEN 1995/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 2173/sshd tcp6 0 0 ::1:25 :::* LISTEN 2492/master tcp6 0 0 :::2049 :::* LISTEN - [root@cham002 ~]# systemctl start httpd [root@cham002 ~]# 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 1995/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2173/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2492/master tcp 0 0 0.0.0.0:43998 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:51879 0.0.0.0:* LISTEN 1226/rpc.statd tcp6 0 0 :::3306 :::* LISTEN 51877/mysqld tcp6 0 0 :::33324 :::* LISTEN 1226/rpc.statd tcp6 0 0 :::37486 :::* LISTEN - tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 52138/httpd tcp6 0 0 :::20048 :::* LISTEN 1995/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 2173/sshd tcp6 0 0 ::1:25 :::* LISTEN 2492/master tcp6 0 0 :::2049 :::* LISTEN - 能夠對zabbix、http等服務設置開機啓動: [root@cham002 ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@cham002 ~]# 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@cham002 ~]# systemctl disable nginx [root@cham002 ~]# ps aux |grep zabbix zabbix 51942 0.0 0.3 256080 3460 ? S 01:55 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf root 52251 0.0 0.0 112680 976 pts/2 S+ 02:23 0:00 grep --color=auto zabbix 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 1995/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2173/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2492/master tcp 0 0 0.0.0.0:43998 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:51879 0.0.0.0:* LISTEN 1226/rpc.statd tcp6 0 0 :::3306 :::* LISTEN 51877/mysqld tcp6 0 0 :::33324 :::* LISTEN 1226/rpc.statd tcp6 0 0 :::37486 :::* LISTEN - tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 52138/httpd tcp6 0 0 :::20048 :::* LISTEN 1995/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 2173/sshd tcp6 0 0 ::1:25 :::* LISTEN 2492/master tcp6 0 0 :::2049 :::* LISTEN -
至此,檢查zabbix服務狀態(ps,netstat)發現,服務啓動了,可是沒有監聽端口,狀態不正常,進行錯誤排查:
查看zabbix日誌:
[root@cham002 ~]# less /var/log/zabbix/zabbix_server.log 51942:20180125:015502.033 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解決辦法:
更改zabbix配置文件。
### 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=localhost DBHost=127.0.0.1 ### Option: DBName # Database name. # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored. # # Mandatory: yes # Default: # DBName= DBName=zabbix ### Option: DBSchema # Schema name. Used for IBM DB2 and PostgreSQL. # # Mandatory: no # Default: # DBSchema= ### Option: DBUser # Database user. Ignored for SQLite. # # Mandatory: no # Default: # DBUser= DBUser=zabbix DBPassword=cham-zabbix
[root@cham002 zabbix-server-mysql-3.2.11]# ps aux |grep zabbix zabbix 3981 0.0 0.4 256260 4124 ? S 22:59 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf zabbix 3983 0.0 0.2 256260 2472 ? S 22:59 0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes] zabbix 3984 0.0 0.2 256260 2680 ? S 22:59 0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.001111 sec, idle 60 sec] zabbix 3985 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 3986 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 3987 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 3988 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000003 sec, idle 5 sec] zabbix 3989 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 3990 0.0 0.5 363204 5196 ? S 22:59 0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 3991 0.0 0.3 256260 3588 ? S 22:59 0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection] zabbix 3992 0.0 0.3 256260 3588 ? S 22:59 0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection] zabbix 3993 0.0 0.3 256260 3588 ? S 22:59 0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection] zabbix 3994 0.0 0.3 256260 3588 ? S 22:59 0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection] zabbix 3995 0.0 0.3 256260 3536 ? S 22:59 0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection] zabbix 3996 0.0 0.2 258836 2612 ? S 22:59 0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000003 sec, idle 5 sec] zabbix 3997 0.0 0.2 256260 2688 ? S 22:59 0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.000387 sec, idle 30 sec] zabbix 3998 0.0 0.2 256260 2468 ? S 22:59 0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes] zabbix 3999 0.0 0.2 256340 2920 ? S 22:59 0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000056 sec, 0 maintenances in 0.000786 sec, idle 30 sec] zabbix 4000 0.0 0.2 256260 2824 ? S 22:59 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000397 sec, idle 5 sec] zabbix 4001 0.0 0.4 360620 5032 ? S 22:59 0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000294 sec, idle 60 sec] zabbix 4002 0.0 0.2 256260 2812 ? S 22:59 0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000001 sec, idle 1 sec] zabbix 4003 0.0 0.2 256260 2812 ? S 22:59 0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000001 sec, idle 1 sec] zabbix 4004 0.0 0.2 256260 2812 ? S 22:59 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000001 sec, idle 1 sec] zabbix 4005 0.0 0.2 256260 2812 ? S 22:59 0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000001 sec, idle 1 sec] zabbix 4006 0.0 0.3 256260 3768 ? S 22:59 0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.000717 sec, idle 3 sec] zabbix 4007 0.0 0.3 256260 3768 ? S 22:59 0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000002 sec, idle 5 sec] zabbix 4008 0.0 0.2 256260 2580 ? S 22:59 0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000003 sec, idle 1 sec] zabbix 4009 0.0 0.2 256260 2800 ? S 22:59 0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000322 sec, idle 5 sec] root 4029 0.0 0.0 112684 976 pts/0 S+ 23:00 0:00 grep --color=auto zabbix [root@cham002 zabbix-server-mysql-3.2.11]# [root@cham002 zabbix-server-mysql-3.2.11]# !net 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:47755 0.0.0.0:* LISTEN 2447/rpc.statd 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 2448/rpc.mountd tcp 0 0 0.0.0.0:43862 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2443/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2646/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 3981/zabbix_server tcp6 0 0 :::3306 :::* LISTEN 2428/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 1286/httpd tcp6 0 0 :::20048 :::* LISTEN 2448/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 2443/sshd tcp6 0 0 ::1:25 :::* LISTEN 2646/master tcp6 0 0 :::35905 :::* LISTEN - tcp6 0 0 :::2049 :::* LISTEN - tcp6 0 0 :::53154 :::* LISTEN 2447/rpc.statd tcp6 0 0 :::10051 :::* LISTEN 3981/zabbix_server
啓動完成後查看其狀態(ps、netstat),正常(服務端zabbix默認監聽10051端口)!
使用瀏覽器訪問server機器上的IP:192.168.230.135/zabbix(進行該操做前保證server已關閉防火牆)進入安裝引導界面。
點擊「Next step」進入檢測界面:
錯誤: 此處有錯誤提示,意識是PHP沒法識別「data.timezone」(時區)。
[root@cham002 ~]# vim /etc/php.ini date.timezone = Asia/Shanghai [root@cham002 ~]# systemctl restart httpd
刷新
點擊「Next step」
確認信息
安裝成功
admin
zabbix
更改密碼、Administration/user
change password 順帶能夠改變語言 點擊 update
刷新一下就會變成中文了。這個就是zabbix的web界面了
若是忘記zabbix(web界面)管理員密碼,可經過zabbix服務器的數據庫進行密碼更改!
[root@cham002 ~]# mysql -uroot -pchampin 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 379 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> show tables; #看一看裏面的表內容太多不復制。 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.02 sec) mysql> update users set passwd=md5('champin1') where alias='Admin'; Query OK, 1 row affected (0.00 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 | f0601ca857f5ec53aa98ea2275fea007 | | 1 | 0 | zh_CN | 30 | 3 | default | 0 | 192.168.230.1 | 1517498390 | 50 | | 2 | guest | | | d41d8cd98f00b204e9800998ecf8427e | | 0 | 900 | en_GB | 30 | 1 | default | 0 | | 0 | 50 | +--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+---------------+---------------+---------------+ 2 rows in set (0.00 sec) mysql> quit Bye 如今就能夠用新密碼登陸zabbix了。
[root@test ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm [root@test ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm [root@test ~]# yum install -y zabbix-agent [root@test ~]# vim /etc/zabbix/zabbix_agentd.conf Server=192.168.230.135 #指定服務端主機IP(設置客戶端的監控主機白名單) ServerActive=192.168.230.135 #該參數決定監控的主動/被動模式 #若是隻改參數Server,則只能採用被動模式(只能等待服務端來採集信息) #主動模式:客戶端主動向服務端發送信息 Hostname=test145 #該參數用於設定客戶端主機的名字,用於服務端添加監控服務 #若是服務端所監控的機器和其Hostname不一致,服務端將沒法識別該機器 #由於zabbix是經過IP進行監控的,該參數不會對監控形成太大影響 #加上該參數有利於更好的辨別服務端監控是哪臺主機的狀態 [root@test ~]# systemctl start zabbix-agent [root@test ~]# ps aux |grep zabbix zabbix 54312 0.0 0.1 80592 1276 ? S 23:43 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf zabbix 54313 0.0 0.1 80592 1292 ? R 23:43 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 54314 0.0 0.1 80592 1832 ? S 23:43 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 54315 0.0 0.1 80592 1836 ? S 23:43 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 54316 0.0 0.1 80592 1836 ? S 23:43 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 54317 0.0 0.2 80720 2216 ? S 23:43 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 54320 0.0 0.0 112664 968 pts/1 R+ 23:43 0:00 grep --color=auto zabbix [root@test ~]# 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 2355/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1994/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 54312/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 9547/mysqld tcp6 0 0 :::21 :::* LISTEN 8833/vsftpd tcp6 0 0 :::22 :::* LISTEN 2355/sshd tcp6 0 0 ::1:25 :::* LISTEN 1994/master tcp6 0 0 :::10050 :::* LISTEN 54312/zabbix_agentd 計入開機啓動 [root@test ~]# 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.
查看zabbix服務狀態(ps、netstat),正常(客戶端zabbix默認監聽10050端口)!
•主動或者被動是相對客戶端來說的
• 被動模式,服務端會主動鏈接客戶端獲取監控項目數據,客戶端被動地接受鏈接,並把監控信息傳遞給服務端
• 主動模式,客戶端會主動把監控數據彙報給服務端,服務端只負責接收便可。
• 當客戶端數量很是多時,建議使用主動模式,這樣能夠下降服務端的壓力。
• 服務端有公網ip,客戶端只有內網ip,但卻能連外網,這種場景適合主動模式
主動模式和被動模式所針對的對象是客戶端,意思是客戶端主動向服務端上報數據和由服務端到客戶端採集數據。數據的提交時間在監控中心設置。
採用主動模式能夠減輕服務器的壓力。
當服務端有公網IP,客戶端只有內網IP可是能夠鏈接外網(使用iptables的nat表規則實現),這種場景適合使用主動模式
該配置在服務端的web界面監控中心進行。
登陸到管理界面後操做以下:
而後再添加主機
此配置要客戶端主機名稱(在客戶端zabbix配置文件:/etc/zabbix/zabbix_agentd.conf中的Hostname參數),該名稱要和客戶端配置文件中的名稱一致;指定主機羣組;指定客戶端IP,若是該IP有對應的域名,則須要添加到「DNS名稱」中,若是沒有能夠不填。有須要的話還能夠進行模板、IPMI、宏等配置,配置完成後點擊「添加」,跳轉到主機列表:
參數解析:
在「模板」中自定義監控規則,而後應用到監控主機中,方便個性化管理。
添加模板的思路:建立模板——指定其所屬模板組(也能夠連接到其餘模板)
添加完成後,在zabbix自帶的監控模板template中(此處要對應監控主機系統版本)爲自定義模板添加監控項目,點擊「監控項目」,選擇要監控的項目,而後「複製」到模板「adai」中。
注意: 在此須要選擇目標類型!!!
複製完成後查看模板「test1」:
配置「自動發現規則」 :
此處沒有「複製」選項,那麼該如何將該規則添加到自定義模板中呢?方法以下:
更新完成後,所連接的模板的規則就應用到adai中,可是在該模板下不能直接刪除監控項目,緣由是該項目下全部規則都是連接到template os Linux中的,須要在連接模板選項下設置「取消連接」——「更新」,而後才能對adai中的監控項目等選項進行編輯。
說明: 應用集中包含了全部的監控項,因此只有先刪除監控項以後才能刪除應用集(應用集列表中監控項數目爲0的能夠直接刪除);觸發器是設定的監控項目對應的規則,不能刪;圖形根據需求刪選;這樣自動發現規則就添加到自定義模板中。
模板配置完成後就能夠在監控主機中進行引用了,應用後再進行更加細化的配置。
將自定義模板應用到監控主機adai-02中:
主機——模板——選擇——添加——更新
設置完成後查看圖形——預覽,發現圖形界面下有亂碼:
如何解決此問題呢?
[root@cham002 ~]# vim /usr/share/zabbix/include/defines.inc.php [1]+ 已中止 vim /usr/share/zabbix/include/defines.inc.php #在該文件下搜ZBX_FONTPATH #在參數「define 'ZBX_FONTPATH'」下定義的是相對/usr/share/zabbix/的相對路徑 #相對路徑下是指定的字庫 graphfont.ttf 查看字庫文件: [root@cham002 ~]# ls /usr/share/zabbix/fonts/ graphfont.ttf [root@cham002 ~]# ls -l !$ ls -l /usr/share/zabbix/fonts/ 總用量 0 lrwxrwxrwx 1 root root 33 1月 25 01:24 graphfont.ttf -> /etc/alternatives/zabbix-web-font [root@cham002 ~]# ls -l /etc/alternatives/zabbix-web-font lrwxrwxrwx 1 root root 38 1月 25 01:24 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf [root@cham002 ~]# fg vim /usr/share/zabbix/include/defines.inc.php [1]+ 已中止 vim /usr/share/zabbix/include/defines.inc.php [root@cham002 ~]# ls /root/STKAITI.TTF /root/STKAITI.TTF [root@cham002 ~]# mv /root/STKAITI.TTF /usr/share/zabbix/fonts/ [root@cham002 ~]# cd !$ cd /usr/share/zabbix/fonts/ [root@cham002 fonts]# ls graphfont.ttf STKAITI.TTF [root@cham002 fonts]# mv graphfont.ttf graphfont.ttf.bak ; ln -s STKAITI.TTF graphfont.ttf [root@cham002 fonts]# ls -l 總用量 12440 lrwxrwxrwx 1 root root 11 2月 2 00:34 graphfont.ttf -> STKAITI.TTF lrwxrwxrwx 1 root root 33 1月 25 01:24 graphfont.ttf.bak -> /etc/alternatives/zabbix-web-font -rw-r--r-- 1 root root 12736196 2月 2 00:31 STKAITI.TTF
之因此圖形界面顯示亂碼是由於該字庫不支持中文字體,解決辦法是將該字庫軟連接到一個支持中文的字庫中,在此咱們將其連接到Windows中文字庫:
打開計算機字庫文件目錄C:\Windows\Fonts——複製一款中文字體到桌面——上傳到虛擬機——將該文件移動到:/usr/share/zabbix/fonts/——而後更改該文件名爲zabbix所連接的字庫名稱graphfont.ttf:
顯示正常!!!
更改自動發現規則監控時間間隔:
打開規則:
更改數據更新間隔,重啓服務端和客戶端zabbix服務,查看監控效果,也能夠傳一些數據看看:
在實際應用中時間間隔不要設置過短,一面增長服務器壓力。
在模板——自發現規則——圖形原型中更改: