l Yum源的配置
cd /etc/yum.repos.d/; mkdir old;mv ./* old/
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum clean all
yun list
l MySQL部署
rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps
yum install mysql55w-server.x86_64
/etc/init.d/mysqld start
mv /etc/yum.repos.d/webtatic* /etc/yum.repos.d/old
yum clean all
l OS 優化
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum -y install iksemel libssh2 zabbix-server-mysql zabbix-web-mysql zabbix-agent net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils net-snmp
mysql -uroot-S /tmp/mysql.sock-e "create database zabbix character set utf8 collate utf8_bin;"
mysql -uroot-S /tmp/mysql.sock -e "grant all privileges on zabbix.* to zabbix@'10.1.1.%' identified by 'zabbix'; flush privileges;"
cd /usr/share/doc/zabbix-server-mysql-2.4.*/create/
mysql -uroot-S /tmp/mysql.sock zabbix < schema.sql
mysql -uroot-S /tmp/mysql.sock zabbix < images.sql
mysql -uroot-S /tmp/mysql.sock zabbix < data.sql
DBHost/DBSocket參數根據須要進行修改
sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/' /etc/zabbix/zabbix_server.conf
缺一鍵修改
egrep -v '(^$|\#)' /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=192.168.1.222
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql.sock
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
啓動zabbix服務
service zabbix-server start
service zabbix-agent start
sed -i 's/^.*date.timezone =.*$/date.timezone = Asia\/Shanghai/g' /etc/php.ini
sed -i 's/^.*post_max_size =.*$/post_max_size = 16M/g' /etc/php.ini
sed -i 's/^.*max_execution_time =.*$/max_execution_time = 300/g' /etc/php.ini
sed -i 's/^.*max_input_time =.*$/max_input_time = 300/g' /etc/php.ini
sed -i 's/^.* memory_limit =.*$/memory_limit = 128M/g' /etc/php.ini
service httpd restart
chkconfig zabbix-server on
chkconfig zabbix-agent on
chkconfig httpd on
登錄Zabbix 用戶名密碼:Admin/zabbix注意Admin的「A」大寫
profile-->Language-->chinese
從Windows中C:\Windows\Fonts拷貝想要的字體到/opt下
cat /opt/msyhbd.ttf > /usr/share/zabbix/fonts/graphfont.ttf
不替換 graphfont.ttf的方法
vi /usr/share/zabbix/include/defines.inc.php
('ZBX_GRAPH_FONT_NAME', 'graphfont');
#將graphfont替換爲下載的文件名便可
('ZBX_FONT_NAME', 'graphfont');
#將graphfont替換爲下載的文件名便可
tail -f /var/log/zabbix/zabbix_server.log
1922:20141126:144903.783 cannot send list of active checks to [127.0.0.1]: host [Zabbix server] not monitored
其中有一個'cannot send list of active checks to ' 這種類型不算錯誤,後續更新Zabbix Agent(active)會描述這個狀況.
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum install zabbix-agent zabbix-sender zabbix-get -y
grep -vE '(^$|^\#)' /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.222
#修改成Server的IP,支持多個IP,逗號分隔,使用域名的話,須要支持反向解析
#ServerActive=192.168.1.222
#修改成Server的IP,不支持寫多個IP
HostnameItem=system.hostname
#默認是用Hostname須要手動指定主機名,改成HostnameItem 使用內部key的自動獲取方式
Include=/etc/zabbix/zabbix_agentd.d/
標準配置文件
[root@Server-B opt]# grep -vE '(^$|^\#)' /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.200
ServerActive=192.168.1.200
HostnameItem=system.hostname
Include=/etc/zabbix/zabbix_agentd.d/
/etc/init.d/zabbix-agent start
chkconfig zabbix-agent on
在windows控制檯下執行如下命令:
E:\zabbix\bin\win32\zabbix_agentd.exe -c E:\zabbix\conf\zabbix_agentd.win.conf –i
啓動命令以下:
E:\zabbix\bin\win32\zabbix_agentd.exe -c E:\zabbix\conf\zabbix_agentd.win.conf –s
手冊地址:http://www.fromdual.com/fpmmm-installation-guide
下載地址:https://support.fromdual.com/admin/download/fpmmm-0.10.5.tar.gz
yum install php-cli php-process php-mysqli
cat << _EOF >/etc/php.d/fpmmm.ini
variables_order = "EGPCS"
date.timezone = 'Asia/Shanghai'
_EOF
rpm -Uvh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum update
yum install zabbix-sender zabbix-agent zabbix
cd /opt
tar xf /tmp/fpmmm-0.10.5.tar.gz
ln -s fpmmm-0.10.5 fpmmm
mkdir /etc/fpmmm
cp /opt/fpmmm/tpl/fpmmm.conf.template /etc/fpmmm/fpmmm.conf
chown -R zabbix: /etc/fpmmm
模板
[default]
Type= mysqld
LogLevel= 2
LogFile= /tmp/fpmmm/fpmmm.log
CacheFileBase = /tmp/fpmmm/fpmmmCache
AgentLockFile = /tmp/fpmmm/fpmmm.lock
# Zabbix Server IP address
ZabbixServer= 192.168.1.233
[G1-MySQL-M1] # This MUST match Hostname in Zabbix!
Type= mysqld
Username= fpmmmonit
Password= fpmmmonit
MysqlPort= 3306
MysqlHost= 192.168.1.210
Modules= process mysql myisam innodb master server fpmmm security
PidFile= /data/mysql3306/G1-MySQL-M1.pid
[G1-MySQL-M1]要和zabbix中的Host name中的定義要一致
GRANT SELECT, PROCESS, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'fpmmmonit'@'127.0.0.1' IDENTIFIED BY 'fpmmmonit';
flush privileges;
/opt/fpmmm/bin/fpmmm --config=/etc/fpmmm/fpmmm.conf
1
cat /tmp/fpmmm/fpmmm.log
6799:2016-03-03 20:56:50.016 - INFO: FromDual Performance Monitor for MySQL and MariaDB (fpmmm) (0.10.5) run started.
6799:2016-03-03 20:56:51.666 - INFO: FromDual Performance Monitor for MySQL and MariaDB (fpmmm) run finished (rc=0).
Go to Configuration > Templates > Import and import all the fpmmm templates.
A host in Zabbix terminology is a device you want to monitor. This can be either a machine or a MySQL database or something else.
First we have to create 2 hosts, one for the machine and one for the database: Configuration > Hosts > Create host.
Make sure that Host name matches exactly the hostname specified in fpmmm.conf (my_machine and my_mysqld).
Then add the templates fpmmm and server to the machine host (my_machine) and the other templates to the database host (my_mysqld).
Then test again if your fpmmm data reaches your Zabbix server: Monitoring > Latest data > fpmmm and check the time stamp of Last check for example.
There are 2 different possibilities to run fpmmm regularly. First by the Zabbix agent:
Put the following line either into its own file (/etc/zabbix/conf.d/fpmmm.conf) or add it to the Zabbix agent configuartion file (/etc/zabbix/zabbix_agentd.conf).
UserParameter=FromDual.MySQL.check,/opt/fpmmm/bin/fpmmm --config=/etc/fpmmm/fpmmm.conf
or second by the crontab:
* * * * * /opt/fpmmm/bin/fpmmm --config=/etc/fpmmm/fpmmm.conf >/dev/null
OneAlter屬於OneAPM下的子模塊,可免費試用
網站首頁:http://www.onealert.com/
下載頁面:http://www.onealert.com/open/alert/download.jsp
設置分派、設置應用,得到應用key
將agent更新到zabbix的外部告警腳本目錄alertscripts,若是是源碼安裝的請自行更改目錄。
tar xzf alert-agent-4.1.3.1-linux-x64.tar.gz
cp -R alert-agent /usr/lib/zabbix/alertscripts
cd /usr/lib/zabbix/alertscripts
chown -R zabbix:zabbix alert-agent
cp alert-agent/plugin/zabbix-plugin/110monitor /usr/lib/zabbix/alertscripts/
chmod +x /usr/lib/zabbix/alertscripts/110monitor
源碼安裝的盆友須要注意看配置文件/etc/zabbix/zabbix_server.conf
# AlertScriptsPath=/zabbix/alertscripts
AlertScriptsPath=/usr/lib/zabbix/alertscripts
請將agent更新至AlertScriptsPath目錄中
alert-agent目錄和110monitor須要放在同一級目錄裏面
建立媒體類型Media types,,「Administrator」->「Media types」->「Create media type」
採用腳本模式script,腳本名爲110monitor. 系統會在/usr/lib/zabbix/alertscripts/下查找上面的110monitor指令
建立用戶110monitor並設置通知媒介,登陸zabbix,「Administrator」->「Users」->「create user」.
l 將110monitor用戶加入到"Zabbix Administrator組"或者是新建組.
l 媒體類型,添加110monitor,而且設置appkey爲發送目標.
l 設置全部權限"Zabbix Super Admin"
新建110monitor用戶.
設置媒介類型.
設置權限.
建立告警通知策略,"Configurationg"->"Actions"->"Create action"
l 名稱110monitor
l 主題爲trigger和resolve,意味着告警觸發和恢復都會同步到110monitor
l 設置告警內容,注意冒號":"前的內容不可變動,冒號":"後的內容能夠自行編輯
alarmName:{TRIGGER.NAME}
entityName:{HOSTNAME}
entityId:{IPADDRESS}
value:{TRIGGER.VALUE}
eventId:{EVENT.ID}
priority:{TRIGGER.SEVERITY}
alarmContent:{IPADDRESS} {ITEM.NAME}:{ITEM.VALUE}
注意!自行配製的通知模板是不行的,須要嚴格按照以上配置。
查看agent日誌,出現sucess字樣表明成功,若是發送的告警通知,則會同步發送微信、移動app、短信、郵件
tail -f /usr/lib/zabbix/alertscripts/alert-agent/log/agent.log
l Python(2.6.6 laster)
加粗地方須要求改
import urllib2
import json
zabbix_url="http://192.168.1.222/zabbix/api_jsonrpc.php"
api_pass='zabbix'
auth_data={ 'jsonrpc':'2.0','method':'user.login','params':{'user':'Admin','password':api_pass},'id':1}
#auth function
def get_auth():
request=urllib2.Request(zabbix_url,json.dumps(auth_data))
request.add_header('Content-Type','application/json')
response=urllib2.urlopen(request)
var1=json.loads(response.read())
return var1
#get auth session
session=get_auth()
print(session)
l 將密鑰寫到粗體位置
[root@G1-WEB-1 tmp]# cat zbx_get.py
import urllib2
import json
zabbix_url="http://192.168.1.222/zabbix/api_jsonrpc.php"
api_pass='zabbix'
auth_data={
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"output": [
"triggerid",
"description",
"priority"]
},
"id": 2,
"auth": "9ef715599db2c9f7600c2d2ab08eb122"
}
#auth function
def get_auth():
request=urllib2.Request(zabbix_url,json.dumps(auth_data))
request.add_header('Content-Type','application/json')
response=urllib2.urlopen(request)
var1=json.loads(response.read())
return var1
#get auth session
session=get_auth()
print(session)
[root@G1-WEB-1 tmp]# cat zbx_get.py
import urllib2
import json
zabbix_url="http://192.168.1.222/zabbix/api_jsonrpc.php"
api_pass='zabbix'
auth_data={
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"output": [
"triggerid",
"description",
"priority"
],
"filter": {
"value": 1
},
"sortfield": "priority",
"sortorder": "DESC"
},
"id": 2,
"auth": "9ef715599db2c9f7600c2d2ab08eb122"
}
#auth function
def get_auth():
request=urllib2.Request(zabbix_url,json.dumps(auth_data))
request.add_header('Content-Type','application/json')
response=urllib2.urlopen(request)
var1=json.loads(response.read())
return var1
#get auth session
session=get_auth()
print(session)
以上粗體部分須要根據Zabbix的API手冊進行修改;
解釋:使用「trigger.get」方法,調用 "triggerid", "description", "priority"對象,經過"filter","sortfield","sortorder"
進行過濾。
返回結果以下
{
'jsonrpc': '2.0',
'result': [
{
'priority': '3',
'triggerid': '13773',
'description': '{
HOST.NAME
} is not reachable'
},
{
'priority': '3',
'triggerid': '13775',
'description': '{
HOST.NAME
} is unavailable by ICMP'
},
{
'priority': '3',
'triggerid': '13779',
'description': 'Zabbix agent on {
HOST.NAME
} is unreachable for 5 minutes'
},
{
'priority': '2',
'triggerid': '13776',
'description': 'Ping loss is too high on {
HOST.NAME
}'
},
{
'priority': '1',
'triggerid': '13744',
'description': 'gzip compression is off for connector http-8080 on {
HOST.NAME
}'
}
],
'id': 2
}
注意:實際只看到4個觸發器,是由於有一個觸發器有依賴,也一塊兒報警
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "0424bd59b807674191e7d77572075f33"
}
{
'jsonrpc': '2.0',
'result': [
{
'interfaces': [
{
'interfaceid': '1',
'ip': '192.168.1.222'
}
],
'host': 'Zabbix server',
'hostid': '10084',
'name': 'Zabbix server'
},
{
'interfaces': [
{
'interfaceid': '6',
'ip': '192.168.1.200'
},
{
'interfaceid': '7',
'ip': '192.168.1.200'
}
],
'host': 'G1-WEB-1',
'hostid': '10120',
'name': 'apache-tomcat-mysql'
},
{
'interfaces': [
{
'interfaceid': '8',
'ip': '192.168.1.110'
}
],
'host': 'a-506ef4ce25484.',
'hostid': '10122',
'name': 'Windos測試'
}
],
'id': 2
}
l 開發自定義監控腳本(經過傳參獲取對應狀態值)
l 增長Zabbix模板及觸發器
l 測試&導出項目
l 主文件
#!/bin/sh
#Version:V1.0
# Load system function library.
. /etc/init.d/functions
#Define the current position
Script_Base_Home=`pwd`
#Load getValue function
. ./Get_Function/MySQL/MySQL_Public_Fun.sh
if [ $# -ne 1];then
echo "Only allow you enter a parameter."
fi
#Receive Values
Input_Value=$1
Get_Value $Input_Value;
l 函數文件
#!/bin/sh
#Version:V1.0
#Public function
function Get_Value()
{
#Based on the input value ,get the value.
echo `grep "^$Input_Value\s" $Script_Base_Home/Tmp/MySQL_GetValue_Tmp | awk -F " " '{print $2}'`
}
l 定時獲取參數腳本
#!/bin/sh
#Version:V1.0
#Load conf function
. ./Conf/MySQL_Get_Configure.sh
#Define the current position
Script_Base_Home=`pwd`
$MySQL_App_Base/bin/mysql -u$MySQL_User -p$MySQL_Password -P$MySQL_Port -h$MySQL_Host -e "SELECT * FROM information_schema.global_variables;">$Script_Base_Home/Tmp/MySQL_GetValue_Tmp
l 參數文件
#!/bin/sh
#Version:V1.0
#MySQL Base Home
MySQL_App_Base=/app/mysql56/
#Remote Connection MySQL User
MySQL_User=GetV
MySQL_Password=GetV
MySQL_Port=3306
MySQL_Host=10.1.1.3
#Other Configure
Log_File=$Script_Base_Home/Log/
UserParameter=MySQL_PERFORMANCE_SCHEMA,sh/opt/Shell_Toos_BrandynX/MySQL_Status_Get.sh PERFORMANCE_SCHEMA
UserParameter=MySQL_QUERY_CACHE_TYPE,sh /opt/Shell_Toos_BrandynX/MySQL_Status_Get.sh QUERY_CACHE_TYPE
UserParameter=MySQL_AUTO_INCREMENT_OFFSET,sh /opt/Shell_Toos_BrandynX/MySQL_Status_Get.sh AUTO_INCREMENT_OFFSET
UserParameter=MySQL_INNODB_IO_CAPACITY,sh /opt/Shell_Toos_BrandynX/MySQL_Status_Get.sh INNODB_IO_CAPACITY