1 引言
1.1 zabbix監控的優點
1)資料采集:可用性和性能檢測,自動發現,支援agent、snmp、JMX、telnet等多種采集方式,支援主動和被動模式資料傳輸、支援使用者自定義插件,自定義間隔收集資料
2)高可用:server對裝置性能要求低,支援proxy分布式監控,分布式集中管理,有自動發現功能,可以實作自動化監控;開放式接口,擴充性強,插件編寫容易
3)告警管理:支援多條件告警,支援多種告警方式,支援多組模闆,模闆繼承。
4)告警設定:告警周期,告警級别,告警恢複通知、告警暫停,時段門檻值、支援維護周期、支援單機停用
5)圖形化展示:允許自定義建立多監控項視圖,網絡拓撲,自定義面闆展示,自定義IT服務可用性
6)曆史資料:曆史資料查詢可配置,内置housekeeping資料清理機制
7)安全審計:具備安全的使用者審計日志,權限認證,使用者可以限制允許維護的清單。
1.2 zabbix監控的缺點
模版的使用相對複雜
2 安裝部署
部署的環境:
Centos7.7
zabbix-web-3.4.15-1.el7.noarch
zabbix-release-3.4-2.el7.noarch
zabbix-server-mysql-3.4.15-1.el7.x86_64
zabbix-web-mysql-3.4.15-1.el7.noarch
zabbix-agent-3.4.15-1.el7.x86_64
2.1 根據官網部署
1)根據官網部署時出現報錯:
curl#18 - "transfer closed with 35810 bytes remaining to read
多次重複安裝直到complete即可,應該是網速原因
2)官網的架構是LAMP,直接根據依賴安裝,使用的是mariadb。
- Install Zabbix repository
#rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
#yum clean all
- Install Zabbix server, frontend, agent
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
- Create initial database
yum install -y mariadb mariadb-server
systemctl enable mariadb
systemctl start mariadb
mysqladmin password 123456
mysql -uroot -p123456 -e “create database zabbix character set utf8 collate utf8_bin;”
mysql -uroot -p123456 -e ‘grant all privileges on zabbix.* to [email protected] identified by “zabbix”;’
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p123456 zabbix
- Configure the database for Zabbix server
echo “DBPassword=zabbix” >> /etc/zabbix/zabbix_server.conf
- Configure PHP for Zabbix frontend
echo “php_value date.timezone Asia/Shanghai” >> /etc/httpd/conf.d/zabbix.conf
- Start Zabbix server and agent processes
systemctl enable zabbix-server zabbix-agent httpd
systemctl restart zabbix-server zabbix-agent httpd
- 頁面登入配置
- 配置好之後的頁面
2.2 分布式安裝部署
- 第一,安裝前準備
- 安裝依賴包:
yum -y install wget net-snmp-devel OpenIPMI-devel httpd openssl-devel java lrzsz fping-devel libcurl-devel perl-DBI pcre-devel libxml2 libxml2-devel mysql-devel gcc php php-bcmath php-gd php-xml php-mbstring php-ldap php-mysql.x86_64 php-pear php-xmlrpc net-tools wget vim-enhanced
- 關閉防火牆
systemctl disable firewalld.service
systemctl stop firewalld.service
setenforce 0
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/sysconfig/selinux
由于修改了selinux,是以建議重新開機OS
- 添加靜态DNS解析。注意:這個也要在被監控節點上寫,保證DNS解析正常
vim /etc/hosts
172.16.212.129 server
172.16.212.131 node1
- 第二,安裝zabbix-server
- 安裝LAMP環境
1)擷取安裝源:
wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo
2)安裝資料庫和php環境:
yum -y install mariadb mariadb-server php php-mysql httpd
3)初始化資料庫
systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation //此處設定root的資料庫密碼為123456
4)配置zabbix使用的資料庫
mysql -uroot -p123456 -e “create database zabbix default character set utf8 collate utf8_bin;”
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to [email protected]’%’ identified by ‘zabbix’; "
可以測試一下能否連接配接該資料庫:
[[email protected] ~]# mysql -uzabbix -pzabbix
MariaDB [(none)]> show databases;
MariaDB [(none)]> quit
5)配置apache
systemctl enable httpd
systemctl start httpd.service
6)配置zabbix-server
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
cd /usr/share/doc/zabbix-server-mysql-3.4.15
zcat create.sql.gz | mysql -uroot -p123456 zabbix
#vim /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
注意:主要關注DB相關的配置要正确
#vim /etc/httpd/conf.d/zabbix.conf
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/app">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/local">
Require all denied
</Directory>
systemctl enable zabbix-server
systemctl start zabbix-server
systemctl restart httpd
- 第三,配置zabbix頁面
http://zabbix_server_ip/zabbix/setup.php
根據提示設定相關内容,尤其是資料庫資訊要填對!
最後使用預設使用者名和密碼登入 Admin/zabbix
将本身添加到監控項中:
然後就可以看到監控的圖形了:
2.3 新增zabbix-agent
- 關閉防火牆,和上面操作一樣,不再贅述
- 配置yum源和zabbix-agent
#1 配置yum
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
#2 安裝zabbix-agent
yum clean all
yum -y install zabbix zabbix-agent
#3 配置zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
LogRemoteCommands=1
Server=172.16.212.129
ServerActive=172.16.212.129
Hostname=node1
Include=/etc/zabbix/zabbix_agentd.d/*.conf
- 頁面添加監控
- 啟動node1的zabbix-agent
systemctl enable zabbix-agent
systemctl start zabbix-agent
- 最後可以在graphs那裡看到監控的圖形
3 後記問題
1)使用https://www.cnblogs.com/yaoyaojcy/p/9884130.html部署應該也可以。
2)不需要修改agent配置檔案直接啟動zabbix-agent就可以監控zabbix-server自己。