專屬小白們的Zabbix部署詳解
zabbix是一個基於WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。
zabbix能監視各種網絡參數,保證服務器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。
zabbix由2部分構成,zabbix server與可選組件zabbix agent。
zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集等功能,它可以運行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平臺上。
特點:
zabbix的主要特點:
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)
- 免費開源
- 自動發現服務器與網絡設備
- 分布式監視以及WEB集中管理功能
- 可以無agent監視
- 用戶安全認證和柔軟的授權方式
- 通過WEB界面設置或查看監視結果
- email等通知功能
功能: - CPU負荷
- 內存使用
-磁盤使用 - 網絡狀況
- 端口監視
- 日誌監視
實驗環境:CentOS7(兩臺:監控服務器、被監控端)
編譯包:鏈接:https://pan.baidu.com/s/19DvMqz0s01ByYBQl79ptqw
提取碼:ha42
具體實驗步驟:
搭建監控服務器:
#關閉防火墻##
[root@cacti ~]# systemctl stop firewalld.service
[root@cacti ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@cacti ~]# setenforce 0
--------安裝LAMP-------------------------------------------------------
[root@cacti ~]# yum install -y \
httpd \
mariadb-server mariadb \
php-mysql \
php-gd \
libjpeg* \
php-ldap \
php-odbc \
php-pear \
php-xml \
php-xmlrpc \
php-mhash
[root@cacti ~]# vim /etc/httpd/conf/httpd.conf
ServerName www.yun.com:80 ##95行
DirectoryIndex index.html index.php ##164行
[root@cacti ~]# vim /etc/php.ini
date.timezone = PRC ##878行 設置中國時區(去掉分號,添加PRC)
[root@cacti ~]# systemctl start httpd.service
[root@cacti ~]# systemctl start mariadb.service
[root@cacti ~]# netstat -ntap | egrep ‘(3306|80)‘
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 45660/mysqld
tcp6 0 0 :::80 ::: LISTEN 45388/httpd
[root@cacti ~]# mysql_secure_installation
y
abc123 (自己設置密碼)
abc123
n
n
n
y
##進入數據庫
[root@cacti ~]# mysql -uroot -p
Enter password: ##輸入密碼
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 . TO ‘zabbix‘@‘%‘ IDENTIFIED BY ‘admin123‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
##測試
[root@cacti ~]# cd /var/www/html/
[root@cacti html]# vim index.php
<?php
phpinfo();
?>
##瀏覽器訪問服務器:192.168.120.181
##測試完成後刪除原來的測試語句
[root@cacti html]# vim index.php
<?php
$link=mysql_connect(‘192.168.120.181‘,‘zabbix‘,‘admin123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>
##修改完成後,刷新網頁
##網頁是Success的可以跳過一下問題(如果是Faill,請按以下步驟操作)##
-------------解決本地無法登錄問題(可忽略)---------------------------
[root@cacti html]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘zabbix‘@‘localhost‘ (using password: YES)
##出錯##
##解決方案:
##進入root用戶數據庫
[root@cacti html]# mysql -uroot -p
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | cacti |
| root | cacti |
| | localhost |
| root | localhost |
+--------+-----------+
##出現空用戶,刪除空用戶
MariaDB [(none)]> drop user ‘‘@localhost;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> drop user ‘‘@cacti;
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 | cacti |
| root | localhost |
+--------+-----------+
##空用戶已刪除
[root@cacti html]# mysql -uzabbix -p
Enter password:
MariaDB [(none)]>
##登錄成功
----------------以下開始部署zabbix Server-------
[root@cacti html]# yum install php-bcmath php-mbstring -y
##會自動生成yum源文件,保證系統可以上網
[root@cacti html]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
##安裝
[root@cacti yum.repos.d]# yum install zabbix-server-mysql zabbix-web-mysql -y
##生成數據庫文件,註意密碼不要輸成root的(是之前設置的admin123)
[root@cacti yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbixEnter password:
[root@cacti yum.repos.d]# grep -n ‘^‘[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
101:DBName=zabbix
117:DBUser=zabbix
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475:Timeout=4
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts
529:ExternalScripts=/usr/lib/zabbix/externalscripts
565:LogSlowQueries=3000
[root@cacti yum.repos.d]# vim /etc/zabbix/zabbix_server.conf
DBPassword=admin123 ##125行
[root@cacti yum.repos.d]# vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai ##20行(修改時區)
------------------修正圖表中文亂碼---------------------
[root@cacti yum.repos.d]# vim /usr/share/zabbix/include/defines.inc.php
##shift:輸入
:%s /graphfont/kaiti/g
##掛載軟件包
[root@cacti yum.repos.d]# mkdir /abc
[root@cacti yum.repos.d]# mount.cifs //192.168.100.10/rhel7 /abc
Password for root@//192.168.100.10/rhel7:
[root@cacti yum.repos.d]# cd /abc/zabbix/
[root@cacti zabbix]# ls
php-bcmath-5.4.16-42.el7.x86_64.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm STKAITI.TTF
[root@cacti zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/
##啟動服務
[root@cacti zabbix]# systemctl start zabbix-server.service
[root@cacti zabbix]# systemctl enable zabbix-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@cacti zabbix]# netstat -anpt | grep zabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0: LISTEN 46594/zabbix_server
tcp6 0 0 :::10051 ::: LISTEN 46594/zabbix_server
[root@cacti zabbix]# systemctl restart httpd.service
http://192.168.120.181/zabbix/ //安裝後登錄 用戶名Admin 密碼:zabbix
設置中文環境
Administrator-Users-點擊用戶-語言中設置
======配置代理端-就是被控服務器----如果服務器也需要被自己監控也需要安裝--zabbix-agent=====
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# 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@localhost ~]# setenforce 0
##安裝yum源
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
[root@localhost ~]# yum install -y zabbix-agent
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.120.181 ##98行(IP為之前的監控服務器)
ServerActive=192.168.120.181 ##139行
Hostname=abc ##150行(名字自定義)
##啟動服務
[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 ~]# netstat -ntap | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0: LISTEN 45402/zabbix_agentd
tcp6 0 0 :::10050 ::: LISTEN 45402/zabbix_agentd
到網頁設置 http://192.168.120.181/zabbix/
選擇監控http、ssh(具體監控什麽,自己定義)
搭建Zabbix及如何設置監控就詳解到這了。
專屬小白們的Zabbix部署詳解