背景
常见的服务和主机已经使用Prometheus进行监控了,但是网络设备还未配置监控。使用基于SNMP对网络设备进行监控。
设备概览
主要类型为H3C的路由器和交换机。H3CS5560交换机 路由器MER5200 er8300
步骤
配置网络设备开启telnet远程;
配置启用snmp协议;
zabbix界面添加主机进行监控;
snmp简介
SNMP simple network managerment protocol 分为三代,v3较为安全,需要配置用户名和密码及v3的加密密码。
组件
- nginx
- php7
- mysql
- zabbix_server
- zabbix_agent
- zabbix_get
MySQL
配置MySQL,容器方式启动
MySQL采用8.0版本,配置文件,数据持久化
docker pull mysql:8.0
mkdir -pv /data/mysql/{conf,data,logs}
[root@localhost ~]# cat /data/mysql/conf/my.cnf
[mysqld]
default_authentication_plugin=mysql_native_password
character-set-server=utf8mb4
collation-server=utf8mb4_bin
default-storage-engine=INNODB
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
docker run -d --restart=always --name mysql -p 3306:3306 -v /data/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=xxxxxxxxxxx mysql:8.0
使用yum repo中自带的是mariadb的MySQL5.x版本的客户端连接8.0版本数据库会报错
ERROR 2059 (HY000): Authentication plugin ‘sha256_password’ cannot be loaded: /usr/lib64/mysql/plugin/sha256_password.so: cannot open shared object file: No such file or directory
解决:安装MySQL community的客户端
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-client --nogpgcheck
mysql -uroot -h127.0.0.1 -pzabbix@123
MySQL [(none)]> create database zabbix character set utf8 collate utf8_bin;
MySQL [(none)]> create user zabbix@'%' identified by 'xxxxxxx';
MySQL [(none)]> grant all privileges on zabbix.* to zabbix@'%';
MySQL [(none)]> set global log_bin_trust_function_creators = 1;
MySQL [(none)]> flush privileges;
zabbix配置
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
...
enabled=1
yum install zabbix-server-mysql zabbix-agent centos-release-scl zabbix-web-mysql-scl zabbix-nginx-conf-scl
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
listen.acl_users = apache,nginx
php_value[date.timezone] = Asia/Shanghai
vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
# listen 80;
# server_name example.com;
systemctl enable --now zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl is-active zabbix-server;systemctl is-active zabbix-agent;systemctl is-active rh-php72-php-fpm;systemctl is-active rh-nginx116-nginx
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
listen.acl_users = apache,nginx
php_value[date.timezone] = Asia/Shanghai
vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
# listen 80;
# server_name example.com;
systemctl enable --now zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
检查所有的组件依赖都是ok
默认web登录账户名密码为Admin zabbix
snmp测试工具
yum install net-snmp-utils
问题
zabbix机器中使用snmpwalk命令测试可以获取到被监控节点的各个oid详细信息,但是zabbix server的web界面中显示timeout或者其他的报错信息。
解决方法:无意间重启了zabbix server,问题得到解决。