zabbix的部署原理
- zabbix server需要把监控数据入sql数据库,所以需要mysql环境
- zabbix的web是基于php开发的,所以需要lnmp环境
- 部署zabbix server和zabbix web
zabbix server编译安装
server端加参数--enable-agent主要是为了使用工具zabbix_get
yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel
useradd -s /sbin/nologin zabbix
cd /usr/local/src/
wget "https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.4/zabbix-4.4.4.tar.gz"
tar -zxvf zabbix-4.4.4.tar.gz
cd zabbix-4.4.4
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install
编译说明
- --prefix 指定安装目录
- --enable-server 安装zabbix server
- --enable-agent 安装zabbix agent
- --with-mysql 用mysql来存储(如果使用yum安装,则不需要后面的mysql的路径)
zabbix server的安装验证
环境变量设置
echo "export PATH=\$PATH:/usr/local/zabbix/sbin:/usr/local/zabbix/bin" >>/etc/profile && source /etc/profile
查看版本
zabbix_server --version
zabbix server的启动
- 需要到mysql里做数据库的初始化
#mysql数据库初始化
mysql -h 127.0.0.1 -uroot -pzabbixpwd -A
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbixpwd';
flush privileges;
set names utf8;
use zabbix;
source /usr/local/src/zabbix-4.4.4/database/mysql/schema.sql;
source /usr/local/src/zabbix-4.4.4/database/mysql/data.sql;
source /usr/local/src/zabbix-4.4.4/database/mysql/images.sql;
- 配置zabbix server
# 配置文件/usr/local/zabbix/etc/zabbix_server.conf
cat >/usr/local/zabbix/etc/zabbix_server.conf <<EOF
LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpwd
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts #配置告警脚本
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000 #慢查询
# SourceIP= 192.168.x.x #监听地址
EOF
- 启动zabbix server
chown zabbix:zabbix -R /usr/local/zabbix/
zabbix_server
验证
- 进程 ps auxf | grep zabbix_server
- 端口 netstat -tulnp|grep zabbix
- 日志 tail -f /usr/local/zabbix/zabbix_server.log
zabbix web安装
mkdir /usr/local/nginx/html/zabbix
cp -a /usr/local/src/zabbix-4.4.4/frontends/php/* /usr/local/nginx/html/zabbix
zabbix web的配置
php配置
# 配置文件/usr/local/php/etc/php.ini
post_max_size = 32M
max_execution_time = 360
max_input_time = 360
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
#重启php-fpm:
systemctl restart php-fpm
登录
- 初始化配置:http://zabbix服务器IP/zabbix
Database type:MySQL
Database host:127.0.0.1
Database port:3306
Database name:zabbix
User:zabbix
Password:zabbixpwd
下载配置文件,保存在/usr/local/nginx/html/zabbix/conf/zabbix.conf.php
- 默认用户名密码:Admin zabbix
- 禁用Zabbix server主机的监控
Hosts-->选中zabbix server -->点击disable
- 禁用guest用户(只能设置用户组权限)
Administration-->Users groups-->选中Guests-->disable
- 更改Admin的密码