1. 程式人生 > >原始碼安裝zabbix部署

原始碼安裝zabbix部署

需求說明

原始碼安裝zabbix並配置監控流量

環境說明

伺服器型別 ip地址 需要安裝的應用
伺服器 172.16.11.11 lamp架構 ,zabbix server ,zabbix agent
客戶端 172.16.11.12 zabbix agent

①.關閉防火牆

[[email protected] ~]# systemctl stop firewalld.service

②.關閉selinux

[[email protected] ~]# setenforce 0
[[email protected] ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config 

操作步驟

  • 服務端

需要搭建好lamp架構,如何搭建,可以看這裡 →lamp伺服器搭建

①.安裝依賴包

[[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
[
[email protected]
~]# sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo [[email protected] ~]# yum -y install net-snmp-devel libevent-devel

②.下載zabbix 的原始碼包並解壓,建立zabbix使用者
zabbix下載

[[email protected] ~]# tar -xf zabbix-3.4.12.tar.gz 
[[email protected] ~]# groupadd -r zabbix
[
[email protected]
~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix

③.配置zabbix資料庫

[[email protected] ~]# mysql -uroot -p
Enter password: 
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.07 sec)

mysql> grant all privileges on zabbix.* to [email protected] identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.13 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

[[email protected] ~]# cd zabbix-3.4.12/database/mysql/
[[email protected] mysql]# ls
data.sql  images.sql  schema.sql
[[email protected] mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure

[[email protected] mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

[[email protected] mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure

④.編譯安裝zabbix

[[email protected] zabbix-3.4.12]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2

[[email protected] zabbix-3.4.12]# make install

⑤.修改服務端配置檔案,新增如下內容,並啟動服務

[[email protected] ~]# vim /usr/local/etc/zabbix_server.conf
DBPassword=zabbix123!
[[email protected] ~]# zabbix_server 
[[email protected] ~]# zabbix_agentd 
[[email protected] ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128          *:10050                    *:*                  
LISTEN     0      128          *:10051                    *:*                  
LISTEN     0      128    127.0.0.1:9000                     *:*                  
LISTEN     0      128         :::80                      :::*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      100        ::1:25                      :::*                  
LISTEN     0      80          :::3306                    :::*  

⑥.配置php並重啟服務

[[email protected] ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[[email protected] ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[[email protected] ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[[email protected] ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[[email protected] ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

⑦.建立zabbix網頁

[[email protected] ~]# mkdir /usr/local/apache/htdocs/zabbix
[[email protected] ~]# cp -a /root/zabbix-3.4.12/frontends/php/* /usr/local/apache/htdocs/zabbix/
[[email protected] ~]# chown -R apache.apache /usr/local/apache/htdocs/

⑧.配置zabbix虛擬主機

[[email protected] ~]# vim /etc/httpd123/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName zabbix.haha.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdo cs/zabbix/$1
      <Directory "/usr/local/apache/htdocs/zabbix">
          Options none
          AllowOverride none
          Require all granted
      </Directory>
</VirtualHost>

⑨.修改zabbix/conf的許可權,重啟apache

[[email protected] ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[[email protected] conf]# apachectl restart

⑩.安裝zabbix的web介面,修改window的hosts檔案

Windows(C):/windows/system32/drrvers/etc/hosts
172.16.11.11 zabbix.haha.com

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述