zabbix安装 - 18965050/zabbix GitHub Wiki

安装

之前在CentOS6.X版本中安装过一次, 没有成功. 因此在我的开发机器(Window)中装了个CentOS7.2的虚拟机, 并在此虚拟机中安装zabbix-server和zabbix-agent. 注意关闭CentOS7中的防火墙配置

systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld	# 需显示为inactive

配置LAMP环境

Apache

zabbix前端使用的是Apache+PHP, 数据库支持MySQL, 因此我们先要安装LAMP环境.

yum install -y httpd 	# 安装Apache
systemctl start httpd	# 启动Apache
systemctl enable httpd	# 开机启动Apache

Apache启动后, 访问http://<server>可看到如下页面: apache-testing

MySQL

这里, 我选择安装的是MariaDB,这个是MySQL的一个分支, 当然安装MySQL也是可以的.

yum install -y mariadb-server mariadb 
systemctl start mariadb		# 启动MySQL
systemctl enable mariadb	# 开机启动MySQL
mysql_secure_installation	# 设置root密码

MySQL的root用户默认是不能远程登录的, 我们可以做如下的操作使其远程登录

  • mysql -uroot -pXXX用root用户登录
  • use mysql选择mysql数据库
  • 执行 update user set host = '%' where user = 'root';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; FLUSH PRIVILEGES; 使其可以远程访问

root远程能访问后, 可使用"TOAD for MySQL"等工具进行访问

PHP

yum install -y php php-mysql php-gd php-pear 

安装完成后, 我们来测试下

vi /var/www/html/testphp.php

编辑如下内容:

<?php 
phpinfo();
?>

并重启apache

systemctl restart httpd

然后访问http://<server>/testphp.php.如果出现如下页面: php-testing 表示PHP安装成功

安装zabbix

  1. 配置zabbix yum源

    yum install epel-release	# 安装epel(Extra Packages for Enterprise Linux)
    
    rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
    rpm -Uv http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm		#安装zabbix GPG-key和yum源
  2. yum安装zabbix-server和zabbix-agent

    yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
  3. 编辑apache中关于zabbix的配置文件/etc/httpd/conf.d/zabbix.conf,更新时区:

    php_value date.timezone Asia/Shanghai

    并重启apache(systemctl restart httpd)

MySQL安装zabbix数据库

  1. 以root用户登录mysql,创建zabbix数据库及zabbix用户
    mysql –u root –pXXX
    create database zabbix character set utf8;
    grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
    flush privileges;
  2. 以zabbix用户登录,执行zabbix初始化脚本
    mysql –uzabbix –pXXX
    use zabbix;
    MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/schema.sql
    MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/images.sql
    MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/data.sql	

zabbix配置文件修改

  1. /etc/zabbix/zabbix_server.conf主要修改如下配置项
配置项 说明
LogFile server日志文件路径
ListenPort server端的监听端口.默认10051
DBName 数据库名称
DBUser 数据库用户
DBPassword 数据库密码
  1. /etc/zabbix/zabbix_agentd.conf主要修改如下配置项
配置项 说明
LogFile agent日志文件路径
Server server IP或主机名
ListenPort agent连接server的端口.默认10050
ServerActive server检测IP
Hostname agent的hostname,web端hosts中配置需要与此相同

php修改

修改/etc/php.ini,修改如下配置项:

max_execution_time = 600
max_input_time = 600
memory_limit = 256
Mpost_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Shanghai

禁用SELinux

  1. 修改/etc/selinux/config配置项:
    SELINUX=disabled
  2. 运行setenforce 0 将会话的SELinux关闭

修改Apache中关于zabbix的配置

修改文件/etc/httpd/conf.d/zabbix.conf,使其和php.ini中的配置相同

#
# 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 date.timezone Asia/Shanghai
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/include">
    Require all denied
</Directory>

另外, 可修改文件/etc/httpd/conf/httpd.conf,设置对根目录所有用户都可以访问(Allow from All)

<Directory />
    AllowOverride none
    Allow from all
</Directory>

启动

systemctl start zabbix-server		# 启动zabbix-server
systemctl start zabbix-agent			# 启动zabbix-agent
systemctl restart httpd				# 重启apache
systemctl restart mariadb			# 重启mysql
systemctl enable zabbix-server		# 开机启动zabbix-server
systemctl enable zabbix-agent  ---- (可选)	# 开机启动zabbix-agent

启动配置

访问http://<server>/zabbix, 可看到如下页面 zabbix-config-1

点击"next",检查包的完整性和参数配置 zabbix-config-2

点击"next",进行数据库的连接 zabbix-config-3

点击"next",输入zabbix-server信息 zabbix-config-4

点击"next",显示预安装summary zabbix-config-5

点击"next",完成安装 zabbix-config-6

安装完成后, 跳转到登录页面, 默认的用户名和密码为admin/zabbix zabbix-config-7

登录成功后, 可看到dashboard zabbix-config-8

⚠️ **GitHub.com Fallback** ⚠️