監控-----zabbix架構(server-client)部署

目錄

一.環境介紹

二.實驗具體操作

在server端部署LAMP架構

在server端部署zabbix server

在本機上安裝zabbix的web界面

在client端部署zabbix agentd

在zabbix的web界面監控client端


一.環境介紹

角色 系統 安裝內容
監控端server(192.168.43.101) CentOS7.4 LAMP架構、Zabbix-server
被監控端clinet(192.168.43.102) CentOS7.4 Zabbix-agentd
  • 本實驗搭建zabbix最簡單的server-client架構,採用zabbix源碼編譯方式安裝,LAMP架構採用yum安裝

二.實驗具體操作

在server端部署LAMP架構

環境準備

#永久修改主機名
[root@localhost ~]# hostnamectl set-hostname server
[root@localhost ~]# su
#正則關閉selinux核心防護
[root@server ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@server ~]# setenforce 0
#查看是否設置成功
[root@server ~]# getenforce 0
Permissive
#關閉防火牆
[root@server ~]# systemctl stop firewalld.service 
[root@server ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@server ~]# 

安裝軟件包

  • 安裝apache
[root@server ~]# yum install -y httpd
  • 安裝mariadb
[root@server ~]# yum install -y mariadb mariadb-server
  • 安裝php以及擴展依賴包
[root@server ~]# yum install -y php php-bcmath php-mbstring \
> php-mysql php-gd php-ldap php-xml
  • 安裝依賴庫
[root@server ~]# yum install -y unixODBC-devel mysql-devel \
> net-snmp-devel libxml2-devel libcurl-devel libevent-devel gcc

修改apache與php的配置文件

#配置apache
[root@server ~]# vi /etc/httpd/conf/httpd.conf 

ServerName 127.0.0.1

DocumentRoot "/var/www/html/zabbix"

[root@server ~]# mkdir -p /var/www/html/zabbix
[root@server ~]# 


#配置php
vim /etc/php.ini
date.timezone = Asia/Shanghai        //設置時區
post_max_size = 32M                //設置上傳文件大小
max_execution_time = 300
max_input_time = 300
always_populate_raw_post_data = -1

配置php界面

[root@server ~]# cat /var/www/html/zabbix/index.php
<?php
phpinfo();
?>
[root@server ~]# 

啓動服務並且驗證php界面

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

初始化mariadb並且設置zabbix數據庫用戶

  • 設置數據庫
#設置安全導向
[root@server ~]# 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            //是否設置mysql的root賬戶的密碼
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] n
 ... skipping.

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] n
 ... skipping.

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] n
 ... skipping.

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@server ~]# 

#登錄mysql數據庫設置zabbix賬戶
[root@server ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.64-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.

##配置zabbix庫
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

##配置zabbix賬戶和密碼
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

##刷新數據庫
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

##刪除空白用戶的數據庫,以防止空白影響數據庫的連接
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | server    |
| root   | server    |
+--------+-----------+
7 rows in set (0.01 sec)

MariaDB [(none)]> drop user ''@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> drop user ''@server;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
| root   | localhost |
|        | server    |
| root   | server    |
+--------+-----------+
6 rows in set (0.00 sec)

  • 設置php界面,驗證用戶數據庫連接是否能夠成功
[root@localhost ~]# vim /var/www/html/zabbix/index.php

<?php
$link=mysql_connect('192.168.43.101','zabbix','123456');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();

在server端部署zabbix server

[root@server opt]# ls
rh
[root@server opt]# rz

[root@server opt]# ls
rh  zabbix-4.0.18.tar.gz
[root@server opt]# tar zxf zabbix-4.0.18.tar.gz 
[root@server opt]# cd zabbix-4.0.18/
[root@server zabbix-4.0.18]# ls
aclocal.m4  build      conf          configure     database   include     m4           man      NEWS    src
AUTHORS     ChangeLog  config.guess  configure.ac  depcomp    INSTALL     Makefile.am  misc     README
bin         compile    config.sub    COPYING       frontends  install-sh  Makefile.in  missing  sass
[root@server zabbix-4.0.18]# 
  • 在數據庫中導入zabbix數據

#按順序導入
[root@server ~]# mysql -u root -p123123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.64-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)]> use zabbix;
Database changed
MariaDB [zabbix]> source /opt/zabbix-4.0.18/database/mysql/schema.sql
MariaDB [zabbix]> source /opt/zabbix-4.0.18/database/mysql/images.sql
MariaDB [zabbix]> source /opt/zabbix-4.0.18/database/mysql/data.sql
  • 將zabbix的前端代碼複製到apache的站點目錄上

[root@server ~]# cd /opt/zabbix-4.0.18/
[root@server zabbix-4.0.18]# cp -a frontends/php/* /var/www/html/zabbix/
cp:是否覆蓋"/var/www/html/zabbix/index.php"? y
##賦予權限
[root@server zabbix-4.0.18]# chmod -R 755 /var/www/html/zabbix/
[root@server zabbix-4.0.18]# chown -R apache:apache /var/www/html/zabbix/
[root@server zabbix-4.0.18]# 
  • 編譯安裝zabbix

[root@server ~]# cd /opt/zabbix-4.0.18/
[root@server zabbix-4.0.18]# groupadd zabbix
[root@server zabbix-4.0.18]# useradd -g zabbix -m -s /sbin/nologin zabbix
[root@server zabbix-4.0.18]# ./configure \
> --prefix=/usr/local/zabbix \
> --sysconfdir=/usr/local/zabbix/etc/ \
> --enable-server \
> --enable-agent \
> --with-net-snmp \
> --with-libcurl \
> --with-mysql \
> --with-libxml2 \
> --with-mysqli

##顯示編譯成功

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@server zabbix-4.0.18]# make && make install
  • 修改zabbix的配置文件

