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
- yum install -y net-snmp net-snmp-devel libxml2 mysql-devel libevent libevent-devel curl-devel OpenIPMI-devel fping nginx
2、编译 Zabbix
- groupadd zabbix
- useradd -g zabbix zabbix
- tar xf zabbix-
.tar.gz cd zabbix- ./configure --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --prefix=/app/zabbix make && make install
错误解决,这时会出现很多错误,如下
- error: Invalid Net-SNMP directory - unable tofind net-snmp-config
- #yum install net-snmp-devel
- configure: error: Jabber library not found
- #yum install iksemel-devel -y
- configure: error: LIBXML2 library not found
- #yum install libxml2-devel -y
- configure: error: unixODBC library not found
- #yum install unixODBC-devel -y
- configure: error: Invalid OPENIPMI directory -unable to findipmiif.h
- #yum install OpenIPMI-devel
- configure:error: Unable to find"javac" executable in path
- #yum install java-devel -y
- configure: error: Curl library not found
- # yum install curl-devel -y
- configure: error: SSH2 library notfound
- #yum install -y libssh2-devel
编辑zabbix_server配置文件
- vim /app/zabbix/etc/zabbix_server.conf
- ListenPort=10051
- SourceIP=172.18.30.253
- LogType=file
- LogFile=/tmp/zabbix_server.log
- PidFile=/app/zabbix/etc/zabbix_server.pid
- DBName=zabbix
- DBUser=zabbix
- DBPassword=123123
- DBSocket=/tmp/mysql.sock
- DBPort=3306
- StartPollers=5
- SNMPTrapperFile=/app/zabbix/etc/zabbix_traps.tmp
- ListenIP=172.18.30.253
- Timeout=4
- LogSlowQueries=3000
3、编译 php
- tar xf php-7.2.1.tar.bz
- cd php-7.2.1
- ./configure --prefix=/app/php \
- --enable-mysqlnd \
- --with-mysqli=mysqlnd \
- --with-openssl \
- --with-pdo-mysql=mysqlnd \
- --enable-mbstring \
- --with-freetype-dir \
- --with-jpeg-dir \
- --with-png-dir \
- --with-zlib \
- --with-libxml-dir=/usr \
- --enable-xml \
- --enable-sockets \
- --enable-fpm \
- --with-config-file-path=/etc \
- --with-config-file-scan-dir=/etc/php.d \
- --enable-maintainer-zts \
- --disable-fileinfo \
- --with-gd \
- --with-gettext \
- --enable-bcmath
- make && make install
启用配置文件
- cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
- cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/default.conf
修改php的运行用户和组
- vim /app/php/etc/php-fpm.d/default.conf
- user = nginx
- group = nginx
配置文件最下面添加指定参数
- vim /app/php/etc/php-fpm.d/default.conf
- php_flag[display_errors] = off
- php_admin_value[error_log] = /var/log/fpm-php.www.log
- php_admin_flag[log_errors] = on
- php_admin_value[memory_limit] = 128M
- php_admin_value[post_max_size] = 16M
- php_admin_value[max_execution_time] = 300
- php_admin_value[max_input_time] = 300
- php_value[date.timezone] = Asia/Shanghai
优化php配置方法http://blog.vservices.top/myblog/?p=1022
启动php
- /app/php/sbin/php-fpm
4、Confige nginx
1)配置文件
- server {
- listen 8080 default_server;
- root /usr/share/nginx/html/zabbix;
- index index.php index.html index.htm;
- location / {
- fastcgi_pass localhost:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/zabbix$fastcgi_script_name;
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
- include fastcgi_params ;
- }
2)拷贝zabbix源码目录下的”frontend/php”目录到”/usr/share/nginx/html/zabbix”
5、安装配置Mysql(二进制包安装) 1)添加用户
- cp -ra /root/zabix-3.4.7/frontend/php /usr/share/nginx/html/zabbix
- chmod -R g+w /usr/share/nginx/zabbix
- chown -R root.nginx /usr/share/nginx/zabbix
- useradd -s /sbin/nologin -M mysql
2)创建数据目录
- mkdir /data/db1
- chown mysql:root /data/db1/
3)解压2禁止mysql包
- cd /root
- tar xf mariadb-10.2.14-linux-x86_64.tar.gz
- cp -ar mariadb-10.2.14-linux-x86_64 /usr/local/
- cd /usr/local/
- ln -s /usr/local/mariadb-10.2.14-linux-x86_64 ./mysql
4)创建配置文件
- cp -ra /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
- vim /etc/my.cnf
- #修改[mysqld]如下项目
- datadir = /data/db1
- innodb_file_per_table = on
- skip_name_resolve = on
5)初始化数据库
- cd /usr/local/mysql/
- scripts/mysql_install_db --datadir=/data/db1 --user=mysql
6)创建日志文件
- touch /var/log/mysqld.log
- chown mysql /var/log/mysqld.log
7)准备服务脚本,并启动服务
- cd /usr/local/mysql/
- cp support-files/mysql.server /etc/init.d/mysqld
- #这个启动脚本需要添加一些配置
- vim /etc/init.d/mysqld
- #修改以下两个变量
- basedir=/usr/local/mysql
- datadir=/data/db1
- #启动mysql
- chkconfig --add mysqld #添加到启动列表
- service mysqld start #启动服务( redhat7 也可以通过systemctl来管理服务)
8)修改mysql用户权限
- #登录数据库
- [root@ansible_master mysql]# mysql
- #修改用户权限
- MariaDB [(none)]> use mysql;
- MariaDB [mysql]> select user,host,password from user;
- +------+-----------------+----------+
- ' user ' host ' password '
- +------+-----------------+----------+
- ' root ' localhost ' '
- ' root ' ansible\_master ' '
- ' root ' 127.0.0.1 ' '
- ' root ' ::1 ' '
- ' ' localhost ' '
- ' ' ansible\_master ' '
- +------+-----------------+----------+
- 6 rows in set (0.00 sec)
- MariaDB [mysql]> grant all on *.* to 'root'@'%' identified by '123123';
- MariaDB [mysql]> delete from user where password='';
- MariaDB [mysql]> flush privileges;
9)创建zabbix数据
- MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
- MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by '123123';
10)导入zabbix的数据信息
- [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/schema.sql ' mysql -uroot -p'123123' -D zabbix
- [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/images.sql ' mysql -uroot -p'123123' -D zabbix
- [root@ansible_master mysql]# cat /root/zabbix-3.4.7/database/mysql/data.sql ' mysql -uroot -p'123123' -D zabbix
注意:三个sql的执行顺序弄错了就要推倒重来了
6、启动zabbix
- /app/zabbix/sbin/zabbix_server
7、登录zabbix页面配置zabbix基础配置
在浏览其中打来http://
一步一步配置即可
配置完毕后使用用户:”Admin”密码:”zabbix”登录页面
三、问题汇总
1、如果你在登录界面后发现web无法连接server端,这时候你需要修改”vim /usr/share/nginx/zabbix/conf/zabbix.conf.php”
- $ZBX_SERVER = '172.18.30.253';
- 该变量必须和你"zabbix_server.conf"文面中"listenIP"的地址一致,
- 同理,如果数据库无法连接,也需要修改数据库相对的配置
2、配置nginx的fastcgi之后显示
配置nginx配置文件,添加”include fastcgi_params ;”