1、zabbix監(jiān)控
- 監(jiān)控服務器
-- 監(jiān)控服務器可以通過snmp和agent來采集數(shù)據(jù)
-- 數(shù)據(jù)可以寫入MySQL、Oracle數(shù)據(jù)庫中
-- zabbix的頁面采用php
-- 服務器使用lnmp實現(xiàn)web端的管理 - 被監(jiān)控主機
-- 被監(jiān)控主機需要安裝zabbix-agentd端
-- 常見的網(wǎng)絡設備都是支持snmp協(xié)議
2循头、搭建監(jiān)控服務器
2.1艇棕、搭建管理zabbix頁面端的lnmp
- 配置前準備
systemctl stop firewalld
systemctl disable firewalld
setenforce 0 #永久配置修改/etc/selinux/conf文件
- 下載并安裝nginx
#安裝依賴
yum install -y gcc pcre-devel zlib-devel openssl-devel
#下載nginx源碼包
wget http://nginx.org/download/nginx-1.20.2.tar.gz
#解壓nginx并編譯安裝
tar -xvf nginx-1.20.2.tar.gz
cd nginx-1.20.2.tar.gz
./configure --with-http_ssl_module #安裝目錄默認/usr/local/nginx;安裝時會自動加nginx用戶和nginx用戶組,不用額外指定
make && make install
#啟動nginx
/usr/local/nginx/sbin/nginx
#修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
... ...
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
... ...
#重啟nginx
/usr/local/nginx/sbin/nginx -s reload
- 安裝MySQL數(shù)據(jù)庫
#下載MySQL的rpm包
wget https://mirrors.aliyun.com/mysql/MySQL-5.7/mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
#查看系統(tǒng)是否有安裝mariadb。如果有需要卸載,否則會沖突
yum remove -y $(rpm -qa | grep mariadb)
#解壓并安裝
mkdir /opt/mysql
tar -xvf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql
cd /opt/mysql
yum install -y mysql*.rpm
#啟動mysql服務
systemctl start mysqld
#獲取初始密碼
grep "password" /var/log/mysqld.log
#登錄數(shù)據(jù)庫修改數(shù)據(jù)庫密碼
mysql -uroot -p'初始密碼'
#修改密碼策略
mysql> set global validate_password_policy=0; #策略等級
mysql> set global validate_password_length=6; #密碼長度
mysql> alter user root@"localhost" identified by "新密碼";
#重啟mysql來生效MySQL的配置
systemctl restart mysqld
- 安裝php
yum install -y php php-fpm
systemctl start php-fpm
]# netstat -ntlp | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 22146/php-fpm: mast
- 測試lnmp平臺
vim /usr/local/nginx/html/test.php
<?php
$i=100;
echo $i;
?>
#訪問
]# curl http://192.168.2.90/test.php
100
2.2嬉荆、安裝zabbix
- 下載并安裝zabbix5.0.9的源碼包
zabbix5.0.9官方源碼包
#解壓并安裝
tar -xvf zabbix-5.0.9.tar.gz
cd zabbix-5.0.9
./configure --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl #安裝一些zabbix-server所需的功能
make install
#查看zabbix的配置文件目錄
]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_proxy.conf zabbix_proxy.conf.d zabbix_server.conf zabbix_server.conf.d
]# ls /usr/local/bin/
zabbix_get zabbix_js zabbix_sender
#查看zabbix管理服務命令目錄
]# ls /usr/local/sbin/
zabbix_agentd zabbix_proxy zabbix_server
- 創(chuàng)建存儲數(shù)據(jù)的庫、表憎亚、以及zabbix連接數(shù)據(jù)庫服務的用戶
]# mysql -uroot -p'數(shù)據(jù)庫密碼'
#創(chuàng)建一個能夠支持中文的zabbix數(shù)據(jù)庫
mysql> create database zabbix set character utf8 collate utf8_bin;
#授權一個zabbix用戶员寇,本地連接對zabbix庫有所有權限
mysql> grant all on zabbix.* to zabbix@'localhost' identified by '密碼';
mysql > flush privileges;
mysql > set name utf8; #避免數(shù)據(jù)出現(xiàn)亂碼
- 修改zabbix-server的配置文件
cat /usr/local/etc/zabbix_server.conf | grep -v '^#'
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword='前面數(shù)據(jù)庫授權zabbix用戶時所設置的密碼'
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
- 將源碼包中的數(shù)據(jù)導入數(shù)據(jù)庫中
]# cd /root/zabbix-5.0.9/database/mysql/
]# ls
data.sql double.sql images.sql Makefile Makefile.am Makefile.in schema.sql
mysql -uzabbix -p'密碼' zabbix < schema.sql
mysql -uzabbix -p'密碼' zabbix < images.sql
mysql -uzabbix -p'密碼' zabbix < double.sql
mysql -uzabbix -p'密碼' zabbix < data.sql
- 初始化準備
#將源碼包中的所有關于php頁面的文件拷貝到nginx中
cp -a /root/zabbix-5.0.9/ui/* /usr/local/nginx/html
#并將所有文件賦上所有權限
chmod -R 777 /usr/local/nginx/html
#配置nginx弄慰,滿足php腳本的運行環(huán)境
vim /usr/local/nginx/conf/nginx.conf
http {
fastcgi_buffers 8 16k; #緩存php生成的頁面內(nèi)容,8個16k
fastcgi_buffer_size 32k; #緩存php生產(chǎn)的頭部信息
fastcgi_connect_timeout 300; #連接php的超時時間
fastcgi_send_timeout 300; #發(fā)送請求的超時時間
fastcgi_read_timeout 300; #讀取請求的超時時間
... ...
#重新加載nginx配置文件
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
#配置php.ini配置文件
vim /etc/php.ini
date.timezone = Asia/Shanghai #設置時區(qū)
max_execution_time = 300 #最大執(zhí)行時間
post_max_size = 32M #post數(shù)據(jù)最大容量
max_input_time = 300 #服務器接受數(shù)據(jù)的時間限制
systemctl restart php-fpm
- 訪問zabbix頁面蝶锋,并做配置
-- http://IP/setup.php陆爽,環(huán)境檢測
如果訪問頁面時出現(xiàn)“Minimum required PHP version is 7.2.0.”,需要對php進行升級
image.png
-- 連接數(shù)據(jù)庫配置
image.png
-- 監(jiān)控服務的IP地址
image.png
-- 配置摘要
image.png - 安裝完成扳缕,會在/usr/local/nginx/html/conf/目錄下有一個zabbix.conf.php的文件慌闭。前提是對/usr/local/nginx/html/conf/有權限才能保存該配置(前面已經(jīng)對該文件加做了權限賦予)
]# cat /usr/local/nginx/html/conf/zabbix.conf.php
-
登錄頁面
-- 賬號:Admin
-- 密碼:zabbix
-- 登錄后可修改密碼和語言
image.png
-- 此時顯示zabbix_server未啟動
image.png
#啟動zabbix_server服務
#不創(chuàng)建用戶無法啟動服務
[root@zabbix_server ~]# zabbix_server
zabbix_server [1223]: user zabbix does not exist
zabbix_server [1223]: cannot run as root!
[root@zabbix_server ~]# useradd zabbix
]# netstat -ntlp | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 7089/zabbix_server
-- 停止服務
killall -9 zabbix_server