安装zabbix监控系统

环境

操作系统 最小化安装CentOS Linux release 7.2.1511
IP 192.168.88.1
zabbix版本 zabbix-3.4.4.tar.gz

zabbix依赖于LNMP环境部署

安装环境依赖包

yum install -y curl curl-devel net-snmp \
net-snmp-devel perl-DBI freetype freetype-devel \
libcurl-devel libxslt-devel pcre pcre-devel libevent-devel \
automake autoconf libtool gd gd-devel zlib zlib-devel openssl \
openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libjpeg-turo-devel libpng libpng-devel 

安装php

rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum --enablerepo=remi install php56 php56-php-fpm php56-php-mysqlnd php56-php-gd \
php56-php-xmlrpc php56-php-pecl-redis php56-php-mbstring php56-php-ldap 
systemctl start php56-php-fpm
systemctl enable php56-php-fpm

启动后netstat -lntp查看9000端口是否起来

安装MySQL

yum install -y mariadb mariadb-server mairadb-devel

编辑/etc/my.cnf修改字符集为utf8

[mysqld]
...
character-set-server=utf8

启动数据库并设置密码为root,即账号密码为root/root,(这里演示用,实际生产环境设置复杂的密码)

systemctl restart mariadb
mysqladmin -uroot -p password 'root'

编译安装zabbix

tar xf zabbix-3.4.4.tar.gz

cd zabbix-3.4.4
./configure \
--prefix=/opt/app/zabbix \
--enable-server \
--enable-agent \
--with-mysql \
--enable-bcmath \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--enable-java      #开启此功能需要安装jdk

make install

创建普通用户zabbix, 因为zabbix不允许root用户运行

useradd zabbix
chown -R zabbix.zabbix /opt/app/zabbix

创建相关目录

cd /opt/app/zabbix
mkdir {logs,script}   #存储日志和脚本的目录

在mysql创建数据库并导入数据

create database zabbix;
source /root/tools/zabbix-3.4.4/database/mysql/schema.sql
source /root/tools/zabbix-3.4.4/database/mysql/images.sql
source /root/tools/zabbix-3.4.4/database/mysql/data.sql

修改配置文件

[root@c1 etc]# cd /opt/app/zabbix/etc
[root@c1 etc]# grep -Ev "#|^$" zabbix_server.conf
LogFile=/opt/app/zabbix/logs/zabbix_server.log
PidFile=/opt/app/zabbix/logs/zabbix_server.pid
DBName=zabbix
DBUser=root
DBPassword=root
Timeout=4
AlertScriptsPath=/opt/app/zabbix/script   #指定脚本目录
LogSlowQueries=3000

[root@c1 etc]# grep -Ev "#|^$" zabbix_agentd.conf
PidFile=/opt/app/zabbix/logs/zabbix_agentd.pid
LogFile=/opt/app/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=c1.heboan.com

启动服务

/opt/app/zabbix/sbin/zabbix_server -c /opt/app/zabbix/etc/zabbix_server.conf
/opt/app/zabbix/sbin/zabbix_agentd -c /opt/app/zabbix/etc/zabbix_agentd.conf

安装web界面

安装nginx

useradd -s /sbin/nologin -M nginx
tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2

./configure \
--prefix=/opt/app/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-cpu-opt=amd64 \
--with-pcre
make
make install 

拷贝web文件到nginx目录

mkdir /opt/app/nginx/html/zabbix
cd  ~/tools/zabbix-3.4.4
cp -r frontends/php/* /opt/app/nginx/html/zabbix/

调整php参数

yum install *bcmath* --skip-broken

/opt/remi/php56/root/etc/php.ini
[Date]     #在此行下添加如下一行
date.timezone = Asia/Shanghai
 
找到如下参数并修改
post_max_size = 20M
max_execution_time = 300
max_input_time = 300
always_populate_raw_post_data = 1
...
extension=bcmath.so

#################
vim /opt/app/nginx/html/zabbix/include/classes/setup/CFrontendSetup.php
    public function checkPhpAlwaysPopulateRawPostData() {
            $current = ini_get('always_populate_raw_post_data');
            $current = -1;      ####添加此行
            return [
                    'name' => _s('PHP option "%1$s"', 'always_populate_raw_post_data'),
                    'current' => ($current != -1) ? _('on') : _('off'),
                    'required' => _('off'),
                    'result' => ($current != -1) ? self::CHECK_FATAL : self::CHECK_OK,
                    'error' => _s('PHP option "%1$s" must be set to "%2$s"', 'always_populate_raw_post_data', -1)
            ];
    }


systemctl restart php56-php-fpm

配置nginx虚拟主机

server {
    listen  80;
    server_name  zabbix.heboan.com;
    location / {
        root  /opt/app/nginx/html/zabbix;
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        root /opt/app/nginx/html/zabbix;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    access_log /opt/app/nginx/logs/zabbix.log;

}

启动nginx,访问http://zabbix.heboan.com进行安装,安装完成后,默认的用户名密码是admin/zabbix

posted @ 2018-10-08 16:20  sellsa  阅读(366)  评论(0编辑  收藏  举报