当前位置: 首页 > news >正文

三. Zabbix安装

目录

2.1 安装准备

2.2 nginx安装

2.3 安装php

2.4 nginx+php配置

2.5 数据库安装

2.6安装zabbix server

2.7 zabbix前端页面准备

2.8 安装zabbix(zabbix 前端页面连接数据库与zabbix-server)

2.9 zabbix docker 安装

zabbix_server.conf

中文简体文件添加

编写docker-compose.yml 文件

中文设置

配置agent客户端

zabbix_agentd.conf(暂不需要)


2.1 安装准备

https://www.zabbix.com/documentation/5.0/zh/manual/installation/requirements

配置静态ip

cd /etc/sysconfig/network-scripts/

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.

GATEWAY=192.168.157.2

NETMASK=255.255.255.0

DNS1=192.168.157.2

安装vim

yum install vim

关闭SELinux及防火墙

1)关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

2)永久禁用SELinux

vi /etc/sysconfig/selinux

重启

SELinux=enforcing改为SELinux=disabled

reboot

环境准备

三个虚拟机一个服务端一个客户端

安装清单

zabbix-server+页面(前端)

1、nginx

2、php

3、数据库

4、zabbix-server

5、web部署

2.2 nginx安装

配置yum源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]

name=nginx stable repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=1

enabled=0

gpgkey=https://nginx.org/keys/nginx_signing.key

module_hotfixes=true

安装

yum install -y nginx --enablerepo=nginx-stable

测试

rpm -qa | grep nginx

2.3 安装php

#nginx 1.20.1 php7.2

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum install epel-release.noarch -y #webtatic 要求

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #webtatic源

yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-process

检查环境

rpm -qa |egrep 'nginx|php72w'

确保包都在

2.4 nginx+php配置

加入启动项

systemctl enable nginx php-fpm.service

systemctl start nginx php-fpm.service

nginx配置

vim /etc/nginx/conf.d/zbx.oldboylinux.cn.conf

server {

    listen 80;

    server_name 192.168.157.135;

    root /app/code/zbx;

    location / {

        index index.php;

    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME /app/code/zbx$fastcgi_script_name;

        include fastcgi_params;

    }

}

重启nginx

[root@m03 ~]# nginx -t

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

    nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@m03 ~]# systemctl reload nginx

php 配置

修改php用户

准备 php会话保持目录

sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf

#查看权限

egrep '^(user|group)' /etc/php-fpm.d/www.conf

显示

user = nginx

group = nginx

配置nginx session

grep 'var/lib/php/session' /etc/php-fpm.d/www.conf

#php_value[session.save_path] = /var/lib/php/session

[root@m03 ~]# mkdir -p /var/lib/php/session

[root@m03 ~]# chown nginx:nginx /var/lib/php/session

php-fpm -t

systemctl reload php-fpm.service

php+nginx测试 (给php创建资源目录)

[root@m03 ~]# mkdir -p /app/code/zbx

[root@m03 ~]# chown nginx:nginx /app/code/zbx

[root@m03 ~]# vim /app/code/zbx/info.php

[root@m03 ~]#

编写代码

<?php

phpinfo();

?>

查看

 # 查看文件权限

 ls -l /app/code/zbx/info.php

# 递归修改目录权限(示例以用户 www-data 为例)

chown -R nginx:nginx /app/code/zbx

find /app/code/zbx -type d -exec chmod 755 {} \;  # 目录权限:755

find /app/code/zbx -type f -exec chmod 644 {} \;  # 文件权限:644

 

cat /app/code/zbx/info.php

测试完成

查看日志

tail -f /var/log/nginx/error.log

PHP-FPM 日志(默认位置)tail -f /var/log/php-fpm.log

2.5 数据库安装

yum install -y mariadb-server

启动mariadb 并加入自启动

systemctl start mariadb

systemctl enable mariadb

免密登录mysql

mysql -u root

查看user

删除多余root账户

delete from user where user='root' and host='127.0.0.1';

delete from user where user='root' and host='::1';

给mysql root设置密码

mysql_secure_installation

查看数据库

select user,host from mysql.user ;

显示数据库

show databases;

配置数据库

create database zabbix charset utf8 collate utf8_bin;

grant all on zabbix.* to 'zabbix'@'localhost' identified by '1' ;

grant all on zabbix.* to 'zabbix'@'10.1.1.7.%' identified by '1' ;

MariaDB [(none)]> show databases;

MariaDB [(none)]> select user,host from mysql.user;

修改root 远程链接

use mysql;

update user set host='%' where user='root';

FLUSH PRIVILEGES;

测试数据库

2.6安装zabbix server

准备工作

下载Zabbix

不支持6.0以上

关闭SELinux及防火墙

1)关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

2)永久禁用SELinux

