当前位置: 代码迷 >> 综合 >> Zabbix搭建笔记[1]--Zabbix Server安装
  详细解决方案

Zabbix搭建笔记[1]--Zabbix Server安装

热度:0   发布时间:2023-12-14 21:36:04.0


搭建前先做一个简单的拓扑结构:

 


在安装前先配置Zabbix官方源和epel源:


[ZabbixServer] #rpm -ivhhttp://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm --replacefiles


[ZabbixServer] # rpm -ivhhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm --replacefiles


 


在安装zabbix-server之前,先安装httpd


[ZabbixServer] # yum install -y httpd


查看安装的httpd版本:


[ZabbixServer] # rpm -q httpd


httpd-2.4.6-45.el7.centos.4.x86_64


 


接着安装php 5.4(安装3.2版本zabbix要求php版本最低5.4):


[ZabbixServer] # yum install -y php php-gd php-bcmath php-ctype php-xml php-xmlreaderphp-xmlwriter php-session php-sockets php-mbstring php-gettext php-ldap


确认一下安装的php版本:


[ZabbixServer] # php -v


PHP5.4.16 (cli) (built: Nov 6 201600:29:02)


Copyright(c) 1997-2013 The PHP Group


ZendEngine v2.4.0, Copyright (c) 1998-2013 Zend Technologies


 


Zabbix server上安装zabbix-server(也要对自身进行一个监控,所以把agent也安装一下):


[ZabbixServer] # yum install -y zabbix-agent zabbix-server-mysql zabbix-web-mysql


 


Database上安装并配置Mysql


[Datebase]# rpm -ivhhttp://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm


[Database]# yum install -y mysql-server


 


修改Mysql配置文件:


[Database]# vim /etc/my.cnf


 


添加下面高亮的两行:


[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

character-set-server=utf8 #这里配置字符集以避免后续Zabbix界面显示乱码

innodb_file_per_table=1

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid


 


启动Mysql服务:


[Database]# systemctl enable mysqld


[Database]# systemctl start mysqld


 


设置Mysqlroot用户的密码:


mysqladmin -u用户名 -p旧密码 password新密码


[Database]# mysqladmin -uroot password admin


 


使用root用户连接Mysql


[Database]# mysql -uroot -padmin


 


创建Zabbix数据库(这里需要utf8的字符集,否则最终界面会出现中文乱码),并赋予用户zabbix权限:


mysql>create database zabbix character set utf8 collate utf8_bin;


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


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


grant <权限1>,<权限2>,…<权限n> on <数据库名称>.<表名称>to <用户名>@<用户地址>identified by '<连接密码>';


mysql>flush privileges;


 


接着从刚刚安装的ZabbixServer上面把下面这个脚本拷贝到Mysql这台机器上(根据版本找到对应路径,我解压后放到Mysql这台机器的/tmp目录下了):


/usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz


然后只用下面的命令导入Zabbix-Server的数据库(如果安装了Zabbix proxy的话,只导入第一个数据库):


[Database]# mysql -uzabbix -pzabbix


mysql>use zabbix;


mysql>source /tmp/create.sql;


 


回到Zabbix Server上,修改/etc/zabbix/zabbix_server.conf这个配置文件(修改高亮的内容):


[Zabbix Server] # egrep -v "(^#|^$)" /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

DBHost=DanMysql #这里填Mysql这台虚拟机的hostname,要保证可以解析

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock

SNMPTrapperFile=/var/log/snmptt/snmptt.log

CacheSize=256M

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts


 


创建两个脚本目录:


[ZabbixServer] # mkdir /etc/zabbix/alertscripts /etc/zabbix/externalscripts


 


启动httpdZabbix服务并设置开机启动:


[ZabbixServer] # systemctl start httpd


[ZabbixServer] # systemctl enable httpd


[ZabbixServer] # systemctl start zabbix-server


[ZabbixServer] # systemctl enable zabbix-server


启动zabbix-server的时候如果提示下面的报错"Job for zabbix-server.servicefailed because a configured resource limit was exceeded. See "systemctlstatus zabbix-server.service" and "journalctl -xe" fordetails.",可以把selinux关闭掉之后再启动一次。


 


测试情况下可以把防火墙关闭掉,如果需要添加规则,server需要放行2280端口,以及10051端口的入站,还有10050的出站。原因是10051server的默认侦听端口,agent采取主动或Trapper的方式进行连接。agent被动的时候,server会连接agent10050端口(默认端口)。


 


关闭selinux


[Zabbix Server] #setenforce 0


[ZabbixServer] # vim /etc/selinux/config


SELINUX=disabled


 


接着打开浏览器,访问"http://<zabbixserver address>/zabbix",出现如下界面:

 


第二步的时候会check所有的预配项,如果有哪一项没有配置的话,对应修改/etc/httpd/conf.d/zabbix.conf配置并重启httpd服务:

修改下面高亮的部分:


……

<Directory "/usr/share/zabbix">

   Options FollowSymLinks

   AllowOverride None

   Order allow,deny

   Allow from all

 

   <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>

……


 


重新启动httpd服务后,继续下一步,配置MysqlDatabase的连接信息:

 


后面保持默认选项进行安装即可。安装完进入登陆界面,默认用户名是Admin,密码是zabbix

 


登陆后界面显示如下:

 


参数配置文件:


/etc/zabbix/zabbix_server.conf


LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

DBHost=DanMysql

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock

SNMPTrapperFile=/var/log/snmptt/snmptt.log

CacheSize=256M

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts


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


<?php

// Zabbix GUI configuration file

global $DB;

 

$DB['TYPE']    = 'MYSQL';

$DB['SERVER']  = 'DanMysql';

$DB['PORT']    = '3306';

$DB['DATABASE'] = 'zabbix';

$DB['USER']    = 'zabbix';

$DB['PASSWORD'] = 'zabbix';

 

// SCHEMA is relevant only for IBM_DB2 database

$DB['SCHEMA'] = '';

 

$ZBX_SERVER     = 'localhost';

$ZBX_SERVER_PORT = '10051';

$ZBX_SERVER_NAME = '';

 

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

?>

[root@DanZabbix web]# pwd

/etc/zabbix/web


 


禁用Guests组:

 


到这里Zabbix Server的安装部分就做完了。


??
  相关解决方案