生產中的服務器幾乎是無監控不上線,開源實現方案中,zabbix屬於後起之秀,的確接合zabbix提供的自定義接口可以比較方便的實現高靈活性的監控本身的業務細節,今天就給你們分享一下zabbix監控的搭建過程。
php
[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<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 0mysql
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 0linux
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 0web
[root@monitor_aodun network-scripts]# cdsql
[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/fstabexpress
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=0vim
innodb_file_per_table
skip_name_resolvewindows
event_scheduler=ON
max_allowed_packet=50Mcentos
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 'zabbix@hehegame.com';
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 </usr/share/doc/zabbix-server-mysql-3.2.6/create.sql
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安裝
檢查安裝環境是否知足
填寫對應配置
信息確認頁
成功安裝後的提示信息
使用系統默認帳戶admin以及密碼zabbix登陸zabbix-web-gui
成功登陸後的界面
修改默認語言及默認密碼(新建zabbix系統必定不要忘記修改默認密碼)
修改爲中文後的zabbix面板示例
至此,zabbix服務器端配置基本完成了,後續文章中將爲你們分享如何建立監控項、如何定義觸發器、若是使用報警功能、以及如何使用自寫腳本實現定製業務項監控,直至實現一個完整的監控系統。 喜歡者請點贊加關注,錯誤之處,還請你們留言指正!