在Ubuntu 16.04上安装和使用服务器监控报警系统Shinken

第一步 安装 Shinken 服务器

Shinken 是一个 Python 框架,我们可以通过 pip 安装或者从源码来安装它,在这一步中,我们将用源代码编译安装 Shinken。

在我们开始安装 Shinken 之前还需要完成几个步骤。

安装一些新的 Python 软件包并创建一个名为 shinken 的系统用户:

 
 
  1. sudo apt-get install python-setuptools python-pip python-pycurl 
  2. useradd -m -s /bin/bash shinken 

从 GitHub 仓库下载 Shinken 源代码:

 
 
  1. git clone https://github.com/naparuba/shinken.git 
  2. cd shinken/ 

然后用以下命令安装 Shinken:

 
 
  1. git checkout 2.4.3 
  2. python setup.py install 

然后,为了得到更好的效果,我们还需要从 Ubuntu 软件库中安装 python-cherrypy3 软件包:

 
 
  1. sudo apt-get install python-cherrypy3 

到这里,Shinken 已经成功安装,接下来我们将 Shinken 添加到系统启动项并且启动它:

 
 
  1. update-rc.d shinken defaults 
  2. systemctl start shinken 

第二步 安装 Shinken Webui2

Webui2 是 Shinken 的 Web 界面(在 shinken.io 可以找到)。最简单的安装 Shinken webui2 的方法是使用shinken CLI 命令(必须作为 shinken 用户执行)。

切换到 shinken 用户:

 
 
  1. su - shinken 

初始化 shiken 配置文件,下面的命令将会创建一个新的配置文件 .shinken.ini :

 
 
  1. shinken --init 

接下来用 shinken CLI 命令来安装 webui2,最好网络能fanqiang:

 
 
  1. shinken install webui2 

至此 webui2 已经安装好,但是我们还需要安装 MongoDB 和用 pip 来安装另一个 Python 软件包。在 root 下运行如下命令:

 
 
  1. sudo apt-get install mongodb 
  2. pip install pymongo>=3.0.3 requests arrow bottle==0.12.8 

接下来,切换到 shinken 目录下并且通过编辑 broker-master.cfg 文件来添加这个新的 webui2 模块:

 
 
  1. cd /etc/shinken/brokers/ 
  2. vim broker-master.cfg 

在第 40 行添加一个模块选项:

 
 
  1. modules webui2 

保存文件并且退出编辑器。

现在进入 contacts 目录下编辑 admin.cfg 来进行管理配置。

 
 
  1. cd /etc/shinken/contacts/ 
  2. vim admin.cfg 

按照如下修改:

 
 
  1. contact_name    admin       # Username 'admin' 
  2. password        yourpass    # Pass 'mypass' 

保存和退出。

第三步 安装 Nagios 插件和 Shinken 软件包

在这一步中,我们将安装 Nagios 插件和一些 Perl 模块。然后从 shinken.io 安装其他的软件包来实现监视。

安装 Nagios 插件和安装 Perl 模块所需要的 cpanminus:

 
 
  1. sudo apt-get install nagios-plugins* cpanminus 

用 cpanm 命令来安装 Perl 模块。

 
 
  1. cpanm Net::SNMP 
  2. cpanm Time::HiRes 
  3. cpanm DBI 
  4. perl -e 'use Net::SNMP;'#如果提示can't locate Net/SNMP.pm in @Inc,则进行下一步
  5. sudo apt-get intall libnet-snmp-perl

现在我们创建一个 utils.pm 文件的链接到 shinken 的目录,并且为 Log_File_Health 创建了一个新的日志目录 。

 
 
  1. chmod u+s /usr/lib/nagios/plugins/check_icmp 
  2. ln -s /usr/lib/nagios/plugins/utils.pm /var/lib/shinken/libexec/ 
  3. mkdir -p /var/log/rhosts/ 
  4. touch /var/log/rhosts/remote-hosts.log 

然后,从 shinken.io 安装 shinken 软件包 ssh 和 linux-snmp 来监视 SSH 和 SNMP :

 
 
  1. su - shinken 
  2. shinken install ssh 
  3. shinken install linux-snmp 

第四步 添加一个 Linux 主机 host-one

我们将添加一个新的将被监控的 Linux 主机,IP 地址为 192.168.1.121,主机名为 host-one 的 Ubuntu 16.04。

连接到 host-one 主机:

 
 
  1. ssh host1@192.168.1.121 

从 Ubuntu 软件库中安装 snmp 和snmpd 软件包:

 
 
  1. sudo apt-get install snmp snmpd 

然后,用 vim 编辑 snmpd.conf 配置文件:

 
 
  1. vim /etc/snmp/snmpd.conf 

注释掉第 15 行并取消注释第 17 行(localhost也要这样)

 
 
  1. #agentAddress  udp:127.0.0.1:161 
  2. agentAddress udp:161,udp6:[::1]:161 

注释掉第 51 和 53 行,然后加一行新的配置,如下:

 
 
  1. #rocommunity mypass  default    -V systemonly 
  2. #rocommunity6 mypass  default   -V systemonly 
  3. rocommunity mypass 

保存并退出。

现在用 systemctl 命令来启动 snmpd 服务:

 
 
  1. systemctl start snmpd 

在 shinken 服务器上通过在 hosts 文件夹下创建新的文件来定义一个新的主机:

 
 
  1. cd /etc/shinken/hosts/ 
  2. vim host-one.cfg 

粘贴如下配置信息:

 
 
  1. define host{ 
  2.         use                 generic-host,linux-snmp,ssh 
  3.         contact_groups      admins 
  4.         host_name           host-one 
  5.         address             192.168.1.121 
  6.         _SNMPCOMMUNITY      mypass        # SNMP Pass Config on snmpd.conf 
  7.     } 