[root@server ~]# cd /opt/zabbix-4.0.18/
#修改zabbix目錄所有者爲zabbix
[root@server zabbix-4.0.18]# chown -R zabbix:zabbix /usr/local/zabbix/
#配置啓動腳本
[root@server zabbix-4.0.18]# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
[root@server zabbix-4.0.18]# sed -i "s/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix\//g" /etc/init.d/zabbix_server

#編輯主配置文件
[root@server zabbix-4.0.18]# vi /usr/local/zabbix/etc/zabbix_server.conf
[root@server zabbix-4.0.18]# cat /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log        #定義日誌文件目錄
DebugLevel=3        #定義bug級別
DBName=zabbix          #定義數據庫名字
DBUser=zabbix          #定義數據庫用戶
DBPassword=123456       #定義數據庫密碼
DBPort=3306            #定義數據庫端口號
StartPollers=10        #輪詢進程數,主動減少該值
StartTrappers=80        #處理agent推送數據的進程數,主動模式加大該值
StartPingers=20
StartDiscoverers=15     #自動發現進程數,有一些自動發現的監控項,也增加該值   
StartTimers=5            
HousekeepingFrequency=1    #歷史數據清理時長,默認一個小時
MaxHousekeeperDelete=500    #每次刪除歷史數據的條數,默認5000,調小該值減少IO慢查詢
CacheSize=128M               
CacheUpdateFrequency=75
StartDBSyncers=10            #數據同步到數據庫的線程
HistoryCacheSize=32M
HistoryIndexCacheSize=16M
ValueCacheSize=32M
Timeout=30
UnreachablePeriod=120
LogSlowQueries=3000
[root@server zabbix-4.0.18]# 
  • 啓動zabbix-server

[root@server zabbix-4.0.18]# service zabbix_server start
Reloading systemd:                                         [  確定  ]
Starting zabbix_server (via systemctl):                    [  確定  ]
[root@server zabbix-4.0.18]# 

在本機上安裝zabbix的web界面

  • 在瀏覽器輸入IP地址

  • 確認所有php需求都通過然後單擊下一步

  • 填寫正確的數據庫信息,然後點擊下一步

  • 填寫zabbix server信息,單擊下一步

  • 確定後,單擊下一步

  • 登錄zabbix-server

  • 登錄成功

  • 語言設置

在client端部署zabbix agentd

  • 部署zabbix agentd
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
[root@client ~]# systemctl stop firewalld.service 
[root@client ~]# setenforce 0
[root@client ~]# 
[root@client ~]# yum install -y gcc gcc-c++ make lrzsz mysql-devel net-snmp-devel
//使用rz命令上傳zabbix軟件包
[root@client ~]# rz

[root@client ~]# ls
::               initial-setup-ks.cfg  公共  視頻  文檔  音樂
anaconda-ks.cfg  zabbix-4.0.18.tar.gz  模板  圖片  下載  桌面
//解壓
[root@client ~]# tar xzf zabbix-4.0.18.tar.gz -C /opt/
//編譯安裝
[root@client ~]# cd /opt/zabbix-4.0.18/
[root@client zabbix-4.0.18]# ./configure --prefix=/usr/local/zabbix --enable-agent

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@client zabbix-4.0.18]# make && make install

//複製執行腳本
[root@client zabbix-4.0.18]# pwd 
/opt/zabbix-4.0.18
[root@client zabbix-4.0.18]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
//修改腳本里的安裝路徑
[root@client zabbix-4.0.18]# sed -i "s/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix\//g" /etc/init.d/zabbix_agentd 

//修改配置文件
[root@client zabbix-4.0.18]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.43.101            ##被動模式指定zabbix服務器
ServerActive=192.168.43.101        ##主動模式指定zabbix服務器
Hostname=Zabbix_server

//創建zabbix用戶,否則啓動失敗
[root@client zabbix-4.0.18]# groupadd zabbix
[root@client zabbix-4.0.18]# useradd zabbix -s /sbin/nologin -M -g zabbix 

//開啓服務
[root@client zabbix-4.0.18]# service zabbix_agentd start
Reloading systemd:                                         [  確定  ]
Starting zabbix_agentd (via systemctl):                    [  確定  ]
[root@client zabbix-4.0.18]# netstat -natp | grep 10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      13371/zabbix_agentd 
[root@client zabbix-4.0.18]# lsof -i :10050
COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
zabbix_ag 13371 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)
zabbix_ag 13373 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)
zabbix_ag 13374 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)
zabbix_ag 13375 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)
zabbix_ag 13376 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)
zabbix_ag 13377 zabbix    4u  IPv4  38414      0t0  TCP *:zabbix-agent (LISTEN)



 

在zabbix的web界面監控client端

  • 具體步驟如下

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章