CentOS 安装Zabbix 手记
请注意,务必先安装好LNMP平台,然后安装zabbix
在sourceforge.net下载最新版本,目前版本是3.0.2
https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/
创建zabbix用户
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
解压源码包
tar zxvf zabbix-3.0.2.tar.gz -C /usr/src/
进入数据库
mysql -u root
创建zabbix数据库
CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
创建zabbix授权库账户zabbix,密码是123456
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
#导入zabbix数据表结构
use zabbix;
source /usr/src/zabbix-3.0.2/database/mysql/schema.sql;
source /usr/src/zabbix-3.0.2/database/mysql/data.sql;
source /usr/src/zabbix-3.0.2/database/mysql/images.sql;
安装组件
yum install -y net-snmp net-snmp-devel curl curl-devel
进入解压目录,编译安装
cd /usr/src/zabbix-3.0.2/
./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy
make && make install
创建日志目录
mkdir /usr/local/zabbix/logs
编辑zabbix_agentd配置文件
cd /usr/local/zabbix/etc/
mv zabbix_agentd.conf zabbix_agentd.conf.bak
vim zabbix_agentd.conf
内容如下:
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
#ServerActive=127.0.0.1
Hostname=Zabbix server
编辑zabbix_server配置文件
mv zabbix_server.conf zabbix_server.conf.bak
vim zabbix_server.conf
内容如下:
LogFile=/usr/local/zabbix/logs/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBHost=localhost
DBPassword=123456
AlertScriptsPath=/usr/local/zabbix/alertscripts
创建自定义脚本目录,设置权限,目录下的脚步,可以被zabbix调用
mkdir /usr/local/zabbix/alertscripts
chown zabbix:zabbix -R /usr/local/zabbix
更改php.ini文件
sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
cgi.fix_pathinfo=0
改为
cgi.fix_pathinfo=1
重启php-fpm
service php-fpm restart
进入源码目录,复制启动脚本
cd /usr/src/zabbix-3.0.2/misc/
cp init.d/tru64/zabbix_server /etc/init.d/
cp init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_*
修改zabbix_agentd、zabbix_server程序目录的位置
vim /etc/init.d/zabbix_agentd
内容如下:
DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
vim /etc/init.d/zabbix_server
内容如下:
DAEMON=/usr/local/zabbix/sbin/zabbix_server
由于zabbix_server 服务不支持 chkconfig,使用下列方法自启动
vim /etc/init.d/zabbix_server
在#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_Server
vim /etc/init.d/zabbix_agentd
在#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_agentd
添加到系统服务
chkconfig zabbix_server on
chkconfig zabbix_agentd on
编辑系统库配置文件
vim /etc/ld.so.conf
加入一行
/usr/local/mysql/lib/
重新加载
ldconfig
启动服务
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
查看端口
netstat -ntpl|grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 21188/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 21140/zabbix_server
复制php页面,并设置权限
cp -rf /usr/src/zabbix-3.0.2/frontends/php/ /usr/local/zabbix/php
chown www:www -R /usr/local/zabbix/php/
编辑nginx配置文件
vim /usr/local/nginx/conf/vhosts/zabbix.conf
内容如下:
server {
listen 80;
server_name localhost;
root /usr/local/zabbix/php;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
重新加载nginx
/usr/local/nginx/sbin/nginx -s reload
访问zabbix安装页面
http://192.168.1.110/setup.php