Zabbix监控安装

19 篇文章 0 订阅
11 篇文章 0 订阅

Zabbix监控安装使用

安装完成后路径
zabbix 配置文件路径 /etc/zabbix/zabbix_server.conf
nginx 代理zabbix配置文件 /opt/nginx/conf.d/zabbix.conf
PHP72 配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

系统
Centos 7系列

1. 安装MySQL

yum 源安装默认为最新版目前是8.0,如果需要5.7一定需要更改版本
如果需要更改其他版本,可以执行完 yum -y localinstall xxx 之后 修改/etc/yum.repos.d/mysql-community.repo
需要安装哪个版本就把参数更改为 1 和 1

systemctl stop mysqld
rm -rf  /var/lib/mysql/*
rm -rf /var/log/mysql*
rm -rf /etc/my.cnf   
wget  https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
rpm -iUvh mysql80-community-release-el7-3.noarch.rpm   
#默认为最新版目前是8.0,如果需要5.7一定需要更改版本
yum -y install  mysql-community-server 

#Make sure you have database server up and running.
systemctl start mysqld
systemctl enable mysqld 
cat /var/log/mysqld/mysql.log |grep "password"   //查看密码

如果yum出现无法安装无法找到证书/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 、设置 gpgcheck=0
登录MySQL,并创建zabbix用户

ALTER USER 'root'@'localhost' IDENTIFIED BY '自定义密码(注意密码强度)';
create database zabbix character set utf8 collate utf8_bin;

create user 'zabbix'@'127.0.0.1' identified with mysql_native_password by '自定义密码';
grant all privileges on zabbix.* to zabbix@localhost;
--flush privileges--;
quit;

2. 安装Zabbix仓库

#Install Zabbix repository

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all


3. 安装Zabbix server 和 agent

#Install Zabbix server and agent

yum install zabbix-server-mysql zabbix-agent


4.安装Zabbix前端页面

  1. Enable Red Hat Software Collections
yum install centos-release-scl
  1. modify zabbix frontend repo
    #编辑配置文件 /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
...
enabled=1     #修改为 1
...
  1. Install Zabbix frontend packages
yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl


5. 导入初始架构和数据

#刚才yum下载已经下载有初始数据包, 需要输入zabbix刚才自己设置的密码

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix


6. 修改Zabbix-server的数据库配置

#编辑配置文件 /etc/zabbix/zabbix_server.conf

DBPassword=password #修改为你刚才为zabbix设置的密码



7. 修改php72的用户和地区

add nginx to listen.acl_users directive Then uncomment and set the right timezone for you
编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

listen.acl_users = apache,nginx      
php_value[date.timezone] = Asia/Shanghai


8. 源码安装NGINX

脚本一键安装:
安装路径:/opt/nginx
源码路径:/root/

 #!/bin/bash
useradd -s /sbin/nologin nginx         

#Installation dependence
yum groupinstall -y "Development tools"
yum install -y gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
yum install -y pcre-devel pcre zlib zlib-devel openssl openssl-devel wget gcc gcc-c++ unzip
yum -y install git

#Download source
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xvf nginx-1.20.1.tar.gz -C /opt

#Compile and install
cd /opt/nginx-1.20.1/
sed -i '49s/nginx/Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '50s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '51s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
./configure \
--prefix=/opt/nginx/ \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module 


make && make install
ln -s /opt/nginx/sbin/nginx  /usr/bin/nginx
mkdir /opt/nginx/conf.d

#拷贝zabbix默认的nginx文件过来
mv /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf  /opt/nginx/conf.d/
rm -rf /etc/opt/rh/rh-nginx116

9. 修改NGINX监听端口和配置Zabbix前端

uncomment and set ‘listen’ and ‘server_name’ directives
vim /opt/nginx/conf.d/zabbix.conf

# listen 80;
# server_name example.com;

以下这些可以自定义修改
LogFile=/var/log/zabbix/zabbix_server.log //如果修改这个就要创建目录
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123qsjfd.b
DBSocket=/var/lib/mysql/mysql.sock
Timeout=30
LogSlowQueries=3000
##JavaGateway=127.0.0.1
##JavaGatewayPort=10052
StartJavaPollers=5

10. 写入NGINX默认文件

rm -rf  /opt/nginx/conf/nginx.conf
cat>/opt/nginx/conf/nginx.conf<<EOF
worker_processes  auto;
error_log               logs/error.log error;
pid             logs/nginx.pid;
events {        
        worker_connections  65535;
        multi_accept on;
}

http {
        include    mime.types;
        default_type  application/octet-stream;

        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       logs/access.log main;
        keepalive_timeout  60;
        add_header Access-Control-Allow-Origin '*';
        add_header Access-Control-Max-Age '3628800';
        add_header Access-Control-Allow-Credentials 'true';
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        add_header Access-Control-Allow-Methods 'GET,POST,PUT,OPTIONS';

        underscores_in_headers on;      

        client_header_buffer_size       32k;
        client_body_buffer_size 20m;
        client_max_body_size    120M;
        client_header_timeout   1m;
        client_body_timeout             1m;
        proxy_connect_timeout    600;
        proxy_read_timeout       600;
        proxy_send_timeout       600;
        large_client_header_buffers     4       32k;
        fastcgi_buffers         4       128k;
        fastcgi_buffer_size             128k;
        fastcgi_busy_buffers_size       256k;

        server_tokens off;
        tcp_nopush on;
        tcp_nodelay on;
        sendfile        on;

        gzip  on; #开启gzip
        #gzip_static on;
        gzip_vary on;
        gzip_min_length 1k;
        gzip_buffers 8 32k;
        gzip_http_version 1.1;
        gzip_comp_level 6; 
        gzip_proxied any;
        gzip_types application/javascript application/json text/css image/png;

        real_ip_header          X-Real-IP;
        proxy_set_header        Host            $host:$server_port;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;   

        include      /opt/nginx/conf.d/*.conf;
}
EOF

11.启动进程

systemctl restart zabbix-server zabbix-agent rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent  rh-php72-php-fpm
nginx 


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值