zabbix5.0安装和部署笔记

发布时间 2023-06-26 09:04:05作者: 阿星777

zabbix版本5.0,操作系统版本Ubuntu 18.04

 

版本5.0,操作系统版本Ubuntu 18.04
1.安装mysql
2.解压这个包
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar

3.rpm所有程序
sudo apt install rpm

rpm -Uvh *.rpm --nodeps --force

error while loading shared libraries: libaio.so.1: cannot open shared object file:
  apt-get install libaio1 libaio-dev
# grep "password" /var/log/mysqld.log

4.service mysqld start

service mysqld status 状态
service mysqld stop  停止

set password for root@localhost = password('Abcd,4321');

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

编辑my.cnf
[client]
socket = /var/lib/mysql/mysql.sock
===========================================
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb
dpkg -i zabbix-release_5.0-1+bionic_all.deb
apt update

apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent


c. 创建初始数据库
产品手册

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 'Abcd,4321';
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
d. 为Zabbix server配置数据库

编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
e. 为Zabbix前端配置PHP

编辑配置文件 /etc/zabbix/apache.conf, uncomment and set the right timezone for you.
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Shanghai

f. 启动Zabbix server和agent进程

启动Zabbix server和agent进程,并为它们设置开机自启:
# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2
g. 配置Zabbix前端

连接到新安装的Zabbix前端: http://server_ip_or_name/zabbix
根据Zabbix文件里步骤操作: Installing frontend

 http://199.199.199.91/zabbix
默认用户名和密码:
Admin
zabbix
=====================================
Details Cannot create the configuration file.
需要手工复制并且上传配置文件到指定的目录:
Save it as "/usr/share/zabbix/conf/zabbix.conf.php"
如果原来有一个文件必须手动删除掉。
===========================================
agent安装
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb
dpkg -i zabbix-release_5.0-1+bionic_all.deb
apt update

apt install zabbix-agent


agent5.0安装报错。

安装agent 4版本
wget http://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.2-1%2Bxenial_all.deb
dpkg -i zabbix-release_4.2-1+xenial_all.deb
apt-get update
apt-get install zabbix-agent
====================================


修改配置文件,/etc/zabbix/zabbix_agentd.conf:
zabbix_agentd.conf修改如下:

  LogFile=/var/log/zabbix/zabbix_agentd.log

  Server=192.168.119.130 #地址主动模式,填写Server的IP

  ServerActive=192.168.119.130  #修改为Server的IP地址

  Hostname=Zabbix server     #重要:客户端的hostname,不配置则使用主机名

systemctl restart  zabbix-agent
systemctl enable  zabbix-agent
=====================================
界面配置:
congiuration->Hosts->Create host
按照界面提示配置。
记得要选择模板:Template OS Linux by Zabbix agent
=====================================
You are not able to choose some of the languages, because locales for them are not installed on the web server.
系统没有中文插件, zabbix5.0 没有办法中文切换。

   sudo apt-get install language-pack-zh-hant language-pack-zh-hans

1.dpkg-reconfigure locales # 选择系统语言包
   # 必须选择的 en_US.UTF-8/zh_CN.UTF-8
   2. 在选择系统环境语言时,必须有必要选 en_US.UTF-8
   #check zabbix 配置
    vim /usr/share/zabbix/include/locales.inc.php
    找到 getLocales() 函数检查 zh_CN 是否为 True
   Debian 就可以这样解决

 service apache2 restart

=================================================

CentOS下安装

zabbix官网: https://www.zabbix.com

zabbix 主要由2部分构成 zabbix server和 zabbix agent

zabbix proxy是用来管理其他的agent,作为代理


centos 7, zabbix 5,mysql
安装:

选择您Zabbix服务器的平台
a. 安装 数据库
产品手册
# 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

[zabbix-frontend]
...
enabled=1
...

Install Zabbix frontend packages.
# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl


d. 创建初始数据库
参考mysql安装步骤

