一、zabbix簡介
zabbix是一個基于WEB界面的提供分布式系統(tǒng)監(jiān)視以及網(wǎng)絡監(jiān)視功能的企業(yè)級的開源解決方案。
zabbix能監(jiān)視各種網(wǎng)絡參數(shù),保證服務器系統(tǒng)的安全運營;并提供靈活的通知機制以讓系統(tǒng)管理員快速定位/解決存在的各種問題。
zabbix由2部分構成,zabbix server與可選組件zabbix agent。
zabbix server可以通過SNMP,zabbix agent,ping,端口監(jiān)視等方法提供對遠程服務器/網(wǎng)絡狀態(tài)的監(jiān)視,數(shù)據(jù)收集等功能,可以運行在眾多平臺上。
二、實驗環(huán)境
操作系統(tǒng): CentOS7.5 Minimal
zabbixServer: 192.168.1.104
zabbixAgent: 192.168.1.104 192.168.1.105
三、編譯工具和基礎組件安裝
zabbix的安裝需要LAMP環(huán)境
# yum -y ?install epel-release
# yum -y ?install gcc ?gcc-c++
# yum ?-y ?install?php php-gd php-mysql php-bcmath php-mbstring php-xml? net-snmp? perl-DBI
#? yum -y ?install ? httpd
#? yum -y ?install ?mariadb ?mariadb-server??
# yum? -y install? ?mariadb-devel? net-snmp-devel? ?libxml2-devel? libevent-devel??curl-devel
四、創(chuàng)建程序運行用戶
#?groupadd -r? zabbix
#?useradd? ?-r? -g? zabbix? -s? /sbin/nologin? ?-M? zabbix
五、數(shù)據(jù)庫mariadb的配置
啟動數(shù)據(jù)庫
# systemctl start mariadb.service
# systemctl enable mariadb.service
# systemctl status mariadb.service
配置數(shù)據(jù)庫管理員root密碼
# mysql_secure_installation
設置的root密碼為 MySQL@123
# mysql -u root? ?-h 127.0.0.1? -p"MySQL@123"
創(chuàng)建zabbix用戶和數(shù)據(jù)庫
# mysql -u root -p"MySQL@123" -e "create database if not exists zabbix default character set utf8 collate utf8_general_ci;"
# mysql -u root -p"MySQL@123" -e "grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix';"
# mysql -u root -p"MySQL@123" -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';"
# mysql -u root -p"MySQL@123" -e "grant all privileges on zabbix.* to zabbix@'192.168.1.104' identified by 'zabbix';"
# mysql -u root -p"MySQL@123" -e "flush privileges;"
# mysql -u root -p"MySQL@123" -e "show databases;"
# mysql -u root -p"MySQL@123" -e "select user,host from mysql.user;"
六、zabbix的編譯安裝
①下載并進行編譯安裝
# yum? -y install wget?
# wget http://soft.xiaoz.org/linux/zabbix-3.4.4.tar.gz
# tar? zxvf zabbix-3.4.4.tar.gz
# cd zabbix-3.4.4
# ./configure? --prefix=/usr/local/zabbix? ?\
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-net-snmp ?\
--enable-server \
--enable-agent?
# make
# make install
#? ll? /usr/local/zabbix
# /usr/local/zabbix/sbin/zabbix_server --help
# /usr/local/zabbix/sbin/zabbix_agentd --help
②導入數(shù)據(jù)庫
# ll zabbix-3.4.4/database/mysql/
# mysql -u root -p"MySQL@123"? -D zabbix? ?-e? "source ?/root/zabbix-3.4.4/database/mysql/schema.sql"
# mysql -u root -p"MySQL@123"? -D zabbix? ? -e? "source ?/root/zabbix-3.4.4/database/mysql/images.sql"
# mysql -u root -p"MySQL@123"? ?-D zabbix? ?-e? "source ?/root/zabbix-3.4.4/database/mysql/data.sql"
注:導入請按以上順序,否則會出現(xiàn)錯誤!
# mysql -u root -p"MySQL@123" -D zabbix -e "show tables;"
七、 配置zabbixServer和zabbixAgent
注意:配置文件=后面的字符串不能加引號
修改zabbixServer的配置文件zabbix_server.conf
# vim? /usr/local/zabbix/etc/zabbix_server.conf
# cat ?/usr/local/zabbix/etc/zabbix_server.conf | grep -Ev "^#|^$"
######################################################
LogFile=/tmp/zabbix_server.log ? ? ? ? ? ? ? ? ? ? ? ? ?
#日志文件地址,默認不用更改
DBHost=localhost ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
#數(shù)據(jù)庫主機IP,我們前面授權了127.0.0.1(localhost)和本機IP 192.168.1.104,或者寫0.0.0.0
DBName=zabbix ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
#zabbix數(shù)據(jù)庫名
DBUser=zabbix ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
#zabbix數(shù)據(jù)庫用戶名
DBPassword=zabbix ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
#zabbix數(shù)據(jù)庫密碼
ListenIP=127.0.0.1,192.168.1.104? ? ? ? ? ? ? ? ? ? ?
?#服務監(jiān)聽IP,寫127.0.0.1和本機IP,如果只寫127.0.0.1,那么其他主機的agent無法連接server
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
#zabbix運行腳本存放目錄
#####################################################
修改zabbixAgent的配置文件zabbix_agentd.conf
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -Ev "^#|^$"
###################################################
PidFile=/tmp/zabbix_agentd.pid? ? ? ? ? ? ? ? ? ? ??
#進程PID
LogFile=/tmp/zabbix_agentd.log? ? ? ? ? ? ? ? ? ? ?
#日志保存位置
EnableRemoteCommands=1? ? ? ? ? ? ? ? ? ? ? ? ??
#允許執(zhí)行遠程命令
Server=127.0.0.1,192.168.1.104? ? ? ? ? ? ? ? ? ? ?
#zabbix被動模式指明zabbixServer的IP ,授權zabbixServer能從zabbixAgent抓取監(jiān)控數(shù)據(jù)
ServerActive=127.0.0.1,192.168.1.104
#zabbix主動模式指明zabbixServer的IP ,指明zabbixAgent將抓取的監(jiān)控數(shù)據(jù)推送到zabbixServer的地址,如果zabbixAgent與zabbixServer不再同一臺服務器或者zabbixServer沒有監(jiān)聽127.0.0.1,不能寫127.0.0.1
Hostname=zabbixServer? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
#在web端添加監(jiān)控主機時,必須與zabbix創(chuàng)建的hostname相同
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/? ?
#添加在定義Key時,存放的位置
UnsafeUserParameters=1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
#啟用自定義key
#########################################################
八、添加zabbix啟動腳本?
# cp? zabbix-3.4.4/misc/init.d/fedora/core5/zabbix_server? ? ? /etc/init.d/zabbix_server
# cp? zabbix-3.4.4/misc/init.d/fedora/core5/zabbix_agentd? ? ?/etc/init.d/zabbix_agentd
# ll? /etc/init.d/??
?# vim? /etc/init.d/zabbix_server?
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
?# vim? /etc/init.d/zabbix_agentd?
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
# chkconfig ?--add??zabbix_server
# chkconfig ?--add??zabbix_agentd
# chkconfig ?zabbix_server on
# chkconfig ??zabbix_agentd on
啟動服務,查看監(jiān)聽端口
# systemctl start??zabbix_server??
# systemctl start??zabbix_agent?
# systemctl enable zabbix_server??
# systemctl enable? zabbix_agent?
# systemctl status zabbix_server??
# systemctl status? zabbix_agent?
# ss? -tan? ??
zabbbixServer 監(jiān)聽端口: 10051
zabbixAgent監(jiān)聽端口:10050
http監(jiān)聽端口:80
mariadb監(jiān)聽端口:3306
查看服務啟動日志
# tail -f /tmp/zabbix_server.log
# tail -f /tmp/zabbix_agentd.log
六、修改PHP相關參數(shù)
# vim /etc/php.ini
##########################
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai
post_max_size = 28M
#############################
# yum -y install php-ldap
# rpm -ql? php-ldap
# echo "extension=ldap.so" >> /etc/php.ini
七、配置web站點
① 拷貝web文件,更改權限
# cp? -r? zabbix-3.4.4/frontends/php? ? /var/www/html/zabbix
# chown? ? -R? ? apache:apache? ? /var/www/html/zabbix
②修改httpd.conf的參數(shù)
# vim /etc/httpd/conf/httpd.conf
? DirectoryIndex index.html index.php
③關閉SELinux
# sed? -i 's/SELINUX=enforcing/SELINUX=permissive/'? ? ?/etc/selinux/config
#? setenforce 0
# systemctl start httpd.service
# systemctl enable??httpd.service
# systemctl status httpd.service
設置防火墻策略,放行相關端口
如果使用firewalld(默認):
# systemctl? start firewalld
# systemctl enable firewalld?
# systemctl status firewalld?
#?firewall-cmd? --zone=public? --add-port=10051/tcp? --permanent
#?firewall-cmd? --zone=public? --add-port=80/tcp? --permanent
# firewall-cmd --reload
如果使用iptables:
# yum? -y install iptables? iptables-services
# iptables -A INPUT -p tcp ?--dport 10051 -m state --state NEW,ESTABLISHED ?-j ACCEPT
# iptables -A INPUT -p tcp ?--dport 80 -m state --state NEW,ESTABLISHED ?-j ACCEPT
# service iptables save
瀏覽器訪問:http://192.168.1.104/zabbix
默認管理員賬號密碼:admin/zabbix
現(xiàn)在zabbix server和 server端的agent安裝完成了,添加模板,開啟了zabbixServer本機監(jiān)控。
八、在其他服務器上安裝zabbixAgent
在zabbixServer端:
# scp -r? /usr/local/zabbix root@192.168.1.105:/usr/local/
# scp /etc/init.d/zabbix_agentd root@192.168.1.105:/etc/init.d/
在zabbixAgent(192.168.1.105)端:
#? rm? -rf??/usr/local/zabbix/sbin/zabbix_server
# rm? -rf? ?/usr/local/zabbix/etc/zabbix_server.conf*
#?groupadd -r? zabbix
#?useradd? ?-r? -g? zabbix? -s? /sbin/nologin? ?-M? zabbix
# vim? ?/usr/local/zabbix/etc/zabbix_agentd.conf
# cat? ?/usr/local/zabbix/etc/zabbix_agentd.conf | grep? -Ev "^#|^$"
###################################################
PidFile=/tmp/zabbix_agentd.pid? ? ? ? ? ? ? ? ? ? ??
#進程PID
LogFile=/tmp/zabbix_agentd.log? ? ? ? ? ? ? ? ? ? ?
#日志保存位置
EnableRemoteCommands=1? ? ? ? ? ? ? ? ? ? ? ? ??
#允許執(zhí)行遠程命令
Server=192.168.1.104? ? ? ? ? ? ??
#zabbix被動模式指明zabbixServer的IP ,授權zabbixServer能從zabbixAgent抓取監(jiān)控數(shù)據(jù)
ServerActive=192.168.1.104
#zabbix主動模式指明zabbixServer的IP ,指明zabbixAgent將抓取的監(jiān)控數(shù)據(jù)推送到zabbixServer的地址,如果zabbixAgent與zabbixServer不再同一臺服務器或者zabbixServer沒有監(jiān)聽127.0.0.1,不能寫127.0.0.1
Hostname=zabbixAgent ? ? ? ? ? ? ? ? ? ? ? ? ? ?
#在web端添加監(jiān)控主機時,必須與zabbix創(chuàng)建的hostname相同
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/? ?
#添加在定義Key時,存放的位置
UnsafeUserParameters=1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
#啟用自定義key
#########################################################
# chkconfig ?--add??zabbix_agentd
# chkconfig ??zabbix_agentd? on
# systemctl start??zabbix_agent
# systemctl enable? zabbix_agent?
# systemctl status? zabbix_agent?
設置防火墻策略,放行相關端口
如果使用firewalld(默認):
# systemctl start firewalld
# systemctl? enable firewalld
#?firewall-cmd? --zone=public? --add-port=10050/tcp? --permanent
# firewall-cmd --reload
如果使用iptables:
# yum? -y install iptables? iptables-services
# iptables -A INPUT -p tcp ?--dport 10050 -m state --state NEW,ESTABLISHED ?-j ACCEPT
# iptables -A INPUT -p tcp ?--dport 10051 -m state --state NEW,ESTABLISHED ?-j ACCEPT
# service iptables save
從zabbixAgent測試到zabbixServer的端口連通性
# echo > /dev/tcp/192.168.1.104/80
# echo > /dev/tcp/192.168.1.104/10051
#? tail -f /tmp/zabbix_agentd.log
九、在zabbixServer添加對zabbixAgent的監(jiān)控
從zabbixServert測試到zabbixAgent的端口連通性
# echo > /dev/tcp/192.168.1.104/50
十、參考
編譯安裝zabbix
https://www.lucissfer.com/2016/06/20/zabbix+install
https://www.zabbix.com/documentation/3.4/zh/manual/installation/install
源碼安裝zabbix3.2.7時PHP ldap Warning
https://www.cnblogs.com/me80/p/7410958.html
Server missing “l(fā)dap.so”
https://stackoverflow.com/questions/20130796/server-missing-ldap-so