zabbix01-zabbix4.0安装部署


监控系统对比

Zabbix

  1. 所有配置WEB化,WEB采用php开发
  2. 支持分布式监控
  3. 支持多种数据采集:简单监控,agent监控,snmp接口监控,JMX接口监控
  4. 告警配置WEB化:邮件,短信,钉钉,微信
  5. Zabbix和Grafana结合,方便监控数据的可视化

Nagios

  1. 重在监控告警
  2. 添加监控需要修改配置文件
  3. 无监控历史数据,图形支持差
  4. 不支持分布式监控

Cacti

  1. 重在采集服务器,网络设备的监控数据并绘图
  2. 依赖于snmp协议
  3. 不好自定义监控
  4. 告警支持不好

搭建概述

zabbix搭建理论

  1. Zabbix server(主程序),去采集数据,让后写入SQL数据库
  2. Zabbix web 使用php开发,所有配置信息,和用户认证信息写入SQL数据库
  3. 企业级zabbix的搭建环境:主流采用LNMP环境(centos7+nginx+mysql+php)

LNMP web环境用户请求流程

       用户-->nginx-->php-fpm-->运行php程序-->操作mysql

部署顺序说明

  1. Nginx,php-fpm
  2. Mysql
  3. Zabbix server
  4. Zabbix web

安装lnmp

  • 安装nginx

    1. 官网下载nginx 下载stable版本 网址 http://nginx.org
    2. Nginx 编译安装
    # yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel
    # wget http://nginx.org/download/nginx-1.16.1.tar.gz
    # tar zxvf nginx-1.16.1.tar.gz
    # cd nginx-1.16.1
    # ./configure --prefix=/usr/local/nginx
    # make && make install

    设置环境变量

    # vim /etc/profile 增加
    # export PATH=$PATH:/usr/local/nginx/sbin
    # source /etc/profile

    nginx基本命令

            1,启动nginx nginx

            2,测试配置文件 nginx -t

            3,关闭nginx nginx -s stop

    验证nginx安装是否成功

    1. 查看进程 ps -ef|grep nginx
    2. 查看端口 netstat -nltp|grep 80
    3. nginx日志
    4. 浏览器访问

    使用systemctl 管理nginx

    # vim /usr/lib/systemd/system/nginx.service
    [Unit]
    Description=nginx
    After=network.target
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    [Install]
    WantedBy=multi-user.target
    • 安装php-fpm

    1. php官网 http://php.net
    2. php编译安装

    # 安装依赖
    # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
    # yum install epel-release.noarch
    # yum -y install gcc gcc-c++ make pcre pcre-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel sqlite3-devel
    
    # wget http://hk1.php.net/distributions/php-5.6.34.tar.gz
    # tar -zxvf php-5.6.34.tar.gz
    # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --with-jpeg-dir=/usr/lib64 --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
    
    # make && make install
    # cp php.ini-production /usr/local/php/etc/php.ini
    启动php-fpm

    1. 设环境变量 export PATH=$PATH:/usr/local/php/sbin:/usr/local/php/bin

    2. 检测配置文件,默认报错 cd /usr/local/php/etc;cp php-fpm.conf.default php-fpm.conf;php-fpm –t

    3. 配置监听,php-fpm.conf 默认配置 listen = 127.0.0.1:9000

    4. 使用systemctl管理php-fpm,/usr/lib/systemd/system/php-fpm.service

    # vim /usr/lib/systemd/system/php-fpm.service
    
    [Unit]
    Description=php-fpm
    After=network.target
    [Service]
    Type=forking
    ExecStart=/usr/local/php/sbin/php-fpm
    [Install]
    WantedBy=multi-user.target

    验证php-fpm是否启动
    1. 进程 ps -ef|grep php-fpm

    2. 端口 netstat -nltp | grep 9000

    3. 日志 tail -f /usr/local/php/var/log/php-fpm.log


    • Nginx 结合 php 配置

    • 修改nginx配置
    location / {
    root html;
    index index.html index.htm index.php;
    }
    
    location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    • 测试php网页
    # cat test.php 
    <?php
    echo "hello world test";


    • 验证

    http://10.80.0.20/test.php


    • 安装mysql

    1. 下载mysql 官网 http://mysql.com 下载步骤略
    2. 编译安装
    # yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel perl perl-devel autoconf
    # tar -zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
    # useradd mysql
    # echo 123456 |passwd --stdin mysql
    # chown -R mysql:mysql /usr/local/mysql/
    # cd /usr/local/mysql
    # ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
    # cp sport-files/mysql_server /etc/init.d/mysqld
    # cp my-default.cnf /etc/my.cnf
    # cp mysql.server /etc/init.d/mysql
    • 修改配置文件
    # vim /etc/init.d/mysql 
    basedir=/usr/local/mysql
    datadir=/data/mysql
    # vim /etc/my.cnf
    basedir = /usr/local/mysql\
    bind-address = 0.0.0.0
    port = 3306datadir = /data/mysql
    user = mysql
    skip-name-resolve
    long_query_time=2
    slow_query_log_file = /data/mysql/mysql-slow.log
    expire_logs_days = 7
    innodb-file-per-table = 1
    innodb_flush_log_at_trx_commit = 2
    log_warnings = 1
    max_allowed_packet = 512M
    connect_timeout = 60
    net_read_timeout = 120
    • 配置环境变量
    # vi /etc/profile
    export MYSQL_HOME=/usr/local/mysql
    export PATH=$MYSQL_HOME/bin:$PATH
    # source /etc/profile
    • 启动mysql
    # chkconfig --add mysql
    # chkconfig mysql on
    # service mysql start
    • 设置root密码,授权
    /usr/local/mysql/bin/mysqladmin -u root password '123456'
    mysql -uroot -p123456
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    mysql> FLUSH PRIVILEGES;
    • 设置开机启动
    # cat /usr/lib/systemd/system/mysql.service 
    
    [Unit]
    Description=mysql
    After=network.target
    [Service]
    Type=forking
    ExecStart=/etc/init.d/mysql start
    [Install]
    WantedBy=multi-user.target
    # systemctl daemon-reload
    # systemctl enable mysql
    • 测试PHP链接MYSQL
    # 编写测试mysql链接程序
    
    # cat test_mysql.php 
    
    <?php
    $link=mysql_connect("10.80.0.20","root","123456");
    if(!$link){
    echo "mysql connect failed";
    }else{
    echo "mysql connect success";
    }
    ?>
    • 验证mysql链接

    C A 10.80.O.20/test mysql.php 
