生产中的服务器几乎是无监控不上线,开源实现方案中,zabbix属于后起之秀,的确接合zabbix提供的自定义接口能够比较方便的实现高灵活性的监控自己的业务细节,今天就给大家分享一下zabbix监控的搭建过程。
 

第一部分:linux命令行的安装配置

[root@monitor_aodun network-scripts]# vim ifcfg-em2
[root@monitor_aodun network-scripts]# cat ifcfg-em2
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=em2
DEVICE=em2
ONBOOT=no
IPADDR=192.168.193.180
NETMASK=255.255.255.0
[root@monitor_aodun network-scripts]# systemctl restart network
[root@monitor_aodun network-scripts]# ifconfig
em1: flags=4163 mtu 1500
inet 125.211.210.180 netmask 255.255.255.192 broadcast 125.211.210.191
inet6 fe80::d6ae:52ff:fea7:fe62 prefixlen 64 scopeid 0x20
ether d4:ae:52:a7:fe:62 txqueuelen 1000 (Ethernet)
RX packets 41 bytes 8543 (8.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 51 bytes 4058 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

em2: flags=4099 mtu 1500
inet 192.168.193.180 netmask 255.255.255.0 broadcast 192.168.193.255
ether d4:ae:52:a7:fe:63 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 15204 bytes 4227698 (4.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15204 bytes 4227698 (4.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@monitor_aodun network-scripts]# cd

[root@monitor_aodun ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 50G 0 part /
└─sda3 8:3 0 875G 0 part
└─centos-data 253:0 0 875G 0 lvm
[root@monitor_aodun ~]# mkdir /data
[root@monitor_aodun ~]# vim /etc/fstab
[root@monitor_aodun ~]# grep -v ^# /etc/fstab

UUID=017db6f7-0eb3-4047-b55b-c440b37b7036 / xfs defaults 0 0
UUID=541fd7d5-6e18-4d61-a548-58ba6c26e47d /boot xfs defaults 0 0
/dev/centos/data /data xfs defaults 0 0
[root@monitor_aodun ~]# mount -a
[root@monitor_aodun ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 50G 0 part /
└─sda3 8:3 0 875G 0 part
└─centos-data 253:0 0 875G 0 lvm /data
[root@monitor_aodun ~]# mkdir -pv /data/{mysql,log/mariadb}
mkdir: created directory ‘/data/mysql’
mkdir: created directory ‘/data/log’
mkdir: created directory ‘/data/log/mariadb’
[root@monitor_aodun ~]# yum install -y mariadb-server
[root@monitor_aodun ~]# cp /etc/my.cnf{,.bak}
[root@monitor_aodun ~]# vim /etc/my.cnf
[root@monitor_aodun ~]# grep -v ^# /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0

innodb_file_per_table
skip_name_resolve

event_scheduler=ON
max_allowed_packet=50M

open_files_limit=4096
max_connections=500

[mysqld_safe]
log-error=/data/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d
[root@monitor_aodun ~]# chown mysql:mysql /data/mysql/
[root@monitor_aodun ~]# chown mysql:mysql /data/log/mariadb/
[root@monitor_aodun ~]# ll /data/
total 0
drwxr-xr-x. 3 root root 20 May 19 02:11 log
drwxr-xr-x. 2 mysql mysql 6 May 19 02:03 mysql
[root@monitor_aodun ~]# ll /data/log/
total 0
drwxr-xr-x. 2 mysql mysql 6 May 19 02:03 mariadb
[root@monitor_aodun ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 :3306 :
LISTEN 0 100 127.0.0.1:25
:
LISTEN 0 128
:22022 :
LISTEN 0 0 ::1:25 :::
LISTEN 0 128 :::22022 :::

[root@monitor_aodun ~]# mysql_secure_installation
[root@monitor_aodun ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> create database zabbix;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '[email protected]';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for zabbix@localhost;
+---------------------------------------------------------------------------------------------------------------+
| Grants for zabbix@localhost |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO 'zabbix'@'localhost' IDENTIFIED BY PASSWORD 'FD810B324C560D38EB7E4BF80CD5FE680BC507D8' |
| GRANT ALL PRIVILEGES ON zabbix.
TO 'zabbix'@'localhost' |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]>
MariaDB [(none)]> quit
Bye
[root@monitor_aodun ~]# yum install -y zabbix-server-mysql.x86_64 zabbix-get.x86_64
[root@monitor_aodun ~]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-3.2.6
/usr/share/doc/zabbix-server-mysql-3.2.6/AUTHORS
/usr/share/doc/zabbix-server-mysql-3.2.6/COPYING
/usr/share/doc/zabbix-server-mysql-3.2.6/ChangeLog
/usr/share/doc/zabbix-server-mysql-3.2.6/NEWS
/usr/share/doc/zabbix-server-mysql-3.2.6/README
/usr/share/doc/zabbix-server-mysql-3.2.6/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
[root@monitor_aodun ~]# gunzip /usr/share/doc/zabbix-server-mysql-3.2.6/create.sql.gz
[root@monitor_aodun ~]# ll /usr/share/doc/zabbix-server-mysql-3.2.6
total 3832
-rw-r--r--. 1 root root 98 May 5 10:50 AUTHORS
-rw-r--r--. 1 root root 752936 May 5 10:50 ChangeLog
-rw-r--r--. 1 root root 17990 May 5 10:50 COPYING
-rw-r--r--. 1 root root 3137133 May 5 20:23 create.sql
-rw-r--r--. 1 root root 52 May 5 10:50 NEWS
-rw-r--r--. 1 root root 188 May 5 10:50 README
[root@monitor_aodun ~]# mysql -h127.0.0.1 -uzabbix -p zabbix Enter password:
[root@monitor_aodun ~]# mysql -h127.0.0.1 -uzabbix -p zabbix -e 'show tables'
Enter password:
+----------------------------+
| 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 |
+----------------------------+
[root@monitor_aodun ~]# cp /etc/zabbix/zabbix_server.conf{,.bak}
[root@monitor_aodun ~]# vim /etc/zabbix/zabbix_server.conf
[root@monitor_aodun ~]# grep -v "^#" /etc/zabbix/zabbix_server.conf | tr -s "[[:space:]]"
SourceIP=192.168.193.180
LogFile=/data/log/zabbix/zabbix_server.log
PidFile=/var/run/zabbix/zabbix_server.pid
LogFileSize=0
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix#hehegame.com
SNMPTrapperFile=/data/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/data/zabbix/alertscripts
ExternalScripts=/data/zabbix/externalscripts
LogSlowQueries=3000
[root@monitor_aodun ~]#
[root@monitor_aodun ~]# mkdir -pv /data/zabbix/{alertscripts,externalscripts}
mkdir: created directory ‘/data/zabbix’
mkdir: created directory ‘/data/zabbix/alertscripts’
mkdir: created directory ‘/data/zabbix/externalscripts’
[root@monitor_aodun ~]# chown -R zabbix:zabbix /data/zabbix
[root@monitor_aodun ~]# chown -R zabbix:zabbix /data/log/{zabbix,snmptrap}
[root@monitor_aodun ~]# ll /data/log/
total 0
drwxr-xr-x. 2 mysql mysql 24 May 19 02:12 mariadb
drwxr-xr-x. 2 zabbix zabbix 6 May 19 04:00 snmptrap
drwxr-xr-x. 2 zabbix zabbix 6 May 19 04:00 zabbix
[root@monitor_aodun ~]# yum install -y httpd php php-mysql php-mbstring php-gd php-xml php-ldap php-bcmath
[root@monitor_aodun ~]# vim /etc/php.ini
修改date.timezone = Asia/Shanghai
[root@monitor_aodun ~]# yum install -y zabbix-web.noarch zabbix-web-mysql.noarch
[root@monitor_aodun ~]# systemctl start httpd
[root@monitor_aodun ~]# systemctl start zabbix-server
[root@monitor_aodun ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 :3306 :
LISTEN 0 100 127.0.0.1:25
:
LISTEN 0 128
:10051 :
LISTEN 0 128 :22022 :
LISTEN 0 128 :::80 :::

LISTEN 0 100 ::1:25 :::
LISTEN 0 128 :::10051 :::

LISTEN 0 128 :::22022 :::*
[root@monitor_aodun ~]#
 

第二部分:浏览器安装部分

使用浏览器打开server_ip/zabbix/setup.php页面进行zabbix-web-gui安装
zabbix监控——ZABBIX服务器配置过程_第1张图片
检查安装环境是否满足
zabbix监控——ZABBIX服务器配置过程_第2张图片
zabbix监控——ZABBIX服务器配置过程_第3张图片
zabbix监控——ZABBIX服务器配置过程_第4张图片
填写对应配置
zabbix监控——ZABBIX服务器配置过程_第5张图片
zabbix监控——ZABBIX服务器配置过程_第6张图片
信息确认页
zabbix监控——ZABBIX服务器配置过程_第7张图片
成功安装后的提示信息
zabbix监控——ZABBIX服务器配置过程_第8张图片
使用系统默认账户admin以及密码zabbix登录zabbix-web-gui
zabbix监控——ZABBIX服务器配置过程_第9张图片
成功登录后的界面
zabbix监控——ZABBIX服务器配置过程_第10张图片
修改默认语言及默认密码(新建zabbix系统一定不要忘记修改默认密码)
zabbix监控——ZABBIX服务器配置过程_第11张图片
修改成中文后的zabbix面板示例
zabbix监控——ZABBIX服务器配置过程_第12张图片
 
至此,zabbix服务器端配置基本完成了,后续文章中将为大家分享如何创建监控项、如何定义触发器、如果使用报警功能、以及如何使用自写脚本实现定制业务项监控,直至实现一个完整的监控系统。
 
喜欢者请点赞加关注,错误之处,还请大家留言指正!