在数据库主机上运行以下代码。
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
密码必须替换成复杂密码,否则无法创建。create user zabbix@localhost identified by 'Abcd,4321';
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=Abcd,4321
f. 为Zabbix前端配置PHP

编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

, uncomment and set the right timezone for you.
; php_value[date.timezone] = Europe/Riga
php_value[date.timezone] = Asia/Shanghai


g. 启动Zabbix server和agent进程

启动Zabbix server和agent进程,并为它们设置开机自启:
# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
h. 配置Zabbix前端
停止防火墙:systemctl stop firewalld
连接到新安装的Zabbix前端: http://server_ip_or_name/zabbix
默认用户名和密码:
Admin
zabbix


根据Zabbix文件里步骤操作: Installing frontend


更新selinux策略,否则启动zabbix  报错
yum update selinux-policy.noarch selinux-policy-targeted.noarch
setenforce 0
vi /etc/selinux/config
重启apache
# systemctl restart zabbix-server
# systemctl restart httpd
# systemctl restart rh-php72-php-fpm

安装java监控组件
#安装
yum -y install zabbix-java-gateway
#启动
systemctl start zabbix-java-gateway
#开机启动
systemctl enable zabbix-java-gateway

zabbix-server默认工作在10051端口,zabbix-agent默认工作在10050端口
修改配置
vi /etc/zabbix/zabbix_java_gateway.conf
LISTEN_IP="127.0.0.1"(本机ip地址,如果和server安装在相同的位置可以不修改)
LISTEN_PORT=10052(端口可以修改为其他,在server段需要相同的配置)
START_POLLERS=5(设置启动多个线程,这里和server段相同)
修改配置
vi  /etc/zabbix/zabbix_server.conf
JavaGateway=127.0.0.1 #如果是本机安装直接使用127.0.0.1
JavaGatewayPort=10052 #端口号和javagateway要对应
StartJavaPollers=5 #线程数和客户端配置对应 不能少于客户端数目

重新启动server
systemctl restart zabbix-server
systemctl restart zabbix-java-gateway
============================================
zabbix agent安装
IP地址:
# 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-agent

修改配置文件,/etc/zabbix/zabbix_agentd.conf:
zabbix_agentd.conf修改如下:

  LogFile=/var/log/zabbix/zabbix_agentd.log

  Server=192.168.119.130 #地址主动模式,填写Server的IP

  ServerActive=192.168.119.130  #修改为Server的IP地址

  Hostname=Zabbix server     #重要:客户端的hostname,不配置则使用主机名,主动式模式必须与服务器上配置的Host一致,所以最好配置主机IP地址。

更新selinux策略,否则启动zabbix agent 报错
yum update selinux-policy.noarch selinux-policy-targeted.noarch
停止防火墙:systemctl stop firewalld

启动命令:

    service zabbix-agent start

    netstat -antup | grep 10050

    chkconfig zabbix-agent on

====================================
tomcat 配置调整
修改tomcat/bin/catalina.sh,添加(注意参数必须一行,否则会无法启动)

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=192.168.119.132(tomcat主机自己的IP地址, 不要写zabbix服务器的地址)"
重启tomcat
./shutdown.sh
./startup.sh

需要添加jmxjar包,存放于tomcat的lib路径下(非必须的)
wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.45/bin/extras/catalina-jmx-remote.jar
================================
zabbix 日志
/var/log/zabbix/zabbix_server.log


=========================================

=====================================
Ubuntu18遇到的问题:
Details Cannot create the configuration file.
需要手工复制并且上传配置文件到指定的目录:
Save it as "/usr/share/zabbix/conf/zabbix.conf.php"
如果原来有一个文件必须手动删除掉。


=====================================
win客户端安装
官网下载:
zabbix_agent2-5.0.14-windows-amd64-openssl.msi
按照下一步方式安装即可。


=========================

Zabbix server Configuration cache % used

More than 75% used in the configuration cache, 可用的配置缓存超过75%。

解决办法: 更改默认缓存配置的大小。
vi /etc/zabbix/zabbix_server.conf
CacheSize=512M
systemctl restart zabbix-server.service