一、zabbix簡介
zabbix是一個基於WEB界面的提供分佈式系統監視以及網絡監視功能的企業級的開源解決方案
二、安裝前提
1.關閉selinux
2.關閉防火牆
3.節點情況
三、安裝環境
1.安裝mariadb數據庫
1)獲取mariadb的yum源(中科大yum源)
vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
2)安裝mariadb及依賴包
yum -y install MariaDB-server MariaDB-client MariaDB-devel
2.安裝httpd和PHP
yum -y install httpd php
3.安裝PHP插件
yum install -y php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix
4.修改httpd配置文件,使其支持PHP
vim /etc/httpd/conf.d/php.conf
添加:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
5.啓動httpd,測試PHP
1)編寫測試網頁
vim /var/www/html/index.php
<?php
phpinfo()
?>
2)瀏覽器訪問
6.啓動mariadb,測試httpd、PHP、mariadb的協同
1)初始化數據庫
mysql_secure_installation
2)編寫測試網頁
vim /var/www/html/test.php
<?php
$link=mysql_connect("localhost","root","密碼");
if($link){echo "ok!!!!!";}else{echo "error";}
?>
顯示ok成功,error則是錯誤
四、安裝zabbix
1.獲取zabbix yum源(阿里雲)
vim /etc/yum.repo.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
下載祕鑰
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
2.安裝
yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
3.創建數據庫
mysql -uroot -p123456
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
4.導入表
cd /usr/share/doc/zabbix-server-mysql-3.2.10/
gunzip create.sql.gz
mysql -uroot -p123456
use zabix;
source create.sql
5.修改配置文件
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix 數據庫名
DBUser=zabbix 數據庫用戶名
DBPassword=123456 數據庫密碼
DBSocket=/var/lib/mysql/mysql.sock
6.啓動zabbix並設置開機啓動
systemctl start zabbix-server
systemctl start zabbix-agent
systemctl enable zabbix-server
systemctl enable zabbix-agent
7.修改PHP時區
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
8.重啓httpd
9.登錄zabbix網頁
master IP/zabbix
截圖是用的以前做的3.4的截圖,但安裝都相同
配置數據庫
開始安裝
登錄,默認賬號Admin,密碼zabbix
五、使用zabbix
1.添加被控主機
被控端安裝zabbix-agent
1)從監控主機獲取yum源和祕鑰
scp [email protected]:/etc/yum.repos.d/zabbix.repo /etc/yum.repo.d/
scp [email protected]:/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX /etc/pki/rpm-gpg/
scp [email protected]:/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 /etc/pki/rpm-gpg/
2)安裝zabbix-agent
yum -y install zabbix-agent
3)修改zabbix-agent的配置文件
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.110.150
#98行 zaibbix-server的IP
ServerActive=192.168.110.150
#139行啓動 zabbix-server的IP
4)啓動zabbix-agent
systemctl start zabbix-agent
systemctl enable zabbix-agent
5)添加被控主機
6)在模板中選擇要監控的服務
2.解決亂碼問題
從Windows的字體文件複製到監控主機的/usr/share/zabbix/assets/fonts/目錄,並將文件名改爲監控主機上原有的文件名,刷新網頁即可