被監(jiān)控端:192.168.136.185
安裝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
vim /etc/httpd/conf/httpd.conf
ServerName www.benet.com
DirectoryIndex index.html index.php
vi /etc/php.ini
date.timezone = PRC //設(shè)置中國時區(qū)
systemctl stop firewalld.service
setenforce 0
systemctl start httpd.service
systemctl start mariadb.service
netstat -ntap | egrep \\\'(80|3306)\\\'
Mysql_secure_installation
vi /var/www/html/index.php
<?php
phpinfo();
?>
http://192.168.175.155/
MYSQL -u root -p
#為zabbix設(shè)置一個數(shù)據(jù)庫,并且要設(shè)置一個用戶去管理它
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all privileges ON *.* TO \\\'zabbix\\\'@\\\'%\\\' IDENTIFIED BY \\\'admin123\\\';
flush privileges;
#寫一個測試首頁
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
#驗證zabbix能否連接數(shù)據(jù)庫
<?php
$link=mysql_connect(\\\'192.168.136.167\\\',\\\'zabbix\\\',\\\'admin123\\\');
if($link) echo <h2>Success!!</h2>;
else echo Fail!!;
mysql_close();
?>
———解決本地?zé)o法登錄問題(可忽略)—————
[root@localhost html]# mysql -u root -p
Enter
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)]> select user,host from mysql.user; //有空用戶名稱占用導(dǎo)致本地?zé)o法登錄遠程可登錄
-------- -----------------------
| user | host |
-------- -----------------------
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
-------- -----------------------
6 rows in set (0.01 sec)
drop user \\\'\\\'@localhost;
drop user \\\'\\\'@cacti;
flush privileges;
—————-以下開始部署zabbix Server——-
yum install php-bcmath php-mbstring -y
rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm //會自動生成yum源文件,保證系統(tǒng)可以上網(wǎng)
yum install zabbix-server-mysql zabbix-web-mysql -y
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix //生成數(shù)據(jù)庫文件,注意密碼不要輸成root的
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
125:DBPassword=admin123 //修改本行
347:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
465:Timeout=4
507:AlertScriptsPath=/usr/lib/zabbix/alertscripts
517:ExternalScripts=/usr/lib/zabbix/externalscripts
553:LogSlowQueries=3000
vim /etc/httpd/conf.d/zabbix.conf //修改時區(qū)
php_value date.timezone Asia/Shanghai
vim /usr/share/zabbix/include/defines.inc.php //修正圖表中文亂碼
:%s /graphfont/kaiti/g //從微軟系統(tǒng)下復(fù)制相應(yīng)的字體文件到 /usr/share/zabbix/fonts 目錄中注意字體名稱要對應(yīng)配置文件,且注意大小寫
cp STKAITI.TTF /usr/share/zabbix/fonts/
systemctl enable zabbix-server
systemctl start zabbix-server
netstat -anpt | grep zabbix //監(jiān)聽在10051端口上
systemctl restart httpd.service
http://192.168.136.168/zabbix/ //安裝后登錄 用戶名Admin 密碼:zabbix
設(shè)置中文環(huán)境
Administrator-Users-點擊用戶-語言中設(shè)置
———–配置代理端-就是被控服務(wù)器—-如果服務(wù)器也需要被自己監(jiān)控也需要安裝–zabbix-agent–
rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
yum install -y zabbix-agent
grep -n \\\'^\\\'[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
98:Server=192.168.175.155
139:ServerActive=192.168.175.155
150:Hostname=test
268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
service firewalld stop
setenforce 0
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
netstat -anpt | grep zabbix //監(jiān)聽在10050端口
---------------增加被控主機--在WEB平臺上做-----
配置-主機-創(chuàng)建主機:
主機頁面根據(jù)需求配置
模板頁需要鏈接模板,根據(jù)需要鏈接相應(yīng)的模板
0K
--------配置郵件報警功能---服務(wù)器上配置---------
yum install mailx
vi /etc/mail.rc //注意網(wǎng)易郵箱需要開啟客戶端授權(quán)碼進行第三方登錄
----文件末尾新增---
set from=1960277503@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=1960277503@qq.com
set smtp-auth-password=郵箱密碼
set smtp-auth=login
echo hello world | mail -s testmail 1960277503@qq.com //測試發(fā)信正常
cd /usr/lib/zabbix/alertscripts
vi mailx.sh //編寫發(fā)郵件腳本
#!/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
------
touch /tmp/mailx.log
chown -R zabbix.zabbix /tmp/mailx.log
chmod x /usr/lib/zabbix/alertscripts/mailx.sh
chown -R zabbix.zabbix /usr/lib/zabbix/
./mailx.sh 13951868284@139.com 主題 內(nèi)容 //測試發(fā)郵件腳本是否可以正常工作
—–在服務(wù)器WEB上配置—-
管理-》報警媒體類型-》創(chuàng)建媒體類型-》
名稱:Mail-Test
類型:腳本
腳本名稱:mailx.sh
腳本參數(shù)://新增以下三個參數(shù)
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
管理-用戶-點擊Admin-報警媒介:
類型:Mail-Test //調(diào)用上面的腳本
收件人:13951868284@139.com
其它默認-保存
配置-》動作-》創(chuàng)建動作-》刪除默認標簽,修改觸發(fā)條件
名稱:Mailx
條件 A 主機群組=Linux servers
操作-》如下配置
默認操作步驟持續(xù)時間 60
默認接收人 : {TRIGGER.STATUS}:{TRIGGER.NAME}
默認信息:
告警主機:{HOST.NAME}
告警 IP:{HOST.IP}
告警時間:{EVENT.DATE}-{EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}:{ITEM.VALUE}
事件 ID:{EVENT.ID}
操作細節(jié):-》
操作類型:發(fā)送消息
發(fā)送到用戶:Admin (Zabbix Administrator)
僅送到:Mail-Test //一定要配置否則郵件發(fā)送不成功
恢復(fù)操作:{TRIGGER.STATUS}:{TRIGGER.NAME}
恢復(fù)信息:
恢復(fù)主機:{HOST.NAME}
恢復(fù) IP:{HOST.IP}
恢復(fù)時間:{EVENT.DATE}-{EVENT.TIME}
恢復(fù)等級:{TRIGGER.SEVERITY}
恢復(fù)信息:{TRIGGER.NAME}:{ITEM.VALUE}
恢復(fù) ID:{EVENT.ID}
操作細節(jié):-》
操作類型:發(fā)送消息
發(fā)送到用戶:Admin (Zabbix Administrator)
僅送到:Mail-Test //一定要配置否則郵件發(fā)送不成功
systemctl restart zabbix-server
systemctl restart zabbix-agent.service
------以下是測試報警-----
可以在被控主機上模擬相關(guān)參數(shù)超過閾值,如磁盤空間。然后驗證郵件收發(fā)。
systemctl stop zabbix-agent.service //在被監(jiān)控主機上關(guān)閉 測試報警郵件接收
更多關(guān)于云服務(wù)器,域名注冊,虛擬主機的問題,請訪問西部數(shù)碼官網(wǎng):www.ps-sw.cn