1.Sensu 是由 Sonian 公司开发的一种监控框架,主要用于拥有大规模节点的云计算平台的检查与监控。目前发行的版本有企业版和开源版两种,收费的企业版本较之免费的开源版本拥有更多的功能。出于介绍的目的,本文的内容都是基于开源版本的 Sensu。ios
开源版本的 Sensu 遵循 MIT 许可,旨在为分布式的平台提供灵活易用、快速简单、便于拓展的监控和维护服务。主要包含如下功能与特性:nginx
2.Sensu支持许多类Unix平台,以及Windows。web
Sensu架构简图:redis
环境:Centos7 最小安装基础版。json
1. Sensu须要安装Redis。要安装Redis,请启用EPEL存储库:vim
[root@web1 ~]# yum install epel-release -y
2.安装redis服务api
[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.
报错解决:重启后服务就正常了ruby
[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
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检查插件规范定义了插件执行的四个返回码:
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.访问网页刷新
1.首页界面
2.客户端管理界面
3.主机状态检查
4.主机数据中心
更多的博客转移到我的博客上了,请点击如下连接:
我的博客