美文网首页
centos7安装zabbix4.2

centos7安装zabbix4.2

作者: 里脊里脊肉 | 来源:发表于2019-05-08 09:58 被阅读0次

    附zabbixdocker镜像地址

    https://hub.docker.com/u/zabbix/

    zabbix官方文档

    https://www.zabbix.com/cn/download

    1、关闭防火墙和selinux

    systemctl stop firewalld

    vi /etc/selinux/config

    SELINUX=permissive

    setenforce 0

    复制代码[root@localhost ~]# systemctl is-active firewalldactive[root@localhost ~]# [root@localhost ~]# systemctl stop firewalld[root@localhost ~]# [root@localhost ~]# getenforce Enforcing[root@localhost ~]# setenforce 0[root@localhost ~]# [root@localhost ~]# vi /etc/selinux/config  # This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.SELINUX=permissive# SELINUXTYPE= can take one of three two values:#     targeted - Targeted processes are protected,#     minimum - Modification of targeted policy. Only selected processes are protected.#     mls - Multi Level Security protection.SELINUXTYPE=targeted
    

    2、添加zabbix存储库

    rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm

    [root@localhost ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpmRetrieving https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpmwarning: /var/tmp/rpm-tmp.fHl7KV: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEYPreparing...                          ################################# [100%]Updating / installing...   1:zabbix-release-4.2-1.el7         ################################# [100%][root@localhost ~]# ls /etc/yum.repos.d/mylocal.repo  zabbix.repo
    

    3、安装zabbix-server-mysql和zabbix-web-mysql

    yum install -y zabbix-server-mysql zabbix-web-mysql

    要在 MySQL支持下安装Zabbix服务器

    要在 MySQL支持下安装Zabbix前端

    要使用MySQL支持安装Zabbix代理

    yum install zabbix-proxy-mysql -y

    [root@localhost ~]# yum install zabbix-proxy-mysql -yInstalled:  zabbix-proxy-mysql.x86_64 0:4.2.0-1.el7 Complete!
    

    对服务器进行自身监控

    安装zabbix-agent客户端

    yum install zabbix-agent -y

    设置开机自启动

    systemctl start zabbix-agent

    chkconfig zabbix-agent on

    Installed:  zabbix-agent.x86_64 0:4.2.0-1.el7 Complete![root@localhost ~]#[root@localhost ~]# chkconfig zabbix-agent onNote: Forwarding request to 'systemctl enable zabbix-agent.service'.Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.[root@localhost ~]#
    

    4、安装并且启动mysql5.6及初始化数据库信息

    rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm

    [root@localhost ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpmRetrieving http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpmPreparing...                          ################################# [100%]Updating / installing...   1:mysql-community-release-el6-5    ################################# [100%][root@localhost ~]# cd /etc/yum.repos.d/[root@localhost yum.repos.d]#[root@localhost yum.repos.d]# lsmylocal.repo  mysql-community.repo  mysql-community-source.repo  zabbix.repo[root@localhost yum.repos.d]#
    

    yum install -y mysql-community-server

    Installed:  mysql-community-libs.x86_64 0:5.6.43-2.el6                                   mysql-community-server.x86_64 0:5.6.43-2.el6                                   Dependency Installed:  mysql-community-client.x86_64 0:5.6.43-2.el6        mysql-community-common.x86_64 0:5.6.43-2.el6        perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7         perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7         perl-DBI.x86_64 0:1.627-4.el7                       perl-IO-Compress.noarch 0:2.061-2.el7                perl-Net-Daemon.noarch 0:0.48-5.el7                 perl-PlRPC.noarch 0:0.2020-14.el7                   Replaced:  mariadb-libs.x86_64 1:5.5.60-1.el7_5                                                                                                                        Complete!
    

    启动mysqld服务

    systemctl start mysqld

    设置开机自启动

    chkconfig mysqld on

    [root@localhost ~]# systemctl start mysqld[root@localhost ~]# [root@localhost ~]# systemctl status mysqld● mysqld.service - SYSV: MySQL database server.   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)   Active: active (running) since Wed 2019-04-03 01:21:03 CST; 12s ago     Docs: man:systemd-sysv-generator(8)  Process: 68300 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS) Main PID: 68584 (mysqld)   CGroup: /system.slice/mysqld.service           ├─68380 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedi...           └─68584 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.... Apr 03 01:21:02 localhost.localdomain mysqld[68300]: Note: new default config file not created.Apr 03 01:21:02 localhost.localdomain mysqld[68300]: Please make sure your config file is currentApr 03 01:21:02 localhost.localdomain mysqld[68300]: WARNING: Default config file /etc/my.cnf exists on the systemApr 03 01:21:02 localhost.localdomain mysqld[68300]: This file will be read by default by the MySQL serverApr 03 01:21:02 localhost.localdomain mysqld[68300]: If you do not want to use this, either remove it, or use theApr 03 01:21:02 localhost.localdomain mysqld[68300]: --defaults-file argument to mysqld_safe when starting the serverApr 03 01:21:02 localhost.localdomain mysqld[68300]: [  OK  ]Apr 03 01:21:03 localhost.localdomain mysqld[68300]: Starting mysqld:  [  OK  ]Apr 03 01:21:03 localhost.localdomain systemd[1]: mysqld.service: Supervising process 68584 which is not our child. We'll most likely not notice w...t exits.Apr 03 01:21:03 localhost.localdomain systemd[1]: Started SYSV: MySQL database server..Hint: Some lines were ellipsized, use -l to show in full.[root@localhost ~]# [root@localhost ~]# chkconfig mysqld on[root@localhost ~]# 
    

    初始化数据库信息

    mysql_secure_installation

    [root@localhost ~]# mysql_secure_installation   NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the currentpassword for the root user.  If you've just installed MySQL, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):    //回车OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n ... skipping.By default, MySQL comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y - Dropping test database...ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed!  Not critical, keep moving... - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y ... Success!All done!  If you've completed all of the above steps, your MySQLinstallation should now be secure. Thanks for using MySQL!  Cleaning up...
    

    5、创建zabbix数据库,创建zabbix账号

    mysql -uroot -p

    创建一个zabbix库并设置为utf8的字符编码格式

    mysql> create database zabbix character set utf8 collate utf8_bin;

    创建账户并且授权设置密码

    给来自loclhost的用户zabbxi分配可对数据库zabbix所有表进行所有操作的权限,并且设定密码为zabbix

    mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';

    刷新

    mysql> flush privileges;

    [root@localhost ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 10Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.#mysql -uroot -p123456 -e "create database zabbix default character set utf8collate utf8_bin;"#mysql -uroot -p123456 -e "grant all on zabbix. to 'zabbix'@'%' identified by 'zabbix';"#mysql -uroot -p123456 -e "grant all on zabbix. to 'zabbix'@'localhost' identified by 'zabbix';"或如下mysql> create database zabbix character set utf8 collate utf8_bin;Query OK, 1 row affected (0.00 sec)mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> exitBye
    

    6、导入默认的zabbix数据库信息

    zcat /usr/share/doc/zabbix-server-mysql-4.2.1/create.sql.gz | mysql zabbix -uzabbix -pzabbix

    [root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-4.2.0/[root@localhost zabbix-server-mysql-4.2.0]#[root@localhost zabbix-server-mysql-4.2.0]# lsAUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README[root@localhost zabbix-server-mysql-4.2.0]#[root@localhost zabbix-server-mysql-4.2.0]# zcat /usr/share/doc/zabbix-server-mysql-4.2.0/create.sql.gz | mysql zabbix -uzabbix -pzabbixWarning: Using a password on the command line interface can be insecure.[root@localhost zabbix-server-mysql-4.2.0]#
    

    7、修改zabbix_server.conf的配置文件

    grep ^DB /etc/zabbix/zabbix_server.conf

    [root@localhost ~]# grep ^DB /etc/zabbix/zabbix_server.confDBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=zabbix
    

    vi /etc/php.ini

    在最后一行添加一下内容

    php_value max_execution_time 300php_value memory_limit 128Mphp_value post_max_size 16Mphp_value upload_max_filesize 2Mphp_value max_input_time 300
    

    8、修改系统时间

    安装ntp服务

    yum install ntpdate -y

    调整为亚洲上海时区

    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    同步时间服务器

    ntpdate us.pool.ntp.org

    [root@localhost ~]# yum install ntpdate -y…………………………………………Installed:  ntpdate.x86_64 0:4.2.6p5-28.el7.centos                                         Complete![root@localhost ~]# ntpdate us.pool.ntp.org 4 Apr 10:00:11 ntpdate[11904]: step time server 4.53.160.75 offset -32351.195618 sec[root@localhost ~]# date Thu Apr  4 10:00:26 CST 2019[root@localhost ~]# [root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime[root@localhost ~]#[root@localhost ~]# ntpdate us.pool.ntp.org 4 Apr 14:40:12 ntpdate[2807]: step time server 72.30.35.89 offset -32392.501158 sec[root@localhost ~]#[root@localhost ~]# dateThu Apr  4 14:40:32 CST 2019[root@localhost ~]#
    
    9、修改配置文件/etc/httpd/conf.d/zabbix.conf,时区改成 Asia/Shanghai # vi /etc/httpd/conf.d/zabbix.conf 
    
    [root@localhost ~]# vi /etc/httpd/conf.d/zabbix.conf## Zabbix monitoring system php web frontend# Alias /zabbix /usr/share/zabbix <Directory "/usr/share/zabbix">    Options FollowSymLinks    AllowOverride None    Require all granted     <IfModule mod_php5.c>        php_value max_execution_time 300        php_value memory_limit 128M        php_value post_max_size 16M        php_value upload_max_filesize 2M        php_value max_input_time 300        php_value max_input_vars 10000        php_value always_populate_raw_post_data -1        php_value date.timezone Asia/Shanghai    </IfModule></Directory> <Directory "/usr/share/zabbix/conf">    Require all denied</Directory> <Directory "/usr/share/zabbix/app">    Require all denied</Directory> <Directory "/usr/share/zabbix/include">    Require all denied</Directory> <Directory "/usr/share/zabbix/local">    Require all denied</Directory>
    

    10、启动apache/zabbix-server服务并设置为开机启动

    启动apache

    systemctl start httpd

    systemctl enable httpd

    [root@localhost ~]# systemctl start httpd[root@localhost ~]# systemctl status httpd● httpd.service - The Apache HTTP Server   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)   Active: active (running) since Wed 2019-04-03 01:41:59 CST; 19s ago     Docs: man:httpd(8)           man:apachectl(8) Main PID: 68678 (httpd)   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"   CGroup: /system.slice/httpd.service           ├─68678 /usr/sbin/httpd -DFOREGROUND           ├─68679 /usr/sbin/httpd -DFOREGROUND           ├─68680 /usr/sbin/httpd -DFOREGROUND           ├─68681 /usr/sbin/httpd -DFOREGROUND           ├─68682 /usr/sbin/httpd -DFOREGROUND           └─68683 /usr/sbin/httpd -DFOREGROUND Apr 03 01:41:59 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...Apr 03 01:41:59 localhost.localdomain httpd[68678]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using l... messageApr 03 01:41:59 localhost.localdomain systemd[1]: Started The Apache HTTP Server.Hint: Some lines were ellipsized, use -l to show in full.[root@localhost ~]# systemctl enable httpdCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.[root@localhost ~]# 
    

    启动zabbix-server服务并设置为开机启动

    systemctl start zabbix-server

    systemctl enable zabbix-server

    [root@localhost ~]# systemctl start zabbix-server[root@localhost ~]# [root@localhost ~]# systemctl enable zabbix-serverCreated symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.[root@localhost ~]# 
    

    查看zabbix-server日志

    tailf /var/log/zabbix/zabbix_server.log

    [root@localhost ~]# tailf  /var/log/zabbix/zabbix_server.log  4618:20190404:164956.559 server #28 started [icmp pinger #1]  4620:20190404:164956.560 server #30 started [preprocessing manager #1]  4622:20190404:164956.560 server #32 started [preprocessing worker #2]  4625:20190404:164956.561 server #35 started [lld worker #1]  4624:20190404:164956.561 server #34 started [lld manager #1]  4626:20190404:164956.561 server #36 started [lld worker #2]  4623:20190404:164956.562 server #33 started [preprocessing worker #3]  4619:20190404:164956.562 server #29 started [alert manager #1]  4621:20190404:164956.562 server #31 started [preprocessing worker #1]  4610:20190404:164958.602 enabling Zabbix agent checks on host "Zabbix server": host became available
    

    zabbix-server的web目录

    ls /usr/share/zabbix

    [root@localhost ~]# ls /usr/share/zabbixactionconf.php                 audio               discoveryconf.php            image.php        map.import.php     slides.phpadm.gui.php                    auditacts.php       disc_prototypes.php          images           map.php            srv_status.phpadm.housekeeper.php            auditlogs.php       favicon.ico                  img              overview.php       stylesadm.iconmapping.php            browserwarning.php  fonts                        imgstore.php     profile.php        sysmap.phpadm.images.php                 chart2.php          graphs.php                   include          queue.php          sysmaps.phpadm.macros.php                 chart3.php          history.php                  index_http.php   report2.php        templates.phpadm.other.php                  chart4.php          host_discovery.php           index.php        report4.php        toptriggers.phpadm.regexps.php                chart5.php          hostgroups.php               items.php        robots.txt         tr_events.phpadm.triggerdisplayoptions.php  chart6.php          hostinventoriesoverview.php  js               screenconf.php     trigger_prototypes.phpadm.triggerseverities.php      chart7.php          hostinventories.php          jsLoader.php     screenedit.php     triggers.phpadm.valuemapping.php           chart.php           host_prototypes.php          jsrpc.php        screen.import.php  usergrps.phpadm.workingtime.php            charts.php          host_screen.php              latest.php       screens.php        users.phpapi_jsonrpc.php                conf                hosts.php                    local            services.php       zabbix.phpapp                            conf.import.php     httpconf.php                 locale           setup.phpapplications.php               correlation.php     httpdetails.php              maintenance.php  slideconf.php
    

    10、访问网站,例如:http://本机IP/zabbix,如下图所示:

    image

    PHP版本

    image

    password是我们设置的数据库密码zabbix

    image

    输入名字

    image

    查看zabbix基础信息

    image

    finish

    image

    Zabbix·server的默认账号Admin 密码zabbix,如图所示:

    image

    基础界面如下

    image

    根据提示可以看到上面图形界面的操作都写到一个配置文件中

    more /etc/zabbix/web/zabbix.conf.php

    [root@localhost ~]# more /etc/zabbix/web/zabbix.conf.php<?php// Zabbix GUI configuration file.global $DB; $DB['TYPE']     = 'MYSQL';$DB['SERVER']   = 'localhost';$DB['PORT']     = '0';$DB['DATABASE'] = 'zabbix';$DB['USER']     = 'zabbix';$DB['PASSWORD'] = 'zabbix'; // Schema name. Used for IBM DB2 and PostgreSQL.$DB['SCHEMA'] = ''; $ZBX_SERVER      = 'localhost';$ZBX_SERVER_PORT = '10051';$ZBX_SERVER_NAME = 'zabbix4.2'; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;[root@localhost ~]#
    

    移除或改名web目录下面的setup.php文件

    mv setup.php setup.php.bak

    [root@localhost ~]# cd /usr/share/zabbix[root@localhost zabbix]#[root@localhost zabbix]# lsactionconf.php                 audio               discoveryconf.php            image.php        map.import.php     slides.phpadm.gui.php                    auditacts.php       disc_prototypes.php          images           map.php            srv_status.phpadm.housekeeper.php            auditlogs.php       favicon.ico                  img              overview.php       stylesadm.iconmapping.php            browserwarning.php  fonts                        imgstore.php     profile.php        sysmap.phpadm.images.php                 chart2.php          graphs.php                   include          queue.php          sysmaps.phpadm.macros.php                 chart3.php          history.php                  index_http.php   report2.php        templates.phpadm.other.php                  chart4.php          host_discovery.php           index.php        report4.php        toptriggers.phpadm.regexps.php                chart5.php          hostgroups.php               items.php        robots.txt         tr_events.phpadm.triggerdisplayoptions.php  chart6.php          hostinventoriesoverview.php  js               screenconf.php     trigger_prototypes.phpadm.triggerseverities.php      chart7.php          hostinventories.php          jsLoader.php     screenedit.php     triggers.phpadm.valuemapping.php           chart.php           host_prototypes.php          jsrpc.php        screen.import.php  usergrps.phpadm.workingtime.php            charts.php          host_screen.php              latest.php       screens.php        users.phpapi_jsonrpc.php                conf                hosts.php                    local            services.php       zabbix.phpapp                            conf.import.php     httpconf.php                 locale           setup.phpapplications.php               correlation.php     httpdetails.php              maintenance.php  slideconf.php[root@localhost zabbix]#[root@localhost zabbix]# mv setup.php setup.php.bak[root@localhost zabbix]#
    

    设置新的密码,界面的主题、语言和登陆后显示的默认界面等

    image

    解决中文乱码无法显示的问题

    image

    Windows字体目录地址

    C:\Windows\Fonts

    复制到zabbix服务器中

    image

    查找Zabbix所使用的语言包

    find / -name font -print | grep zabbix

    ll find / -name *font* -print | grep zabbix

    [root@localhost ~]# find / -name *font* -print | grep zabbix/etc/alternatives/zabbix-web-font/var/lib/alternatives/zabbix-web-font/usr/share/zabbix/fonts/usr/share/zabbix/fonts/graphfont.ttf[root@localhost ~]#[root@localhost ~]# ll `find / -name *font* -print | grep zabbix`lrwxrwxrwx. 1 root root 38 Apr  4 14:43 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttflrwxrwxrwx. 1 root root 33 Apr  4 14:43 /usr/share/zabbix/fonts/graphfont.ttf -> /etc/alternatives/zabbix-web-font-rw-r--r--. 1 root root 86 Apr  4 14:43 /var/lib/alternatives/zabbix-web-font /usr/share/zabbix/fonts:total 0lrwxrwxrwx. 1 root root 33 Apr  4 14:43 graphfont.ttf -> /etc/alternatives/zabbix-web-font[root@localhost ~]#
    

    备份本身语言包

    mv /usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf.bak

    替换成Windows的语言包

    mv simkai.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf

    [root@localhost ~]# mv /usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf.bak[root@localhost ~]#[root@localhost ~]# lsanaconda-ks.cfg  simkai.ttf[root@localhost ~]#[root@localhost ~]# mv simkai.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf[root@localhost ~]#
    

    刷新页面已经恢复

    image

    参考博客:

    https://www.cnblogs.com/Sungeek/p/9069999.html

    http://www.cnblogs.com/xiewenming/p/7732144.html

    zabbix4.2学习请参考这位博主
    https://www.cnblogs.com/AutoSmart/p/10505090.html

    https://www.cnblogs.com/djlsunshine/p/10644150.html

    相关文章

      网友评论

          本文标题:centos7安装zabbix4.2

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