redhat Linux6下搭建Zabbix

时间:2021-08-27 22:36:26

Linux:6.2x86
IP地址:192.168.0.105
环境:Apache+MySQL+PHP

注意:Linux下安装zabbix需要有LAMP或者LNMP运行环境

搭建LAMP环境:

1、配置Apache

[root@192 ~]# yum -y install httpd*
[root@192 ~]# /etc/init.d/httpd start

2、安装mysql

[root@192 ~]# yum -y install mysql*
[root@192 ~]# /etc/init.d/mysqld start
修改root密码为123456
[root@192 ~]# /usr/bin/mysqladmin -u root password '123456'

3、安装php

[root@192 ~]# yum -y install php*
重启服务
[root@192 ~]# /etc/init.d/httpd restart
测试Apache、php
[root@192 ~]# vim /var/www/html/info.php
<?php
phpinfo();
?>

出现如下图所示的页面,说明服务安装正确

redhat Linux6下搭建Zabbix

安装zabbix

1、将zabbix-2.0.3上传到/usr/local/src/目录下,并解压

[root@192 ~]# cd /usr/local/src/
[root@192 src]# tar zxf zabbix-2.0.3.tar.gz

2、新建zabbix用户,并创建数据库

[root@192 src]# useradd zabbix

[root@192 src]# mysql -u root -p

mysql> create database zabbix character set utf8;

mysql> grant all on zabbix.* TO zabbix@'localhost' identified by '123456';

mysql> flush privileges;

mysql> use zabbix

mysql> source /usr/local/src/zabbix-2.0.3/database/mysql/schema.sql

mysql> source /usr/local/src/zabbix-2.0.3/database/mysql/images.sql

mysql> source /usr/local/src/zabbix-2.0.3/database/mysql/data.sql

3、编译安装zabbix-2.0.3

[root@192 zabbix-2.0.3]# ./configure --with-mysql --with-libcurl --with-net-snmp --enable-server --enable-agent --enable-proxy --prefix=/usr/local/zabbix
编译过程中可能出现以下问题:
configure: error: no acceptable C compiler found in $PATH
#yum install -y gcc
configure: error: Curl library not found
#yum install curl-devel 
configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config
#yum install net-snmp-devel
[root@192 zabbix-2.0.3]# make && make install

4、修改配置文件

[root@192 zabbix-2.0.3]# vim /etc/httpd/conf/httpd.conf 
DirectoryIndex index.html index.html.var index.php



[root@192 zabbix-2.0.3]# sed -i 's#LogFile=/tmp/zabbix_server.log#LogFile=/var/log/zabbix_server.log#g' /usr/local/zabbix/etc/zabbix_server.conf
[root@192 zabbix-2.0.3]# vim /usr/local/zabbix/etc/zabbix_server.conf
DBPassword=123456
[root@192 zabbix-2.0.3]# grep -vEn '^#|""|^$' /usr/local/zabbix/etc/zabbix_server.conf
39:LogFile=/var/log/zabbix_server.log
87:DBName=zabbix
103:DBUser=root
113:DBPassword=123456
[root@192 zabbix-2.0.3]# touch /var/log/zabbix_server.log
[root@192 zabbix-2.0.3]# chmod 777 /var/log/zabbix_server.log 



[root@192 zabbix-2.0.3]# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
[root@192 zabbix-2.0.3]# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
[root@192 zabbix-2.0.3]# chmod 777 /etc/init.d/zabbix_*



[root@192 zabbix-2.0.3]# sed -i 's#ZABBIX_BIN="/usr/local/sbin/zabbix_server"#ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"#g' /etc/init.d/zabbix_server
[root@192 zabbix-2.0.3]# head -n 21 /etc/init.d/zabbix_server | tail -n 1
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"



[root@192 zabbix-2.0.3]# sed -i 's#ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"#ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"#g' /etc/init.d/zabbix_agentd
[root@192 zabbix-2.0.3]# head -n 21 /etc/init.d/zabbix_agentd | tail -n 1
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"

5、启动服务并设置加入到开机启动项

[root@192 zabbix-2.0.3]# /etc/init.d/zabbix_server start
[root@192 zabbix-2.0.3]# /etc/init.d/zabbix_agentd start
[root@192 zabbix-2.0.3]# chkconfig zabbix_server on
[root@192 zabbix-2.0.3]# chkconfig zabbix_agentd on

6、修改php参数并配置php文件

[root@192 zabbix-2.0.3]# vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai       #去掉前面的分号
post_max_size = 16M
bcmath.scale = 1
[root@192 ~]# /etc/init.d/httpd restart



[root@192 zabbix-2.0.3]# cd frontends/
[root@192 frontends]# cp -rf php /var/www/html/
[root@192 frontends]# cd /var/www/html/
[root@192 html]# mv php zabbix
[root@192 html]# chown -R zabbix:zabbix zabbix

7、安装zabbix

redhat Linux6下搭建Zabbix

出现以下问题,需要安装php-bcmath和php-mbstring两个rpm包,http://pan.baidu.com/s/1cuC4UE,下载后上传到服务器,利用rpm命令安装后重启httpd服务。

[root@192 ~]# /etc/init.d/httpd restart

redhat Linux6下搭建Zabbix

刷新网页

redhat Linux6下搭建Zabbix

redhat Linux6下搭建Zabbix

redhat Linux6下搭建Zabbix

redhat Linux6下搭建Zabbix

redhat Linux6下搭建Zabbix

出现上图的问题:

1)点击下方的download下载文件

2)执行命令

[root@192 Downloads]# cp /root/Downloads/zabbix.conf.php /var/www/html/zabbix/conf

刷新网页

redhat Linux6下搭建Zabbix

redhat Linux6下搭建Zabbix

默认登录名:admin 密码:zabbix

redhat Linux6下搭建Zabbix

若出现zabbix server未启动,可以将selinux与iptables关闭,刷新就好了。命令为:
[root@192~]# service iptables stop
[root@192~]#chkconfig iptables off
[root@192~]#setenforce 0