参考文档
官方文档 :https://www.zabbix.com/documentation/3.4/zh/manual/installation
其他:https://juejin.cn/post/6844903517019176973
如果你的服务器是一台全新的服务器,想要快速搭建zabbix请点击这里:
https://www.cnblogs.com/ops-ywt/p/11942311.html (根据官方文档搭建,lamp )
如果你不想使用官方的lamp 环境,而是想用自己搭建的 lnmp 环境可以参考本篇文章
全新的服务器centos7.3 系统,最小化安装
yum_lnmp环境安装-->https://www.cnblogs.com/51fly/p/14688448.html
我们不完全采用官网步骤进行安装,因为根据官网的步骤安装的zabbix环境是基于 lamp
而我们要使用 lnmp 环境安装zabbix,所以官方文档中 yum -y zabbix-web-mysql 这条命令就不要使用了,因为在安装zabbix-web-mysql 时会自动安装Apache(httpd2.4.x版本)和PHP(5.4版本)具体在 安装Zabbix web会详细说明
添加Zabbix存储库
[root@localhost ~]#rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
安装Zabbix server
[root@localhost ~]#yum install -y zabbix-server-mysql
在mysql中创建zabbix帐号
[root@localhost ~]# mysql -uroot -p
mysql>create database zabbix character set utf8;
mysql>grant all privileges on zabbix.* to ‘zabbix‘@‘localhost‘ identified by ‘Zabbix#123‘ with grant option;
mysql>flush privileges;
导入初始架构(Schema)和数据
[root@localhost ~]#cd /usr/share/doc/zabbix-server-mysql-3.4.15
[root@localhost ~]#zcat create.sql.gz | mysql -uzabbix -p zabbix
配置Zabbix服务器端
vim /etc/zabbix/zabbix_server.conf
,找到配置项,并更改配置
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix#123
切换文件夹所有人
chown -R zabbix:zabbix /etc/zabbix
chown -R zabbix:zabbix /usr/lib/zabbix
设置开机启动zabbixserver systemctl enable zabbix-server
启动zabbix server systemctl start zabbix-server
修改/etc/php.ini 文件 vim /etc/php.ini
,找到配置项,并修改成如下内容
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1 默认是注释的,需要手动打开注释
安装Zabbix web
注意:官网文档的安装步骤有 yum install -y zabbix-web-mysql 操作,安装zabbix-web-mysql 时会自动帮我们安装28个相对应的依赖包,安装完成后在 /usr/share/zabbix 有一些PHP文件,这些文件都是zabbix web相关的
从下图中可以看出执行 yum install -y zabbix-web-mysql
命令后默认帮我们安装了 httpd 和 PHP 还有一些其他的依赖
而此时我们的系统已经用yum 安装lnmp环境,这时候在 yum install -y zabbix-web-mysql 会报错,因为我们已经安装了 PHP5.6
这个命令又会自动帮我们安装PHP5.4和httpd,所以会冲突
正确的打开方式
wget https://cdn.zabbix.com/zabbix/sources/oldstable/3.4/zabbix-3.4.15.tar.gz
解压并进入zabbix目录 tar zxvf zabbix-3.4.15.tar.gz
拷贝zabbix-3.4.15/frontends/php
文件夹中所有内容到 /data/www/zabbix
文件夹中
cp -rf ./zabbix-3.4.15/frontends/php/* /data/www/zabbix
注意:/data/www 是nginx网站的根目录,默认没有此目录,先创建目录
mkdir -p /data/www/zabbix
新建配置文件
mv /data/www/zabbix/conf/zabbix.conf.php.example /data/www/zabbix/conf/zabbix.conf.php
vi /data/www/zabbix/conf/zabbix.conf.php,修改其中数据ip地址,数据库名,用户名密码
我的nginx配置 如下图:
完整nginx配置文件
cat /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
server_name localhost;
root /data/www;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.html index.htm index.php;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
进入zabbix web配置,访问 http://ip/zabbix
这一步是检查PHP 扩展模块是否都OK,如果不是ok会有报错提示,根据报错提示安装对应的PHP模块
填入我们在前面创建的mysql zabbix账号信息
根据提示,下载配置文件,然后放在 /data/www/zabbix/conf/ 目录下
然后在访问 http://ip/zabbix
默认账号:Admin
默认密码:zabbix
遇到的问题
yum 安装PHP-gd 遇到的问题
使用yum已经安装了 php-gd, 但是php -m 发现没有加载gd模块
php -m|grep gd 发现有警告,百度一下发现还要安装,yum -y install harfbuzz , 之后gd 模块就加载出来了(不知道为什么)
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/gd.so‘ - /lib64/libraqm.so.0: undefined symbol: hb_ft_font_set_load_flags in Unknown on line 0
https://blog.csdn.net/Late_vegetables/article/details/110930746
原文:https://www.cnblogs.com/51fly/p/14689317.html