Site updated: 2022-10-18 10:31:32
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
219
2022/10/18/nagios安装与配置/index.html
Normal file
219
2022/10/18/nagios安装与配置/index.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
257
atom.xml
257
atom.xml
@ -8,7 +8,7 @@
|
|||||||
<author>
|
<author>
|
||||||
<name>Hito li</name>
|
<name>Hito li</name>
|
||||||
</author>
|
</author>
|
||||||
<updated>2022-10-17T06:07:00.000Z</updated>
|
<updated>2022-10-18T01:39:00.000Z</updated>
|
||||||
<category term="hito" />
|
<category term="hito" />
|
||||||
<category term="無言" />
|
<category term="無言" />
|
||||||
<category term="博客" />
|
<category term="博客" />
|
||||||
@ -16,6 +16,261 @@
|
|||||||
<category term="笔记" />
|
<category term="笔记" />
|
||||||
<category term="心得体会" />
|
<category term="心得体会" />
|
||||||
<category term="踩坑" />
|
<category term="踩坑" />
|
||||||
|
<entry>
|
||||||
|
<id>https://blog.jingxiyuan.cn/2022/10/18/nagios%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/</id>
|
||||||
|
<title>搭建nagios监控</title>
|
||||||
|
<link rel="alternate" href="https://blog.jingxiyuan.cn/2022/10/18/nagios%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/"/>
|
||||||
|
<content type="html"><h4 id="监控端服务安装与配置"><a class="anchor" href="#监控端服务安装与配置">#</a> 监控端服务安装与配置</h4>
|
||||||
|
<ol>
|
||||||
|
<li>nagios 需要安装主程序和 nrpe(nagios 和各被监控主机都必须安装)。如需使用自研前端可通过安装 ndoutils (用于把 nagios 监控信息写入数据库) 和 mysql 实现。具体安装见<span class="exturl" data-url="aHR0cHM6Ly9zdXBwb3J0Lm5hZ2lvcy5jb20va2Iv">官网</span></li>
|
||||||
|
<li>nagios 默认监控命令脚本放置在 libexec 中,自定义脚本后也放到此处</li>
|
||||||
|
<li>etc/objects/commands.cfg 用于保存 nagios 默认监控命令</li>
|
||||||
|
<li>etc/nrpe.cfg 文件中需要添加用于被监控执行命令项(各被监控主机中都需要添加)<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image.png" alt="" /></li>
|
||||||
|
<li>etc/objects/hosts 目录下配置需要被监控的主机信息<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image2.png" alt="" /></li>
|
||||||
|
<li>etc/objects/servers 目录下配置需要在被监控主机上执行的监控命令(第 4 项中的命令)<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image3.png" alt="" /></li>
|
||||||
|
</ol>
|
||||||
|
<h4 id="被监控端服务安装与配置"><a class="anchor" href="#被监控端服务安装与配置">#</a> 被监控端服务安装与配置</h4>
|
||||||
|
<ol>
|
||||||
|
<li>被监控端需要安装 nrpe</li>
|
||||||
|
<li>被监控端需要把监控端的命令写入到 nrpe 的配置文件中</li>
|
||||||
|
<li>被监控端需要把命令执行脚本放入 libexec 目录中</li>
|
||||||
|
<li>被监控端自动安装脚本(可借鉴)</li>
|
||||||
|
</ol>
|
||||||
|
<pre><code class="language-bash">1、请先修改脚本中的服务端IP。
|
||||||
|
2、如被监控端不支持let计算命令请执行sudo dpkg-reconfigure dash命令,弹出选择窗口后选择no。
|
||||||
|
3、需要在脚本同目录下创建CentOS、Ubuntu、sh和conf目录,目录下分别放置nrpe的tar安装包、监控脚本和nrpe配置文件。
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
#服务端ip
|
||||||
|
SERVER_IP=10.10.10.121
|
||||||
|
#安装目录
|
||||||
|
INSTALL_HOME=`pwd`
|
||||||
|
#安装ubuntu版本
|
||||||
|
INSTALL_UBUNTU()
|
||||||
|
&#123;
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget openssl
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz
|
||||||
|
cp $INSTALL_HOME/Ubuntu/nrpe.tar.gz ./
|
||||||
|
tar xzf nrpe.tar.gz
|
||||||
|
|
||||||
|
cd /tmp/nrpe-nrpe-4.0.3/
|
||||||
|
sudo ./configure --enable-command-args --with-ssl-lib=/usr/lib/x86_64-linux-gnu/
|
||||||
|
sudo make all
|
||||||
|
|
||||||
|
sudo make install-groups-users
|
||||||
|
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
sudo make install-config
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo &gt;&gt; /etc/services&quot;
|
||||||
|
sudo sh -c &quot;sudo echo '# Nagios services' &gt;&gt; /etc/services&quot;
|
||||||
|
sudo sh -c &quot;sudo echo 'nrpe 5666/tcp' &gt;&gt; /etc/services&quot;
|
||||||
|
|
||||||
|
#判断系统是高版本还是低版本
|
||||||
|
VERSION=`lsb_release -r --short`
|
||||||
|
IS_LOW_VERSION=`echo &quot;$VERSION &lt; 15&quot; | bc`
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
sudo make install-init
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
sudo make install-init
|
||||||
|
sudo systemctl enable nrpe.service
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo mkdir -p /etc/ufw/applications.d
|
||||||
|
sudo sh -c &quot;echo '[NRPE]' &gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'title=Nagios Remote Plugin Executor' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'description=Allows remote execution of Nagios plugins' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'ports=5666/tcp' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo ufw allow NRPE
|
||||||
|
sudo ufw reload
|
||||||
|
|
||||||
|
sudo sh -c &quot;sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
|
||||||
|
cd $INSTALL_HOME
|
||||||
|
sudo cp ./sh/* /usr/local/nagios/libexec/
|
||||||
|
sudo chmod +xr /usr/local/nagios/libexec/*
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \$ARG1\$' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=1
|
||||||
|
for NETWORK_NAME in `cat /proc/net/dev | awk '&#123;i++; if(i&gt;2)&#123;print $1&#125;&#125;' | sed 's/^[\t]*//g' | sed 's/[:]*$//g'`;do
|
||||||
|
if [ $NETWORK_NAME != 'lo' ]; then
|
||||||
|
sudo sh -c &quot;echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=`expr $NETWORK_INDEX + 1 `
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
sudo start nrpe
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
sudo systemctl start nrpe.service
|
||||||
|
fi
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#安装centos版本
|
||||||
|
INSTALL_CENTOS()
|
||||||
|
&#123;
|
||||||
|
yum install -y gcc glibc glibc-common openssl openssl-devel perl wget
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz
|
||||||
|
cp $INSTALL_HOME/CentOS/nrpe.tar.gz ./
|
||||||
|
tar xzf nrpe.tar.gz
|
||||||
|
|
||||||
|
cd /tmp/nrpe-nrpe-4.0.3/
|
||||||
|
./configure --enable-command-args
|
||||||
|
make all
|
||||||
|
|
||||||
|
make install-groups-users
|
||||||
|
|
||||||
|
make install
|
||||||
|
|
||||||
|
make install-config
|
||||||
|
|
||||||
|
echo &gt;&gt; /etc/services
|
||||||
|
echo '# Nagios services' &gt;&gt; /etc/services
|
||||||
|
echo 'nrpe 5666/tcp' &gt;&gt; /etc/services
|
||||||
|
|
||||||
|
#判断系统是高版本还是低版本
|
||||||
|
VERSION=`rpm -q centos-release|cut -d- -f3`
|
||||||
|
#安装bc命令
|
||||||
|
yum -y install bc
|
||||||
|
IS_LOW_VERSION=`echo &quot;$VERSION &lt; 7&quot; | bc`
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
make install-init
|
||||||
|
|
||||||
|
iptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
|
||||||
|
service iptables save
|
||||||
|
ip6tables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
|
||||||
|
service ip6tables save
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
make install-init
|
||||||
|
systemctl enable nrpe.service
|
||||||
|
|
||||||
|
firewall-cmd --zone=public --add-port=5666/tcp
|
||||||
|
firewall-cmd --zone=public --add-port=5666/tcp --permanent
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo sh -c &quot;sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
|
||||||
|
cd $INSTALL_HOME
|
||||||
|
sudo cp ./sh/* /usr/local/nagios/libexec/
|
||||||
|
sudo chmod +xr /usr/local/nagios/libexec/*
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \$ARG1\$' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=1
|
||||||
|
for NETWORK_NAME in `cat /proc/net/dev | awk '&#123;i++; if(i&gt;2)&#123;print $1&#125;&#125;' | sed 's/^[\t]*//g' | sed 's/[:]*$//g'`;do
|
||||||
|
if [ $NETWORK_NAME != 'lo' ]; then
|
||||||
|
sudo sh -c &quot;echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=`expr $NETWORK_INDEX + 1 `
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
if [ $(echo &quot;$VERSION &lt; 6&quot; | bc) -eq 1 ]; then
|
||||||
|
service nrpe start
|
||||||
|
else
|
||||||
|
start nrpe
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
systemctl start nrpe.service
|
||||||
|
fi
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#安装其它版本
|
||||||
|
INSTALL_OTHER()
|
||||||
|
&#123;
|
||||||
|
echo &quot;Not supported at the moment.&quot;
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#根据不同系统安装不同版本
|
||||||
|
INSTALL()
|
||||||
|
&#123;
|
||||||
|
if grep -Eqii &quot;CentOS&quot; /etc/issue || grep -Eq &quot;CentOS&quot; /etc/*-release; then
|
||||||
|
DISTRO='CentOS'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_CENTOS
|
||||||
|
elif grep -Eqi &quot;Red Hat Enterprise Linux Server&quot; /etc/issue || grep -Eq &quot;Red Hat Enterprise Linux Server&quot; /etc/*-release; then
|
||||||
|
DISTRO='RHEL'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Aliyun&quot; /etc/issue || grep -Eq &quot;Aliyun&quot; /etc/*-release; then
|
||||||
|
DISTRO='Aliyun'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Fedora&quot; /etc/issue || grep -Eq &quot;Fedora&quot; /etc/*-release; then
|
||||||
|
DISTRO='Fedora'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Debian&quot; /etc/issue || grep -Eq &quot;Debian&quot; /etc/*-release; then
|
||||||
|
DISTRO='Debian'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Ubuntu&quot; /etc/issue || grep -Eq &quot;Ubuntu&quot; /etc/*-release; then
|
||||||
|
DISTRO='Ubuntu'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_UBUNTU
|
||||||
|
elif grep -Eqi &quot;Raspbian&quot; /etc/issue || grep -Eq &quot;Raspbian&quot; /etc/*-release; then
|
||||||
|
DISTRO='Raspbian'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_OTHER
|
||||||
|
else
|
||||||
|
echo &quot;unknow linux.&quot;
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo $DISTRO
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
INSTALL
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
</code></pre>
|
||||||
|
<h4 id="常见问题"><a class="anchor" href="#常见问题">#</a> 常见问题</h4>
|
||||||
|
<ol>
|
||||||
|
<li>监控日志未写入 mysql(可能是 ndoutils 服务不正常导致)。采用以下脚本命令解决</li>
|
||||||
|
</ol>
|
||||||
|
<pre><code class="language-bash">#!/bin/bash
|
||||||
|
sudo rm -f /usr/local/nagios/var/ndo2db.pid
|
||||||
|
sudo rm -f /usr/local/nagios/var/ndo.sock
|
||||||
|
sudo systemctl restart ndo2db.service
|
||||||
|
sudo systemctl status ndo2db.service
|
||||||
|
</code></pre>
|
||||||
|
</content>
|
||||||
|
<category term="技术分享" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/" />
|
||||||
|
<category term="经验分享" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB/" />
|
||||||
|
<category term="心得体会" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB/%E5%BF%83%E5%BE%97%E4%BD%93%E4%BC%9A/" />
|
||||||
|
<category term="nagios" scheme="https://blog.jingxiyuan.cn/tags/nagios/" />
|
||||||
|
<category term="服务监控" scheme="https://blog.jingxiyuan.cn/tags/%E6%9C%8D%E5%8A%A1%E7%9B%91%E6%8E%A7/" />
|
||||||
|
<updated>2022-10-18T01:39:00.000Z</updated>
|
||||||
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<id>https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/</id>
|
<id>https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/</id>
|
||||||
<title>redis主从基础配置</title>
|
<title>redis主从基础配置</title>
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
categories/技术分享/经验分享/index.html
Normal file
1
categories/技术分享/经验分享/index.html
Normal file
File diff suppressed because one or more lines are too long
1
categories/技术分享/经验分享/心得体会/index.html
Normal file
1
categories/技术分享/经验分享/心得体会/index.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
259
rss.xml
259
rss.xml
@ -10,8 +10,8 @@
|
|||||||
</author>
|
</author>
|
||||||
<description>hito的博客</description>
|
<description>hito的博客</description>
|
||||||
<language>zh-CN</language>
|
<language>zh-CN</language>
|
||||||
<pubDate>Mon, 17 Oct 2022 14:07:00 +0800</pubDate>
|
<pubDate>Tue, 18 Oct 2022 09:39:00 +0800</pubDate>
|
||||||
<lastBuildDate>Mon, 17 Oct 2022 14:07:00 +0800</lastBuildDate>
|
<lastBuildDate>Tue, 18 Oct 2022 09:39:00 +0800</lastBuildDate>
|
||||||
<category term="hito" />
|
<category term="hito" />
|
||||||
<category term="無言" />
|
<category term="無言" />
|
||||||
<category term="博客" />
|
<category term="博客" />
|
||||||
@ -19,6 +19,261 @@
|
|||||||
<category term="笔记" />
|
<category term="笔记" />
|
||||||
<category term="心得体会" />
|
<category term="心得体会" />
|
||||||
<category term="踩坑" />
|
<category term="踩坑" />
|
||||||
|
<item>
|
||||||
|
<guid isPermalink="true">https://blog.jingxiyuan.cn/2022/10/18/nagios%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/</guid>
|
||||||
|
<title>搭建nagios监控</title>
|
||||||
|
<link>https://blog.jingxiyuan.cn/2022/10/18/nagios%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/</link>
|
||||||
|
<category term="技术分享" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/" />
|
||||||
|
<category term="经验分享" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB/" />
|
||||||
|
<category term="心得体会" scheme="https://blog.jingxiyuan.cn/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB/%E5%BF%83%E5%BE%97%E4%BD%93%E4%BC%9A/" />
|
||||||
|
<category term="nagios" scheme="https://blog.jingxiyuan.cn/tags/nagios/" />
|
||||||
|
<category term="服务监控" scheme="https://blog.jingxiyuan.cn/tags/%E6%9C%8D%E5%8A%A1%E7%9B%91%E6%8E%A7/" />
|
||||||
|
<pubDate>Tue, 18 Oct 2022 09:39:00 +0800</pubDate>
|
||||||
|
<description><![CDATA[ <h4 id="监控端服务安装与配置"><a class="anchor" href="#监控端服务安装与配置">#</a> 监控端服务安装与配置</h4>
|
||||||
|
<ol>
|
||||||
|
<li>nagios 需要安装主程序和 nrpe(nagios 和各被监控主机都必须安装)。如需使用自研前端可通过安装 ndoutils (用于把 nagios 监控信息写入数据库) 和 mysql 实现。具体安装见<span class="exturl" data-url="aHR0cHM6Ly9zdXBwb3J0Lm5hZ2lvcy5jb20va2Iv">官网</span></li>
|
||||||
|
<li>nagios 默认监控命令脚本放置在 libexec 中,自定义脚本后也放到此处</li>
|
||||||
|
<li>etc/objects/commands.cfg 用于保存 nagios 默认监控命令</li>
|
||||||
|
<li>etc/nrpe.cfg 文件中需要添加用于被监控执行命令项(各被监控主机中都需要添加)<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image.png" alt="" /></li>
|
||||||
|
<li>etc/objects/hosts 目录下配置需要被监控的主机信息<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image2.png" alt="" /></li>
|
||||||
|
<li>etc/objects/servers 目录下配置需要在被监控主机上执行的监控命令(第 4 项中的命令)<br />
|
||||||
|
<img data-src="https://file.jingxiyuan.cn/images/2022/10/18/image3.png" alt="" /></li>
|
||||||
|
</ol>
|
||||||
|
<h4 id="被监控端服务安装与配置"><a class="anchor" href="#被监控端服务安装与配置">#</a> 被监控端服务安装与配置</h4>
|
||||||
|
<ol>
|
||||||
|
<li>被监控端需要安装 nrpe</li>
|
||||||
|
<li>被监控端需要把监控端的命令写入到 nrpe 的配置文件中</li>
|
||||||
|
<li>被监控端需要把命令执行脚本放入 libexec 目录中</li>
|
||||||
|
<li>被监控端自动安装脚本(可借鉴)</li>
|
||||||
|
</ol>
|
||||||
|
<pre><code class="language-bash">1、请先修改脚本中的服务端IP。
|
||||||
|
2、如被监控端不支持let计算命令请执行sudo dpkg-reconfigure dash命令,弹出选择窗口后选择no。
|
||||||
|
3、需要在脚本同目录下创建CentOS、Ubuntu、sh和conf目录,目录下分别放置nrpe的tar安装包、监控脚本和nrpe配置文件。
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
#服务端ip
|
||||||
|
SERVER_IP=10.10.10.121
|
||||||
|
#安装目录
|
||||||
|
INSTALL_HOME=`pwd`
|
||||||
|
#安装ubuntu版本
|
||||||
|
INSTALL_UBUNTU()
|
||||||
|
&#123;
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget openssl
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz
|
||||||
|
cp $INSTALL_HOME/Ubuntu/nrpe.tar.gz ./
|
||||||
|
tar xzf nrpe.tar.gz
|
||||||
|
|
||||||
|
cd /tmp/nrpe-nrpe-4.0.3/
|
||||||
|
sudo ./configure --enable-command-args --with-ssl-lib=/usr/lib/x86_64-linux-gnu/
|
||||||
|
sudo make all
|
||||||
|
|
||||||
|
sudo make install-groups-users
|
||||||
|
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
sudo make install-config
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo &gt;&gt; /etc/services&quot;
|
||||||
|
sudo sh -c &quot;sudo echo '# Nagios services' &gt;&gt; /etc/services&quot;
|
||||||
|
sudo sh -c &quot;sudo echo 'nrpe 5666/tcp' &gt;&gt; /etc/services&quot;
|
||||||
|
|
||||||
|
#判断系统是高版本还是低版本
|
||||||
|
VERSION=`lsb_release -r --short`
|
||||||
|
IS_LOW_VERSION=`echo &quot;$VERSION &lt; 15&quot; | bc`
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
sudo make install-init
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
sudo make install-init
|
||||||
|
sudo systemctl enable nrpe.service
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo mkdir -p /etc/ufw/applications.d
|
||||||
|
sudo sh -c &quot;echo '[NRPE]' &gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'title=Nagios Remote Plugin Executor' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'description=Allows remote execution of Nagios plugins' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo sh -c &quot;echo 'ports=5666/tcp' &gt;&gt; /etc/ufw/applications.d/nagios&quot;
|
||||||
|
sudo ufw allow NRPE
|
||||||
|
sudo ufw reload
|
||||||
|
|
||||||
|
sudo sh -c &quot;sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
|
||||||
|
cd $INSTALL_HOME
|
||||||
|
sudo cp ./sh/* /usr/local/nagios/libexec/
|
||||||
|
sudo chmod +xr /usr/local/nagios/libexec/*
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \$ARG1\$' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=1
|
||||||
|
for NETWORK_NAME in `cat /proc/net/dev | awk '&#123;i++; if(i&gt;2)&#123;print $1&#125;&#125;' | sed 's/^[\t]*//g' | sed 's/[:]*$//g'`;do
|
||||||
|
if [ $NETWORK_NAME != 'lo' ]; then
|
||||||
|
sudo sh -c &quot;echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=`expr $NETWORK_INDEX + 1 `
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
sudo start nrpe
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
sudo systemctl start nrpe.service
|
||||||
|
fi
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#安装centos版本
|
||||||
|
INSTALL_CENTOS()
|
||||||
|
&#123;
|
||||||
|
yum install -y gcc glibc glibc-common openssl openssl-devel perl wget
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz
|
||||||
|
cp $INSTALL_HOME/CentOS/nrpe.tar.gz ./
|
||||||
|
tar xzf nrpe.tar.gz
|
||||||
|
|
||||||
|
cd /tmp/nrpe-nrpe-4.0.3/
|
||||||
|
./configure --enable-command-args
|
||||||
|
make all
|
||||||
|
|
||||||
|
make install-groups-users
|
||||||
|
|
||||||
|
make install
|
||||||
|
|
||||||
|
make install-config
|
||||||
|
|
||||||
|
echo &gt;&gt; /etc/services
|
||||||
|
echo '# Nagios services' &gt;&gt; /etc/services
|
||||||
|
echo 'nrpe 5666/tcp' &gt;&gt; /etc/services
|
||||||
|
|
||||||
|
#判断系统是高版本还是低版本
|
||||||
|
VERSION=`rpm -q centos-release|cut -d- -f3`
|
||||||
|
#安装bc命令
|
||||||
|
yum -y install bc
|
||||||
|
IS_LOW_VERSION=`echo &quot;$VERSION &lt; 7&quot; | bc`
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
make install-init
|
||||||
|
|
||||||
|
iptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
|
||||||
|
service iptables save
|
||||||
|
ip6tables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
|
||||||
|
service ip6tables save
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
make install-init
|
||||||
|
systemctl enable nrpe.service
|
||||||
|
|
||||||
|
firewall-cmd --zone=public --add-port=5666/tcp
|
||||||
|
firewall-cmd --zone=public --add-port=5666/tcp --permanent
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo sh -c &quot;sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
|
||||||
|
cd $INSTALL_HOME
|
||||||
|
sudo cp ./sh/* /usr/local/nagios/libexec/
|
||||||
|
sudo chmod +xr /usr/local/nagios/libexec/*
|
||||||
|
|
||||||
|
sudo sh -c &quot;echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \$ARG1\$' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
sudo sh -c &quot;echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=1
|
||||||
|
for NETWORK_NAME in `cat /proc/net/dev | awk '&#123;i++; if(i&gt;2)&#123;print $1&#125;&#125;' | sed 's/^[\t]*//g' | sed 's/[:]*$//g'`;do
|
||||||
|
if [ $NETWORK_NAME != 'lo' ]; then
|
||||||
|
sudo sh -c &quot;echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' &gt;&gt; /usr/local/nagios/etc/nrpe.cfg&quot;
|
||||||
|
NETWORK_INDEX=`expr $NETWORK_INDEX + 1 `
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $IS_LOW_VERSION = 1 ]; then
|
||||||
|
#低版本
|
||||||
|
if [ $(echo &quot;$VERSION &lt; 6&quot; | bc) -eq 1 ]; then
|
||||||
|
service nrpe start
|
||||||
|
else
|
||||||
|
start nrpe
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
#高版本
|
||||||
|
systemctl start nrpe.service
|
||||||
|
fi
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#安装其它版本
|
||||||
|
INSTALL_OTHER()
|
||||||
|
&#123;
|
||||||
|
echo &quot;Not supported at the moment.&quot;
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
#根据不同系统安装不同版本
|
||||||
|
INSTALL()
|
||||||
|
&#123;
|
||||||
|
if grep -Eqii &quot;CentOS&quot; /etc/issue || grep -Eq &quot;CentOS&quot; /etc/*-release; then
|
||||||
|
DISTRO='CentOS'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_CENTOS
|
||||||
|
elif grep -Eqi &quot;Red Hat Enterprise Linux Server&quot; /etc/issue || grep -Eq &quot;Red Hat Enterprise Linux Server&quot; /etc/*-release; then
|
||||||
|
DISTRO='RHEL'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Aliyun&quot; /etc/issue || grep -Eq &quot;Aliyun&quot; /etc/*-release; then
|
||||||
|
DISTRO='Aliyun'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Fedora&quot; /etc/issue || grep -Eq &quot;Fedora&quot; /etc/*-release; then
|
||||||
|
DISTRO='Fedora'
|
||||||
|
PM='yum'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Debian&quot; /etc/issue || grep -Eq &quot;Debian&quot; /etc/*-release; then
|
||||||
|
DISTRO='Debian'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_OTHER
|
||||||
|
elif grep -Eqi &quot;Ubuntu&quot; /etc/issue || grep -Eq &quot;Ubuntu&quot; /etc/*-release; then
|
||||||
|
DISTRO='Ubuntu'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_UBUNTU
|
||||||
|
elif grep -Eqi &quot;Raspbian&quot; /etc/issue || grep -Eq &quot;Raspbian&quot; /etc/*-release; then
|
||||||
|
DISTRO='Raspbian'
|
||||||
|
PM='apt'
|
||||||
|
INSTALL_OTHER
|
||||||
|
else
|
||||||
|
echo &quot;unknow linux.&quot;
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo $DISTRO
|
||||||
|
&#125;
|
||||||
|
|
||||||
|
INSTALL
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
</code></pre>
|
||||||
|
<h4 id="常见问题"><a class="anchor" href="#常见问题">#</a> 常见问题</h4>
|
||||||
|
<ol>
|
||||||
|
<li>监控日志未写入 mysql(可能是 ndoutils 服务不正常导致)。采用以下脚本命令解决</li>
|
||||||
|
</ol>
|
||||||
|
<pre><code class="language-bash">#!/bin/bash
|
||||||
|
sudo rm -f /usr/local/nagios/var/ndo2db.pid
|
||||||
|
sudo rm -f /usr/local/nagios/var/ndo.sock
|
||||||
|
sudo systemctl restart ndo2db.service
|
||||||
|
sudo systemctl status ndo2db.service
|
||||||
|
</code></pre>
|
||||||
|
]]></description>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<guid isPermalink="true">https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/</guid>
|
<guid isPermalink="true">https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/</guid>
|
||||||
<title>redis主从基础配置</title>
|
<title>redis主从基础配置</title>
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
tags/nagios/index.html
Normal file
1
tags/nagios/index.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
tags/服务监控/index.html
Normal file
1
tags/服务监控/index.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user