ddsdjn 发表于 2019-1-18 08:07:17

Zabbix 3.0.20 搭建之路

      Zabbix 3.0.20LNMP 搭建之路   
           
         我一开始搭建zabbix时,在百度上搜索zabbix的资料,鱼龙混杂,大部分都是Zabbix2.2的搭建资料,搭建之路很苦逼。其中不乏有很多坑,特别是nginx属主属组权限的赋予和zabbix网页文件的设置这两块,对于我一个刚刚接触服务这一块的人来说,很难去把握住其中的要点。故在此记录下自己搭建的过程。全程只用一个yum装包,额。

  
  一、 搭建准备:
  linux/平台centos7.5 ,php5.4 + php-fpm+ VMworkstation12
            >>> centos 7.5自带php5.4的yum源很方便,php5.3不支持zabbix3.0版本,centos6的要改自带的php5.3的yum源后再装php。
  nginxversion: nginx/1.14.0

            >>>centos默认不带nginx的yum源,需要在/etc/yum.repo目录下手动加源,然后用yum装
               #vim /etc/yum.repo/nginx.repo
              
               enable=1
             gpgcheck=1
             gpgkey=http://nginx.org/packages/keys/nginx_signing.key
             name=nginx.o
             baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
mysqlVer 15.1 Distrib 5.5.56-MariaDB
         >>> centos 7以上的mysql,MariaDB ,mysql的兄弟      
      
二 、 nginx 、php 、mysql的安装和配置:


2.1、安装nginx并配置      
#yum install nginx
装完然后更改nginx的默认设置
  # cat /etc/nginx/conf.d/default.conf
  # The default server
  server {
  listen 80;
  server_name localhost;
  root /usr/share/zabbix;
  #charset koi8-r;
  #access_log logs/host.access.log main;
  location / {
  root /usr/share/zabbix;
  indexindex.php;
  # example
  #ModSecurityEnabled on;
  #ModSecurityConfig /etc/nginx/modsecurity.conf;
  }
  #error_page 404 /404.html;
  #location = /404.html {
  #root /usr/share/zabbix;
  #}
  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  root   /usr/share/nginx/html;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #location ~ \.php$ {
  # proxy_pass http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~ \.php$ {
  root/usr/share/zabbix;               #nginx识别zabbix的目录,重要
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #location ~ /\.ht {
  # deny all;
  #}
  }
#service nginx start   



这个时候,在本地打开localhost,即自己的ip号可以看到nginx代理服务。最小系统可以yum install lynx,lynx localhost查看网页。然后在/var/www目录下新建一个index.html,直接用浏览器访问localhost/index.html 就可以直接看到你在index.html文件输入的内容了,nginx设置成功。


2.2、安装Mysql、mariadb-server


#yum install -y mysql
#yum install mariadb-server -y

#systemctl startmariadb.service                   #启动服务


#systemctl enablemariadb.service               #开机启动


接着等后面装完zabbix再建立zabbix的数据库。


2.3、安装php、php-mysql、php-fpm

# yum install php php-mysql php-fpm
配置php:
# vim /etc/php.ini
 date.timezone = Asia/Shanghai
 max_execution_time = 300
 max_input_time = 300
 post_max_size = 16M
 memory_limit = 128M
配置php-fpm:
# vim /etc/php-fpm.d/www.conf

user = nobody
group = nobody
改为
user = nginx
group = nginx
#systemctl start php-fpm                   #启动php-fpm
# systemctl enable php-fpm               #设置开机自启
添加php详情页面

# vim /var/www/index.php

然后访问localhost/index.php看到php详情页,php配置成功。


三、安装zabbix并配置zabbix数据库


3.1、安装zabbix
进入 https://www.zabbix.com/download
ZABBIX VERSIONOS DISTRIBUTIONDATABASE
3.0 LTS (要求php5.3以上)CENTOS 7 / 6Mysql(这里用mysql)
2.2 LTS( php 5.3及以下)RED HAT 7 / 6PostgreSQL
在安装zabbix先看一下自己的php版本:

# rpm-qa|grep php
php-fpm-5.4.16-45.el7.x86_64
php-mysql-5.4.16-45.el7.x86_64
php-5.4.16-45.el7.x86_64
----------------------------------------------------------
接下来按照网页给的那些教程走,复制粘贴,
安装zabbix3.0的源码包:
# rpm -i https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
安装 Zabbixserver, frontend, agent
# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent
查看zabbix安装情况:

  # rpm -qa|grep zabbix
  zabbix-server-mysql-3.0.20-1.el7.x86_64
  zabbix-release-3.0-1.el7.noarch
  zabbix-web-mysql-3.0.20-1.el7.noarch
  zabbix-agent-3.0.20-1.el7.x86_64
  zabbix-web-3.0.20-1.el7.noarch
  >>>zabbix安装完成。
zabbix设置:
#cat /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
  3.2 创建zabbix数据库(教程的步骤,密码自定义哦)
# mysql -uroot
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql> quit;
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix


四、zabbix主文件的移动,让nginx识别
更改了nginx识别zabbix网页文件的默认配置文件,/etc/nginx/conf.d/default.conf

location ~ \.php$ {
root/usr/share/zabbix;               #nginx识别zabbix的目录,重要
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;


修改了这里的内容后,再赋予nginx权限:
chown nginx.nginx /etc/zabbix/web -R


然后在wins10的google浏览器打开localhost/zabbix/setup.php,就可以看到zabbix安装界面了。
比如我的http://192.168.194.128/zabbix.php


五、遇到过的错误和解决方法




5.1、zabbix3.2 httpd页面500错误

nginx
原因是php由nginx启动,/etc/zabbix/web目录权限如下,所以导致nginx无进入这个目录的权限。
修改一下属主:
#cd /etc/zabbix/web
# chown nginx.nginx -R .*
# ll
总用量 8
-rwxr-xr-x. 1 zabbix zabbix 1036 2月27 17:23 maintenance.inc.php
-rwxr-xr-x. 1 zabbix zabbix424 4月12 16:10 zabbix.conf.php
# pwd
/etc/zabbix/web

https://blog.csdn.net/xiegh2014/article/details/70228992


5.2、zabbix web站点安装时无法跳转到下一步或者点击下一步没有反应

lamp平台 执行命令 chown -R apache:apache /var/lib/php/session

lnmp平台 执行命令 chown -R nginx:anginx /var/lib/php/session

  来自




              



页: [1]
查看完整版本: Zabbix 3.0.20 搭建之路