layout: post
title: Zabbix—Server端安装步骤
date: 2018-03-28
tags: [“Zabbix”,”软件服务”]


一、Get source codes

https://www.zabbix.com/download_sources

二、Install Server

1、Install Packeges

  1. yum install -y net-snmp net-snmp-devel libxml2 mysql-devel libevent libevent-devel curl-devel OpenIPMI-devel fping nginx

2、编译 Zabbix

  1. groupadd zabbix
  2. useradd -g zabbix zabbix
  3.  
  4. tar xf zabbix-.tar.gz
  5. cd zabbix-
  6. ./configure --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --prefix=/app/zabbix
  7. make && make install

错误解决,这时会出现很多错误,如下

  1. error: Invalid Net-SNMP directory - unable tofind net-snmp-config
  2. #yum install net-snmp-devel
  3.  
  4. configure: error: Jabber library not found
  5. #yum install iksemel-devel -y
  6.  
  7. configure: error: LIBXML2 library not found
  8. #yum install libxml2-devel -y
  9.  
  10. configure: error: unixODBC library not found
  11. #yum install unixODBC-devel -y
  12.  
  13. configure: error: Invalid OPENIPMI directory -unable to findipmiif.h
  14. #yum install OpenIPMI-devel
  15.  
  16. configure:error: Unable to find"javac" executable in path
  17. #yum install java-devel -y
  18.  
  19. configure: error: Curl library not found
  20. # yum install curl-devel -y
  21.  
  22. configure: error: SSH2 library notfound
  23. #yum install -y libssh2-devel

编辑zabbix_server配置文件

  1. vim /app/zabbix/etc/zabbix_server.conf
  2. ListenPort=10051
  3. SourceIP=172.18.30.253
  4. LogType=file
  5. LogFile=/tmp/zabbix_server.log
  6. PidFile=/app/zabbix/etc/zabbix_server.pid
  7. DBName=zabbix
  8. DBUser=zabbix
  9. DBPassword=123123
  10. DBSocket=/tmp/mysql.sock
  11. DBPort=3306
  12. StartPollers=5
  13. SNMPTrapperFile=/app/zabbix/etc/zabbix_traps.tmp
  14. ListenIP=172.18.30.253
  15. Timeout=4
  16. LogSlowQueries=3000

3、编译 php

  1. tar xf php-7.2.1.tar.bz
  2. cd php-7.2.1
  3.  
  4. ./configure --prefix=/app/php \
  5. --enable-mysqlnd \
  6. --with-mysqli=mysqlnd \
  7. --with-openssl \
  8. --with-pdo-mysql=mysqlnd \
  9. --enable-mbstring \
  10. --with-freetype-dir \
  11. --with-jpeg-dir \
  12. --with-png-dir \
  13. --with-zlib \
  14. --with-libxml-dir=/usr \
  15. --enable-xml \
  16. --enable-sockets \
  17. --enable-fpm \
  18. --with-config-file-path=/etc \
  19. --with-config-file-scan-dir=/etc/php.d \
  20. --enable-maintainer-zts \
  21. --disable-fileinfo \
  22. --with-gd \
  23. --with-gettext \
  24. --enable-bcmath
  25.  
  26. make && make install

启用配置文件

  1. cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
  2. cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/default.conf

修改php的运行用户和组

  1. vim /app/php/etc/php-fpm.d/default.conf
  2. user = nginx
  3. group = nginx

配置文件最下面添加指定参数

  1. vim /app/php/etc/php-fpm.d/default.conf
  2. php_flag[display_errors] = off
  3. php_admin_value[error_log] = /var/log/fpm-php.www.log
  4. php_admin_flag[log_errors] = on
  5. php_admin_value[memory_limit] = 128M
  6. php_admin_value[post_max_size] = 16M
  7. php_admin_value[max_execution_time] = 300
  8. php_admin_value[max_input_time] = 300
  9. php_value[date.timezone] = Asia/Shanghai

优化php配置方法http://blog.vservices.top/myblog/?p=1022

启动php

  1. /app/php/sbin/php-fpm

4、Confige nginx

