生产中的服务器几乎是无监控不上线,开源实现方案中,zabbix属于后起之秀,的确接合zabbix提供的自定义接口能够比较方便的实现高灵活性的监控自己的业务细节,今天就给大家分享一下zabbix监控的搭建过程。
??
第一部分:linux命令行的安装配置
[[email protected]_aodun network-scripts]# vim ifcfg-em2
[[email protected]_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
[[email protected]_aodun network-scripts]# systemctl restart network
[[email protected]_aodun network-scripts]# ifconfig
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> 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<link>
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<UP,BROADCAST,MULTICAST> 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<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
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
[[email protected]_aodun network-scripts]# cd
[[email protected]_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
[[email protected]_aodun ~]# mkdir /data
[[email protected]_aodun ~]# vim /etc/fstab
[[email protected]_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
[[email protected]_aodun ~]# mount -a
[[email protected]_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
[[email protected]_aodun ~]# mkdir -pv /data/{mysql,log/mariadb}
mkdir: created directory ‘/data/mysql’
mkdir: created directory ‘/data/log’
mkdir: created directory ‘/data/log/mariadb’
[[email protected]_aodun ~]# yum install -y mariadb-server
[[email protected]_aodun ~]# cp /etc/my.cnf{,.bak}
[[email protected]_aodun ~]# vim /etc/my.cnf
[[email protected]_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
[[email protected]_aodun ~]# chown mysql:mysql /data/mysql/
[[email protected]_aodun ~]# chown mysql:mysql /data/log/mariadb/
[[email protected]_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
[[email protected]_aodun ~]# ll /data/log/
total 0
drwxr-xr-x. 2 mysql mysql 6 May 19 02:03 mariadb
[[email protected]_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 :::
[[email protected]_aodun ~]# mysql_secure_installation
[[email protected]_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 [email protected] identified by ‘[email protected]‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show grants for [email protected];
+---------------------------------------------------------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------------------------------------------------------+
| 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
[[email protected]_aodun ~]# yum install -y zabbix-server-mysql.x86_64 zabbix-get.x86_64
[[email protected]_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
[[email protected]_aodun ~]# gunzip /usr/share/doc/zabbix-server-mysql-3.2.6/create.sql.gz
[[email protected]_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
[[email protected]_aodun ~]# mysql -h127.0.0.1 -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-3.2.6/create.sql
Enter password:
[[email protected]_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 |
+----------------------------+
[[email protected]_aodun ~]# cp /etc/zabbix/zabbix_server.conf{,.bak}
[[email protected]_aodun ~]# vim /etc/zabbix/zabbix_server.conf
[[email protected]_aodun ~]# grep -v ^# /etc/zabbix/zabbix_server.conf | tr -s [[:space:]]
SourceIP=192.168.193.180br/>LogFile=/data/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
[email protected]
SNMPTrapperFile=/data/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/data/zabbix/alertscripts
ExternalScripts=/data/zabbix/externalscripts
LogSlowQueries=3000
[[email protected]_aodun ~]#
[[email protected]_aodun ~]# mkdir -pv /data/zabbix/{alertscripts,externalscripts}
mkdir: created directory ‘/data/zabbix’
mkdir: created directory ‘/data/zabbix/alertscripts’
mkdir: created directory ‘/data/zabbix/externalscripts’
[[email protected]_aodun ~]# chown -R zabbix:zabbix /data/zabbix
[[email protected]_aodun ~]# chown -R zabbix:zabbix /data/log/{zabbix,snmptrap}
[[email protected]_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
[[email protected]_aodun ~]# yum install -y httpd php php-mysql php-mbstring php-gd php-xml php-ldap php-bcmath
[[email protected]_aodun ~]# vim /etc/php.ini
修改date.timezone = Asia/Shanghai
[[email protected]_aodun ~]# yum install -y zabbix-web.noarch zabbix-web-mysql.noarch
[[email protected]_aodun ~]# systemctl start httpd
[[email protected]_aodun ~]# systemctl start zabbix-server
[[email protected]_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 :::*
[[email protected]_aodun ~]#
?
第二部分:浏览器安装部分
使用浏览器打开server_ip/zabbix/setup.php页面进行zabbix-web-gui安装
检查安装环境是否满足
填写对应配置
信息确认页
成功安装后的提示信息
使用系统默认账户admin以及密码zabbix登录zabbix-web-gui
?
至此,zabbix服务器端配置基本完成了,后续文章中将为大家分享如何创建监控项、如何定义触发器、如果使用报警功能、以及如何使用自写脚本实现定制业务项监控,直至实现一个完整的监控系统。
??
喜欢者请点赞加关注,错误之处,还请大家留言指正!
原文地址:http://blog.51cto.com/183530300/2085790