Docker Website (18) Nezha Monitor

1. What is a probe

The cloud probe can monitor the running status of the server. Its main purpose is to monitor the status of the server and give an alarm in time when the service is not running normally, so that maintenance can be carried out as soon as possible.

2. Installation

Tip:
If you want to use CDN, please prepare two domain names, one is configured with CDN for public access, and the CDN needs to support the WebSocket protocol; the other domain name does not use CDN, it is used for communication between Agent and Dashboard
This document uses two domain names "cdn.example.com" and "data.example.com" to demonstrate

2.1. Prepare OAuth application

Nezha monitoring requires access to Github, Gitlab, Jihulab or Gitee as the background administrator account.

Create a new verification application (take Github as an example):

After logging into Github, open

https://github.com/settings/developers

Select "OAuth Apps" - "New OAuth App"
The configuration items are as follows:

  • Application name - fill in freely
  • Homepage URL - fill in the Access Domain Name of the panel, such as: "http://cdn.example.com"
  • Authorization callback URL - fill in the callback address, such as: "http://cdn.example.com/oauth2/callback"

After filling, click "Register application"
Save the Client ID on the page, and then click "Generate a new client secret" to create a new Client Secret. The newly created secret will only be displayed once, please keep it safe

If it is JihuLab, the application creation entry is:

https://jihulab.com/-/profile/applications

The callback address should be filled in Redirect URL,
Check read_user and read_api in the scope below
After the creation is complete, save the application ID and password.

2.2, Install the panel side

Note:
The panel side only needs to be installed on one server for monitoring. It is recommended to configure a higher configuration (1 core 2G is enough), otherwise the machine may not be able to bear it.

If you are abroad, execute:

Bash
1
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

If your panel server is located in mainland China, you can use the mirror image:

Bash
1
curl -L https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo CN=true ./nezha.sh

Qingbei Science and Technology CDN also supports acceleration of front-end and GitHub resources. For documentation reference:

Qingbei Technology CDN
https://cdn.tsinbei.com

If there is no Docker environment, it will be installed; after waiting for Docker to be installed, enter the following values respectively:

  • `OAuth Provider| - Github, Gitlab, Jihulab, Gitee choose one
  • Client ID: the previously saved Client ID
  • Client Secret: previously saved secret key
  • username : the username from the OAuth provider
  • Site Title: Customize the site title
  • Access port: public access port, customizable, default 8008
  • Agent communication port: the communication port between Agent and Dashboard, default 5555

After the input is complete, wait for the image to be pulled;
After the installation is complete, if everything is normal, you can visit the domain name + port number, such as "http://cdn.example.com:8008" to view the panel.

If HTTPS or standard ports are required on the panel side, reverse proxy can be used, so I won’t repeat them here.

2.3, install Agent

Reference documents:

One-click installation of Agent
https://nezha.wiki/guide/agent.html

Note: If your system is a weird non-mainstream Linux distribution, such as TencentOS or its new name OpenCloudOS, when you download the Agent side during one-click installation, it will report an error and exit. At this time, you only need to write the Systemd file yourself:

/usr/lib/systemd/system/nezha-agent.service
Text
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]

Description=Nezha Agent Service

[Service]

ExecStart=/opt/nezha/agent/nezha-agent -s <panel IP>:<panel port> -p <Agent key>

Restart=always

[Install]

WantedBy=multi-user.target

Save after replacing the information.

instruction:

Bash
1
2
systemctl start nezha-agent #start
systemctl stop nezha-agent #stop

It may take a few minutes to see the Agent go online on the panel after startup.

Services started in this way cannot be started automatically by systemctl enable, but can:

Bash
1
echo 'systemctl start nezha-agent' >> /etc/rc.d/rc.local

Put the startup command in the list of autostart scripts.

Docker Website (18) Nezha Monitor

https://blog.tsinbei.com/en/archives/719/

Author
Hsukqi Lee
Posted on

2023-05-21

Edited on

2023-05-21

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet