标签 zabbix 下的文章

查看系统版本:

cat /etc/redhat-release
uname -a 

centos8安装zabbix-agent:

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
dnf install zabbix-agent
systemctl restart zabbix-agent
systemctl enable zabbix-agent

centos7安装zabbix-agent:

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install -y zabbix-agent
systemctl restart zabbix-agent
systemctl enable zabbix-agent

centos6安装zabbix-agent:

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/6/x86_64/zabbix-release-5.0-1.el6.noarch.rpm
yum clean all
yum install -y zabbix-agent
service zabbix-agent restart
chkconfig --level 35 zabbix-agent on

如果使用yum出现repomd.xml 404, 可以先备份一下yum的源配置文件,再恢复成centos官网yum源

cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.`date +%Y%m%d%H%I%S`
curl https://www.getpagespeed.com/files/centos6-eol.repo --output /etc/yum.repos.d/CentOS-Base.repo
mv epel.repo epel.repo.`date +%Y%m%d%H%I%S`
curl https://www.getpagespeed.com/files/centos6-epel-eol.repo --output /etc/yum.repos.d/epel.repo
yum makecache

修改zabbix-agent配置文件:
vim /etc/zabbix/zabbix_agentd.conf

LogFileSize=50
Server=172.19.0.16
ListenIP=172.19.0.9 #客户端IP
ServerActive=172.19.0.16:10051
Hostname=sem

BT面板安全设置里面,开放端口:10050 zabbix-agent

BT服务器,需要将mysqladmin命令添加到全局

ln -s /www/server/mysql/bin/mysqladmin /usr/bin/

添加数据库监控账号及授权:

mysql -uroot -p

CREATE USER 'zabbix'@'localhost' IDENTIFIED BY '<password>';
GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zabbix'@'localhost';
flush privileges;

===mysql config:
mkdir /var/lib/zabbix
vim /var/lib/zabbix/.my.cnf

[client]
user=zabbix
password=saYdX5G2FJs2iEMZ
socket=/tmp/mysql.sock

修改数据库配置的访问权限(新版mysql要求,不然进不了数据库):
chmod 644 /var/lib/zabbix/.my.cnf

===test数据库配置是否可用,能成功进入即可:
mysql --defaults-file=/var/lib/zabbix/.my.cnf

添加mysql模板(参考配置)到配置目录:
下载地址:
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent/template_db_mysql.conf
放到这个路径:
vim /etc/zabbix/zabbix_agentd.d/template_db_mysql.conf
template_db_mysql.conf参考内容:

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default) 
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user='zbx_monitor'
#password='<password>'
#
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"

nginx php-fpm监控:
vhost/phpfpm_status.conf (修改 phpfpm_56_status、fastcgi_pass 127.0.0.1:9000)

server {

        listen 80;
        server_name 127.0.0.1;
        allow 127.0.0.1;
        location /nginx_status {
                stub_status on;
                access_log off;
        }

        location /phpfpm_56_status {
                fastcgi_pass unix:/tmp/php-cgi.sock;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }

}

php-fpm配置:

pm.status_path = /phpfpm_54_status

版本:
zabbix-agent: 5.0.7
mysql: 10.4.12-MariaDB
报错信息
Warning: World-writable config file '/var/lib/zabbix/.my.cnf' is ignored

原因是 .my.cnf 权限过多,人人可改,mysql为了安全不会加载这样的配置文件,所以被忽略

将文件改为644权限即可

chmod 644 /var/lib/zabbix/.my.cnf

测试,能正常进入即可:

mysql --defaults-file=/var/lib/zabbix/.my.cnf

/var/lib/zabbix/.my.cnf 文件内容:

[client]
user=xxxxxxx
password=xxxxxx
host=localhost

测试环境:
centos 7, mysql, nginx

根据官方下载安装文档一路下来:
https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=nginx
原文如下:

Install and configure Zabbix server for your platform
a. Install Zabbix repository
产品手册
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all
b. Install Zabbix server and agent
# yum install zabbix-server-mysql zabbix-agent
c. Install Zabbix frontend
产品手册
Enable Red Hat Software Collections

# yum install centos-release-scl
编辑配置文件 /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.

[zabbix-frontend]
...
enabled=1
...
Install Zabbix frontend packages.

# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
d. 创建初始数据库
产品手册
Make sure you have database server up and running.

在数据库主机上运行以下代码。

# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
e. 为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf

DBPassword=password
f. 为Zabbix前端配置PHP
编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf, uncomment and set 'listen' and 'server_name' directives.

# listen 80;
# server_name example.com;
编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, add nginx to listen.acl_users directive.

listen.acl_users = apache,nginx
Then uncomment and set the right timezone for you.

; php_value[date.timezone] = Europe/Riga
g. 启动Zabbix server和agent进程
启动Zabbix server和agent进程,并为它们设置开机自启:

# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm

我的不同:
机子已经先安装了bt的宝塔系统,安装有nginx + mysql + php 环境

按照zabbix步骤,我安装nginx和php的时候用了官方的方法安装了nging和php72,mysql用了宝塔安装的mysql

当我进入后台时,看到了 zabbix-server is not runing的提示,找到 /etc/zabbix/zabbix_server.conf 中的日志文件路径 /var/log/zabbix/zabbix_server.log ,再查看日志,发现报错是没有连接到mysql,原因是默认配置的DBSocket和我的环境不一致,宝塔的mysql 套接字路径是 /tmp/mysql.sock,修改配置,重启zabbix-server,发现跑起来了

解决切换成中文后,图表中的汉字显示成方框的问题

进入win10系统 C:\Windows\Fonts 目录,双击一个简体字包,进去后有三个字体,ctrl+c复制出来一个字体文件,上传到 /usr/share/zabbix/assets/fonts

原来的文件是一个软链接
graphfont.ttf -> /etc/alternatives/zabbix-web-font
备份一下
mv graphfont.ttf graphfont.ttf.bak
添加一个软链接 graphfont.ttf -> msyhl.ttc
ln -s msyhl.ttc graphfont.ttf

现在刷新图表页面,显示正常的汉字内容了