CentOS 7.2安装zabbix 3.0 LTS

Posted StaryJie

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7.2安装zabbix 3.0 LTS相关的知识,希望对你有一定的参考价值。

1、zabbix简介

  zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
  zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
  zabbix由2部分构成,zabbix server与可选组件zabbix agent。
  zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

  更多详细信息请访问zabbix官网:https://www.zabbix.com/

2、zabbix版本选择

  企业使用建议选择zabbix的LTS版本(Long Time Support),尝鲜的可以选择官方的最新版本。

3、zabbix安装

  本篇随笔基于CentOS 7.2编写。适用于CentOS 7所有版本及RedHat系列。

  安装官方的yum源 
[root@zabbix-server ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.Putphp: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-3.2-1.el7         ################################# [100%]
[root@zabbix-server ~]#
View Code

  查看都安装了什么 

[root@zabbix-server ~]# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-3.0
/usr/share/doc/zabbix-release-3.0/GPL
[root@zabbix-server ~]#
View Code

  安装zabbix及其他必须的软件 

[root@zabbix-server ~]# yum install -y zabbix-server-mysql zabbix-web-mysql
View Code

  由于CentOS 7比较特殊,MySQL已经没了,只能安装mariadb: 

[root@zabbix-server ~]# yum install -y mariadb-server
View Code

  启动并设置开机自启动数据库 

[root@zabbix-server bin]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@zabbix-server bin]# systemctl start mariadb.service
[root@zabbix-server bin]#
View Code

  初始化数据库 

[root@zabbix-server ~]# find / -type f -name "mysql_secure_installation"
/usr/bin/mysql_secure_installation    #mariadb数据库自带的初始化脚本
[root@zabbix-server ~]#
[root@zabbix-server bin]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we\'ll need the current
password for the root user.  If you\'ve just installed MariaDB, and
you 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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:    #123456
Re-enter new password:    #123456
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from \'localhost\'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named \'test\' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done!  If you\'ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@zabbix-server bin]#
View Code

  创建zabbix数据库 

