Zabbix安裝實驗報告

耿*先生發表於2020-12-22

Zabbix安裝實驗報告(centos7 zabbix-4.0)

一、Zabbix 主機的初始配置

配置IP地址、主機名,關閉 kdump 與 SELinux

配置IP地址
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="c6ccf3d4-1631-4ad8-b106-767335dfd119"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.22.39"
GATEWAY="192.168.22.254"
NETMASK="255.255.255.0"
DNS1="114.114.114.114"
DNS2="8.8.8.8"

設定主機名
[root@localhost ~]# vim /etc/sysconfig/network
# Created by anaconda
HOSTNAME=gzt.linux.org
[root@localhost ~]#  vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
192.168.22.39  gzt gzt.linux.org 

關閉 kdump 與 SELinux
[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost ~]# systemctl disable kdump
[root@localhost ~]# systemctl stop kdump
[root@localhost ~]# reboot


二、部署 LAMP

安裝Apache 和 Mariadb
[root@localhost ~]# yum -y install httpd
[root@localhost ~]#  yum install mariadb-server -y
[root@gzt ~]# systemctl start httpd.service 
[root@gzt ~]# systemctl enable  httpd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@gzt ~]# systemctl start mariadb.service
[root@gzt ~]#  systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

安裝php包
[root@localhost ~]# yum -y install php
安裝PHP元件,使PHP支援 MariaDB
[root@localhost ~]# yum -y install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

重啟MariaDB、 Apache
[root@gzt ~]# systemctl restart mariadb.service
[root@gzt ~]# systemctl restart httpd.service

三、部署Zabbix

1、安裝“Zabbix安裝包”資源儲存庫

[root@gzt ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.ox4o84: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-4.0-2.el7         ################################# [100%]
[root@gzt ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: yum zabbix zabbix-non-supported
Cleaning up everything
Cleaning up list of fastest mirrors

2、安裝Zabbix server,Web前端,agent

[root@gzt ~]# yum -y install  zabbix-server-mysql zabbix-web-mysql zabbix-agent
 [root@gzt ~]#yum -y install centos-release-scl 

3、對資料庫進行初始化並建立Zabbix資料庫

[root@gzt ~]# mysqladmin -u root password 123456789
[root@gzt ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by'Z123456789';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

[root@gzt ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.27/create.sql.gz |mysql -uroot zabbix -p  (123456789)

3、編輯Zabbix資料庫配置檔案並啟動Zabbix服務

[root@gzt ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=localhost //第91行
DBName=zabbix //第101行
DBUser=zabbix //第117行
DBPassword=Z123456789 //第125行
[root@gzt ~]# systemctl start zabbix-server
[root@gzt ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.

4、修改 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

[root@gzt ~]# vim /etc/httpd/conf.d/zabbix.conf
。。。。。。
php_value date.timezone Asia/Chongqing
。。。。。。

5、配置防火牆

[root@gzt ~]# firewall-cmd --permanent --zone=public --add-port=10051/tcp
success
[root@gzt ~]# firewall-cmd --zone=public --add-port=10051/tcp
success
[root@gzt ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@gzt ~]# firewall-cmd --zone=public --add-port=80/tcp
success

6、啟動 Zabbix server and agent

[root@gzt ~]# systemctl restart zabbix-server zabbix-agent httpd
[root@gzt ~]# systemctl enable zabbix-server zabbix-agent httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

7、在WebUI中繼續安裝

[root@gzt ~]# firefox http://127.0.0.1/zabbix

8、在WebUI中繼續安裝

8.1歡迎使用Zabbix

在這裡插入圖片描述

8.2檢查先決條件

在這裡插入圖片描述

8.3配置資料庫連線(密碼:Z123456789)

在這裡插入圖片描述

8.4配置伺服器詳細資訊

在這裡插入圖片描述

8.5 預安裝總結

在這裡插入圖片描述

8.6安裝完成

在這裡插入圖片描述

9、在WebUI中登入

第一次登入,使用者名稱:Admin,密碼:zabbix
在這裡插入圖片描述

WebUI主介面

在這裡插入圖片描述

10、修改WebUI介面語言為中文

10.1點選右上角“個人配置”

在這裡插入圖片描述

10.2選擇Language為Chinese(zh_CN),再點選“Update”

在這裡插入圖片描述

11、被監測端(Agent)配置

11.1 Linux Agent的安裝與配置

關閉 kdump 與 SELinux
[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost ~]# systemctl disable kdump
[root@localhost ~]# systemctl stop kdump
[root@localhost ~]# reboot

Linux Agent的安裝與配置
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.6AMf64: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-4.0-2.el7         ################################# [100%]
[root@localhost ~]# yum -y install zabbix-agent
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.22.222 //第98行
ServerActive=192.168.22.222 //第139行
[root@localhost ~]# systemctl  start zabbix-agent.service 
[root@localhost ~]# systemctl  enable  zabbix-agent.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# netstat -anpt |grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1097/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      1097/zabbix_agentd 

11.2、在zabbix中新增客戶機資訊

右上角“建立主機”——> 主機:新增主機名,群組,客戶機IP——>模板:選擇模板型別;新增;新增。
在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述