1. 程式人生 > >Zabbix監控系統部署及添加被控節點

Zabbix監控系統部署及添加被控節點

fonts start restart dex ble epo timezone 沒有 iat

zabbix

zabbix是由 Alexei Vladishev開發的一種網絡監視、管理系統,基於 Server-Client架構。可用於監視各種網絡服務、服務器和網絡機器等狀態。

使用各種 Database-end 如 MySQL, PostgreSQL, SQLite, Oracle 或 IBM DB2 儲存資料。Server 端基於 C語言、Web 管理端frontend則是基於PHP所制作的。Zabbix可以使用多種方式監視。可以只使用 Simple Check 不需要安裝 Client 端,亦可基於 SMTP 或 HTTP ... 各種協定做死活監視。

在客戶端如 UNIX, Windows 中安裝 Zabbix Agent 之後,可監視 CPU Load、網絡使用狀況、硬盤容量等各種狀態。而就算沒有安裝 Agent 在監視對象中,Zabbix 也可以經由 SNMP、TCP、ICMP、利用 IPMI、SSH、telnet 對目標進行監視。

另外,Zabbix 包含 XMPP 等各種 Item 警示功能。

zabbix官網: https://www.zabbix.com

zabbix主要由二個部分構成 zabbix server和 zabbix agent;
zabbix proxy是用來管理其他的agent,作為代理使用。

系統環境:

主機名 操作系統 IP地址 服務名
zabbix centos7.4 192.168.96.70 zabbix2.2.23
www centos7.4 192.168.96.71 zabbix-agent
客戶端 windows 10 192.168.96.2 網頁瀏覽器

百度網盤 密碼:x1uy

一、安裝LAMP環境

1.安裝lamp相關軟件包

yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash php-bcmath php-mbstring

2.關閉防火墻及selinux

systemctl stop firewalld.service
setenforce 0

3.編輯httpd.conf

vim /etc/httpd/conf/httpd.conf

#設置域名
ServerName www.yun.com:80

#修改監聽地址
Listen 192.168.96.70:80
#Listen 80

#添加主頁類型index.php
DirectoryIndex index.html index.php

4.設置php配置中的時區

vim /etc/php.ini

#PRC:中國時區
date.timezone = PRC

技術分享圖片

5.啟動httpd、mariadb服務

systemctl enable httpd.service
systemctl start httpd.service
systemctl enable mariadb.service
systemctl start mariadb.service

6.檢查服務信息

netstat -ntap | egrep ‘(80|3306)‘

技術分享圖片

7.添加php測試頁

vim /var/www/html/index.php

<?php
    phpinfo();
?>

8.客戶端訪問php測試頁

http://192.168.96.70/index.php

技術分享圖片

9.初始化mysql數據庫

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] n     //是否移除anonymous用戶
 ... 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       //是否允許root用戶遠程登錄
 ... 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    //是否移除test數據庫
 ... 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!

10.登錄mysql,創建zabbix數據庫及創建zabbix用戶並設置密碼

mysql -u root -p

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> grant all privileges on zabbix.* to zabbix@‘%‘ identified by ‘123123‘;

mysql>flush privileges;

11.創建mysql數據庫的測試網頁文件

vim /var/www/html/mysql.php

<?php
$link=mysql_connect(‘192.168.96.70‘,‘zabbix‘,‘123123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

12.客戶端訪問mysql.php網頁,顯示success則訪問mysql正常,fail則訪問失敗,請檢查mysql.php中連接地址、用戶名、密碼是否正確,若還是有問題請檢查mysql.user表用戶名稱是否有空而導致的錯誤,以下為解決方法

> select user,host from mysql.user;   

#用戶名稱為空占用導致本地無法登錄遠程可登錄
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | zabbix    |
| root   | zabbix    |
+--------+-----------+

> drop user ‘‘@localhost;

> drop user ‘‘@zabbix;

> flush privileges;

技術分享圖片

技術分享圖片

二、部署zabbix Server

1.下載zabbix官方yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

2.安裝zabbix服務端及被控端軟件包

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

3.導入zabbix數據庫(必須安裝此順序導入,不然會報錯)

cd /usr/share/doc/zabbix-server-mysql-2.2.23/create/

mysql -uzabbix -p  zabbix < schema.sql
mysql -uzabbix -p  zabbix < images.sql
mysql -uzabbix -p  zabbix < data.sql

4.編輯zabbix_service.conf配置,結果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_server.conf

39:LogFile=/var/log/zabbix/zabbix_server.log
50:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
91:DBName=zabbix
107:DBUser=zabbix
115:DBPassword=123123
124:DBSocket=/var/lib/mysql/mysql.sock
288:SNMPTrapperFile=/var/log/snmptt/snmptt.log
426:Timeout=3
468:AlertScriptsPath=/usr/lib/zabbix/alertscripts
478:ExternalScripts=/usr/lib/zabbix/externalscripts
512:LogSlowQueries=3000

5.編輯zabbix配置文件,指定時區

vim /etc/httpd/conf.d/zabbix.conf

php_value date.timezone Asia/Shanghai

技術分享圖片

6.修正zabbix-web圖表中文亂碼

vim /usr/share/zabbix/include/defines.inc.php

#替換全文中所有graphfot為kaiti
:%s/graphfont/kaiti/g

技術分享圖片

7.復制字體文件至zabbix/fonts/目錄下

cp kaiti.ttf /usr/share/zabbix/fonts/

8.啟動zabbix-server服務

systemctl enable zabbix-server
systemctl start zabbix-server

9.檢查是否已監聽10051端口

netstat -anpt | grep zabbix

技術分享圖片

10.重啟httpd服務

systemctl restart httpd.service

11.客戶端訪問(用戶名:Admin 密碼:zabbix),進入zabbix的安裝界面

http://192.168.96.70/zabbix/

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

三、設置中文環境

1. Profile ---->User -----> Languages 中設置chinese(zh_cn)

技術分享圖片

2. 網頁界面已經顯示為中文了

技術分享圖片

四、添加被控服務器

服務器:zabbix

zabbix之前已經安裝好了zabbix—agent軟件包,這裏就不用再安裝,直接進行設置

1.編輯zabbix_agentd.conf配置,結果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=zabbix
246:Include=/etc/zabbix/zabbix_agentd.d/

2.啟動zabbix-agent服務

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

3.檢查是否已監聽10050端口

netstat -anpt | grep zabbix

技術分享圖片

服務器:www

1.關閉防火墻及selinux

systemctl stop firewalld
setenforce 0

2.下載安裝yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

3.安裝zabbix-agent軟件包

yum install -y zabbix-agent httpd

4.編輯zabbix_agentd.conf配置,結果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=www
246:Include=/etc/zabbix/zabbix_agentd.d/

5.啟動zabbix-agent服務

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
systemctl enable httpd.service
systemctl start httpd.service

6.檢查是否已監聽10050端口

netstat -anpt | grep zabbix_agent

技術分享圖片

五、添加被控主機:

1. 配置-主機-創建主機:

技術分享圖片

2.添加主機信息

技術分享圖片

3.成功添加2臺被控主機

技術分享圖片

Zabbix監控系統部署及添加被控節點