vi /etc/sysconfig/selinux

将SELinux=enforcing改为SELinux=disabled

3)、重启

reboot

注意:如果不关闭selinux,参照设置:https://www.zabbix.com/documentation/6.0/zh/manual/installation/install_from_packages/rhel_centos#%E9%85%8D%E7%BD%AE-selinux

如果不关闭防火墙,参照设置:

a.开放端口

firewall-cmd --zone=public --add-port=10050/tcp --permanent

firewall-cmd --zone=public --add-port=10051/tcp --permanent

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --zone=public --add-port=80/tcp --permanent

b.重新载入防火墙使设置生效

firewall-cmd --reload

安装zabbix yum源

rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g'

vim /etc/yum.repos.d/zabbix.repo

[zabbix]

name=Zabbix Official Repository - $basearch

baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/

enabled=1

gpgcheck=0

[zabbix-frontend]

name=Zabbix Official Repository frontend - $basearch

baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/frontend

enabled=0

gpgcheck=0

[zabbix-debuginfo]

name=Zabbix Official Repository debuginfo - $basearch

baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/

enabled=0

gpgcheck=0

[zabbix-non-supported]

name=Zabbix Official Repository non-supported - $basearch

baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/

enabled=1

gpgcheck=0

安装server

yum install -y zabbix-server-mysql zabbix-agent2

zabbix 数据库导入数据

zcat /usr/share/doc/zabbix-server-mysql-5.0.46/create.sql.gz |mysql -uzabbix -p1 zabbix

配置连接数据库

vim /etc/zabbix/zabbix_server.conf

grep ^DB /etc/zabbix/zabbix_server.conf

:91

91:DBHost=localhost

100:DBName=zabbix

116:DBUser=zabbix

124:DBPassword=1

启动zabbix-server

#启动zabbix-server

systemctl enable zabbix-server.service

systemctl start zabbix-server.service

ss -lntup|grep zabbix

2.7 zabbix前端页面准备

源码包下载5.0.18版本

https://cdn.zabbix.com/zabbix/sources/stable/5.0/#使用源码包

tar xf zabbix-5.0.18.tar.gz

cd zabbix-5.0.18/

