浓缩版:云计算运维KVM监控工具之Sensu开源版

浓缩版:云计算运维KVM监控工具之Sensu开源版

零、Sensu说明

1.Sensu 是由 Sonian 公司开发的一种监控框架,主要用于拥有大规模节点的云计算平台的检查与监控。目前发行的版本有企业版和开源版两种,收费的企业版本较之免费的开源版本拥有更多的功能。出于介绍的目的,本文的内容都是基于开源版本的 Sensu。

开源版本的 Sensu 遵循 MIT 许可,旨在为分布式的平台提供灵活易用、快速简单、便于拓展的监控和维护服务。主要包含以下功能与特性:

  • 检查系统、服务和程序的运行状态。
  • 基于分布式的设计,能够轻松的动态伸缩规模。
  • 支持通过插件的形式自定义检查的内容,拥有丰富的插件库。
  • 收集信息,获取被监控节点上的各项数据指标等。
  • 可视化的操作界面,提供实时的 GUI 用于显示和操作相关信息。
  • 内置的集成工具,可用于和其它系统集成,如 PagerDuty、Graphite、Email 等。
  • 提供丰富的 API 接口,支持通过 API 调用访问事件和客户端信息,触发检测等。
  • 加密的安全通信,支持各种复杂的网络拓扑。

2.Sensu支持许多类Unix平台,以及Windows。
浓缩版:云计算运维KVM监控工具之Sensu开源版

浓缩版:云计算运维KVM监控工具之Sensu开源版

Sensu架构简图:
浓缩版:云计算运维KVM监控工具之Sensu开源版

一、服务器端安装

环境:Centos7 最小安装基础版。

1. Sensu需要安装Redis。要安装Redis,请启用EPEL存储库:

[root@web1 ~]# yum install epel-release -y

2.安装redis服务

[root@web1 ~]# yum install redis -y

修改redis配置,禁用保护模式,设置redis服务密码

[root@web1 ~]# sed -i 's/^protected-mode yes/protected-mode no/g' /etc/redis.conf
[root@web1 ~]# sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf
[root@web1 ~]# ed -i 's/^# requirepass foobared/requirepass password123/g' /etc/redis.conf

启动redis服务报错

[root@web1 ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[root@web1 ~]# systemctl start redis
Warning: redis.service changed on disk. Run 'systemctl daemon-reload' to reload units.

报错解决:重启后服务就正常了

[root@web1 ~]# systemctl daemon-reload
[root@web1 ~]# reboot
[root@web1 ~]# systemctl status  redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Wed 2019-03-13 19:33:27 CST; 3min 6s ago
Main PID: 875 (redis-server)
   CGroup: /system.slice/redis.service
           └─875 /usr/bin/redis-server 0.0.0.0:6379

Mar 13 19:33:27 web1 systemd[1]: Starting Redis persistent key-value database...
Mar 13 19:33:27 web1 systemd[1]: Started Redis persistent key-value database.

3.Sensu监控组件安装
添加Sensu的软件源

[root@web1 ~]# tee /etc/yum.repos.d/sensu.repo << EOF
> [sensu]
> name=sensu
> baseurl=https://sensu.global.ssl.fastly.net/yum/$releasever/$basearch/
> gpgcheck=0
> enabled=1
> EOF

安装Sensu

[root@web1 ~]#  yum install sensu uchiwa -y

设置Sensu基础配置文件,使用端口4567配置Sensu-api以侦听localhost

[root@web1 ~]# tee /etc/sensu/conf.d/api.json << EOF
> {"api": { "host": "127.0.0.1", "port": 4567 }}
> EOF

将Sensu配置连接使用redis作为Transport以及redis侦听的地址。客户端需要连接到Transport,每台客户端计算机都需要这两个配置文件

[root@web1 ~]# tee /etc/sensu/conf.d/redis.json << EOF
> {"redis": { "host": "192.168.0.230", "port": 6379, "password": "password123" }}              
> EOF
[root@web1 ~]# tee /etc/sensu/conf.d/transport.json << EOF
> {"transport": { "name": "redis" }}
> EOF

我们配置Uchiwa监听端口3000上的每个接口(0.0.0.0)。我们还配置Uchiwa使用sensu-api(已配置)

[root@web1 ~]# tee /etc/sensu/uchiwa.json << EOF
> {"sensu": [ { "name": "sensu", "host": "127.0.0.1", "port": 4567 } ], "uchiwa": { "host": "0.0.0.0", "port": 3000 }}
> EOF

安全设置,配置文件夹的所有者

[root@web1 ~]#  chown -R sensu:sensu /etc/sensu

启动并设置开机自启动Sensu服务

[root@web1 ~]# systemctl enable sensu-server sensu-api sensu-client
Created symlink from /etc/systemd/system/multi-user.target.wants/sensu-server.service to /usr/lib/systemd/system/sensu-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/sensu-api.service to /usr/lib/systemd/system/sensu-api.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/sensu-client.service to /usr/lib/systemd/system/sensu-client.service.
[root@web1 ~]# systemctl start sensu-server sensu-api sensu-client
[root@web1 ~]# systemctl enable uchiwa
uchiwa.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig uchiwa on
[root@web1 ~]# /sbin/chkconfig uchiwa on
[root@web1 ~]# systemctl start uchiwa
[root@web1 ~]# chkconfig --list|grep uchiwa

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

uchiwa          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@web1 ~]#

