zabbix部署(server端)
阿新 • • 發佈:2018-08-21
ima use mat ini rec rac 說明 virt col Linux下常用的系統監控軟件有Nagios、Cacti、Zabbix、Monit等,這些開源的軟件,可以幫助我們更好的管理機器,在第一時間內發現,並警告系統維護人員。
今天開始研究下Zabbix,使用Zabbix的目的,是為了能夠更好的監控mysql數據庫服務器,並且能夠生成圖形報表,雖然Nagios也能夠生成圖形報表,但沒有Zabbix這麽強大。
首先,我們先來介紹下Zabblx:
一.Zabbix簡介
zabbix是一個基於WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。 zabbix由zabbix server與可選組件zabbix agent兩部門組成。 zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視。 zabbix agent需要安裝在被監視的目標服務器上,它主要完成對硬件信息或與操作系統有關的內存,CPU等信息的收集。
zabbix的主要特點:
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)
- 免費開源
- 自動發現服務器與網絡設備
- 分布式監視以及WEB集中管理功能
- 可以無agent監視
- 用戶安全認證和柔軟的授權方式
- 通過WEB界面設置或查看監視結果
- email等通知功能
等等
Zabbix主要功能:
- CPU負荷
- 內存使用
- 磁盤使用
- 網絡狀況
- 端口監視
- 日誌監視
zabbix部署
1.環境說明
環境 | IP | 需要的應用 |
---|---|---|
服務端 | 192.168.24.168 | LAMP zabbix-serverzabbix-agent |
因為zabbix是由PHP語言開發的,所以要先部署LAMP架構 來支持php網頁
2.zabbix安裝
安裝依賴包
[root@linfan ~]# yum -y install net-snmp-devel libevent-devel
下載zabbix
[root@linfan ~]# cd /usr/src/
[root@linfan src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
解壓
[root@linfan src]# tar xf zabbix-3.4.12.tar.gz [root@linfan src]# ls apr-1.6.3 apr-util-1.6.1.tar.bz2 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz zabbix-3.4.12 apr-1.6.3.tar.bz2 debug php-7.2.8 zabbix-3.4.12.tar.gz apr-util-1.6.1 kernels php-7.2.8.tar.xz
創建zabbix用戶和組
[root@linfan ~]# groupadd -r zabbix
[root@linfan ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
配置zabbix數據庫
root@linfan ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by ‘linfan123‘;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> grant all privileges on zabbix.* to [email protected] identified by ‘linfan123‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> show grants for zabbix@localhost;
+------------------------------------------------------------+
| Grants for zabbix@localhost |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘zabbix‘@‘localhost‘ |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO ‘zabbix‘@‘localhost‘ |
+------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for [email protected];
+------------------------------------------------------------+
| Grants for [email protected] |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘zabbix‘@‘127.0.0.1‘ |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO ‘zabbix‘@‘127.0.0.1‘ |
+------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> quit
Bye
[root@linfan ~]# cd /usr/src/zabbix-3.4.12/database/mysql/
[root@linfan mysql]# ls
data.sql images.sql schema.sql
//倒著追加
[root@linfan mysql]# mysql -uzabbix -plinfan123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@linfan mysql]# mysql -uzabbix -plinfan123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@linfan mysql]# mysql -uzabbix -plinfan123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
編譯安裝zabbix
[root@linfan ~]# cd /usr/src/zabbix-3.4.12
[root@linfan zabbix-3.4.12]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
[root@linfan zabbix-3.4.12]# make install
修改服務端配置文件
設置數據庫信息
[root@linfan ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@linfan ~]# vim /usr/local/etc/zabbix_server.conf
...
...
DBUser=zabbix
### Option: DBPassword
# Database password. Ignored for SQLite.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=linfan123 搜索‘DBPassword=‘在後面添加設置的zabbix連接密碼並取消#號註釋
啟動zabbix_server和zabbix_agentd服務
[root@linfan ~]# zabbix_server
[root@linfan ~]# ss -natl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@linfan ~]# zabbix_agentd
[root@linfan ~]# ss -natl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
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 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
zabbix web界面安裝前配置
修改/etc/php.ini的配置並重啟php-fpm
[root@linfan ~]# sed -ri ‘s/(post_max_size =).*/\1 16M/g‘ /etc/php.ini
[root@linfan ~]# sed -ri ‘s/(max_execution_time =).*/\1 300/g‘ /etc/php.ini
[root@linfan ~]# sed -ri ‘s/(max_input_time =).*/\1 300/g‘ /etc/php.ini
[root@linfan ~]# sed -i ‘/;date.timezone/a date.timezone = Asia/Shanghai ‘ /etc/php.ini
[root@linfan ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@linfan ~]# cd /usr/src/zabbix-3.4.12
[root@linfan zabbix-3.4.12]# ls
aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README
AUTHORS compile config.status COPYING include Makefile misc sass
bin conf config.sub database INSTALL Makefile.am missing src
build config.guess configure depcomp install-sh Makefile.in NEWS upgrades
[root@linfan zabbix-3.4.12]# mkdir /usr/local/apache/htdocs/zabbix
[root@linfan zabbix-3.4.12]# cp -r frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@linfan zabbix-3.4.12]# chown -R apache.apache /usr/local/apache/htdocs
配置apache虛擬主機
在配置文件末尾添加如下內容:
[root@linfan ~]# vim /etc/httpd24/httpd.conf
...
...
</IfModule>
<VirtualHost 192.168.24.168:80>
ServerName zabbix.doudou.com
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
設置zabbix/conf目錄的權限,讓zabbix有權生成配置文件zabbix.conf.php
[root@linfan ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@linfan ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 2 apache apache 81 Jul 30 19:41 /usr/local/apache/htdocs/zabbix/conf
重啟apache
[root@linfan ~]# apachectl -t
Syntax OK
[root@linfan ~]# apachectl stop
[root@linfan ~]# apachectl start
[root@linfan ~]# ss -nalt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
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 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
安裝zabbix web界面
- 恢復zabbix/conf的755權限
[root@linfan ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@linfan ~]# ll /usr/local/apache/htdocs/zabbix/conf -d
drwxr-xr-x. 2 apache apache 104 Aug 21 15:37 /usr/local/apache/htdocs/zabbix/conf
- 修改/etc/hosts文件,添加域名與IP映射
- 在瀏覽器上訪問域名
zabbix部署(server端)