[root@zabbix-server ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \\g.
Your MariaDB connection id is 10
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type \'help;\' or \'\\h\' for help. Type \'\\c\' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by \'123456\';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \\q
Bye
[root@zabbix-server ~]#
View Code

  导入zabbix库的数据

[root@zabbix-server ~]# ll /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz
-rw-r--r-- 1 root root 1161488 Jul 19 00:09 /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz
[root@zabbix-server ~]# zcat /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz|mysql -uzabbix -p zabbix
Enter password:
[root@zabbix-server ~]# mysql -uzabbix -p123456 -e "use zabbix;show tables;"
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| groups                     |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| httpstep                   |
| httpstepitem               |
| httptest                   |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| items                      |
| items_applications         |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_url         |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| task                       |
| task_close_problem         |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
+----------------------------+
[root@zabbix-server ~]#
View Code

  修改zabbix-server配置文件 

[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
# This is a configuration file for Zabbix server daemon
# To get more information about Zabbix, visit http://www.zabbix.com
############ GENERAL PARAMETERS #################
### Option: ListenPort
#       Listen port for trapper.
#
# Mandatory: no
# Range: 1024-32767
# Default:
# ListenPort=10051
### Option: SourceIP
#       Source IP address for outgoing connections.
#
# Mandatory: no
# Default:
# SourceIP=
### Option: LogType
#       Specifies where log messages are written to:
#               system  - syslog
#               file    - file specified with LogFile parameter
#               console - standard output
#
# Mandatory: no
# Default:
# LogType=file
### Option: LogFile
#       Log file name for LogType \'file\' parameter.
#
# Mandatory: no
# Default:
# LogFile=
LogFile=/var/log/zabbix/zabbix_server.log
### Option: LogFileSize
#       Maximum size of log file in MB.
#       0 - disable automatic log rotation.
/DBHost
#       1 - critical information
#       2 - error information
#       3 - warnings
#       4 - for debugging (produces lots of information)
#       5 - extended debugging (produces even more information)
#
# Mandatory: no
# Range: 0-5
# Default:
# DebugLevel=3
### Option: PidFile
#       Name of PID file.
#
# Mandatory: no
# Default:
# PidFile=/tmp/zabbix_server.pid
PidFile=/var/run/zabbix/zabbix_server.pid
### Option: DBHost
#       Database host name.
#       If set to localhost, socket is used for MySQL.
#       If set to empty string, socket is used for PostgreSQL.
#
# Mandatory: no
# Default:
# DBHost=localhost
### Option: DBName
#       Database name.
#       For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
#
# Mandatory: yes
# Default:
# DBName=
DBName=zabbix
### Option: DBSchema
#       Schema name. Used for IBM DB2 and PostgreSQL.
#
# Mandatory: no
# Default:
# DBSchema=
### Option: DBUser
#       Database user. Ignored for SQLite.
#
# Mandatory: no
# Default:
# DBUser=
DBUser=zabbix
### Option: DBPassword
#       Database password. Ignored for SQLite.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=123456
### Option: DBSocket
#       Path to MySQL socket.
#
# Mandatory: no
# Default:
# DBSocket=/tmp/mysql.sock
### Option: DBPort
"/etc/zabbix/zabbix_server.conf" 642L, 14894C written                                                  
[root@zabbix-server ~]#
View Code

  启动zabbix-server服务 

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

  设置正确的时区 

[root@zabbix-server conf.d]# vim /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 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>
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
"zabbix.conf" 37L, 831C written                                                                        
[root@zabbix-server conf.d]#
View Code

  启动httpd 

[root@zabbix-server conf.d]# systemctl start httpd
[root@zabbix-server conf.d]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix-server conf.d]#
View Code

  浏览器访问:http://10.0.0.11/zabbix

  web界面会自动检查所有的条件是否满足,未满足的会提示。
  配置数据库连接
  默认不需要修改,只需要自己随便设置一个name就可以了。
 
所有的设置信息全部显示,可以查看校验是否有误
成功界面,显示成功安装zabbix,并告知配置文件及路径
登录界面,默认用户名Admin,默认密码zabbix。
登陆之后,进入zabbix监控页
zabbix3.0之后,默认支持中文显示,修改成中文步骤如下
 
中文显示界面如下

  zabbix-agent客户端安装 

[root@zabbix-server~]# yum install -y zabbix-get zabbix-agent    #其中zabbix-agent负责数据收集,zabbix-get是一个server端模拟数据收集的命令,常用语部署自定义监控前的测试工具
View Code

  启动zabbix-agent 

[root@zabbix-server conf.d]# systemctl start zabbix-agent.service
[root@zabbix-server conf.d]# 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.
View Code

  检查 

[root@zabbix-server conf.d]# netstat -lnutp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      4398/mysqld         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1465/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1774/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      5293/zabbix_agentd  
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      4538/zabbix_server  
tcp6       0      0 :::80                   :::*                    LISTEN      4685/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1465/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1774/master         
tcp6       0      0 :::10050                :::*                    LISTEN      5293/zabbix_agentd  
tcp6       0      0 :::10051                :::*                    LISTEN      4538/zabbix_server  
udp        0      0 127.0.0.1:323           0.0.0.0:*                           3293/chronyd        
udp6       0      0 ::1:323                 :::*                                3293/chronyd        
[root@zabbix-server conf.d]#
View Code

以上是关于CentOS 7.2安装zabbix 3.0 LTS的主要内容,如果未能解决你的问题,请参考以下文章

zabbix 3.0.7 for Centos 7.2 安装

Zabbix 3.4 在CentOS 7.2 上安装详细步骤

centos 7 上zabbix 3.0 服务端安装

CentOS 7 安装 Zabbix 3.0

CentOS6上编译安装ZABBIX 3.0

CentOS-7 编译安装 Zabbix-3.0