6.16和6.17 稍微提一下。 重點關注 6.15和6.18
6.15 SSH Agent
通過SSH連接被監控設備,並且執行命令或者腳本來獲取監控數據
(只要是支持ssh的設備就可以使用這個方式獲取數據)
前提條件
zabbix-server端
- zabbix server 安裝時需要支持ssh
- 驗證到被監控設備的ssh登陸
- 添加ssh agent監控
數據收集流程
語法
ssh.run[<unique short description>,<ip>,<port>,<encoding>]
Password方式
第一步:確認是否安裝SSH
在客戶端:
#mkdir /home/zabbix
#chown zabbix:zabbix /home/zabbix/
#chmod 700 /home/zabbix/
#usermod -s /bin/bash zabbix //修改用戶登入後所使用的shell
#passwd zabbix
#usermod -m -d /home/zabbix zabbix //修改用戶登入時的目錄
在服務端:
查看從Server端到被監控的Agent端,SSH的登錄情況
#ssh [email protected]
第二步:在Web前端增加SSH的監控項
結果:
密鑰方式
第一步:確認zabbix
在服務端:
#mkdir /home/zabbix
#chown zabbix:zabbix /home/zabbix/
#chmod 700 /home/zabbix/
#usermod -s /bin/bash zabbix //修改用戶登入後所使用的shell
#passwd zabbix
#usermod -m -d /home/zabbix zabbix //修改用戶登入時的目錄
第二步:創建密鑰
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
SSHKeyLocation=/home/zabbix/.ssh
[root@localhost ~]# systemctl restart zabbix-server.service
創建RSA登錄的key
使用如下命令生產SSH密鑰:
[root@localhost zabbix]# mkdir -p /home/zabbix/.ssh
[root@localhost zabbix]# chown zabbix:zabbix -R /home/zabbix/
[root@localhost zabbix]# sudo -u zabbix ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/zabbix/.ssh/id_rsa): /home/zabbix/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zabbix/.ssh/id_rsa.
Your public key has been saved in /home/zabbix/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/+vkeeKEJye+v+q0Th5x1NZMClQyLo3clCJWVc2Jm7Q zabbix@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| ..oB++oo|
| o..*.B *o|
| . .+.* B o|
| o E |
| S . . |
| . + |
| O = |
| = %... |
| oO*X= |
+----[SHA256]-----+
[root@localhost zabbix]# ls -l /home/zabbix/.ssh
總用量 8
-rw------- 1 zabbix zabbix 1675 5月 27 23:06 id_rsa
-rw-r--r-- 1 zabbix zabbix 410 5月 27 23:06 id_rsa.pub
傳輸公鑰
[root@localhost zabbix]# sudo -u zabbix ssh-copy-id [email protected]
ssh祕鑰分發錯誤“/usr/bin/ssh-copy-id: ERROR: No identities found”
因爲 要分發的祕鑰/root/.ssh/id_dsa.pub,根本不存在,纔會提示這個錯誤,於是使用ssh-keygen -t dsa 生成公鑰後即可。
[root@localhost zabbix]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fWFwTMnKD/frL+yYe4l108v9ddIUbWqnFZXk9fdjCmQ root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| .+o...+|
| o+ ..=|
| . Eo +=|
| .*... o=|
| S .=..oo*|
| .o.=B+|
| =++B|
| .o*++|
| +=oo+|
+----[SHA256]-----+
[root@localhost zabbix]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
zabbix@192.168.93.147's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'zabbix@192.168.93.147'"
and check to make sure that only the key(s) you wanted were added.
測試目標機器能否免密碼訪問,使用如下命令:
sudo -u zabbix ssh [email protected] ‘ifconfig’
6.16 JMX Agent
JMX java管理擴展
前提條件
zabbix-server
- zabbix server安裝時需要啓用JAVA Gateway
- zabbix server 配置啓動JAVA Gateway
- zabbix server 配置JAVA Gateway/JAVA GatewayPort參數
- zabbix server配置Start JavaPollers參數
- 保障zabbix server和JMX 應用的IP+Port通信
被監控設備
- 開啓並正確配置JMX
數據收集流程
語法
jmx[object_name,attribute_name]
jmx.discovery[,]
attribute模式
{#JMXVALUE}
{#JMXTYPE}
{#JMXOBJ}
{#JMXDESC}
{#JMXATTR}
beans模式
{#JMXDOMAIN}
{#JMXOBJ}
{#JMX<key property>}
在zabbix server上 拿本機演示
yum install zabbix-java-gateway -y
修改zabbix_java_gateway.conf
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
START_POLLERS=5
JAVA_OPTIONS="$JAVA_OPTIONS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
啓動服務
systemctl start zabbix-java-gateway.service
修改zabbix_server.conf
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=5
重啓zabbix-server
web界面找到zabbix server
添加JMX interfaces
添加jmx模板
可以在監控的最新數據中 查看監控數據
用jconsole查看
在agent上部署一個tomcat 來監控
修改tomcat的catalina.sh添加(也可以啓用認證)
CATALINA_OPTS="
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=18080
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
"
啓動tomcat
在web界面添加端口監聽
…略,以後用到再補充
6.17 IPMI Agent
硬件設備的監控一般都可以通過SNMP和IPMI實現
IMPI(智能平臺管理接口)是獨立於系統的,只要系統是通電的,就可以實現對服務器的管理和監控(物理狀態,溫度,電壓,電源等等)。
前提條件
zabbix-server
- zabbix-server 安裝時需要支持IPMI
- zabbix-server配置StartIPMIPollers參數
- 驗證訪問被監控設備的IPMI設置
被監控設備 開始並正確配置IPMI
數據收集流程
Zabbix Server
[root@localhost ~]# tail -n 500 /var/log/zabbix/zabbix_server.log
配置StartIPMIPollers參數
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
tartIPMIPollers=5
[root@localhost ~]# systemctl restart zabbix-server.service
安裝 ipmi 命令
[root@localhost ~]# which ipmi
[root@localhost ~]# yum search ipmi
[root@localhost ~]# yum -y install ipmitool OpenIPMI OpenIPMI-libs
接下來登錄服務器的iDrac管理頁面開啓戴爾服務器的IPMI服務器支持,以及配置對應的Zabbix 監控用戶相應的權限
配置一個zabbix用戶
在zabbix-server上執行命令 測試獲取數據,看是否能獲取
ipmitool -I lanplus -H 192.168.93.148 -U zabbix -P zabbix -L user sensor list
ipmitool -I lanplus -H 192.168.93.148 -U zabbix -P zabbix -L user sensor get “Fan1”
web界面配置
1.創建主機
2.創建監控項
Key是自定義的,保證唯一即可
6.18 Database monitor
Uninx ODBC支持常見的數據庫系統:MySQL、SQL Server、Oracle、MongoDB
前提條件
zabbix-server
- zabbix server安裝時需要啓用unuxODBC
- zabbix server安裝和配置unixODBC
- zabbix server配置對應的ODBC Driver
- 保障zabbix server和數據庫的IP+Port通信
被監控設備
- 數據庫配置正確的賬號和權限
數據庫監控收集流程
語法
db.odbc.select[<unique short description>,<dsn>]
zabbix server上安裝ODBC
yum search ODBC
yum install unixODBC unixODBC-devel
yum search odbc
yum install mysql-connector-odbc
[root@localhost ~]# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
配置數據庫連接
#vim /etc/odbc.ini
[zabbix]
Decription= MySQL zabbix DB
Driver = mysql
Server = localhost
User = zabbix
Password = zabbix@findsec123
Port = 3306
Database = zabbix
isql測試數據源的連接情況
[root@localhost ~]# isql zabbix
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
1.創建監控項
以select count(*) from users; 來監控數據庫用戶數量
Key的第二個參數 dsn是上面配置數據庫連接的 【zabbix】的zabbix
2.驗證結果
到這裏爲止,數據收集的基本概念和配置管理大致完成,還剩下三個管理小功能,在已有的監控項基礎之上進行一些數值處理。