Zabbix server 安装配置文档
环境准备
Zabbix Server需要运行在CentOS、RedHat Linux、Debain等Linux系统上,这里以linux6.6作为部署环境,Root用户安装必须的包,建议配置好yum,通过yum安装下列包,解决包的依赖关系。
安装包的下载地址:
http://httpd.apache.org/download.cgi#apache24
http://www.mysql.com/downloads/
http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz
http://www.php.net/downloads.php
http://124.205.69.167/files/5064000004934930/cn2.php.net/distributions/php-5.6.26.tar.gz
下载的安装包全部放在lamp文件夹
LAMP(Linux + Apache + Mysql + PHP)环境
apache安装:
[root@zabbix Desktop]# mkdir lamp
[root@zabbix Desktop]# tar -xvf httpd-2.4.23.tar.gz -C lamp/
[root@zabbix Desktop]# cd lamp/
[root@zabbix lamp]# ls
[root@zabbix lamp]# cd httpd-2.4.23/
[root@zabbix httpd-2.4.23]# ./configure (直接执行这个命令会出现以下的错误,所以提前可以将下面的单个包安装上)
--------------------------------------------------------------------------
出现问题:configure: error: APR not found. Please read the documentation
解决:
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
tar -vxf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make && make install
--------------------------------------------------------------------------
出现错误:configure: error: APR-util not found. Please read the documentation.
解决:
wgethttp://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
tar -vxf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util-with-apr=/usr/local/apr/bin/apr-1-config
make && make install
---------------------------------------------------------------------------
出现错误:configure: error: pcre-config forlibpcre not found. PCRE is required and available from http://pcre.org/
可以从http://pcre.org/上去下载
wgethttp://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=/usr/local/pcre
make && make install
----------------------------------------------------------------------------
[root@zabbix httpd-2.4.23]# ./configure --prefix=/usr/local/apache--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util--with-pcre=/usr/local/pcre(再次执行./configure并加上指定路径)
[root@zabbix httpd-2.4.23]# make &&make install
[root@zabbix httpd-2.4.23]#/usr/local/apache/bin/apachectl start
------------------------------------------------------------------------------
为了方便:cp/usr/local/apache/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
#在#!/bin/sh后添加下面两行(包含"#")
# chkconfig:2345 85 15
# description:Apache
#添加到系统服务中
chkconfig --add httpd
service httpd start
执行service httpd start如果出现以下错误:
[root@zabbix ~]# service httpd start
/etc/init.d/httpd: line 97: lynx: command notfound
解决:
[root@zabbix ~]# yum install lynx -y]
------------------------------------------------------------------------------
用浏览器访问http://localhost时提示It works!
mysql安装 :
[root@zabbixDesktop]# yum install ncurses-devel -y
需要提前安装好这个包,不然后面在运行cmake . 的时候会出现错误
[root@zabbixDesktop]# yum install cmake -y
[root@zabbixDesktop]# groupadd mysql
[root@zabbix Desktop]# useradd -r -g mysql -s /bin/false mysql
[root@zabbixDesktop]# mkdir -p /usr/local/mysql
[root@zabbixDesktop]# mkdir -p /usr/local/mysql/data
[root@zabbixDesktop]# tar -xvf mysql-5.6.28.tar.gz -C lamp/
[root@zabbixDesktop]# cd mysql-5.6.28
[[email protected]]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DENABLED_LOCAL_INFILE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
[[email protected]]# make
[root@zabbixmysql]# make install
[[email protected]]# cd /usr/local/mysql/
[root@zabbixmysql]# chown -R root:mysql .
[root@zabbixmysql]# chown -R mysql:mysql data
[root@zabbixmysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@zabbixmysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@zabbixmysql]# vim /etc/my.cnf
去掉注释并添加目录:
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
socket =/tmp/mysql.sock
[root@zabbixmysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@zabbixmysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
创建系统数据库的表
[root@zabbixmysql]# /etc/init.d/mysqld restart
以下这样设置可以直接查看版本号:
[root@zabbixmysql]# vim /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@zabbixmysql]# source /root/.bash_profile
[root@zabbixmysql]# mysql_secure_installation
除了要求输入密码的地方,其他地方直接回车
[root@zabbixmysql]# mysql -uroot -p
能够通过输入密码登录,mysql安装完成
php安装:
[root@zabbixDesktop]# tar -xvf php-5.6.25.tar.gz -C lamp/
[root@zabbixDesktop]# cd lamp/php-5.6.25/
[root@zabbixDesktop]# yum install gcc make gd-devel libjpeg-devel libpng-devellibxml2-devel bzip2-devel libcurl-devel -y
[[email protected]]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache/bin/apxs --with-bz2 --with-curl --enable-ftp--enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local--with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf--with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext--with-libxml-dir=/usr/local --with-zlib --with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-pdo-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --enable-bcmath
[[email protected]]# make && make install
[[email protected]]# cp php.ini-development /usr/local/php/etc/php.ini
[[email protected]]# vim /usr/local/apache/conf/httpd.conf
添加:
AddHandler php5-script .php
AddType text/html .php
并且在DirectoryIndex 后面追加(或修改)index.php
[[email protected]]# /usr/local/apache/bin/apachectl restart
zabbix安装
安装依赖包
如果是×××的lamp则yum安装:
yum install net-snmp-devel curl curl-devel mysql-devel OpenIPMI-devel -y
可以到官网下载最新安装包
http://219.239.26.9/files/5231000008FE1627/120.52.73.49/tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
安装步骤
1)创建zabbix用户和组
groupadd zabbix
useradd zabbix-g zabbix
2)创建数据库,添加授权账号
create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
3) 编译安装zabbix
tar xzf zabbix-3.0.3.tar.gz
cd zabbix-3.0.3
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \
--with-mysql --with-net-snmp --with-libcurl (支持web监控)
make
make install
4)导入数据库
出现:
[[email protected]]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
ERROR 2002(HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2)
---------------------------------------------------------------------------------
解决:
[[email protected]]# mkdir /var/lib/mysql
[[email protected]]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
---------------------------------------------------------------------------------
mysql -uzabbix-pzabbix zabbix < database/mysql/schema.sql
mysql -uzabbix-pzabbix zabbix < database/mysql/p_w_picpaths.sql
mysql -uzabbix -pzabbixzabbix < database/mysql/data.sql
5)修改配置文件
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp -R frontends/php /usr/local/apache/htdocs/zabbix
chownzabbix:zabbix /usr/local/apache/htdocs/zabbix -R
sed -i's/^DBUser=.*$/DBUser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
6)添加服务端口
cat>>/etc/services <
zabbix-agent10050/tcp # Zabbix Agent
zabbix-agent10050/udp # Zabbix Agent
zabbix-trapper10051/tcp # Zabbix Trapper
zabbix-trapper10051/udp # Zabbix Trapper
EOF
7)启动服务并开机启动
/etc/init.d/zabbix_serverstart
/etc/init.d/zabbix_agentdstart
echo"/etc/init.d/zabbix_server start" >> /etc/rc.local
echo"/etc/init.d/zabbix_agentd start" >> /etc/rc.local
也可以chkconfig zabbix_server on
chkconfig zabbix_agentd on
8)修改php.ini
Vi /etc/php.ini
取消注释:always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
9)web页面安装配置,打开浏览器输入http://zabbixserver ip地址/zabbix
确认每个Required都是ok的才会显示Next按钮,如果有Fail的需要完善系统要求
直接next step
这里一定要全部显示为OK才能够进行下一步
这里填写上之前在MySQL库中设置好的相应用户的密码,next step
这里直接默认下一步
直接下一步
根据页面上的步骤进行操作
登录进入
zabbix server安装完成