CentOS 7上搭建Zabbix4.0

2020-08-10 14:26:05

zabbix介紹

Zabbix 是一個基於 WEB 介面的提供分佈式系統監視以及網路監視功能的企業級的開源解決方案。它能監視各種網路參數,保證伺服器系統的安全運營;並提供靈活的通知機制 機製以讓系統管理員快速定位/解決存在的各種問題。

zabbix軟體組成

zabbix-server: 監控伺服器端

zabbix-agent: 監控用戶端

zabbix-web: 監控網站服務

php: 處理動態請求

mysql: 數據庫儲存監控數據

zabbix: 負責收集agent資訊彙總告知zabbix-server

1.關閉防火牆和selinux

[root@zabbix ~]# setenforce 0
[root@zabbix ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux 
[root@zabbix ~]# systemctl stop firewalld ; systemctl disable firewalld

2.新增zabbix源和epel源

[root@zabbix ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm ##這裏使用的是清華源
[root@zabbix ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ##新增epel源

3.安裝zabbix和相關服務元件

[root@zabbix ~]# wget  https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/{zabbix-server-mysql-4.0.20-1.el7.x86_64.rpm,zabbix-web-4.0.22-1.el7.noarch.rpm} ##把這兩個包先拿下來,因爲安裝的時候網路問題會出現安裝超時
[root@zabbix ~]# yum install -y httpd php zabbix-server-mysql-4.0.20-1.el7.x86_64.rpm  zabbix-web-mysql ###安裝zabbix的服務程式和web程式
[root@zabbix ~]# yum install -y mariadb-server ##安裝數據庫服務

4.修改zabbix組態檔

[root@zabbix ~]# sed -ri.bak '/# DBPassword=/cDBPassword=zabbix' /etc/zabbix/zabbix_server.conf ##修改zabbix數據庫密碼爲zabbix
[root@zabbix ~]# sed -ri.bak 's/ #(.*)date.timezone.*/\1date.timezone Asia\/Shanghai/' /etc/httpd/conf.d/zabbix.conf ##修改時區爲國內

5.設定數據庫服務

[root@zabbix ~]# systemctl start mariadb #啓動數據庫
[root@zabbix ~]# mysql_secure_installation ##初始化數據庫

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@zabbix ~]# mysql -uroot -p ##登錄數據庫
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, 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; ##建立zabbix數據庫 
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; ##建立數據庫管理使用者
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.20/create.sql.gz  | mysql -uzabbix -pzabbix zabbix  ##將數據表寫入到zabbix庫中 

6.啓動zabbix和相關服務

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

7.登錄zabbix的web介面,進行初始化

初始化地址http://172.16.210.56/zabbix/setup.php

點選Next step

檢查php的一些變數條件,如果沒有報錯的資訊可以點選next step

填寫好對應的數據庫密碼和帳號點選Next step

設定主機和埠還有監控頁面名字,然後點選Next step

確認資訊.然後點選Next step

點選Finish

帳號Admin 密碼zabbix ,再點Sign in

登錄成功。

8.更改zabbix介面語言爲中文

點選右上角的小人

選擇Chinese

再點選update

更改成功!

更多文章和資料|點選下方文字直達 ↓↓↓ 阿裡雲K8s實戰手冊 [阿裡雲CDN排坑指南]CDN ECS運維指南 DevOps實踐手冊 Hadoop大數據實戰手冊 Knative雲原生應用開發指南 OSS 運維實戰手冊