保存并退出。

在 shinken 服务器上编辑 SNMP 配置文件。

 
 
  1. vim /etc/shinken/resource.d/snmp.cfg 

将 public 改为 mypass -必须和你在客户端 snmpd 配置文件中使用的密码相同:

 
 
  1. $SNMPCOMMUNITYREAD$=mypass 

保存并退出。

现在将服务端和客户端都重启:

 
 
  1. reboot 

现在 Linux 主机已经被成功地添加到 shinken 服务器中了。

第五步 访问 Shinken Webui2

在端口 7677 访问 Shinken webui2 (将 URL 中的 IP 替换成你自己的 IP 地址):

 
 
  1. http://192.168.1.120:7767 

用管理员用户和密码登录(你在 admin.cfg 文件中设置的)

第6步 Shinken 的常见问题

NTP 服务器相关的问题

当你得到如下的 NTP 错误提示

 
 
  1. TimeSync - CRITICAL ( NTP CRITICAL: No response from the NTP server) 
  2. TimeSync - CRITICAL ( NTP CRITICAL: Offset unknown ) 

为了解决这个问题,在所有 Linux 主机上安装 ntp。

 
 
  1. sudo apt-get install ntp ntpdate 

编辑 ntp 配置文件:

 
 
  1. vim /etc/ntp.conf 

注释掉所有 pools 并替换为:

 
 
  1. #pool 0.ubuntu.pool.ntp.org iburst 
  2. #pool 1.ubuntu.pool.ntp.org iburst 
  3. #pool 2.ubuntu.pool.ntp.org iburst 
  4. #pool 3.ubuntu.pool.ntp.org iburst 
  5. pool 0.id.pool.ntp.org 
  6. pool 1.asia.pool.ntp.org 
  7. pool 2.asia.pool.ntp.org 

然后,在新的一行添加如下限制规则:

 
 
  1. Local users may interrogate the ntp server more closely. 
  2. restrict 127.0.0.1 
  3. restrict 192.168.1.120 #shinken server IP address 
  4. restrict ::1 
  5. NOTE: 192.168.1.120 is the Shinken server IP address. 

保存并退出。

启动 ntp 并且检查 Shinken 面板。

 
 
  1. ntpd 

check_netint.pl Not Found 问题

从 github 仓库下载源代码到 shinken 的库目录下:

 
 
  1. cd /var/lib/shinken/libexec/ 
  2. wget https://raw.githubusercontent.com/Sysnove/shinken-plugins/master/check_netint.pl 
  3. chmod +x check_netint.pl 
  4. chown shinken:shinken check_netint.pl 

网络占用的问题

这是错误信息:

 
 
  1. ERROR : Unknown interface eth\d+ 

检查你的网络接口并且编辑 linux-snmp 模版。

在我的 Ununtu 服务器,网卡是 “enp0s8”,而不是 eth0,所以我遇到了这个错误。

vim 编辑 linux-snmp 模版:

 
 
  1. vim /etc/shinken/packs/linux-snmp/templates.cfg 

在第 24 行添加网络接口信息:

 
 
  1. _NET_IFACES eth\d+|em\d+|enp0s8 

保存并退出。




附上另一片文章:

Install shinken on monitoring server

Prereqs

yum install perl-App-cpanminus gcc mysql55 mysql-devel sqlite nagios-plugins*
pip install cherrypy
cpanm Net::SNMP
cpanm Time::HiRes
cpanm DBI
cpanm DBD::mysql
ln -s /usr/lib64/nagios/ /usr/lib/nagios
chmod u+s /usr/lib/nagios/plugins/check_icmp
mkdir /usr/local/lib64/perl
ln -s /usr/lib/nagios/plugins/utils.pm /usr/local/lib64/perl/utils.pm

This should get you going with everything you need to get started. Now lets start setting up shinken.

Setup

yum update
adduser shinken
pip install --upgrade pip
pip install shinken
su - shinken
shinken --init
shinken install webui auth-cfg-password sqlitedb linux-snmp mysql http https ssh smtp

Configure broker-master

vim /etc/shinken/brokers/broker-master.cfg

Update the line:
modules

To

modules webui

This will load the webui module on 7767 but I run it behind nginx with a proxypass so I can have a nice easy url to remember.

Setup host config

vim /etc/shinken/hosts/server.cfg
define host{
        use                     linux-snmp,https,ssh,mysql
	contact_groups		admins
        host_name               domain.com # Domain you are monitoring
        address                 1.2.3.4 # Put the server your monitoring here
        }

Setup SNMP Community String

This one is easy, just modify /etc/shinken/resource.d/snmp.cfg with your SNMP community string.

Setup MySQL Credentials

Also, easy. Just modify /etc/shinken/resource.d/mysql.cfg with a user and password that we will set up on the monitored host in a short time.

Setting up the monitored host

yum install net-snmp net-snmp-libs net-snmp-utils
systemctl start snmpd.service
systemctl enable snmpd.service

Configure snmpd

vim /etc/snmp/snmpd.conf
com2sec AllUser         default         somepassword
group   AllGroup        v2c             AllUser
view    AllView         included        .1
access  AllGroup        ""      any     noauth  exact   AllView         none    none

Setup MySQL

mysql 
GRANT usage ON *.* TO 'shinken'@'1.2.3.4' IDENTIFIED BY 'password';
flush privileges;

Starting it up

If all went well when we start up shinken everything will just work. If not, I recommend checking the logs at /var/logs/shinken/* as they can normally tell you what is missing or broken.

service shinken start

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值