1)配置文件

  1. server {
  2. listen 8080 default_server;
  3. root /usr/share/nginx/html/zabbix;
  4. index index.php index.html index.htm;
  5. location / {
  6. fastcgi_pass localhost:9000;
  7. fastcgi_index index.php;
  8. fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/zabbix$fastcgi_script_name;
  9. fastcgi_param QUERY_STRING $query_string;
  10. fastcgi_param REQUEST_METHOD $request_method;
  11. fastcgi_param CONTENT_TYPE $content_type;
  12. fastcgi_param CONTENT_LENGTH $content_length;
  13. include fastcgi_params ;
  14. }

2)拷贝zabbix源码目录下的”frontend/php”目录到”/usr/share/nginx/html/zabbix”

  1. cp -ra /root/zabix-3.4.7/frontend/php /usr/share/nginx/html/zabbix
  2. chmod -R g+w /usr/share/nginx/zabbix
  3. chown -R root.nginx /usr/share/nginx/zabbix
  5、安装配置Mysql(二进制包安装) 1)添加用户
  1. useradd -s /sbin/nologin -M mysql

2)创建数据目录

  1. mkdir /data/db1
  2. chown mysql:root /data/db1/

3)解压2禁止mysql包

  1. cd /root
  2. tar xf mariadb-10.2.14-linux-x86_64.tar.gz
  3. cp -ar mariadb-10.2.14-linux-x86_64 /usr/local/
  4. cd /usr/local/
  5. ln -s /usr/local/mariadb-10.2.14-linux-x86_64 ./mysql

4)创建配置文件

  1. cp -ra /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
  2.  
  3. vim /etc/my.cnf
  4.  
  5. #修改[mysqld]如下项目
  6.  
  7. datadir = /data/db1
  8. innodb_file_per_table = on
  9. skip_name_resolve = on

5)初始化数据库

  1. cd /usr/local/mysql/
  2. scripts/mysql_install_db --datadir=/data/db1 --user=mysql

6)创建日志文件

  1. touch /var/log/mysqld.log
  2. chown mysql /var/log/mysqld.log

7)准备服务脚本,并启动服务

  1. cd /usr/local/mysql/
  2. cp support-files/mysql.server /etc/init.d/mysqld
  3.  
  4. #这个启动脚本需要添加一些配置
  5. vim /etc/init.d/mysqld
  6. #修改以下两个变量
  7. basedir=/usr/local/mysql
  8. datadir=/data/db1
  9.  
  10. #启动mysql
  11. chkconfig --add mysqld #添加到启动列表
  12. service mysqld start #启动服务( redhat7 也可以通过systemctl来管理服务)

8)修改mysql用户权限

  1. #登录数据库
  2. [root@ansible_master mysql]# mysql
  3.  
  4. #修改用户权限
  5. MariaDB [(none)]> use mysql;
  6. MariaDB [mysql]> select user,host,password from user;
  7. +------+-----------------+----------+
  8. ' user ' host ' password '
  9. +------+-----------------+----------+
  10. ' root ' localhost ' '
  11. ' root ' ansible\_master ' '
  12. ' root ' 127.0.0.1 ' '
  13. ' root ' ::1 ' '
  14. ' ' localhost ' '
  15. ' ' ansible\_master ' '
  16. +------+-----------------+----------+
  17. 6 rows in set (0.00 sec)
  18.  
  19. MariaDB [mysql]> grant all on *.* to 'root'@'%' identified by '123123';
  20. MariaDB [mysql]> delete from user where password='';
  21. MariaDB [mysql]> flush privileges;

9)创建zabbix数据

  1. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  2. MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by '123123';

10)导入zabbix的数据信息

  1. [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/schema.sql ' mysql -uroot -p'123123' -D zabbix
  2. [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/images.sql ' mysql -uroot -p'123123' -D zabbix
  3. [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/data.sql ' mysql -uroot -p'123123' -D zabbix

注意:三个sql的执行顺序弄错了就要推倒重来了

6、启动zabbix

  1. /app/zabbix/sbin/zabbix_server

7、登录zabbix页面配置zabbix基础配置

在浏览其中打来http://:

一步一步配置即可

配置完毕后使用用户:”Admin”密码:”zabbix”登录页面

三、问题汇总

1、如果你在登录界面后发现web无法连接server端,这时候你需要修改”vim /usr/share/nginx/zabbix/conf/zabbix.conf.php”

  1. $ZBX_SERVER = '172.18.30.253';
  2.  
  3. 该变量必须和你"zabbix_server.conf"文面中"listenIP"的地址一致,
  4. 同理,如果数据库无法连接,也需要修改数据库相对的配置

2、配置nginx的fastcgi之后显示

配置nginx配置文件,添加”include fastcgi_params ;”

文档更新时间: 2019-01-02 10:00   作者:张尚