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等平臺上。php
Zabbix agent:負責部署在被監控主機上,把被監控主機的數據傳送給zabbix server
Zabbix server:負責接收agent發送的信息,組織配置信息,統計配置信息和操做數據等
Zabbix database: 用於存儲zabbix的全部配置信息,監控數據的數據庫
Zabbix web: zabbix的web界面,管理能夠經過zabbix的web界面管理zabbix配置以及查看zabbix的監控信息,能夠獨一部署在一臺服務器上
Zabbix proxy:分佈式環境中使用,zabbix proxy表明server端管理該區域中的信息收集,最終統一發往zabbix serverhtml
agent:經過專用的代理程序進行監控
ssh/Telnet:經過遠程控制協議進行通信
SNMP:經過SNMP協議與被監控對象進行通信,路由器和交換機支持SNMP,其實也是一種agent
IPMI:經過IPMI接口進行監控,經過IPMI硬件接口監控,電壓,溫度,風扇,和電源狀態
JMX:經過(java management extensions Java管理擴展)監控JVM虛擬機~~java
分佈式的監控體系:監控數據被提交給zabbix proxy 再 提交給zabbix server
主動模式:由agent端主動收集信息發送給server端 工具是zabbix_sender 被動模式:由server端主動拉取信息 工具是zabbix_get
檢測端server 192.168.13.128 被檢測端agent 192.168.13.130
[root@server ~]# systemctl stop firewalld.service ##關閉防火牆 [root@server ~]# systemctl disable firewalld.service [root@server ~]# setenforce 0 ##安裝lamp架構## [root@server ~]# 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 [root@server ~]# vim /etc/httpd/conf/httpd.conf 95 ServerName www.yun.com:80 #第95行,刪除註釋,域名自定義 164 DirectoryIndex index.html index.php #164行,添加首頁支持類類型index.php [root@server ~]# vim /etc/php.ini 878 date.timezone = PRC #878行,把前面模板的;號刪除,後面添加中國時區PRC [root@server ~]# systemctl start httpd.service ##開啓服務 [root@server ~]# systemctl start mariadb.service [root@server ~]# netstat -natp | egrep '(3306|80)' ##查看端口號 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5087/mysqld tcp6 0 0 :::80 :::* LISTEN 4807/httpd [root@server ~]# mysql_secure_installation ##初始化數據庫 Enter current password for root (enter for none): #此處直接回車 Set root password? [Y/n] y #設置密碼 New password: #abc123 Re-enter new password: #確認輸入:abc123 Password updated successfully! Remove anonymous users? [Y/n] n #是否刪除匿名用戶,選擇不刪除 Disallow root login remotely? [Y/n] y #是否遠程鏈接 Remove test database and access to it? [Y/n] n #是否刪除測試數據庫 Reload privilege tables now? [Y/n] y #是否從新加載 ... Success! [root@server ~]# mysql -u root -p ##登陸數據庫 MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) ##建立zabbix數據庫,而且設置爲utf8形式,把裏面的字符串轉換爲二進制 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | zabbix | +--------------------+ 5 rows in set (0.00 sec) MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; Query OK, 0 rows affected (0.01 sec) #把全部數據庫和全部表都交給zabbix用戶進行管理,而且設置密碼爲admin123 MariaDB [(none)]> flush privileges; #刷新 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit #退出數據庫 Bye //測試php基本信息// [root@server ~]# cd /var/www/html/ [root@server html]# ls [root@server html]# vim index.php <?php phpinfo(); ?> //用瀏覽器訪問網頁//
//測試數據庫鏈接狀況// [root@localhost html]# vim index.php <?php $link=mysql_connect('192.168.13.128','zabbix','admin123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; mysql_close(); ?>
[root@server html]# mysql -u zabbix -p Enter password: #此時輸入admin123沒法登陸數據庫,說明有用戶佔用 ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES) `先使用root用戶登陸數據庫` [root@server html]# mysql -u root -p MariaDB [(none)]> select user,host from mysql.user; ##查看用戶表 +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | server | | | localhost | | root | localhost | +--------+-----------+ MariaDB [(none)]> drop user ''@localhost; ##刪除空用戶 MariaDB [(none)]> drop user ''@server; ##刪除空用戶 MariaDB [(none)]> select user,host from mysql.user; +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | +--------+-----------+ 4 rows in set (0.00 sec) MariaDB [(none)]> quit Bye ##此時再次刷新頁面就會顯示Success!!成功登陸
[root@server html]# yum install php-bcmath php-mbstring -y [root@server html]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm ##安裝zabbix源 [root@server html]# cd /etc/yum.repos.d/ [root@server yum.repos.d]# cat zabbix.repo ##這是下載的zabbix的源 [zabbix] name=Zabbix Official Repository - $basearch baseurl=http://repo.zabbix.com/zabbix/3.5/rhel/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 [root@server yum.repos.d]# yum install zabbix-server-mysql zabbix-web-mysql -y ##安裝zabbix [root@server yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -u zabbix -p zabbix ##在zabbix數據庫中生成數據文件 [root@server yum.repos.d]# vim /etc/zabbix/zabbix_server.conf ##修改zabbix配置文件 125 DBPassword=admin123 ##添加zabbix數據庫密碼 [root@server yum.repos.d]# vim /etc/httpd/conf.d/zabbix.conf 20 php_value date.timezone Asia/Shanghai ##修改成中國時區 [root@server yum.repos.d]# vim /usr/share/zabbix/include/defines.inc.php #####修正圖表中文亂碼#### ##在末行模式下進行替換 :%s /graphfont/kaiti/g [root@server yum.repos.d]# cd /usr/share/zabbix/fonts/ ##在此目錄下上傳stkaiti.ttf字體 [root@server fonts]# rz -E [root@server fonts]# ls graphfont.ttf stkaiti.ttf [root@server fonts]# systemctl start zabbix-server.service ##開啓zabbix服務 [root@server fonts]# systemctl enable zabbix-server.service [root@server fonts]# netstat -antp | grep zabbix (端口10051) tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 43984/zabbix_server tcp6 0 0 :::10051 :::* LISTEN 43984/zabbix_server [root@server fonts]# systemctl restart httpd.service ##重啓httpd服務
點擊右上角人物頭像,在Language語言欄選擇Chinese(zh_CN)簡體中文,點擊Update更新
[root@agent ~]# systemctl stop firewalld.service [root@agent ~]# systemctl disable firewalld.service [root@agent ~]# setenforce 0 [root@agent ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm ##安裝yum源 [root@agent ~]# yum install zabbix-agent -y ##安裝代理agent [root@agent ~]# vim /etc/zabbix/zabbix_agentd.conf ##修改配置文件 98 Server=192.168.13.128 ##指定監控端server地址 139 ServerActive=192.168.13.128 ##指定監控端server地址 150 Hostname=test ##名稱 [root@agent ~]# systemctl start zabbix-agent.service ##開啓服務 [root@agent ~]# systemctl enable zabbix-agent.service [root@agent ~]# netstat -natp | grep zabbix (agent端口號10050) tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 41189/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 41189/zabbix_agentd
[root@server ~]# yum install mailx -y ##安裝mailx軟件 [root@server ~]# vim /etc/mail.rc ##修改配置文件 ##末行添加 set from=706858376@qq.com set smtp=smtp.qq.com set smtp-auth-user=706858376@qq.com set smtp-auth-password=受權碼 ##此處是你郵箱的第三方登陸的受權碼 set smtp-auth=login [root@server ~]# echo "hello world" | mail -s "testmail" 706858376@qq.com ##發送郵件
[root@server ~]# cd /usr/lib/zabbix/alertscripts/ ##切換到zabbix腳本目錄下 [root@server alertscripts]# vim mailx.sh ##編輯發送郵件腳本 #!/bin/bash #send mail messages=`echo $3 | tr '\r\n' '\n'` subject=`echo $2 | tr '\r\n' '\n'` echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1 [root@server alertscripts]# touch /tmp/mailx.log ##建立日誌 [root@server alertscripts]# chown -R zabbix.zabbix /tmp/mailx.log ##受權屬主屬組 [root@server alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh ##執行權限 [root@server alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/ ##受權屬主屬組 [root@server alertscripts]# ./mailx.sh 706858376@qq.com "yun" "heihei"
模板: 默認操做步驟持續時間 60 默認接收人 : {TRIGGER.STATUS}:{TRIGGER.NAME} 默認信息: 告警主機:{HOST.NAME} 告警 IP:{HOST.IP} 告警時間:{EVENT.DATE}-{EVENT.TIME} 告警等級:{TRIGGER.SEVERITY} 告警信息:{TRIGGER.NAME}:{ITEM.VALUE} 事件 ID:{EVENT.ID}
模板: 恢復操做:{TRIGGER.STATUS}:{TRIGGER.NAME} 恢復信息: 恢復主機:{HOST.NAME} 恢復 IP:{HOST.IP} 恢復時間:{EVENT.DATE}-{EVENT.TIME} 恢復等級:{TRIGGER.SEVERITY} 恢復信息:{TRIGGER.NAME}:{ITEM.VALUE} 恢復 ID:{EVENT.ID}
[root@agent yum.repos.d]# systemctl stop sshd ##關閉被監控端的ssh服務
[root@agent yum.repos.d]# systemctl start sshd ##開啓被監控端的ssh服務