CentOS7 yum 安装 Zabbix4.2

原创
2019/08/27 00:18
阅读数 547

环境

  • centos 7
  • nginx 1.16
  • php 7.2
  • zabbix 4.2
  • mysql 5.7

虚拟机

  • 192.168.1.100 安装 nginx, php, mysql, zabbix-server, zabbix-agent
  • 192.168.1.101 安装 zabbix-agent

导入软件源

  • 只在 192.168.1.100 上操作
  • 创建 /etc/yum.repos.d/epel.repo,内容如下
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    baseurl=http://mirrors.aliyun.com/epel/7/$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
    baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Source
    baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
    
  • 创建 /etc/yum.repos.d/nginx.repo,内容如下
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    enabled=1
    gpgcheck=0
    gpgkey=https://nginx.org/keys/nginx_signing.key
    
  • 安装 webtatic 源,用于安装 php7.2
    yum install epel-release #没办法,webtatic 依赖这个
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
  • 创建 /etc/yum.repos.d/mysql5.7.repo,内容如下
    [mysql-connectors-community]
    name=MySQL Connectors Community
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    [mysql-tools-community]
    name=MySQL Tools Community
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    [mysql57-community]
    name=MySQL 5.7 Community Server
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
  • 创建 /etc/yum.repos.d/zabbix.repo,内容如下
    [zabbix]
    name=Zabbix Official Repository - $basearch
    baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/$basearch/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    
    [zabbix-debuginfo]
    name=Zabbix Official Repository debuginfo - $basearch
    #baseurl=http://repo.zabbix.com/zabbix/4.2/rhel/7/$basearch/debuginfo/
    baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/$basearch/debuginfo/
    enabled=0
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
    
    [zabbix-non-supported]
    name=Zabbix Official Repository non-supported - $basearch
    #baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
    baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
    
  • 重建 yum 缓存
    yum clean all
    yum makecache fast
    

安装 nginx

  • 安装
    yum install nginx
    
  • 修改 /etc/nginx/nginx.conf,内容如下
    # Nginx main config
    user                 nginx;
    pid                  /run/nginx.pid;
    error_log            /var/log/nginx/error.log;
    worker_processes     auto;
    worker_rlimit_nofile 65535;
    include              /usr/share/nginx/modules/*.conf;
    events {
        use                epoll;
        multi_accept       on;
        worker_connections 10240;
    }
    http {
        log_format main     '$remote_addr - [$time_local] "$request_method $uri" "$args" '
                            '"-" $status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
        access_log          /var/log/nginx/access.log main;
        gzip                on;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         off;
        server_tokens       off;
        keepalive_timeout   65;
        types_hash_max_size 2048;
        default_type        application/octet-stream;
        include             /etc/nginx/mime.types;
        include             /etc/nginx/conf.d/*.conf;
    }
    
  • 创建 /etc/nginx/conf.d/10080.conf,内容如下
    # nginx listen 10080
    server {
        listen      10080;
        server_name _;
        location /zabbix/ {
            root       /usr/share;
            access_log /var/log/nginx/access-zabbix.log main;
            index      index.php index.html index.html;
        }
        location ~ ^/zabbix/.+\.php$ {
            root                    /usr/share;
            access_log              /var/log/nginx/access-zabbix.log main;
            index                   index.php index.html index.html;
            expires                 -1s;
            include                 fastcgi_params;
            try_files               $uri =404;
            fastcgi_pass            unix:/var/lib/php/phpfpm.sock;
            fastcgi_index           index.php;
            fastcgi_param           PATH_INFO $fastcgi_path_info;
            fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            break;
        }
        location / {
            access_log /var/log/nginx/access-illegal.log main;
            return     403;
        }
    }
    
  • 开机自启
    systemctl enable nginx
    
  • 启动 nginx
    systemctl start nginx
    

安装 php

  • 安装
    yum install php72w \
        php72w-cli \
        php72w-fpm \
        php72w-gd \
        php72w-mbstring \
        php72w-xml \
        php72w-mysqlnd \
        php72w-bcmath
    
  • 修改 /etc/php.ini 中如下配置项
    max_execution_time = 300
    memory_limit = 128M
    post_max_size = 16M
    upload_max_filesize = 2M
    max_input_time = 300
    max_input_vars = 10000
    date.timezone = PRC
    #php 与 mysql 同机可指定 mysql 本地套接字
    pdo_mysql.default_socket = /var/lib/mysql/mysql.sock
    mysqli.default_socket = /var/lib/mysql/mysql.sock
    
  • 修改 /etc/php-fpm.d/www.conf 中如下配置
    listen = /var/lib/php/phpfpm.sock
    listen.mode = 0666
    
  • 开机自启
    systemctl enable php-fpm
    
  • 启动 php-fpm
    systemctl start php-fpm
    

安装 mysql 5.7

  • 安装,参考 CentOS7 yum 安装 MySQL5.7
  • 启动 mysqld 服务,创建 zabbix 数据库及其用户
    create database zabbix default charset utf8mb4;
    grant all on zabbix.* to zbx@localhost identified by 'Zbx_123456';
    

安装 zabbix server

  • 安装
    yum install zabbix-server-mysql zabbix-web-mysql
    
  • 导入 zabbix server 初始数据
    zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzbx -p -Dzabbix
    
  • 修改 /etc/zabbix/zabbix_server.conf 中如下配置
    DBName=zabbix
    DBUser=zbx
    DBPassword=Zbx_123456
    DBSocket=/var/lib/mysql/mysql.sock
    AllowRoot=1
    
  • 开机自启
    systemctl enable zabbix-server
    
  • 启动 zabbix-server
    systemctl enable zabbix-server
    

web 界面设置

  • 使用常用浏览器访问: http://192.168.1.100:10080/zabbix/
  • 根据界面提示提供数据库等信息
  • zabbix 安装完成,进入系统登陆界面,默认 admin/zabbix

安装 zabbix agent

  • 可以直接 yum 安装,这里推荐先下载 rpm 包,方便复制到其他服务器中运行
    yum install zabbix-agent --downloadonly --downloaddir=.
    
  • 安装
    rpm -Uvh zabbix-agent-4.2.*.rpm
    
  • 修改 /etc/zabbix/zabbix_agentd.conf 中如下配置
    EnableRemoteCommands=1
    AllowRoot=1
    #UnsafeUserParameters=1
    #UserParameter=UP[*],/etc/zabbix/UP.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
    
  • 开机自启
    systemctl enable zabbix-agent
    
  • 启动 zabbix-agent
    systemctl enable zabbix-agent
    

在其它服务器上安装 zabbix agent

  • 从 192.168.1.100 复制 zabbix-agent-4.2.*.rpm 到 192.168.1.101 下
  • 登陆 192.168.1.101,安装 zabbix-agent
    rpm -Uvh zabbix-agent-4.2.*.rpm
    
  • 修改 /etc/zabbix/zabbix_agentd.conf 中如下配置
    EnableRemoteCommands=1
    Server=192.168.1.100
    ServerActive=192.168.1.100:10051
    Hostname=app101 #自定义,别和其他 agent 重名即可
    AllowRoot=1
    #UnsafeUserParameters=1
    #UserParameter=UP[*],/etc/zabbix/UP.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
    
  • 开机自启
    systemctl enable zabbix-agent
    
  • 启动 zabbix-agent
    systemctl enable zabbix-agent
    

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部
返回顶部
顶部