mysql connect success

    部署zabbix(server+web)

    zabbix部署原理

    1. Zabbix server 需要把监控数据写入sql数据库,所以需要mysql
    2. Zabbix 的web是基于php开发的,所以需要LNMP环境
    3. 部署zabbix server 和zabbix web

    Zabbix 的官网

           https://www.zabbix.com

    • Zabbix server编译安装

    • 编译安装
    # yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel
    # useradd -s /sbin/nologin zabbix
    # cd /usr/local/src/
    # tar -zxvf zabbix-4.0.27.tar.gz
    # cd zabbix-4.0.27
    # ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp -with-libcurl --with-libxml2
    # make && make install
    • 安装验证
    # vim /etc/profile
    export PATH=$PATH:/usr/local/zabbix/bin:/usr/local/zabbix/sbin
    # source /etc/profile
    # zabbix_server --version
    zabbix_server (Zabbix) 4.0.27
    Revision ff3187cec7 30 November 2020, compilation time: Dec 5 2020 09:51:21
    • mysql数据初始化
    # mysql -uroot -p123456
    mysql> create database zabbix character set utf8 collate utf8_bin;
    mysql> grant all privileges on zabbix.* to zabbix@'%' identified by '123456';
    mysql> flush privileges;
    mysql> set names utf8;
    mysql> use zabbix
    mysql> source /usr/local/src/zabbix-4.0.27/database/mysql/schema.sql
    mysql> source /usr/local/src/zabbix-4.0.27/database/mysql/data.sql
    mysql> source /usr/local/src/zabbix-4.0.27/database/mysql/images.sql
    • 配置zabbixserver,主要配置链接mysql的用户和密码
    # cat zabbix_server.conf|grep -v ^# |grep -v ^$
    
    LogFile=//usr/local/zabbix/zabbix_server.log
    DBHost=10.80.0.20
    DBName=zabbix
    DBUser=zabbix
    DBPassword=123456
    DBPort=3306
    Timeout=30
    AlertScriptsPath=/usr/local/zabbix/alertscripts
    ExternalScripts=/usr/local/zabbix/externalscripts
    LogSlowQueries=3000
    • 启动zabbix server
    # chown -R zabbix:zabbix /usr/local/zabbix
    # zabbix_server
    • 验证zabbix 启动
    # ps -ef|grep zabbix
    # netstat -nltp|grep 10051
    # tail /usr/local/zabbix/zabbix_server.log
    • Zabbix web安装

    • 安装zabbix web
    # mkdir /usr/local/nginx/html/zabbix
    # cp -a /usr/local/src/zabbix-4.0.27/frontends/php/* /usr/local/nginx/html/zabbix/
    • 访问zabbix web 初始化配置

             http://10.80.0.20/zabbix/setup.php

    ZABBIX 
