Centos8安装zabbix5.4.7(一)

zabbix实验笔记,并实现企业微信告警通知。安装centos linux时建议最小化安装。

Centos8安装相关系统包

  • 因为最小化安装系统,所以软件包特别少,因此需要安装一些常用的包

    1
    yum -y install net-tools vim net-snmp-utils
  • 关闭selinux,需要修改vim /etc/selinux/config,重启后生效

    1
    2
    - SELINUX=enforcing
    + SELINUX=disabled
  • 卸载防火墙

    1
    yum -y remove firewalld
  • 验证一些OID的命令

    1
    snmpwalk -v 2c -c public IP地址 OID

下载zabbix相关安装包

  • 从官网下载相关包

    1
    2
    rpm -Uvh https://repo.zabbix.com/zabbix/5.4/rhel/8/x86_64/zabbix-release-5.4-1.el8.noarch.rpm
    dnf clean all
  • 使用dnf安装相关软件包

    1
    dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-agent

安装MySQL数据库

  • 下载MySQL8.0版本的rpm包

    1
    wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
  • 本地安装rpm包

    1
    2
    yum localinstall mysql80-community-release-el8-1.noarch.rpm  #rpm包
    yum update
  • 安装数据库并启动设置开机自启

    1
    2
    3
    systemctl start mysqld
    systemctl enable mysqld
    systemctl status mysqld # 查看服务状态
  • 设置数据库root密码

    1
    2
    3
    use mysql; //选择数据库
    alter user 'root'@'localhost' identified by 'password'; //修改密码
    flush privileges; //刷新权限表

zabbix相关设置

  • 创建zabbix库

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # 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;
  • 导入zabbix库

    1
    zcat /usr/share/doc/zabbix-sql-scripts/mysql/create.sql.gz | mysql -uzabbix -p zabbix #这个zabbix为库名
  • 修改配置文件 /etc/zabbix/zabbix_server.conf

    1
    2
    - DBPassword=password
    + DBPassword=设置的zabbix数据库密码
  • 在/etc/my.cnf.d/自定义一个zabbix.cnf实现数据库调优

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    [mysqld]
    user = mysql
    local_infile = 0

    datadir = /var/lib/mysql/

    default-storage-engine = InnoDB
    skip-name-resolve
    key_buffer_size = 32M
    max_allowed_packet = 128M
    table_open_cache = 1024
    table_definition_cache = 1024
    max_connections = 2000
    join_buffer_size = 1M
    sort_buffer_size = 2M
    read_buffer_size = 256K
    read_rnd_buffer_size = 256K
    myisam_sort_buffer_size = 1M
    thread_cache_size = 512
    open_files_limit = 65535
    wait_timeout = 86400

    optimizer_switch=index_condition_pushdown=off

    tmp_table_size = 32M
    max_heap_table_size = 32M

    log_bin = 1
    binlog_format=mixed
    binlog_cache_size = 32M
    max_binlog_size = 256M
    binlog_expire_logs_seconds = 604800

    # #innodb_page_size = 32K

    innodb_buffer_pool_size = 512M
    innodb_log_file_size = 256M
    innodb_log_buffer_size = 64M
    innodb_file_per_table = 1
    innodb_flush_method = O_DIRECT
    innodb_buffer_pool_instances = 4
    innodb_write_io_threads = 4
    innodb_read_io_threads = 4
    innodb_adaptive_flushing = 1
    innodb_lock_wait_timeout = 50

    innodb_flush_log_at_trx_commit = 2

    innodb_io_capacity = 300
    innodb_io_capacity_max = 400
    innodb_flush_neighbors = 0

    innodb_doublewrite = 1
    innodb_thread_concurrency = 0

    innodb_purge_threads = 1

    server_id = 1
    binlog_checksum = crc32

    innodb_lru_scan_depth = 512

    innodb_stats_on_metadata = 0
  • 创建zabbix server 站点配置文件,vim /etc/nginx/conf.d/zabbix.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    server {
    # listen 80;
    # server_name example.com;

    root /usr/share/zabbix;

    index index.php;

    location = /favicon.ico {
    log_not_found off;
    }

    location / {
    try_files $uri $uri/ =404;
    }

    location /assets {
    access_log off;
    expires 10d;
    }

    location ~ /\.ht {
    deny all;
    }

    location ~ /(api\/|conf[^\.]|include|locale|vendor) {
    deny all;
    return 404;
    }

    location ~ [^/]\.php(/|$) {
    fastcgi_pass unix:/run/php-fpm/zabbix.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;

    fastcgi_param DOCUMENT_ROOT /usr/share/zabbix;
    fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;

    include fastcgi_params;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    }
    }

  • 启动zabbix server和agent进程并设置开机自启

    1
    2
    # systemctl restart zabbix-server zabbix-agent nginx php-fpm
    # systemctl enable zabbix-server zabbix-agent nginx php-fp

web页面中文乱码问题

  • 复制本地电脑C:\Windows\Fonts\simkai.ttf(楷体)上传到zabbix服务器网站目录的fonts目录下。此步骤可以使用winscp软件。2、修改zabbix字体为刚才上传的字体,graphfont.ttf是zabbix默认字符集。

    1
    2
    3
    cd /usr/share/zabbix/fonts
    mv graphfont.ttf graphfont.ttf.bak
    mv msyh.ttc graphfont.ttf
  • 刷新页面,可以看到监控页面中文正常显示

主机名不能输入中文

  • 修改zabbix的php文件:/usr/share/zabbix/include/defines.inc.php

    1
    2
    - define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-]+)');
    + define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-\x{80}-\x{ff}]+)');