mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
翻译完成
This commit is contained in:
parent
d699b42ab2
commit
408048b977
@ -1,292 +0,0 @@
|
|||||||
translating by MjSeven
|
|
||||||
|
|
||||||
Getting started with Sensu monitoring
|
|
||||||
======
|
|
||||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003601_05_mech_osyearbook2016_cloud_cc.png?itok=XSV7yR9e)
|
|
||||||
|
|
||||||
Sensu is an open source infrastructure and application monitoring solution that monitors servers, services, and application health, and sends alerts and notifications with third-party integration. Written in Ruby, Sensu can use either [RabbitMQ][1] or [Redis][2] to handle messages. It uses Redis to store data.
|
|
||||||
|
|
||||||
If you want to monitor your cloud infrastructure in a simple and efficient manner, Sensu is a good option. It can be integrated with many of the modern DevOps stacks your organization may already be using, such as [Slack][3], [HipChat][4], or [IRC][5], and it can even send mobile/pager alerts with [PagerDuty][6].
|
|
||||||
|
|
||||||
Sensu's [modular architecture][7] means every component can be installed on the same server or on completely separate machines.
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
Sensu's main communication mechanism is the Transport. Every Sensu component must connect to the Transport in order to send messages to each other. Transport can use either RabbitMQ (recommended in production) or Redis.
|
|
||||||
|
|
||||||
Sensu Server processes event data and takes action. It registers clients and processes check results and monitoring events using filters, mutators, and handlers. The server publishes check definitions to the clients and the Sensu API provides a RESTful API, providing access to monitoring data and core functionality.
|
|
||||||
|
|
||||||
[Sensu Client][8] executes checks either scheduled by Sensu Server or local checks definitions. Sensu uses a data store (Redis) to keep all the persistent data. Finally, [Uchiwa][9] is the web interface to communicate with Sensu API.
|
|
||||||
|
|
||||||
![sensu_system.png][11]
|
|
||||||
|
|
||||||
### Installing Sensu
|
|
||||||
|
|
||||||
#### Prerequisites
|
|
||||||
|
|
||||||
* One Linux installation to act as the server node (I used CentOS 7 for this article)
|
|
||||||
|
|
||||||
* One or more Linux machines to monitor (clients)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### Server side
|
|
||||||
|
|
||||||
Sensu requires Redis to be installed. To install Redis, enable the EPEL repository:
|
|
||||||
```
|
|
||||||
$ sudo yum install epel-release -y
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Then install Redis:
|
|
||||||
```
|
|
||||||
$ sudo yum install redis -y
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Modify `/etc/redis.conf` to disable protected mode, listen on every interface, and set a password:
|
|
||||||
```
|
|
||||||
$ sudo sed -i 's/^protected-mode yes/protected-mode no/g' /etc/redis.conf
|
|
||||||
|
|
||||||
$ sudo sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf
|
|
||||||
|
|
||||||
$ sudo sed -i 's/^# requirepass foobared/requirepass password123/g' /etc/redis.conf
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Enable and start Redis service:
|
|
||||||
```
|
|
||||||
$ sudo systemctl enable redis
|
|
||||||
$ sudo systemctl start redis
|
|
||||||
```
|
|
||||||
|
|
||||||
Redis is now installed and ready to be used by Sensu.
|
|
||||||
|
|
||||||
Now let’s install Sensu.
|
|
||||||
|
|
||||||
First, configure the Sensu repository and install the packages:
|
|
||||||
```
|
|
||||||
$ sudo 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
|
|
||||||
|
|
||||||
$ sudo yum install sensu uchiwa -y
|
|
||||||
```
|
|
||||||
|
|
||||||
Let’s create the bare minimum configuration files for Sensu:
|
|
||||||
```
|
|
||||||
$ sudo tee /etc/sensu/conf.d/api.json << EOF
|
|
||||||
{
|
|
||||||
"api": {
|
|
||||||
"host": "127.0.0.1",
|
|
||||||
"port": 4567
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
```
|
|
||||||
|
|
||||||
Next, configure `sensu-api` to listen on localhost, with Port 4567:
|
|
||||||
```
|
|
||||||
$ sudo tee /etc/sensu/conf.d/redis.json << EOF
|
|
||||||
{
|
|
||||||
"redis": {
|
|
||||||
"host": "<IP of server>",
|
|
||||||
"port": 6379,
|
|
||||||
"password": "password123"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
|
|
||||||
$ sudo tee /etc/sensu/conf.d/transport.json << EOF
|
|
||||||
{
|
|
||||||
"transport": {
|
|
||||||
"name": "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
```
|
|
||||||
|
|
||||||
In these two files, we configure Sensu to use Redis as the transport mechanism and the address where Redis will listen. Clients need to connect directly to the transport mechanism. These two files will be required on each client machine.
|
|
||||||
```
|
|
||||||
$ sudo 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
|
|
||||||
```
|
|
||||||
|
|
||||||
In this file, we configure Uchiwa to listen on every interface (0.0.0.0) on Port 3000. We also configure Uchiwa to use `sensu-api` (already configured).
|
|
||||||
|
|
||||||
For security reasons, change the owner of the configuration files you just created:
|
|
||||||
```
|
|
||||||
$ sudo chown -R sensu:sensu /etc/sensu
|
|
||||||
```
|
|
||||||
|
|
||||||
Enable and start the Sensu services:
|
|
||||||
```
|
|
||||||
$ sudo systemctl enable sensu-server sensu-api sensu-client
|
|
||||||
$ sudo systemctl start sensu-server sensu-api sensu-client
|
|
||||||
$ sudo systemctl enable uchiwa
|
|
||||||
$ sudo systemctl start uchiwa
|
|
||||||
```
|
|
||||||
|
|
||||||
Try accessing the Uchiwa website: http://<IP of server>:3000
|
|
||||||
|
|
||||||
For production environments, it’s recommended to run a cluster of RabbitMQ as the Transport instead of Redis (a Redis cluster can be used in production too), and to run more than one instance of Sensu Server and API for load balancing and high availability.
|
|
||||||
|
|
||||||
Sensu is now installed. Now let’s configure the clients.
|
|
||||||
|
|
||||||
#### Client side
|
|
||||||
|
|
||||||
To add a new client, you will need to enable Sensu repository on the client machines by creating the file `/etc/yum.repos.d/sensu.repo`.
|
|
||||||
```
|
|
||||||
$ sudo 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
|
|
||||||
```
|
|
||||||
|
|
||||||
With the repository enabled, install the package Sensu:
|
|
||||||
```
|
|
||||||
$ sudo yum install sensu -y
|
|
||||||
```
|
|
||||||
|
|
||||||
To configure `sensu-client`, create the same `redis.json` and `transport.json` created in the server machine, as well as the `client.json` configuration file:
|
|
||||||
```
|
|
||||||
$ sudo tee /etc/sensu/conf.d/client.json << EOF
|
|
||||||
{
|
|
||||||
"client": {
|
|
||||||
"name": "rhel-client",
|
|
||||||
"environment": "development",
|
|
||||||
"subscriptions": [
|
|
||||||
"frontend"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
```
|
|
||||||
|
|
||||||
In the name field, specify a name to identify this client (typically the hostname). The environment field can help you filter, and subscription defines which monitoring checks will be executed by the client.
|
|
||||||
|
|
||||||
Finally, enable and start the services and check in Uchiwa, as the new client will register automatically:
|
|
||||||
```
|
|
||||||
$ sudo systemctl enable sensu-client
|
|
||||||
$ sudo systemctl start sensu-client
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sensu checks
|
|
||||||
|
|
||||||
Sensu checks have two components: a plugin and a definition.
|
|
||||||
|
|
||||||
Sensu is compatible with the [Nagios check plugin specification][12], so any check for Nagios can be used without modification. Checks are executable files and are run by the Sensu client.
|
|
||||||
|
|
||||||
Check definitions let Sensu know how, where, and when to run the plugin.
|
|
||||||
|
|
||||||
#### Client side
|
|
||||||
|
|
||||||
Let’s install one check plugin on the client machine. Remember, this plugin will be executed on the clients.
|
|
||||||
|
|
||||||
Enable EPEL and install `nagios-plugins-http` :
|
|
||||||
```
|
|
||||||
$ sudo yum install -y epel-release
|
|
||||||
$ sudo yum install -y nagios-plugins-http
|
|
||||||
```
|
|
||||||
|
|
||||||
Now let’s explore the plugin by executing it manually. Try checking the status of a web server running on the client machine. It should fail as we don’t have a web server running:
|
|
||||||
```
|
|
||||||
$ /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
|
|
||||||
```
|
|
||||||
|
|
||||||
It failed, as expected. Check the return code of the execution:
|
|
||||||
```
|
|
||||||
$ echo $?
|
|
||||||
2
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
The Nagios check plugin specification defines four return codes for the plugin execution:
|
|
||||||
|
|
||||||
| **Plugin return code** | **State** |
|
|
||||||
|------------------------|-----------|
|
|
||||||
| 0 | OK |
|
|
||||||
| 1 | WARNING |
|
|
||||||
| 2 | CRITICAL |
|
|
||||||
| 3 | UNKNOWN |
|
|
||||||
|
|
||||||
With this information, we can now create the check definition on the server.
|
|
||||||
|
|
||||||
#### Server side
|
|
||||||
|
|
||||||
On the server machine, create the file `/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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In the command field, use the command we tested before. `Interval` will tell Sensu how frequently, in seconds, this check should be executed. Finally, `subscribers` will define the clients where the check will be executed.
|
|
||||||
|
|
||||||
Restart both sensu-api and sensu-server and confirm that the new check is available in Uchiwa.
|
|
||||||
```
|
|
||||||
$ sudo systemctl restart sensu-api sensu-server
|
|
||||||
```
|
|
||||||
|
|
||||||
### What’s next?
|
|
||||||
|
|
||||||
Sensu is a powerful tool, and this article covers just a glimpse of what it can do. See the [documentation][13] to learn more, and visit the Sensu site to learn more about the [Sensu community][14].
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://opensource.com/article/18/8/getting-started-sensu-monitoring-solution
|
|
||||||
|
|
||||||
作者:[Michael Zamot][a]
|
|
||||||
选题:[lujun9972](https://github.com/lujun9972)
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]:https://opensource.com/users/mzamot
|
|
||||||
[1]:https://www.rabbitmq.com/
|
|
||||||
[2]:https://redis.io/topics/config
|
|
||||||
[3]:https://slack.com/
|
|
||||||
[4]:https://en.wikipedia.org/wiki/HipChat
|
|
||||||
[5]:http://www.irc.org/
|
|
||||||
[6]:https://www.pagerduty.com/
|
|
||||||
[7]:https://docs.sensu.io/sensu-core/1.4/overview/architecture/
|
|
||||||
[8]:https://docs.sensu.io/sensu-core/1.4/installation/install-sensu-client/
|
|
||||||
[9]:https://uchiwa.io/#/
|
|
||||||
[10]:/file/406576
|
|
||||||
[11]:https://opensource.com/sites/default/files/uploads/sensu_system.png (sensu_system.png)
|
|
||||||
[12]:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/pluginapi.html
|
|
||||||
[13]:https://docs.sensu.io/
|
|
||||||
[14]:https://sensu.io/community
|
|
@ -0,0 +1,287 @@
|
|||||||
|
Sensu 监控入门
|
||||||
|
======
|
||||||
|
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003601_05_mech_osyearbook2016_cloud_cc.png?itok=XSV7yR9e)
|
||||||
|
|
||||||
|
Sensu 是一个开源基础设施和应用程序监控解决方案,它监控服务器、相关服务和应用程序健康状况,并通过第三方集成发送警报和通知。Sensu 用 Ruby 编写,可以使用 [RabbitMQ][1] 或 [Redis][2] 来处理消息,它使用 Redis 来存储数据。
|
||||||
|
|
||||||
|
如果你想以一种简单而有效的方式监控云基础设施,Sensu 是一个不错的选择。它可以与你组织已经使用的许多现代 DevOps 堆栈集成,比如 [Slack][3]、[HipChat][4 ] 或 [IRC][5],它甚至可以用 [PagerDuty][6] 发送移动或寻呼机警报。
|
||||||
|
|
||||||
|
Sensu 的[模块化架构][7]意味着每个组件都可以安装在同一台服务器上或者在完全独立的机器上。
|
||||||
|
|
||||||
|
### 结构
|
||||||
|
|
||||||
|
Sensu 的主要通信机制是 `Transport`。每个 Sensu 组件必须连接到 `Transport` 才能相互发送消息。`Transport` 可以使用 RabbitMQ(在生产中推荐使用)或 Redis。
|
||||||
|
|
||||||
|
Sensu 服务器处理事件数据并采取行动。它注册客户端并使用过滤器、增变器和处理程序检查结果和监视事件。服务器向客户端发布检查说明,Sensu API 提供 RESTful API,提供对监控数据和核心功能的访问。
|
||||||
|
|
||||||
|
[Sensu 客户端][8]执行 Sensu 服务器安排的检查或本地检查定义。Sensu 使用数据存储(Redis)来保存所有的持久数据。最后,[Uchiwa][9] 是与 Sensu API 进行通信的 Web 界面。
|
||||||
|
|
||||||
|
![sensu_system.png][11]
|
||||||
|
|
||||||
|
### 安装 Sensu
|
||||||
|
|
||||||
|
#### 条件
|
||||||
|
|
||||||
|
* 一个 Linux 系统作为服务器节点(本文使用了 CentOS 7)
|
||||||
|
* 要监控的一台或多台 Linux 机器(客户机)
|
||||||
|
|
||||||
|
#### 服务器侧
|
||||||
|
|
||||||
|
Sensu 需要安装 Redis。要安装 Redis,启用 EPEL 仓库:
|
||||||
|
```
|
||||||
|
$ sudo yum install epel-release -y
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
然后安装 Redis:
|
||||||
|
```
|
||||||
|
$ sudo yum install redis -y
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
修改 `/etc/redis.conf` 来禁用保护模式,监听每个地址并设置密码:
|
||||||
|
```
|
||||||
|
$ sudo sed -i 's/^protected-mode yes/protected-mode no/g' /etc/redis.conf
|
||||||
|
|
||||||
|
$ sudo sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf
|
||||||
|
|
||||||
|
$ sudo sed -i 's/^# requirepass foobared/requirepass password123/g' /etc/redis.conf
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
启用并启动 Redis 服务:
|
||||||
|
```
|
||||||
|
$ sudo systemctl enable redis
|
||||||
|
$ sudo systemctl start redis
|
||||||
|
```
|
||||||
|
|
||||||
|
Redis 现在已经安装并准备好被 Sensu 使用。
|
||||||
|
|
||||||
|
现在让我们来安装 Sensu。
|
||||||
|
|
||||||
|
首先,配置 Sensu 仓库并安装软件包:
|
||||||
|
```
|
||||||
|
$ sudo 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
|
||||||
|
|
||||||
|
$ sudo yum install sensu uchiwa -y
|
||||||
|
```
|
||||||
|
|
||||||
|
让我们为 Sensu 创建最简单的配置文件:
|
||||||
|
```
|
||||||
|
$ sudo tee /etc/sensu/conf.d/api.json << EOF
|
||||||
|
{
|
||||||
|
"api": {
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 4567
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
然后,配置 `sensu-api` 在本地主机上使用端口 4567 监听:
|
||||||
|
```
|
||||||
|
$ sudo tee /etc/sensu/conf.d/redis.json << EOF
|
||||||
|
{
|
||||||
|
"redis": {
|
||||||
|
"host": "<IP of server>",
|
||||||
|
"port": 6379,
|
||||||
|
"password": "password123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
$ sudo tee /etc/sensu/conf.d/transport.json << EOF
|
||||||
|
{
|
||||||
|
"transport": {
|
||||||
|
"name": "redis"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
在这两个文件中,我们将 Sensu 配置为使用 Redis 作为传输机制,还有 Reids 监听的地址。客户端需要直接连接到传输机制。每台客户机都需要这两个文件。
|
||||||
|
```
|
||||||
|
$ sudo 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
|
||||||
|
```
|
||||||
|
|
||||||
|
在这个文件中,我们配置 `Uchiwa` 监听端口 3000 上的每个地址(0.0.0.0)。我们还配置 `Uchiwa` 使用 `sensu-api`(已配置好)。
|
||||||
|
|
||||||
|
出于安全原因,更改刚刚创建的配置文件的所有者:
|
||||||
|
```
|
||||||
|
$ sudo chown -R sensu:sensu /etc/sensu
|
||||||
|
```
|
||||||
|
|
||||||
|
启用并启动 Sensu 服务:
|
||||||
|
```
|
||||||
|
$ sudo systemctl enable sensu-server sensu-api sensu-client
|
||||||
|
$ sudo systemctl start sensu-server sensu-api sensu-client
|
||||||
|
$ sudo systemctl enable uchiwa
|
||||||
|
$ sudo systemctl start uchiwa
|
||||||
|
```
|
||||||
|
|
||||||
|
尝试访问 `Uchiwa` 网站:http://<服务器的 IP 地址>:3000
|
||||||
|
|
||||||
|
对于生产环境,建议运行 RabbitMQ 集群作为 Transport 而不是 Redis(虽然 Redis 集群也可以用于生产),运行多个 Sensu 服务器实例和 API 实例,以实现负载均衡和高可用性。
|
||||||
|
|
||||||
|
Sensu 现在安装完成,让我们来配置客户端。
|
||||||
|
|
||||||
|
#### 客户端侧
|
||||||
|
|
||||||
|
要添加一个新客户端,你需要通过创建 `/etc/yum.repos.d/sensu.repo` 文件在客户机上启用 Sensu 仓库。
|
||||||
|
```
|
||||||
|
$ sudo 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:
|
||||||
|
```
|
||||||
|
$ sudo yum install sensu -y
|
||||||
|
```
|
||||||
|
|
||||||
|
要配置 `sensu-client`,创建在服务器中相同的 `redis.json` 和 `transport.json`,还有 `client.json` 配置文件:
|
||||||
|
```
|
||||||
|
$ sudo tee /etc/sensu/conf.d/client.json << EOF
|
||||||
|
{
|
||||||
|
"client": {
|
||||||
|
"name": "rhel-client",
|
||||||
|
"environment": "development",
|
||||||
|
"subscriptions": [
|
||||||
|
"frontend"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
在 `name` 字段中,指定一个名称来标识此客户机(通常是主机名)。`environment` 字段可以帮助你过滤,订阅定义客户机将执行哪些监视检查。
|
||||||
|
|
||||||
|
最后,启用并启动服务并检查 `Uchiwa`,因为客户机会自动注册:
|
||||||
|
```
|
||||||
|
$ sudo systemctl enable sensu-client
|
||||||
|
$ sudo systemctl start sensu-client
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sensu 检查
|
||||||
|
|
||||||
|
Sensu 检查有两个组件:一个插件和一个定义。
|
||||||
|
|
||||||
|
Sensu 与 [Nagios 检查插件规范][12]兼容,因此无需修改即可使用针对 Nagios 的任何检查。检查是可执行文件,由 Sensu 客户机运行。
|
||||||
|
|
||||||
|
检查定义让 Sensu 知道如何、在哪以及何时运行插件。
|
||||||
|
|
||||||
|
#### 客户端侧
|
||||||
|
|
||||||
|
让我们在客户机上安装一个检查插件。请记住,此插件将在客户机上执行。
|
||||||
|
|
||||||
|
启用 EPEL 并安装 `nagios-plugins-http` :
|
||||||
|
```
|
||||||
|
$ sudo yum install -y epel-release
|
||||||
|
$ sudo yum install -y nagios-plugins-http
|
||||||
|
```
|
||||||
|
|
||||||
|
现在让我们通过手动执行它来研究这个插件。尝试检查客户机上运行的 Web 服务器的状态。它应该会失败,因为我们并没有运行 Web 服务器:
|
||||||
|
```
|
||||||
|
$ /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
|
||||||
|
```
|
||||||
|
|
||||||
|
不出所料,它失败了。检查执行的返回值:
|
||||||
|
```
|
||||||
|
$ echo $?
|
||||||
|
2
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Nagios 检查插件规范定义了插件执行的四个返回值:
|
||||||
|
|
||||||
|
| **Plugin return code** | **State** |
|
||||||
|
|------------------------|-----------|
|
||||||
|
| 0 | OK |
|
||||||
|
| 1 | WARNING |
|
||||||
|
| 2 | CRITICAL |
|
||||||
|
| 3 | UNKNOWN |
|
||||||
|
|
||||||
|
有了这些信息,我们现在可以在服务器上创建检查定义。
|
||||||
|
|
||||||
|
#### 服务器侧
|
||||||
|
|
||||||
|
在服务器机器上,创建 `/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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
在 `command ` 字段中,使用我们之前测试过的命令。`Interval` 会告诉 Sensu 这个检查的频率,以秒为单位。最后,`subscribers` 将定义执行检查的客户机。
|
||||||
|
|
||||||
|
重新启动 sensu-api 和 sensu-server 并确认新检查在 Uchiwa 中可用。
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo systemctl restart sensu-api sensu-server
|
||||||
|
```
|
||||||
|
|
||||||
|
### 接下来
|
||||||
|
|
||||||
|
Sensu 是一个功能强大的工具,本文只简要介绍它可以干什么。参阅[文档][13]了解更多信息,访问 Sensu 网站了解有关 [Sensu 社区][14]的更多信息。
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/18/8/getting-started-sensu-monitoring-solution
|
||||||
|
|
||||||
|
作者:[Michael Zamot][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:https://opensource.com/users/mzamot
|
||||||
|
[1]:https://www.rabbitmq.com/
|
||||||
|
[2]:https://redis.io/topics/config
|
||||||
|
[3]:https://slack.com/
|
||||||
|
[4]:https://en.wikipedia.org/wiki/HipChat
|
||||||
|
[5]:http://www.irc.org/
|
||||||
|
[6]:https://www.pagerduty.com/
|
||||||
|
[7]:https://docs.sensu.io/sensu-core/1.4/overview/architecture/
|
||||||
|
[8]:https://docs.sensu.io/sensu-core/1.4/installation/install-sensu-client/
|
||||||
|
[9]:https://uchiwa.io/#/
|
||||||
|
[10]:/file/406576
|
||||||
|
[11]:https://opensource.com/sites/default/files/uploads/sensu_system.png (sensu_system.png)
|
||||||
|
[12]:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/pluginapi.html
|
||||||
|
[13]:https://docs.sensu.io/
|
||||||
|
[14]:https://sensu.io/community
|
Loading…
Reference in New Issue
Block a user