zabbix fast

源码安装步骤

来源它站:

官方文档:https://www.zabbix.com/documentation/2.4/manual/installation/install#from_the_sources

环境:Centos6.4 64bit

1.安装依赖包和LAMP环境

安装开发软件包

yum -y groupinstall  "Development Tools"

安装LAMP(Linux,Apache, Mysql, Php)环境及zabbix所需644的依赖包

yum -y install httpd mysql mysql-server php php-mysql php-common php-mbstring php-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate  php-bcmath

备注:除LAMP之外,还有常见的LNMP(Linux, Nginx, MySQL, Php)。

2.创建zabbix服务运行所需要的用户和组

groupadd zabbix
useradd -g zabbix zabbix
passwd zabbixuser #修改用户密码

3. 初始化及配置mysql数据库

启动mysql服务:

chkconfig mysqld on #设置mysql服务开机启动
service mysqld start 或者/etc/init.d/mysqld start #来启动mysql服务

 进入mysql的sql命令状态,创建zabbix运行所需要的数据库及用户权限:

[root@cloudstack local]# mysqladmin -u root –h 127.0.0.1 password "123456" --root用户初始化后无密码,此处设定密码为123456
[root@cloudstack local]# mysql –u root –h 127.0.0.1 –p -- -p是强制输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
--创建zabbix数据库
mysql>create database zabbix character set utf8;
--插入zabbix用户
mysql>grant all privileges on zabbix.* to zabbixuser@'%' identified by 'zabbixpassword';
--或者insert into mysql.user(Host,User,Password) values("localhost","zabbixuser",password("zabbixpassword"));
Query OK, 1 row affected, 3 warnings (0.00 sec)
mysql>flush privileges;

4.安装配置zabbix

4.1下载zabbix-2.4.7

mkdir /lyy
cd /lyy
wget #将源码包下载到/lyy目录下
tar -zxvf zabbix-2.4.7.tar.gz #解压

4.2 编译安装zabbix

cd zabbix-2.4.7
./configure --sysconfdir=/usr/local/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql
如果configure过程中提示少包,可以及时安装,如:yum –y install mysql-devel。

Configure正确完成后,根据提示执行:

make install
注意:此处sysconfdir指定配置文件的路径(zabbix_server.conf和zabbix_agent.conf),指定就在/usr/local/zabbix/目录下的etc目录了,如果不指定默认在/usr/local/下的etc目录下。

 

4.3配置 zabbix server端及agent端的系统服务脚本

cp /lyy/zabbix-2.4.7/misc/init.d/tru64/zabbix_agentd /etc/init.d/
cp /lyy/zabbix-2.4.7/misc/init.d/tru64/zabbix_server /etc/init.d/
chown zabbixuser:zabbixuser /etc/init.d/zabbix_*
以上配置完毕后,可以直接在zabbixuser用户下的任意目录,执行

service zabbix_server start/stop/restart
如果不配置以上系统服务脚本,则需执行/usr/local/zabbix/sbin/zabbix_server(或者缺省的usr/local/sbin/zabbix_server)启动服务。

 

4.4将zabbix的初始数据导入到数据库zabbix中

mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/schema.sql
mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/images.sql
mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/data.sql

登录数据库查看下表是否都创建成功

 

4.5 配置zabbix的网站

将zabbix的页面文件copy到指定目录(跟apache配置的相同即可)

mkdir /var/www/html/zabbix
cp -rf /lyy/zabbix-2.4.7/frontends/php/* /var/www/html/zabbix/
chown -R zabbixuser.zabbixuser /var/www/html/zabbix/

4.6配置php文件,适应zabbix安装所需的参数

vim /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
注意: 其中参数mbstring.func_overload = 2是要求注释掉的,否则会在后边产生错误。

 

5.配置apache文件,定义访问zabbix的主机

vim /etc/httpd/conf/httpd.conf
ServerName 192.168.229.131
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName 192.168.229.131
</VirtualHost>

6.启动apache服务跟zabbix服务

chkconfig httpd on #设置开机启动httpd服务
service httpd start #启动httpd服务
此时查看并确认服务(主要是httpd,mysqld, zabbix_server)启动情况:

netstat -plunt | grep LISTEN

 

4.7配置zabbix server端的配置文件

修改zabbix_server.conf(缺省位置在/usr/local/etc/zabbix_server.conf,此处为/usr/local/zabbix/etc/zabbix_server.conf),定义其中数据库的IP、用户名、密码参数。

vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=192.168.1.46
DBName= zabbix
DBUser=zabbixuser
DBPassword=zabbixpassword
#后面的供参考
StartPollers=30 #开启多线程数,一般不要超过30个
StartTrappers=20 #trapper线程数
StartPingers=10 #fping线程数
StartDiscoverers=120
MaxHousekeeperDelete=5000
CacheSize=1024M #用来保存监控数据的缓存数,根据监控主机的数量适当调整
StartDBSyncers=8 #数据库同步时间
HistoryCacheSize=1024M
TrendCacheSize=128M #总趋势缓存大小
HistoryTextCacheSize=512M
AlertScriptsPath=/etc/zabbix/alertscripts
LogSlowQueries=1000

 

7.访问安装界面并根据提示逐步完成安装

7.1访问网站并初始化

在浏览器中输入:http://192.168.1.46/zabbix/ ,然后根据网页提示一步一步往下进行。

注意以下常见错误及解决:

当遇到配置/var/www/html/zabbix/conf/zabbix.conf.php失败的情况,如下图:

解决方法:

根据提示下载配置文件zabbix.conf.php,并拷贝到/var/www/html/zabbix/conf/目录下,并给zabbixuser授权,之后点击网页上的重试即可。

[root@cloudstack conf]# cp /home/centos6/Desktop/zabbix.conf.php /var/www/html/zabbix/conf/
[root@cloudstack conf]# chown zabbixuser:zabbixuser zabbix.conf.php

 

 

7.2登录监控器主界面

一切准备完毕后,进入登陆界面,初始的用户名是admin和密码是zabbix,之后会进入主界面。

 

 

 

注意以下常见错误及解决:

1.在zabbix主界面遇到以下报错:

date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead [dashboard.php:130 →

解决方法:

第1步

[root@cloudstack init.d]# vi /etc/php.ini
配置date.timezone = Aisa/Shanghai
第2步

[root@cloudstack init.d]# vi /var/www/html/zabbix/include/page_header.php
在最前边添加ini_set('date.timezone','Asia/Shanghai');

2.在zabbix主界面遇到报错:server is not running

解决方法:

1.先看日志情况

vi /tmp/zabbix_server.log
2. 查看防火墙设置情况

3.参考http://my.oschina.net/jincon/blog/269870,可以其中一个函数被禁用导致的问题,解决:

vi /etc/php.ini
将其中disable_function=注释掉即可。

8. Zabbix的简单试用

8.1配置和添加host

posted @ 2017-06-08 15:35  Alex_Footprint  阅读(198)  评论(0编辑  收藏  举报