美文网首页
CentOS 7上yum安装Zabbix 3.0(单机版)

CentOS 7上yum安装Zabbix 3.0(单机版)

作者: thinkc | 来源:发表于2017-06-24 11:32 被阅读0次

    01、最小化安装操作系统,推荐 x86_64 版本

    02、升级系统组件到最新版本
    yum -y update

    03、关闭 SELinux
    sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

    04、关闭防火墙
    systemctl stop firewalld.service && systemctl disable firewalld.service

    05、开启端口(如果已执行了第4步,则第5步可忽略。如果有信息安全合规要求,不能直接关闭防火墙,则跳过第4步,执行第5步)
    firewall-cmd --zone=public --list-interfaces
    firewall-cmd --zone=public --permanent --add-interface=eth0
    firewall-cmd --zone=public --add-port=10050/tcp --permanent
    firewall-cmd --zone=public --add-port=10050/udp --permanent
    firewall-cmd --set-default-zone=public
    firewall-cmd --complete-reload

    06、增加 nproc 和 nofile 的上限值
    vi /etc/security/limits.conf,增加以下内容
    *     soft     nproc    65535
    *     hard    nproc    65535
    *     soft     nofile    65535
    *     hard    nofile    65535

    07、修改 vm.swappiness 的值
    vi /etc/sysctl.conf,增加以下内容
    vm.swappiness = 1

    08、安装 MariaDB 源
    vi /etc/yum.repos.d/MariaDB.repo,增加以下内容
    [mariadb]
    name = MariaDB
    baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
    gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
    gpgcheck=1

    09、安装 zbx 所需软件支持包
    yum -y install ntsysv wget telnet net-tools python-paramiko php php-mysqlnd php-gd libjpeg* php-snmp php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-common httpd gcc gcc-c++ dejavu-sans-fonts python-setuptools python-devel sendmail mailx pcre-devel net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC unixODBC-devel MariaDB-server MariaDB-client MariaDB-devel MySQL-python vim epel-release xorg-x11-xauth tree deltarpm

    10、停止并卸载 postfix
    systemctl disable postfix.service && rpm -e --nodeps postfix

    11、启动 MariaDB
    systemctl enable mariadb && systemctl start mariadb

    12、进行 MariaDB 安全配置,除了修改为自定义密码(第 14 步设置 MariaDB 参数时会用到),其它选项选择 y 即可
    mysql_secure_installation

    13、配置相关参数
    mkdir -p /etc/systemd/system/mariadb.service.d/
    vim /etc/systemd/system/mariadb.service.d/limits.conf,增加以下内容
    [Service]
    LimitNOFILE=65535

    systemctl daemon-reload
    systemctl stop mariadb
    systemctl start mariadb

    14、设置 MariaDB 参数(以 8GB 内存为例)
    vim /etc/my.cnf.d/server.cnf,在 [mysqld] 字段下增加以下内容

    port=3306
    socket=/var/lib/mysql/mysql.sock
    user=mysql

    character-set-server=utf8mb4
    collation-server=utf8mb4_unicode_ci
    character-set-client-handshake=0
    init_connect='SET NAMES utf8mb4'

    max_connections=1000
    connect_timeout=60
    wait_timeout=600
    interactive_timeout=600
    lock_wait_timeout=3600
    skip_name_resolve=1
    skip_external_locking=1
    open_files_limit=65535
    explicit_defaults_for_timestamp=1
    pid_file=zabbix.pid
    log_error=zabbix.err
    slow_query_log=1
    slow_query_log_file=zabbix.slow
    thread_concurrency=16
    key_buffer_size=1M
    read_buffer_size=4M
    read_rnd_buffer_size=2M
    table_open_cache=1024
    table_definition_cache=2000
    table_open_cache_instances=64
    thread_cache_size=512
    sort_buffer_size=4M
    join_buffer_size=4M
    bulk_insert_buffer_size=128M
    tmp_table_size=32M
    max_heap_table_size=32M
    query_cache_limit=0
    query_cache_size=0
    symbolic-links=0
    max_allowed_packet=32M
    bind-address=0.0.0.0

    # 如果需要开启复制或搭建高可用,则以下 7 行内容需要启用,否则禁用
    #log_bin = mariadb1-bin
    #binlog_format = ROW
    # 如果对数据完整性要求高,则 sync_binlog = 1
    #sync_binlog = 0
    #binlog_cache_size = 4M
    #max_binlog_cache_size = 1G
    #max_binlog_size = 1G
    #expire_logs_days = 7

    innodb_buffer_pool_size=6G
    innodb_buffer_pool_instances=8
    innodb_buffer_pool_load_at_startup=1
    innodb_buffer_pool_dump_at_shutdown=1
    innodb_log_file_size=1G
    innodb_log_buffer_size=32M
    innodb_log_files_in_group=2
    # 如果对数据完整性要求高,则 innodb_flush_log_at_trx_commit = 1
    innodb_flush_log_at_trx_commit=2
    innodb_lock_wait_timeout=10
    innodb_autoinc_lock_mode=2
    innodb_doublewrite=1
    innodb_thread_concurrency=0
    innodb_flush_method=O_DIRECT
    innodb_io_capacity=10000
    innodb_io_capacity_max=20000
    innodb_purge_threads=1
    innodb_page_cleaners=1
    innodb_open_files=65535
    innodb_max_dirty_pages_pct=50
    innodb_lru_scan_depth=4000
    innodb_status_file=1
    innodb_change_buffer_max_size=50
    innodb_sync_spin_loops=288
    innodb_write_io_threads=16
    innodb_read_io_threads=16
    innodb_random_read_ahead=OFF
    innodb_file_format=Barracuda
    innodb_strict_mode=0
    innodb_file_per_table=1

    thread_handling=pool-of-threads
    thread_pool_oversubscribe=30
    thread_pool_size=64
    thread_pool_idle_timeout=3600
    thread_pool_max_threads=2000

    # 有性能监控要求的,则开启以下参数,否则禁用
    performance_schema = 1
    performance_schema_instrument = '%=on'

    innodb_monitor_enable = "module_srv"
    innodb_monitor_enable = "module_os"
    innodb_monitor_enable = "module_lock"
    innodb_monitor_enable = "module_buffer"
    innodb_monitor_enable = "module_buf_page"
    innodb_monitor_enable = "module_trx"
    innodb_monitor_enable = "module_purge"
    innodb_monitor_enable = "module_file"
    innodb_monitor_enable = "module_index"
    innodb_monitor_enable = "module_adaptive_hash"
    innodb_monitor_enable = "module_ibuf_system"
    innodb_monitor_enable = "module_ddl"
    innodb_monitor_enable = "module_dml"
    innodb_monitor_enable = "module_log"
    innodb_monitor_enable = "module_icp"
    innodb_monitor_enable = "module_metadata"

    vim /etc/my.cnf.d/mysql-clients.cnf,在 [mysql] 字段下增加以下内容
    prompt = "\U[\R:\m][\d]> "
    no-auto-rehash
    default-character-set = utf8mb4
    user=root
    password=Qingdao,2018 # 此处就是第 12 步设置的 MariaDB root 密码

    在 [mysqldump] 字段下增加以下内容
    quick

    注:
    1、原则上 innodb_buffer_pool_size 需要设置为主机内存的 80%,如果主机内存不是 8GB,以上参数可依据相应比例进行调整,例如主机内存为 16GB,则 innodb_buffer_pool_size 建议设置为 12GB。请注意innodb_buffer_pool_size的值必须是整数,例如主机内存是4G,那么innodb_buffer_pool_size可以设置为3G,而不能设置为3.2G
    2、本设置以提升数据库性能为目标,降低了数据安全性。如果要保证数据安全,需对部分参数进行调整,具体请参考 MariaDB 官方文档中的相关内容,本文不展开讨论

    15、配置 MariaDB 中 zbx 所需要的库和账号权限
    systemctl start mariadb
    mysql
    mysql>create database zabbix character set utf8 collate utf8_bin;
    mysql>create user zabbix@'localhost' identified by 'Qingdao,2018';
    mysql>grant all privileges on zabbix.* to zabbix@'localhost';
    mysql>flush privileges;
    mysql>exit;

    16、安装 zbx 源
    rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

    17、安装 zbx
    yum -y install zabbix-server-mysql zabbix-web-mysql

    18、导入 zbx 所需信息(本文编写时,Zabbix 3.0 最新版本为 3.0.19)
    cd /usr/share/doc/zabbix-server-mysql-3.0.19
    zcat create.sql.gz | mysql zabbix

    19、配置 zbx 参数
    vim /etc/zabbix/zabbix_server.conf,主要是以下几个选项参数需要设置(以 8GB 内存为例)DBPassword 配置为第 15 步中设置的自定义密码
    CacheSize=512M
    HistoryCacheSize=128M
    HistoryIndexCacheSize=128M
    TrendCacheSize=128M
    ValueCacheSize=256M
    Timeout=30
    其它参数保持默认值即可(如果监控主机数量较多,则调大 StartPollers 的值)

    如果需要监控VMware虚拟机,则还需要设置以下选项参数:
    StartVMwareCollectors=2
    VMwareCacheSize=256M
    VMwareTimeout=300

    20、配置 Apache 中的 PHP 参数(以 8GB 内存为例)
    vim /etc/httpd/conf.d/zabbix.conf

    max_execution_time 600
    memory_limit 256M
    post_max-size 32M
    upload_max_filesize 32M
    max_input_time 600
    date.timezone 去掉注释符号#,并将值修改为 Asia/Shanghai

    21、重启系统
    systemctl stop mariadb && reboot

    22、启动 zbx
    systemctl start httpd && systemctl start zabbix-server

    23、在浏览器中输入 http://zbx监控服务器的IP地址/zabbix,进行 zabbix 的页面初始化配置,根据页面提示信息进行设置即可。

    “Check of pre-requisites”页面中,需要全部为绿色 ok

    “Zabbix server detail”页面中,“Name”处可填写对此监控系统的描述性文字,支持中文

    24、第一次登录zbx监控系统,默认用户名 admin(或Admin),默认密码 zabbix,确认可正常登录系统,且红色箭头处为绿色的 Yes 后,点击右上角图标退出

    25、将 Windows 7 系统自带的雅黑字体( 此字体文件的默认位置是 c:\windows\fonts\msyh.ttf)上传到 zbx监控服务器系统的 /usr/share/zabbix/fonts 目录下

    注:有人说雅黑字体有版权限制,不能使用在非 Windows 操作系统的环境下,可以更换为宋体等字体文件。

    26、修改 /usr/share/zabbix/include/defines.inc.php 文件,将其中的 45 行 ZBX_GRAPH_FONT_NAME 和 93 行 ZBX_FONT_NAME 的值改为 msyh
    vim /usr/share/zabbix/include/defines.inc.php

    27、重启 Apache 和 zbx
    systemctl enable httpd && systemctl enable zabbix-server && systemctl restart httpd && systemctl restart zabbix-server

    28、在浏览器中输入 http://zbx监控服务器的IP地址/zabbix,用户名 admin(或Admin),默认密码 zabbix,登录进入系统后,选择 Administrator --> Users --> Admin,Language 设置为 Chinese(zh_CN),点击 Update 按钮使之生效

    29、回到“监测中” --> “仪表板”,就可以看到监控系统已设置为中文界面了

    相关文章

      网友评论

          本文标题:CentOS 7上yum安装Zabbix 3.0(单机版)

          本文链接:https://www.haomeiwen.com/subject/hhxkcxtx.html