一、概述
Zabbix 是一种开源的监控软件东西,旨在监测和盯梢各种网络服务、服务器和其他 IT 资源的功能和可用性。它用于监测网络设备、服务器硬件、应用程序和其他 IT 基础设施组件的状况。Zabbix 能够监测各种指标,包含 CPU 运用率、内存运用率、磁盘空间、网络流量等等。它支撑多种监控方法,包含 SNMP、JMX、IPMI、SSH 等。Zabbix 还供给了实时监测、历史数据存储、图表和报告生成等功能,以便 IT 运维团队进行功能剖析和毛病排除。由于其灵活性和可扩展性,Zabbix 成为了企业级监控解决方案的主要选择之一。
二、zabbix 装置实战操作
-
操作系统:centos7
-
zabbix版本: 4.4
-
mysql: 5.7.28
1)zabbix server 装置
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum install epel-release numactl
yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf -y
留意:假如呈现yum装置不了,则能够修正**/etc/yum.repos.d/zabbix.repo**
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=http://repo.zabbix.com/zabbix/4.4/rhel/7/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.4/rhel/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
skip_if_unavailable = 1
keepcache = 0
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://repo.zabbix.com/zabbix/4.4/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1
2)mysql 装置
1、前期准备
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /app/
cd /app/
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
mkdir /app/mysql/{data,logs}
groupadd mysql
useradd -g mysql mysql
chown mysql:mysql /app/mysql -R
2、装备mysql 装备文件
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
# 装备账号暗码、ip;完成命令行直接"免暗码"登录
[mysql]
host=192.168.182.132user=zabbixpassword=zabbix[mysqladmin]host=192.168.182.132user=zabbixpassword=zabbix
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /app/mysql
datadir = /app/mysql/data
pid-file = /app/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
log_timestamps=SYSTEM
skip-name-resolve
back_log = 300
max_connections = 613
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 256
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 16M
thread_cache_size = 16
query_cache_type = 1
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
log_error = /app/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /app/mysql/logs/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 128M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 16M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
3、数据库初始化
cd /app/mysql/
bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
登录的临时暗码在error文件中(/app/mysql/logs/mysql-error.log)
##
porary password is generated for root@localhost: Jm=%mM7w)UBq
##
cp -a /app/mysql/support-files/mysql.server /etc/init.d/mysql
echo "export PATH=/app/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
# 发动mysql
/etc/init.d/mysql start
# 运用日志中的临时暗码(Jm=%mM7w)UBq)登录mysql
mysql -u root -p
# 设置root暗码:
mysql>set password for root@localhost = password('root');
# 创立zabbix库:
create database zabbix character set utf8 collate utf8_bin;
# 授权:
grant all privileges on *.* to zabbix@'%' identified by 'zabbix';
# 改写权限
flush privileges;
# 导入数据到zabbix
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p zabbix
3)装备zabbix_server
1、修正装备
# vi /etc/zabbix/zabbix_server.conf
LogFile=/app/zabbix/logs/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=192.168.182.132
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql.sock
SNMPTrapperFile=/app/zabbix/logs/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/app/zabbix/alertscripts
ExternalScripts=/app/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
2、创立相关目录
mkdir -p /app/zabbix/logs/snmptrap
mkdir /app/zabbix/{alertscripts,externalscripts}
chown zabbix:zabbix /app/zabbix/ -R
3、修正时区
# vim /etc/httpd/conf.d/zabbix.conf
# 增加/修正装备:
php_value date.timezone Asia/Shanghai
4、发动apache
systemctl start httpd.service
5、发动php
systemctl start php-fpm.service
6、发动zabbix server
systemctl start zabbix-server.service
# 访问: http:ip/zabbix
# 留意:第一次登录填写mysql衔接信息时候地址需求填0.0.0.0
三、修正字体
# 上传windows中的字体MSYH.TTC(微软雅黑) 到/home/wwwroot/default/zabbix/fonts目录
ln -s /home/wwwroot/default/zabbix/fonts/MSYH.TTC /etc/alternatives/zabbix-web-font
四、装置graphtree插件(可选)
# graphtree是一个图形展现插件
wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3.0.4.patch
yum install -y patch
cp -a /usr/share/zabbix /usr/share/zabbix.bak
mv graphtree3.0.4.patch /usr/share/zabbix/
cd /usr/share/zabbix
patch -Np0 <graphtree3.0.4.patch
chown apache:apache oneoaas -R
#增加装备:vim /etc/httpd/conf.d/zabbix.conf
Alias /oneoaas /usr/share/zabbix/oneoaas
# 重启服务
systemctl restart httpd.service zabbix-server.service
五、装置 zabbix-proxy 详解进程
1)通过 yum 装置 zabbix-proxy
1、装置 zabbix-proxy 和 zabbix-agent
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
yum clean all
# 先查找zabbix-proxy,yum search zabbix-proxy
yum install zabbix-proxy-mysql.x86_64 zabbix-agent.x86_64
【问题】假如呈现如下过错
Error: Package: zabbix-proxy-mysql-4.4.3-1.el7.x86_64 (zabbix)
Requires: fping
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
【解决】依据过错提示,需求装置fping命令这个依赖,在进行yum装置之后显示该装置包不存在,因而进行推测应该是epel源装备呈现问题,因而在阿里源中装备epel源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
# 再履行
yum install zabbix-proxy-mysql.x86_64 zabbix-agent.x86_64
2、创立 zabbix_proxy 库
create database zabbix_proxy character set utf8 collate utf8_bin;
# 授权:
grant all privileges on zabbix_proxy.* to zabbix@'%' identified by 'zabbix';
# 改写权限
flush privileges;
# 布置mysql 过程和在zabbix server中布置相同,区别在导入数据时候不相同:
# zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -uroot -p zabbix_proxy
3、修正zabbix-proxy装备
# vim /etc/zabbix/zabbix_proxy.conf
Server=192.168.182.132 # 真正的服务端(zabbix server)
ServerPort=10051 # 依据个人需求修正,一般能够不改,默许端口是10051,要完成转发的话运用这个选项(zabbix server)
ListenPort=10051 # zabbix-proxy服务监听的端口,默许就好
Hostname=Zabbix proxy # proxy的hostname,在web端网页装备时需求用到
DBHost=192.168.182.130 # 数据库,运用本地,也能够运用ip,我喜欢运用localhost,由于我授权便是本地,也由于装备ip失败踩过坑
DBName=zabbix_proxy # 数据库名称,创立zabbix-proxy的mysql的数据库名称
DBUser=zabbix # 用户
DBPassword=zabbix # 暗码
DBPort=3306 # 当DBHost填写localhost时,默许是运用socket通讯的,这儿装备一下也无碍
#HeartbeatFrequency=60 # 心跳线(具体效果网了,看装备文件吧,这个默许便是60)
ConfigFrequency=600 # 这个好像是同步装备文件的时间
DataSenderFrequency=1 # 这个是proxy端向server端发送数据的时间,单位是秒,简直等于实时同步
4、发动 zabbix-proxy
systemctl start zabbix-proxy.service
2)通过源码装置 zabbix-proxy
yum -y install curl-devel libevent-devel libevent curl libxml2-devel libxml2 pcre pcre-devel
yum install mysql-devel -y
yum install -y net-snmp-devel
# 编译装置zabbix proxy:
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.0/zabbix-4.4.0.tar.gz
tar -xzvf zabbix-4.4.0.tar.gz
cd zabbix-4.4.0
# proxy:
./configure --prefix=/app/zabbix_proxy_4.4 --enable-proxy --with-mysql --with-libcurl --with-libxml2 --enable-ipv6 --with-net-snmp --with-openssl
ln -s /app/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
# 发动:
/app/zabbix_proxy_4.4/sbin/zabbix_proxy -c /app/zabbix_proxy_4.4/etc/zabbix_proxy.conf
六、通过 web 端装备代理
创立代理
装备代理信息
增加主机时选择代理
假如呈现如下图,则zabbix server不能与zabbix proxy正常通讯
正常通讯如图:
七、zabbix-agent 装置
被监控的机器上有必要装置 zabbix-agent,通过 zabbix-agent 与zabbix-proxy或许zabbix-server通讯
1)yum 装置 zabbix-agent
# 增加yum源rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
# 装置yum install zabbix-agent# 发动
service zabbix-agent start
2)源码装置 zabbix-agent
yum -y install curl-devel libevent-devel libevent curl libxml2-devel libxml2 pcre pcre-devel
yum install mysql-devel -y
yum install -y net-snmp-devel
# 编译装置zabbix客户端:
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.0/zabbix-4.4.0.tar.gz
tar -xzvf zabbix-4.4.0.tar.gz
cd zabbix-4.4.0
# agent:
./configure --prefix=/app/zabbix_agent_4.4 --enable-agent --enable-ipv6 --with-net-snmp --with-openssl
# 发动:
/app/zabbix_agent_4.4/sbin/zabbix_agentd -c /app/zabbix_agent_4.4/etc/zabbix_agentd.conf
3)修正装备(/etc/zabbix/zabbix_agentd.conf)
Server=[zabbix server/zabbix proxy ip]
ServerActive=[zabbix server/zabbix proxy ip]
Hostname=[ Hostname of client system ]# 例:Server=192.168.182.130ServerActive=192.168.182.130Hostname=192.168.182.129
4)装置 zabbix-get,并测验agent端是否server端连通
# 装置
yum install -y zabbix-get
# 在服务端测验(192.168.182.132),-s --host:agent端ip;-p,--port:端口;-k,--key:监控项key
zabbix_get -s 192.168.182.130 -p 10050 -k system.hostname
# zabbix server与zabbix proxy的装备的同步是有延时的,假如需求立即同步能够手动履行命令:
zabbix_proxy -c /etc/zabbix/zabbix_proxy.conf -R config_cache_reload
zabbix 详细布置进程就先到这儿了,有任何疑问欢迎给我留言或私信哦,也可重视我的大众号【大数据与云原生技术共享】加群沟通哦~