zabbix3.4.2的安装及配置
zabbix3.4.2的安装及配置是建立在lnmp环境搭建的基础上,前面的博文已详尽介绍了lnmp环境的安装,可移步参考。
一、安装依赖库
#yum install -y net-snmp net-snmp-devel curl curl-devel mariadb-devel libevent libevent-devel pcre-devel libxml2-devel libcurl-deve
# yum -y install mariadb-server
二、下载源码包,顺带着也安装一下zabbix-get
#
wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.2/zabbix-3.4.2.tar.gz/download
#
wget http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-get-3.4.4-2.el6.x86_64.rpm
#yum install -y zabbix-get-3.4.4-2.el6.x86_64.rpm
里面有几种数据库,但是我们用mysql,所以进入mysql数据库创建脚本目录,可以看到有schema.sql、images.sql、data.sql这三个文件 ,进入准备好的mysql数据库,输入密码,进入MySQL控制台,创建数据库zabbix,并且数据库编码使用utf8,允许账户zabbix能从本机连接到数据库zabbix,刷新系统授权表
#
cd
/usr/local/src/zabbix-3
.4.2
/database/mysql
#
mysql -uroot -p
mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci;
grant all on zabbix.* to
'zabbix'
@
'127.0.0.1'
identified by
'zabbix';
flush privileges;
#groupadd zabbix
#useradd -g zabbix zabbix -s /sbin/nologin
# cd /usr/local && chown -R zabbix:zabbix zabbix
mysql -uzabbix -pzabbix;
进入数据库,准备导库,注意:请按照以上顺序进行导入,否则会出错,
导入zabbix数据表结构:#
mysql> use zabbix;
mysql> source /usr/local/src/zabbix-3.4.2/database/mysql/schema.sql;
mysql> source /usr/local/src/zabbix-3.4.2/database/mysql/data.sql;
mysql> source /usr/local/src/zabbix-3.4.2/database/mysql/images.sql;
mysql> quit
退出
#exit
也可以或者这样导入
#
mysql -uzabbix -pzabbix -hlocalhost zabbix <
/usr/local/src/zabbix-3
.4.2
/database/mysql/schema
.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix < /usr/local/src/zabbix-3
.4.2
/
database/mysql/images
.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix <
/usr/local/src/zabbix-3
.4.2
/
database/mysql/data
.sql
三、 编译安装zabbix
#yum install zabbix-server-mysql zabbix-web-mysql -y
#cd /usr/local/src/zabbix-3.4.2
#./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
--with-mysql
=/usr/bin/mysql_config
--enable-proxy
如果出现报错,安装报错提示的依赖包,再次运行上面的编译命令,直到没有报错(如下面截图):
然后运行:
#
make && make install
四、zabbix相关配置
创建日志目录文件:
# mkdir /usr/local/zabbix/logs
# chown zabbix:zabbix logs
可以查看启动日志:
# tail -100f /usr/local/zabbix/logs/zabbix_server.log
常见启动错误:
./zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决:
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
修改agent配置文件:
#cd /usr/local/zabbix/etc/
#mv zabbix_agentd.conf zabbix_agentd.conf.bak
# cat zabbix_agentd.conf.bak | grep -v "#" | grep -v "^$" > zabbix_agentd.conf
#vim zabbix_agentd.conf
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1 # 主动向zabbix server发送监控内容
Hostname=Zabbix server
#配置zabbix 服务器
#
cd /usr/local/zabbix/etc/
#cp zabbix_server.conf zabbix_server.conf.bak
#vim /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=root
DBPassword=zabbix
DBPort=3306
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
ldconfig
/usr/local/zabbix/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
/usr/local/zabbix/sbin/zabbix_agentd
#配置zabbix web
vim /usr/local/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name localhost;
access_log /usr/local/nginx/zabbix/localhost/access.log main;
index index.php index.html index.html;
root /home/data/zabbix;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.(php)?$ {
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
cp /home/data/zabbix/zabbix/conf/zabbix.conf.php.example /home/data/zabbix/zabbix/conf/zabbix.conf.php
vim /home/data/zabbix/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'root';
$DB['PASSWORD'] = 'xxxxx';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'zabbix-server';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
#绑定hosts之后,打开浏览器访问
修改server端配置文件:
备份原配置文件,然后去掉注释:
[root@console etc]# mv zabbix_server.conf zabbix_server.conf.bak
[root@console etc]# cat zabbix_server.conf.bak | grep -v "#" | grep -v "^$" > zabbix_server.conf
最终改后的配置文件内容如下:
#mv zabbix_server.conf zabbix_server.conf.bak
# cat zabbix_server.conf
LogFile=/usr/local/zabbix/logs/
zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
# 注意mysql服务器上的mysql.sock文件路径,一般zabbix server和mysql在同一台就改为/tmp/mysql.sock,否则不修改
DBSocket=/tmp/mysql.sock
Timeout=4
LogSlowQueries=3000
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=1
重启php-fpm
#/etc/init.d/php-fpm restart
进入源码目录,复制启动脚本
#cd /usr/local/src/zabbix-3.4.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_*
#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 ##这里再配置问价里面行首“#”表示注释
设置开机自启:
添加开机启动脚本
cp /usr/local/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server #服务端
cp /usr/local/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd #客户端
chmod +x /etc/rc.d/init.d/zabbix_server #添加脚本执行权限
chmod +x /etc/rc.d/init.d/zabbix_agentd #添加脚本执行权限
chkconfig zabbix_server on #添加开机启动
chkconfig zabbix_agentd on #添加开机启动
#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
必须要看到10050和10051端口都起来
复制php页面,并设置权限
#cp -rf /usr/local/zabbix-3.4.2/frontends/php/ /usr/local/zabbix/php
#chown www.www -R /usr/local/zabbix/php/
配置虚拟主机
请相应修改你的配置文件路径
编辑nginx配置文件
server {
listen 80;
server_name localhost;
access_log /data/logs/nginx/nginxaccess.log ;
index index.php index.html index.html;
root /data/site/huotouyihao;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
#gzip on;
server {
listen 80;
server_name localhost;
access_log /data/logs/nginx/nginxaccess.log;
index index.phpindex.html;
location / {
try_files $uri$uri/ /index.php?$args;
}
location ~ \.php${
root html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefastcgi_params;
fastcgi_paramSCRIPT_FILENAME /usr/local/nginx/html(注意前面目录是用户自定义的数据目录)$fastcgi_script_name;
}
error_page 500 502 503 504 /50x.html;
location =/50x.html {
root html;
}
vim /usr/local/nginx/conf/nginx.conf
# cat /usr/local/nginx/conf/nginx.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
/etc/init.d/nginx restart
停止zabbix server
# killall -9 zabbix_server
编辑php配置文件,开启中文
#vim /usr/local/zabbix/php/include/locales.inc.php
'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],
#/etc/init.d/php-fpm restart
拷贝前端文件
接下来就是进入zabbix的web界面了,这时候需要把前端文件copy到nginx的HTML目录下
1 mkdir /usr/local/nginx/html/zabbix
2 cd /usr/local/src/zabbix-3.4.2/frontends/php/
3 cp * /usr/local/nginx/html/zabbix/
进入web界面:http://ip/zabbix/
下面是安装过程遇到的问题
提示不满足zabbix的先决条件
根据提示去更改php.ini的相关数值,参考上面的先决条件
在这个过程可能会涉及到php模块的安装,可以参考php扩展模块的安装方法安装就能完成
到网页访问,开始安装:(访问之前检查下防火墙,selinux)
这里就有问题了,报了一个小错。解决办法:
#ln -s /var/lib/mysql/mysql.sock /tmp/
#vim /usr/local/php/etc/php.ini
Mysql.default_socket = /var/lib/mysql/mysql.sock
#/etc/init.d/php-fpm restart
在退回一步,然后再接着下一步就可以了
这就安装成功了!
如果想将语言调成中文也可以:
至此就大功告成了!
附一些可能出现的错误以后慢慢补充:
解决办法:
打开/usr/local/php/etc/php.ini文件把always_populate_raw_post_data = -1这一行注释打开,
保存重启php-fpm
后续会继续补充其他可能报错