简介
zabbix proxy 可以代替 zabbix server 收集性能和可用性数据,然后把数据汇报给 zabbix server,并且在一定程度上分担了zabbix server 的压力.
zabbix-agent可以指向多个proxy或者server
zabbix-proxy不能指向多个server
zabbix proxy 使用场景:
1,监控远程区域设备
2,监控本地网络不稳定区域
3,当 zabbix 监控上千设备时,使用它来减轻 server 的压力
4,简化分布式监控的维护
1,安装mysql
1.1,创建用户
groupadd mysql
useradd -r -g mysql mysql
1.2,上传,解压安装包,并做软链接
tar zxf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql-5.7.31
ln -s mysql-5.7.31 mysql
1.3,编辑配置文件
cp /etc/my.cnf{,.bak}
cat >/etc/my.cnf<<\EOF
[client]
port = 3306
socket = /data/3306/dbdata/mysql.sock
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
[mysqld]
#=========================>[mysql Base]<=====================
skip_name_resolve
basedir = /usr/local/mysql
datadir = /data/3306/dbdata
socket = /data/3306/dbdata/mysql.sock
user = mysql
bind-address = 0.0.0.0
port = 3306
innodb_file_per_table = ON
default-storage-engine = InnoDB
character-set-server = utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
interactive_timeout = 28800
wait_timeout = 28800
# transaction_isolation = REPEATABLE-READ
# skip-networking
# lower_case_table_names = 1
# skip-grant-tables
# skip-external-locking
#========================>[mysql log related]<===============
log_bin = /data/3306/binlog/mysql-bin
binlog_format = mixed
expire_logs_days = 3
slow_query_log = 1
long_query_time = 1.5
slow_query_log_file = /data/3306/slowlog/mysql-slow.log
#general_log = ON
#general_log_file = /data/3306/slowlog/sql.log
#========================>[ mysql Replication]<================
log_slave_updates = true
master-info-repository = TABLE
relay_log_info_repository = TABLE
relay_log = /data/3306/relaylog/relay-bin
relay_log_purge = OFF
sync_master_info = 1
sync_binlog = 1
slave_parallel_workers = 2
binlog_checksum = CRC32
master_verify_checksum = 1
slave_sql_verify_checksum = 1
binlog_rows_query_log_events = 1
server-id = 1
report_port = 3306
report_host = nlpt252-zabbix-mysql
replicate_wild_ignore_table=test.%
replicate_wild_ignore_table = information_schema.%
slave-skip-errors=1022,1032,1062
#read_only = 1
#========================>[mysql perfomance]<===============
back_log = 600
max_connections = 3000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 16M
binlog_cache_size = 32768
max_heap_table_size = 1024M
tmp_table_size = 128M
join_buffer_size = 16M
sort_buffer_size = 16M
read_rnd_buffer_size = 8M
read_buffer_size = 4M
thread_cache_size = 64
# query_cache_type = OFF
# query_cache_size = 8M
# query_cache_limit = 2M
key_buffer_size = 256M
#======================>[mysql storage-engine]<==============
# InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM.
# 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少.
# 在一个独立使用的数据库服务器上,你可以设置这个变量到服务器物理内存大小的80%
# 不要设置过大,否则,由于物理内存的竞争可能导致操作系统的换页颠簸.
# 注意在32位系统上你每个进程可能被限制在 2-3.5G 用户层面内存限制,
# 所以不要设置的太高.
innodb_buffer_pool_size = 2G
innodb_open_files = 1000
# innodb使用后台线程处理数据页上的读写 I/O(输入输出)请求,根据你的 CPU 核数来更改,默认是4
innodb_write_io_threads = 4
innodb_read_io_threads =4
innodb_thread_concurrency = 0
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 16M
EOF
1.4,创建所需的目录
mkdir -p /data/3306/{dbdata,logs,binlog,tmp,lib,undolog,relaylog,slowlog}
1.5,初始化mysql
cd /usr/local/mysql-5.7.31
bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/3306/dbdata --user=mysql
输出的最后一行 root@localhost: i#g0auLF17vW ----默认root密码
1.6,授权,添加环境变量
chown -R mysql.mysql /usr/local/mysql/*
chown -R mysql.mysql /data/3306/
echo "export PATH=$PATH:/opt/mysql/bin" >> /root/.bash_profile
source ~/.bash_profile
1.7,做启动项
ln -s /usr/local/mysql/bin/mysql /usr/bin
cp /usr/local/mysql-5.7.31/support-files/mysql.server /etc/init.d/mysql
#修改启动项
vim /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/data/3306/dbdata
chmod +x /etc/init.d/mysql
chkconfig --add mysql
service mysql start
1.8,登录mysql,修改密码,创建用户和库
mysql -uroot -p
#修改密码
set password=password('zbx2013');
flush privileges;
#创建用户和建库
create database zabbix_proxy character set utf8 collate utf8_bin;
create user 'zabbix_proxy'@'%' identified by 'Zbxpass';
grant all privileges on zabbix_proxy.* to 'zabbix_proxy'@'%';
flush privileges;
quit;
2,安装zabbix_proxy
2.1,解压,并创建用户
cd /usr/local/
tar zxvf zabbix-5.0.5.tar.gz
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
2.2,进去到导入数据
#进到数据的目录下
cd /usr/local/zabbix-5.0.5/database/mysql
登录mysql,并导入数据
mysql -uroot -p
use zabbix_proxy;
source schema.sql;
2.3,安装依赖包
yum -y install gcc libxml2-devel unixODBC-devel net-snmp-devel libcurl-devel libssh2-devel OpenIPMI-devel openssl-devel openldap-devel libevent libevent-devel
2.4,编译并安装
cd /usr/local/zabbix-5.0.5/
#编译
./configure --prefix=/usr/local/zabbix_proxy \
--enable-server \
--enable-agent \
--enable-proxy \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-unixodbc \
--with-ssh2 \
--with-openipmi \
--with-openssl
#安装
make install
2.5,编辑配置文件
cp /usr/local/zabbix_proxy/etc/zabbix_proxy.conf{,.bak}
cat >/usr/local/zabbix_proxy/etc/zabbix_proxy.conf<<\EOF
Server=10.135.81.4 #zabbix-server的地址
ServerPort=10051
Hostname=XXXXX #主机名
LogFile=/usr/local/zabbix_proxy/logs/zabbix_proxy.log
LogFileSize=1 #日志文件超过 1M 就进行切割。值为 0时表示不切割日志。 默认为 1
PidFile=/usr/local/zabbix_proxy/zabbix_proxy.pid
SocketDir=/usr/local/zabbix_proxy
DebugLevel=3
DBHost=10.135.82.3 #数据库主机
DBName=zabbix_proxy #数据库用户名
DBUser=zabbix_proxy #数据库用户名
DBPassword=Zbxpass@2023 #数据库密码
DBPort=3306 #数据库端口
DBSocket=/data/3306/dbdata/mysql.sock
ConfigFrequency=60
StartPollers=50
Timeout=30 #指定时间内,agent没把监控项的数据返回则超时
LogSlowQueries=3000
StartDiscoverers=5
CacheSize=4G #保存监控项而占用的最大内存
HistoryCacheSize=1G #历史数据缓存大小;尽量大的分配空间
StartPollersUnreachable=20
UnreachablePeriod=60
DataSenderFrequency=70 #主动模式下,proxy间隔多长时间向server发送数据;单位秒,范围1-3600
EOF
2.6,授权
chown -R zabbix.zabbix /usr/local/zabbix_proxy
2.7,添加启动项,并启动
cat >/usr/lib/systemd/system/zabbix-proxy.service<<\EOF
[Unit]
Description=Zabbix Proxy
After=syslog.target
After=network.target
[Service]
User=zabbix
Group=zabbix
Environment="CONFFILE=/usr/local/zabbix_proxy/etc/zabbix_proxy.conf"
Type=forking
Restart=on-failure
PIDFile=/usr/local/zabbix_proxy/zabbix_proxy.pid
KillMode=control-group
ExecStart=/usr/local/zabbix_proxy/sbin/zabbix_proxy -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOF
#加载
systemctl daemon-reload
#启动
systemctl start zabbix-proxy
#开机自启
systemctl enable zabbix-proxy
systemctl status zabbix-proxy
2.8,在页面配置