浏览器访问Uchiwa(后期可以自主设置nginx反向代理)
http://192.168.0.230:3000
浓缩版:云计算运维KVM监控工具之Sensu开源版

二、客户端

1.设置Sensu的仓库源

[root@client-1 ~]#  tee /etc/yum.repos.d/sensu.repo << EOF
> [sensu]
> name=sensu
> baseurl=https://sensu.global.ssl.fastly.net/yum/$releasever/$basearch/
> gpgcheck=0
> enabled=1
> EOF

2.安装Sensu,配置client

[root@client-1 ~]#  yum install sensu -y

要配置sensu-client,请创建在服务器计算机中创建的相同redis.json和transport.json,以及client.json配置文件:(在名称字段中,指定用于标识此客户端的名称(通常是主机名)。 环境字段可以帮助过滤,订阅定义客户端将执行哪些监视检查。)

[root@client-1 ~]# vim /etc/sensu/conf.d/client.json 
> {"client": { "name": "leo-client", "environment": "development", "subscriptions": [ "frontend" ] }}    
> EOF

最后,启用并启动服务并检查Uchiwa,因为新客户端将自动注册:

[root@client-1 ~]#  systemctl enable sensu-client
Created symlink from /etc/systemd/system/multi-user.target.wants/sensu-client.service to /usr/lib/systemd/system/sensu-client.service.
[root@client-1 ~]# systemctl start sensu-client
[root@client-1 ~]# systemctl status  sensu-client
● sensu-client.service - sensu client
   Loaded: loaded (/usr/lib/systemd/system/sensu-client.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-03-14 01:39:24 CST; 6s ago
Main PID: 1852 (sensu-client)
   CGroup: /system.slice/sensu-client.service
           └─1852 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-client -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extension...

Mar 14 01:39:24 client-1 systemd[1]: Started sensu client.
Mar 14 01:39:24 client-1 systemd[1]: Starting sensu client...
[root@client-1 ~]#

3.Sensu检查
Sensu检查有两个组件:插件和定义。
Sensu与Nagios检查插件规范兼容,因此可以无需修改即可使用对Nagios的任何检查。 检查是可执行文件,由Sensu客户端运行。
检查定义让Sensu知道运行插件的方式,位置和时间。

4.我们在客户端计算机上安装一个check插件。 请记住,此插件将在客户端上执行
启用EPEL并安装nagios-plugins-http:

[root@client-1 ~]# yum install -y epel-release && yum install -y nagios-plugins-http

5.尝试检查客户端运行的web服务器的状态,结果是失败的,因为并没有运行web服务。

[root@client-1 ~]# /usr/lib64/nagios/plugins/check_http -I 127.0.0.1
connect to address 127.0.0.1 and port 80: Connection refused
HTTP CRITICAL - Unable to open TCP socket
[root@client-1 ~]# echo $?
2
[root@client-1 ~]#

Nagios检查插件规范定义了插件执行的四个返回码:
浓缩版:云计算运维KVM监控工具之Sensu开源版

三、服务端

1.在服务器计算机上,创建文件/etc/sensu/conf.d/check_http.json:

[root@web1 ~]# vim /etc/sensu/conf.d/check_http.json
{"checks":
        { "check_http":
                { "command": "/usr/lib64/nagios/plugins/check_http -I 127.0.0.1", "interval": 10, "subscribers": [ "frontend" ] }
        }
}

在命令字段中,使用我们之前测试的命令。 Interval会告诉Sensu这个检查应该在几秒钟内执行的频率。 最后,订户将定义将执行检查的客户端。

2.重新启动sensu-api和sensu-server并确认Uchiwa中有新检查

[root@web1 ~]# systemctl restart sensu-api sensu-server  uchiwa

3.访问网页刷新
浓缩版:云计算运维KVM监控工具之Sensu开源版

四.界面说明

1.首页界面
浓缩版:云计算运维KVM监控工具之Sensu开源版

2.客户端管理界面
浓缩版:云计算运维KVM监控工具之Sensu开源版

3.主机状态检查

浓缩版:云计算运维KVM监控工具之Sensu开源版

4.主机数据中心
浓缩版:云计算运维KVM监控工具之Sensu开源版

更多的博客转移到个人博客上了,请点击以下链接:
个人博客

转载于:https://blog.51cto.com/leoheng/2363065

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值