cp -a ui/* /app/code/zbx/

chown -R nginx.nginx /app/code/zbx/

2.8 安装zabbix(zabbix 前端页面连接数据库与zabbix-server)

http://10.1.1.7/setup.php

出现问题

#php最后的配置

Minimum required size of PHP post is 16M (configuration option "post_max_size").

Minimum required limit on execution time of PHP scripts is 300 (configuration

option "max_execution_time").

Minimum required limit on input parse time for PHP scripts is 300 (configuration

option "max_input_time").

Time zone for PHP is not set (configuration parameter "date.timezone").

post_max_size 16M

max_execution_time 300

max_input_time 300

date.timezone

[root@m03 ~]# egrep -n '^(max_|date.timezone|post_max)' /etc/php.ini

368:max_execution_time = 300

378:max_input_time = 600

656:post_max_size = 80M

802:max_file_uploads = 20

877:date.timezone = Asia/Shanghai

出现报错

[root@m03 ~]# systemctl reload php-fpm.service

web连接数据库

zabbix页面连接 zabbxi 服务端

zabbix前端页面安装完成

chown -R nginx:nginx /app/code/zbx/

登录 Admin: zabbix

效果

到此安装完成

2.9 zabbix docker 安装

zabbix版本和源代码:

https://cdn.zabbix.com/zabbix/sources/stable/5.0/

创建目录

mkdir -p /data2/zabbix/zabbix-server    用于存储 Zabbix 服务器容器的配置文件等相关数据

mkdir -p /data2/zabbix/alertscripts     用于存储 Zabbix 服务器容器中的告警脚本

mkdir -p /data2/zabbix/fonts            用于存储 Zabbix Web 容器中的字体文件

mkdir -p /data2/zabbix/db               用于存储 MySQL 数据库容器的数据文件

zabbix_server.conf

LogType=console

DBHost=zabbix-mysql

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBPort=3306

User=zabbix

中文简体文件添加

从主机(C:\Windows\Fonts)上传一个.ttf的字体文件到/data2/zabbix/fonts目录

可使用rz命令,或者ftp,或远程传输工具(如:xftp)

并将文件名称改成DejaVuSans.ttf(yml文件中有指明)

编写docker-compose.yml 文件

services:

  zabbix-web-nginx-mysql:

    image: zabbix/zabbix-web-nginx-mysql:centos-5.2-latest

    restart: always

    environment:

      - DB_SERVER_HOST=zabbix-mysql

      - MYSQL_DATABASE=zabbix

      - MYSQL_USER=zabbix

      - MYSQL_PASSWORD=zabbix

      - MYSQL_ROOT_PASSWORD=root

      - ZBX_SERVER_HOST=zabbix-server-mysql

    ports:

      - 8080:8080

    volumes:

      - /etc/localtime:/etc/localtime

      - /data2/zabbix/fonts/DejaVuSans.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf

    networks:

      - zbx_net

    depends_on:

      - zabbix-server-mysql

      - zabbix-mysql

  zabbix-mysql:

    image: mysql:8.0.23

    restart: always

    ports:

      - 3306:3306

    environment:

      - MYSQL_DATABASE=zabbix

      - MYSQL_USER=zabbix

      - MYSQL_PASSWORD=zabbix

      - MYSQL_ROOT_PASSWORD=root

    command:

      - mysqld

      - --default-authentication-plugin=mysql_native_password

      - --character-set-server=utf8

      - --collation-server=utf8_bin

    volumes:

      - /etc/localtime:/etc/localtime

      - /data2/zabbix/db:/var/lib/mysql

    networks:

      - zbx_net

  zabbix-java-gateway:

    image: zabbix/zabbix-java-gateway:centos-5.2-latest

    restart: always

    volumes:

      - /etc/localtime:/etc/localtime

    networks:

      - zbx_net

  zabbix-server-mysql:

    image: zabbix/zabbix-server-mysql:centos-5.2-latest

    restart: always

    volumes:

      - /data/zabbix/zabbix-server:/etc/zabbix

      - /data2/zabbix/alertscripts:/usr/lib/zabbix/alertscripts

      - /etc/localtime:/etc/localtime

    ports:

      - 10052:10051

    environment:

      - DB_SERVER_HOST=zabbix-mysql

      - MYSQL_DATABASE=zabbix

      - MYSQL_USER=zabbix

      - MYSQL_PASSWORD=zabbix

      - MYSQL_ROOT_PASSWORD=root

      - ZBX_JAVAGATEWAY=zabbix-java-gateway

      - ZBX_JAVAGATEWAY_ENABLE=true

      - ZBX_JAVAGATEWAYPORT=10052

    depends_on:

      - zabbix-mysql

    networks:

      - zbx_net

  zabbix-agent:

    image: zabbix/zabbix-agent:centos-5.2-latest

    restart: always

    ports:

      - 10050:10050

    environment:

      - ZBX_HOSTNAME=Zabbix server

      - ZBX_SERVER_HOST=zabbix-server-mysql

      - ZBX_SERVER_PORT=10051

    networks:

      - zbx_net

networks:

  zbx_net:

    driver: bridge

中文设置

配置agent客户端

测试数据

观察数据的变化

到此 docker安装完成

zabbix_agentd.conf(暂不需要)

LogType=console

Server=zabbix-server

ServerActive=zabbix-server

Hostname=zabbix-server-docker

User=zabbix

Include=/etc/zabbix/zabbix_agentd.d/*.conf

UserParameterDir=/var/lib/zabbix/user_scripts

LoadModulePath=/var/lib/zabbix/modules/

相关文章:

  • ​详细介绍 SetWindowPos() 函数
  • 基于 SSE 和 WebSocket 的在线文本实时传输工具
  • 【商城实战(37)】Spring Boot配置优化:解锁高效商城开发密码
  • 【VBA】excel获取股票实时行情(历史数据,基金数据下载)
  • 基于Springboot+服务器磁盘的本地文件存储方案
  • 1.5 Spring Boot项目打包和运行
  • C语言内存函数讲解
  • perl的package中“Subroutine new redefined”问题
  • UDP协议栈之整体架构处理
  • 【Prometheus01】可观测性系统之Prometheus简介、优缺点对比、组件介绍、数据采集流程、TSDB简介
  • 【MATLAB例程】AOA(到达角度)法,多个目标定位算法,三维空间、锚点数量自适应(附完整代码)
  • JavaWeb基础五(MVC)
  • matlab数值精度就1e15
  • 基于Spring Boot的民宿租赁系统的设计与实现(LW+源码+讲解)
  • Maxscript如何通过单击现有按钮添加新按钮?
  • Leetcode做题记录----3
  • 如何在Linux中切换用户?
  • Linux--进程优先级
  • docker部署sflow-rt使用
  • PHP与MySQL的高效数据交互:最佳实践与优化技巧
  • 讲述“外国货币上的中国故事”,《世界钱币上的中国印记》主题书刊出版发布
  • 减重人生|吃得越少越好?比体重秤上的数字,更有意义的是什么?
  • 俄美元首通话超2小时,普京称愿与乌方共同起草和平备忘录
  • 大巴车高速上撞山致2死2伤,广东肇庆警方通报
  • 专访|金七猫奖得主:以非遗为舟,在现实题材中疗愈与成长
  • 国家统计局:中美大幅降低关税有利于双方贸易增长,也有利于世界经济复苏