Welcome 
Check of pre-requisites 
Configure 0B connection 
Zabbix server details 
Pre-installation Summary 
Install 
Check of pre-requisites 
Minimum required size of FHP post is 16M (configuration option 
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 
optlon 
Time zone for PNP is not set (configuration parameter "datetimezone"). 
— PH? option -always _ must be set to I" 
— PHP gd JPEG image support missing. 
version 
PHP option -memory_limit" 
PHP option 
PHP option 
PHP option 
Current value 
56.35 
128M 
30 
Required 
540 
128M 
16M 
300 
Back 
Next step

    • Zabbix web 对php的配置有要求,优化php配置
    # 根据上图提示的 需要优化的参数逐个调整为 required的值。
    
    # vim /usr/local/php/etc/php.ini
    date.timezone=Asia/shanghai
    # systemctl restart php-fpm
    • 登录zabbix

      默认用户名/密码 Admin/zabbix,禁用zabbix server监控

      ZABBIX 
Monitoring Inventory Reports 
nfiguration Administration 
Host groups Templates Hosts Maintenance 
Hosts 
Actions 
Triggers 
Event correlation 
Name 
Templates 
Monitored by 
Discovery Services 
type here to search 
DNS 
Any 
V 
Name 
Zabblx server 
Server 
Web 
Web 
select 
Apply 
Templates 
Template App Zabbix Server, Template C 
Applications 
Applications Il 
Disable 
Items 
Items 76 
Export 
Graphs 
Graphs I 
Delete 
Discovery 
Discovery 2 
Interface 
12700.1, 10050 
1 selected 
Enable 
Triggers 46 
Mass update

               禁用guest用户

               ZABBIX 
General Proxies 
User groups 
Monitoring Inventory Reports 
Configuratio 
Media types 
users 
Administratio 
Authentication 
User groups Users 
Scnpts 
Queue 
Name 
Members 
guest 
Admin Zabbix Administrator 
Apply 
Status 
Reset 
Any 
Enabled 
Name 
led debug mode 
Guests 
NO access to the frontend 
Zabbix administrators 
Users 1 
Users 
Users 1 
Disable debug mode 
Disabled 
Frontend access 
Sys!em 
Internal 
Disabled 
System default 
I selected 
Enable 
Disable

               更改Admin密码,改成自己的密码

               image


    zabbix乱码问题

    Zabbix 默认使用英文

    1. 如果英文好,建议直接用英文
    2. 把admin 改为中文

    zabbix默认的字段问题

    1. 中文会有部分乱码的情况
    2. 检测-->图形里面会有乱码的产生

    Proc essor load (1 m in average per core) 
Processor load (5 min average per core) 
Processor load (15 min average per core) 
O load is too h igh on Zabbix server 5 J

    解决zabbix部分乱码问题

    1. 下载微软雅黑字体 https://raw.githubusercontent.com/chenqing/ng-mini/master/font/msyh.ttf 或者C:/windows/fonts下获取
    2. Zabbix字体目录: /usr/local/nginx/html/zabbix/assets/fonts/
    3. 上传到这个目录
    4. 配置修改:/usr/local/nginx/html/zabbix/include/defines.inc.php
    5. 默认是DejaVuSans字体,改为msyh微软雅黑字体
    6. 验证中文是否正常

    Processor load (1 min average per core) 
Processor load (S min average per core) 
Processor load (15 min average per core) 
O Eh": Processor load is too high on Zabbix server 51

    posted @ 2020-12-09 22:27  snailshadow  阅读(166)  评论(0编辑  收藏  举报