Use agent's builtin support for services instead (#357)
This commit is contained in:
parent
f5ca66d924
commit
eaba7abd35
@ -4,7 +4,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
||||||
<br><br>
|
<br><br>
|
||||||
<img alt="GitHub release (with filter)" src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&style=for-the-badge&logo=github&label=Dashboard"> <img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.16.2-brightgreen?style=for-the-badge&logo=linux">
|
<img alt="GitHub release (with filter)" src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&style=for-the-badge&logo=github&label=Dashboard"> <img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.16.3-brightgreen?style=for-the-badge&logo=linux">
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<p>:trollface: <b>Nezha Monitoring: Self-hostable, lightweight, servers and websites monitoring and O&M tool.</b></p>
|
<p>:trollface: <b>Nezha Monitoring: Self-hostable, lightweight, servers and websites monitoring and O&M tool.</b></p>
|
||||||
|
@ -69,6 +69,11 @@
|
|||||||
data-tooltip="{{tr "ClickToCopy"}}">
|
data-tooltip="{{tr "ClickToCopy"}}">
|
||||||
<i class="windows icon"></i>
|
<i class="windows icon"></i>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="ui icon green mini button"
|
||||||
|
data-clipboard-text="{{if $.Conf.GRPCHost}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.command -o nezha.command && chmod +x nezha.command && sudo ./nezha.command install_agent {{$.Conf.GRPCHost}} {{if $.Conf.ProxyGRPCPort}}{{$.Conf.ProxyGRPCPort}}{{else}}{{$.Conf.GRPCPort}}{{end}} {{$server.Secret}}{{if $.Conf.TLS}} --tls{{end}}{{else}}{{tr "NoDomainAlert"}}{{end}}"
|
||||||
|
data-tooltip="{{tr "ClickToCopy"}}">
|
||||||
|
<i class="apple icon"></i>
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td style="word-break: break-word;white-space: pre-wrap;">{{$server.Note}}</td>
|
<td style="word-break: break-word;white-space: pre-wrap;">{{$server.Note}}</td>
|
||||||
<td>
|
<td>
|
||||||
|
291
script/install.command
Normal file
291
script/install.command
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#========================================================
|
||||||
|
# System Required: macOS 10.13+
|
||||||
|
# Description: Nezha Agent Install Script (macOS)
|
||||||
|
# Github: https://github.com/naiba/nezha
|
||||||
|
#========================================================
|
||||||
|
|
||||||
|
NZ_BASE_PATH="/opt/nezha"
|
||||||
|
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||||
|
|
||||||
|
red='\033[0;31m'
|
||||||
|
green='\033[0;32m'
|
||||||
|
yellow='\033[0;33m'
|
||||||
|
plain='\033[0m'
|
||||||
|
export PATH=$PATH:/usr/local/bin
|
||||||
|
|
||||||
|
pre_check() {
|
||||||
|
# check root
|
||||||
|
[[ $EUID -ne 0 ]] && echo -e "${red}ERROR: ${plain} This script must be run with the root user!\n" && exit 1
|
||||||
|
|
||||||
|
## os_arch
|
||||||
|
if [[ $(uname -m | grep 'x86_64') != "" ]]; then
|
||||||
|
os_arch="amd64"
|
||||||
|
elif [[ $(uname -m | grep 'arm64\|arm64e') != "" ]]; then
|
||||||
|
os_arch="arm64"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## China_IP
|
||||||
|
if [[ -z "${CN}" ]]; then
|
||||||
|
if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||||
|
echo "According to the information provided by ipapi.co, the current IP may be in China"
|
||||||
|
read -e -r -p "Is the installation done with a Chinese Mirror? [Y/n] (Custom Mirror Input 3):" input
|
||||||
|
case $input in
|
||||||
|
[yY][eE][sS] | [yY])
|
||||||
|
echo "Use Chinese Mirror"
|
||||||
|
CN=true
|
||||||
|
;;
|
||||||
|
|
||||||
|
[nN][oO] | [nN])
|
||||||
|
echo "No Use Chinese Mirror"
|
||||||
|
;;
|
||||||
|
|
||||||
|
[3])
|
||||||
|
echo "Use Custom Mirror"
|
||||||
|
read -e -r -p "Please enter a custom image (e.g. :dn-dao-github-mirror.daocloud.io), leave blank to nouse: " input
|
||||||
|
case $input in
|
||||||
|
*)
|
||||||
|
CUSTOM_MIRROR=$input
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "No Use Chinese Mirror"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${CUSTOM_MIRROR}" ]]; then
|
||||||
|
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||||
|
GITHUB_URL=$CUSTOM_MIRROR
|
||||||
|
else
|
||||||
|
if [[ -z "${CN}" ]]; then
|
||||||
|
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||||
|
GITHUB_URL="github.com"
|
||||||
|
Get_Docker_URL="get.docker.com"
|
||||||
|
Get_Docker_Argu=" "
|
||||||
|
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||||
|
else
|
||||||
|
GITHUB_RAW_URL="gitee.com/naibahq/nezha/raw/master"
|
||||||
|
GITHUB_URL="github.com"
|
||||||
|
Get_Docker_URL="get.docker.com"
|
||||||
|
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||||
|
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
before_show_menu() {
|
||||||
|
echo && echo -n -e "${yellow}* Press Enter to return to the main menu *${plain}" && read temp
|
||||||
|
show_menu
|
||||||
|
}
|
||||||
|
|
||||||
|
install_agent() {
|
||||||
|
echo -e "> Install Nezha Agent"
|
||||||
|
|
||||||
|
echo -e "Obtaining Agent version"
|
||||||
|
|
||||||
|
local version=$(curl -m 10 -sL "https://api.github.com/repos/nezhahq/agent/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||||
|
if [ ! -n "$version" ]; then
|
||||||
|
version=$(curl -m 10 -sL "https://fastly.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
|
||||||
|
fi
|
||||||
|
if [ ! -n "$version" ]; then
|
||||||
|
version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -n "$version" ]; then
|
||||||
|
echo -e "Fail to obtaine agent version, please check if the network can link https://api.github.com/repos/nezhahq/agent/releases/latest"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e "The current latest version is: ${version}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Nezha Agent Folder
|
||||||
|
mkdir -p $NZ_AGENT_PATH
|
||||||
|
chmod -R 777 $NZ_AGENT_PATH
|
||||||
|
|
||||||
|
echo -e "Downloading Agent"
|
||||||
|
curl -o nezha-agent_darwin_${os_arch}.zip -L -f --retry 2 --retry-max-time 60 https://${GITHUB_URL}/nezhahq/agent/releases/download/${version}/nezha-agent_darwin_${os_arch}.zip >/dev/null 2>&1
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo -e "${red}Fail to download agent, please check if the network can link ${GITHUB_URL}${plain}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
unzip -qo nezha-agent_darwin_${os_arch}.zip &&
|
||||||
|
mv nezha-agent $NZ_AGENT_PATH &&
|
||||||
|
rm -rf nezha-agent_darwin_${os_arch}.zip README.md
|
||||||
|
|
||||||
|
if [ $# -ge 3 ]; then
|
||||||
|
modify_agent_config "$@"
|
||||||
|
else
|
||||||
|
modify_agent_config 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
before_show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
modify_agent_config() {
|
||||||
|
echo -e "> Modify Agent Configuration"
|
||||||
|
|
||||||
|
if [ $# -lt 3 ]; then
|
||||||
|
echo "Please add Agent in the admin panel first, record the secret" &&
|
||||||
|
read -ep "Please enter a domain that resolves to the IP where the panel is located (no CDN sets): " nz_grpc_host &&
|
||||||
|
read -ep "Please enter the panel RPC port (default 5555): " nz_grpc_port &&
|
||||||
|
read -ep "Please enter the Agent secret: " nz_client_secret &&
|
||||||
|
read -ep "Do you want to enable SSL/TLS encryption for the gRPC port (--tls)? Press [y] if yes, the default is not required, and users can press Enter to skip if you don't understand: " nz_grpc_proxy
|
||||||
|
grep -qiw 'Y' <<<"${nz_grpc_proxy}" && args='--tls'
|
||||||
|
if [[ -z "${nz_grpc_host}" || -z "${nz_client_secret}" ]]; then
|
||||||
|
echo -e "${red}All options cannot be empty${plain}"
|
||||||
|
before_show_menu
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -z "${nz_grpc_port}" ]]; then
|
||||||
|
nz_grpc_port=5555
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
nz_grpc_host=$1
|
||||||
|
nz_grpc_port=$2
|
||||||
|
nz_client_secret=$3
|
||||||
|
shift 3
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
args=" $*"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
${NZ_AGENT_PATH}/nezha-agent service uninstall >/dev/null 2>&1
|
||||||
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "Agent configuration ${green} modified successfully, please wait for agent self-restart to take effect${plain}"
|
||||||
|
|
||||||
|
#if [[ $# == 0 ]]; then
|
||||||
|
# before_show_menu
|
||||||
|
#fi
|
||||||
|
}
|
||||||
|
|
||||||
|
show_agent_log() {
|
||||||
|
echo -e "> > View Agent Log"
|
||||||
|
|
||||||
|
tail -n 10 /var/log/nezha-agent.err.log
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
before_show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_agent() {
|
||||||
|
echo -e "> Uninstall Agent"
|
||||||
|
|
||||||
|
${NZ_AGENT_PATH}/nezha-agent service uninstall
|
||||||
|
|
||||||
|
rm -rf $NZ_AGENT_PATH
|
||||||
|
clean_all
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
before_show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
restart_agent() {
|
||||||
|
echo -e "> Restart Agent"
|
||||||
|
|
||||||
|
${NZ_AGENT_PATH}/nezha-agent service restart
|
||||||
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
before_show_menu
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_all() {
|
||||||
|
if [ -z "$(ls -A ${NZ_BASE_PATH})" ]; then
|
||||||
|
rm -rf ${NZ_BASE_PATH}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
show_usage() {
|
||||||
|
echo "Nezha Agent Management Script Usage: "
|
||||||
|
echo "--------------------------------------------------------"
|
||||||
|
echo "./nezha.sh install_agent - Install Agent"
|
||||||
|
echo "./nezha.sh modify_agent_config - Modify Agent Configuration"
|
||||||
|
echo "./nezha.sh show_agent_log - View Agent Log"
|
||||||
|
echo "./nezha.sh uninstall_agent - Uninstall Agent"
|
||||||
|
echo "./nezha.sh restart_agent - Restart Agent"
|
||||||
|
echo "./nezha.sh update_script - Update Script"
|
||||||
|
echo "--------------------------------------------------------"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_menu() {
|
||||||
|
echo -e "
|
||||||
|
${green}Nezha Agent Management Script${plain} ${red}macOS${plain}
|
||||||
|
--- https://github.com/naiba/nezha ---
|
||||||
|
${green}1.${plain} Install Agent
|
||||||
|
${green}2.${plain} Modify Agent Configuration
|
||||||
|
${green}3.${plain} View Agent Log
|
||||||
|
${green}4.${plain} Uninstall Agent
|
||||||
|
${green}5.${plain} Restart Agent
|
||||||
|
————————————————-
|
||||||
|
${green}0.${plain} Exit Script
|
||||||
|
"
|
||||||
|
echo && read -ep "Please enter [0-5]: " num
|
||||||
|
case "${num}" in
|
||||||
|
0)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
install_agent
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
modify_agent_config
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
show_agent_log
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
uninstall_agent
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
restart_agent
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${red}Please enter the correct number [0-5]${plain}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
pre_check
|
||||||
|
|
||||||
|
if [[ $# > 0 ]]; then
|
||||||
|
case $1 in
|
||||||
|
"install_agent")
|
||||||
|
shift
|
||||||
|
if [ $# -ge 3 ]; then
|
||||||
|
install_agent "$@"
|
||||||
|
else
|
||||||
|
install_agent 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"modify_agent_config")
|
||||||
|
modify_agent_config 0
|
||||||
|
;;
|
||||||
|
"show_agent_log")
|
||||||
|
show_agent_log 0
|
||||||
|
;;
|
||||||
|
"uninstall_agent")
|
||||||
|
uninstall_agent 0
|
||||||
|
;;
|
||||||
|
"restart_agent")
|
||||||
|
restart_agent 0
|
||||||
|
;;
|
||||||
|
*) show_usage ;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
show_menu
|
||||||
|
fi
|
@ -7,64 +7,69 @@ if($PSVersionTable.PSVersion.Major -lt 5){
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
$agentrepo = "nezhahq/agent"
|
$agentrepo = "nezhahq/agent"
|
||||||
$nssmrepo = "nezhahq/nssm-backup"
|
# x86 or x64 or arm64
|
||||||
# x86 or x64
|
|
||||||
if ([System.Environment]::Is64BitOperatingSystem) {
|
if ([System.Environment]::Is64BitOperatingSystem) {
|
||||||
|
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
|
||||||
|
$file = "nezha-agent_windows_arm64.zip"
|
||||||
|
} else {
|
||||||
$file = "nezha-agent_windows_amd64.zip"
|
$file = "nezha-agent_windows_amd64.zip"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$file = "nezha-agent_windows_386.zip"
|
$file = "nezha-agent_windows_386.zip"
|
||||||
}
|
}
|
||||||
$agentreleases = "https://api.github.com/repos/$agentrepo/releases"
|
$agentreleases = "https://api.github.com/repos/$agentrepo/releases"
|
||||||
$nssmreleases = "https://api.github.com/repos/$nssmrepo/releases"
|
|
||||||
#重复运行自动更新
|
#重复运行自动更新
|
||||||
if (Test-Path "C:\nezha") {
|
if (Test-Path "C:\nezha\nezha-agent.exe") {
|
||||||
Write-Host "Nezha monitoring already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
|
Write-Host "Nezha monitoring already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White
|
||||||
C:/nezha/nssm.exe stop nezha
|
C:\nezha\nezha-agent.exe service uninstall
|
||||||
C:/nezha/nssm.exe remove nezha
|
|
||||||
Remove-Item "C:\nezha" -Recurse
|
Remove-Item "C:\nezha" -Recurse
|
||||||
}
|
}
|
||||||
#TLS/SSL
|
#TLS/SSL
|
||||||
Write-Host "Determining latest nezha release" -BackgroundColor DarkGreen -ForegroundColor White
|
Write-Host "Determining latest nezha release" -BackgroundColor DarkGreen -ForegroundColor White
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
$agenttag = (Invoke-WebRequest -Uri $agentreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
|
$agenttag = (Invoke-WebRequest -Uri $agentreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
|
||||||
$nssmtag = (Invoke-WebRequest -Uri $nssmreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
|
if ([string]::IsNullOrWhiteSpace($agenttag)) {
|
||||||
|
$optionUrl = "https://fastly.jsdelivr.net/gh/nezhahq/agent/"
|
||||||
|
Try {
|
||||||
|
$response = Invoke-WebRequest -Uri $optionUrl -UseBasicParsing -TimeoutSec 10
|
||||||
|
if ($response.StatusCode -eq 200) {
|
||||||
|
$versiontext = $response.Content | findstr /c:"option.value"
|
||||||
|
$version = [regex]::Match($versiontext, "@(\d+\.\d+\.\d+)").Groups[1].Value
|
||||||
|
$agenttag = "v" + $version
|
||||||
|
}
|
||||||
|
} Catch {
|
||||||
|
$optionUrl = "https://gcore.jsdelivr.net/gh/nezhahq/agent/"
|
||||||
|
$response = Invoke-WebRequest -Uri $optionUrl -UseBasicParsing -TimeoutSec 10
|
||||||
|
if ($response.StatusCode -eq 200) {
|
||||||
|
$versiontext = $response.Content | findstr /c:"option.value"
|
||||||
|
$version = [regex]::Match($versiontext, "@(\d+\.\d+\.\d+)").Groups[1].Value
|
||||||
|
$agenttag = "v" + $version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#Region判断
|
#Region判断
|
||||||
$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
|
$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
|
||||||
$region=$ipapi.cc
|
$region=$ipapi.cc
|
||||||
echo $ipapi
|
echo $ipapi
|
||||||
if($region -ne "CN"){
|
if($region -ne "CN"){
|
||||||
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
||||||
$nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
|
|
||||||
Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
|
Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green
|
||||||
}else{
|
}else{
|
||||||
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
||||||
$nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip"
|
|
||||||
Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
|
Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green
|
||||||
}
|
}
|
||||||
echo $download
|
echo $download
|
||||||
echo $nssmdownload
|
|
||||||
Invoke-WebRequest $download -OutFile "C:\nezha.zip"
|
Invoke-WebRequest $download -OutFile "C:\nezha.zip"
|
||||||
#使用nssm安装服务
|
|
||||||
Invoke-WebRequest $nssmdownload -OutFile "C:\nssm.zip"
|
|
||||||
#解压
|
#解压
|
||||||
Expand-Archive "C:\nezha.zip" -DestinationPath "C:\temp" -Force
|
Expand-Archive "C:\nezha.zip" -DestinationPath "C:\temp" -Force
|
||||||
Expand-Archive "C:\nssm.zip" -DestinationPath "C:\temp" -Force
|
|
||||||
if (!(Test-Path "C:\nezha")) { New-Item -Path "C:\nezha" -type directory }
|
if (!(Test-Path "C:\nezha")) { New-Item -Path "C:\nezha" -type directory }
|
||||||
#整理文件
|
#整理文件
|
||||||
Move-Item -Path "C:\temp\nezha-agent.exe" -Destination "C:\nezha\nezha-agent.exe"
|
Move-Item -Path "C:\temp\nezha-agent.exe" -Destination "C:\nezha\nezha-agent.exe"
|
||||||
if ($file = "nezha-agent_windows_amd64.zip") {
|
|
||||||
Move-Item -Path "C:\temp\nssm-2.24\win64\nssm.exe" -Destination "C:\nezha\nssm.exe"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Move-Item -Path "C:\temp\nssm-2.24\win32\nssm.exe" -Destination "C:\nezha\nssm.exe"
|
|
||||||
}
|
|
||||||
#清理垃圾
|
#清理垃圾
|
||||||
Remove-Item "C:\nezha.zip"
|
Remove-Item "C:\nezha.zip"
|
||||||
Remove-Item "C:\nssm.zip"
|
|
||||||
Remove-Item "C:\temp" -Recurse
|
Remove-Item "C:\temp" -Recurse
|
||||||
#安装部分
|
#安装部分
|
||||||
C:\nezha\nssm.exe install nezha C:\nezha\nezha-agent.exe -s $server -p $key $tls -d
|
C:\nezha\nezha-agent.exe service install -s $server -p $key $tls
|
||||||
C:\nezha\nssm.exe start nezha
|
|
||||||
#enjoy
|
#enjoy
|
||||||
Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red
|
Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red
|
@ -10,11 +10,9 @@
|
|||||||
NZ_BASE_PATH="/opt/nezha"
|
NZ_BASE_PATH="/opt/nezha"
|
||||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
|
||||||
NZ_AGENT_SERVICERC="/etc/init.d/nezha-agent"
|
|
||||||
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
||||||
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
||||||
NZ_VERSION="v0.16.2"
|
NZ_VERSION="v0.16.3"
|
||||||
|
|
||||||
red='\033[0;31m'
|
red='\033[0;31m'
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
@ -359,21 +357,6 @@ install_agent() {
|
|||||||
modify_agent_config() {
|
modify_agent_config() {
|
||||||
echo -e "> 修改Agent配置"
|
echo -e "> 修改Agent配置"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
|
||||||
wget -t 2 -T 60 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
wget -t 2 -T 60 -O $NZ_AGENT_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-agent >/dev/null 2>&1
|
|
||||||
chmod +x $NZ_AGENT_SERVICERC
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# -lt 3 ]; then
|
if [ $# -lt 3 ]; then
|
||||||
echo "请先在管理面板上添加Agent,记录下密钥" &&
|
echo "请先在管理面板上添加Agent,记录下密钥" &&
|
||||||
read -ep "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_grpc_host &&
|
read -ep "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_grpc_host &&
|
||||||
@ -399,29 +382,15 @@ modify_agent_config() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
|
|
||||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
|
if [ $? -ne 0 ]; then
|
||||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
|
${NZ_AGENT_PATH}/nezha-agent service uninstall >/dev/null 2>&1
|
||||||
[ -n "${args}" ] && sed -i "/ExecStart/ s/$/ ${args}/" ${NZ_AGENT_SERVICE}
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
else
|
|
||||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
[ -n "${args}" ] && sed -i "/command_args/ s/\"$/ ${args}\"/" ${NZ_AGENT_SERVICERC}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
|
echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable nezha-agent
|
|
||||||
systemctl restart nezha-agent
|
|
||||||
else
|
|
||||||
rc-update add nezha-agent
|
|
||||||
rc-service nezha-agent restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
#if [[ $# == 0 ]]; then
|
#if [[ $# == 0 ]]; then
|
||||||
# before_show_menu
|
# before_show_menu
|
||||||
#fi
|
#fi
|
||||||
@ -709,16 +678,7 @@ show_agent_log() {
|
|||||||
uninstall_agent() {
|
uninstall_agent() {
|
||||||
echo -e "> 卸载Agent"
|
echo -e "> 卸载Agent"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service uninstall
|
||||||
systemctl disable nezha-agent.service
|
|
||||||
systemctl stop nezha-agent.service
|
|
||||||
rm -rf $NZ_AGENT_SERVICE
|
|
||||||
systemctl daemon-reload
|
|
||||||
else
|
|
||||||
rc-update del nezha-agent
|
|
||||||
rc-service nezha-agent stop
|
|
||||||
rm -rf $NZ_AGENT_SERVICERC
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf $NZ_AGENT_PATH
|
rm -rf $NZ_AGENT_PATH
|
||||||
clean_all
|
clean_all
|
||||||
@ -731,11 +691,7 @@ uninstall_agent() {
|
|||||||
restart_agent() {
|
restart_agent() {
|
||||||
echo -e "> 重启Agent"
|
echo -e "> 重启Agent"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service restart
|
||||||
systemctl restart nezha-agent.service
|
|
||||||
else
|
|
||||||
rc-service nezha-agent restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $# == 0 ]]; then
|
if [[ $# == 0 ]]; then
|
||||||
before_show_menu
|
before_show_menu
|
||||||
|
@ -10,11 +10,9 @@
|
|||||||
NZ_BASE_PATH="/opt/nezha"
|
NZ_BASE_PATH="/opt/nezha"
|
||||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
|
||||||
NZ_AGENT_SERVICERC="/etc/init.d/nezha-agent"
|
|
||||||
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
NZ_DASHBOARD_SERVICE="/etc/systemd/system/nezha-dashboard.service"
|
||||||
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
NZ_DASHBOARD_SERVICERC="/etc/init.d/nezha-dashboard"
|
||||||
NZ_VERSION="v0.16.2"
|
NZ_VERSION="v0.16.3"
|
||||||
|
|
||||||
red='\033[0;31m'
|
red='\033[0;31m'
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
@ -355,21 +353,6 @@ install_agent() {
|
|||||||
modify_agent_config() {
|
modify_agent_config() {
|
||||||
echo -e "> Modify Agent Configuration"
|
echo -e "> Modify Agent Configuration"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
|
||||||
wget -t 2 -T 60 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
wget -t 2 -T 60 -O $NZ_AGENT_SERVICERC https://${GITHUB_RAW_URL}/script/nezha-agent >/dev/null 2>&1
|
|
||||||
chmod +x $NZ_AGENT_SERVICERC
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# -lt 3 ]; then
|
if [ $# -lt 3 ]; then
|
||||||
echo "Please add Agent in the admin panel first, record the secret" &&
|
echo "Please add Agent in the admin panel first, record the secret" &&
|
||||||
read -ep "Please enter a domain that resolves to the IP where the panel is located (no CDN sets): " nz_grpc_host &&
|
read -ep "Please enter a domain that resolves to the IP where the panel is located (no CDN sets): " nz_grpc_host &&
|
||||||
@ -395,29 +378,15 @@ modify_agent_config() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
|
|
||||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
|
if [ $? -ne 0 ]; then
|
||||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
|
${NZ_AGENT_PATH}/nezha-agent service uninstall >/dev/null 2>&1
|
||||||
[ -n "${args}" ] && sed -i "/ExecStart/ s/$/ ${args}/" ${NZ_AGENT_SERVICE}
|
${NZ_AGENT_PATH}/nezha-agent service install -s "$nz_grpc_host:$nz_grpc_port" -p $nz_client_secret $args >/dev/null 2>&1
|
||||||
else
|
|
||||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICERC}
|
|
||||||
[ -n "${args}" ] && sed -i "/command_args/ s/\"$/ ${args}\"/" ${NZ_AGENT_SERVICERC}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "Agent configuration ${green} modified successfully, please wait for agent self-restart to take effect${plain}"
|
echo -e "Agent configuration ${green} modified successfully, please wait for agent self-restart to take effect${plain}"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable nezha-agent
|
|
||||||
systemctl restart nezha-agent
|
|
||||||
else
|
|
||||||
rc-update add nezha-agent
|
|
||||||
rc-service nezha-agent restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
#if [[ $# == 0 ]]; then
|
#if [[ $# == 0 ]]; then
|
||||||
# before_show_menu
|
# before_show_menu
|
||||||
#fi
|
#fi
|
||||||
@ -705,16 +674,7 @@ show_agent_log() {
|
|||||||
uninstall_agent() {
|
uninstall_agent() {
|
||||||
echo -e "> Uninstall Agent"
|
echo -e "> Uninstall Agent"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service uninstall
|
||||||
systemctl disable nezha-agent.service
|
|
||||||
systemctl stop nezha-agent.service
|
|
||||||
rm -rf $NZ_AGENT_SERVICE
|
|
||||||
systemctl daemon-reload
|
|
||||||
else
|
|
||||||
rc-update del nezha-agent
|
|
||||||
rc-service nezha-agent stop
|
|
||||||
rm -rf $NZ_AGENT_SERVICERC
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf $NZ_AGENT_PATH
|
rm -rf $NZ_AGENT_PATH
|
||||||
clean_all
|
clean_all
|
||||||
@ -727,11 +687,7 @@ uninstall_agent() {
|
|||||||
restart_agent() {
|
restart_agent() {
|
||||||
echo -e "> Restart Agent"
|
echo -e "> Restart Agent"
|
||||||
|
|
||||||
if [ "$os_alpine" != 1 ]; then
|
${NZ_AGENT_PATH}/nezha-agent service restart
|
||||||
systemctl restart nezha-agent.service
|
|
||||||
else
|
|
||||||
rc-service nezha-agent restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $# == 0 ]]; then
|
if [[ $# == 0 ]]; then
|
||||||
before_show_menu
|
before_show_menu
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
#!/sbin/openrc-run
|
|
||||||
supervisor=supervise-daemon
|
|
||||||
name=nezha-agent
|
|
||||||
output_log=/var/log/${name}.log
|
|
||||||
error_log=/var/log/${name}.err
|
|
||||||
SERVER="nz_grpc_host:nz_grpc_port" #Dashboard 地址 ip:port
|
|
||||||
SECRET="nz_client_secret" #SECRET
|
|
||||||
pidfile="/run/${RC_SVCNAME}.pid"
|
|
||||||
command="/opt/nezha/agent/nezha-agent"
|
|
||||||
command_args="-s ${SERVER} -p ${SECRET}"
|
|
||||||
command_background=true
|
|
||||||
|
|
||||||
depend() {
|
|
||||||
need net
|
|
||||||
}
|
|
||||||
|
|
||||||
start_pre() {
|
|
||||||
checkpath -f -m 0644 -o root:root "/var/log/${name}.log"
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Nezha Agent
|
|
||||||
After=syslog.target
|
|
||||||
#After=network.target
|
|
||||||
#After=nezha-dashboard.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
# Modify these two values and uncomment them if you have
|
|
||||||
# repos with lots of files and get an HTTP error 500 because
|
|
||||||
# of that
|
|
||||||
###
|
|
||||||
#LimitMEMLOCK=infinity
|
|
||||||
#LimitNOFILE=65535
|
|
||||||
Type=simple
|
|
||||||
User=root
|
|
||||||
Group=root
|
|
||||||
WorkingDirectory=/opt/nezha/agent/
|
|
||||||
ExecStart=/opt/nezha/agent/nezha-agent -s nz_grpc_host:nz_grpc_port -p nz_client_secret
|
|
||||||
Restart=always
|
|
||||||
#Environment=DEBUG=true
|
|
||||||
|
|
||||||
# Some distributions may not support these hardening directives. If you cannot start the service due
|
|
||||||
# to an unknown option, comment out the ones not supported by your version of systemd.
|
|
||||||
#ProtectSystem=full
|
|
||||||
#PrivateDevices=yes
|
|
||||||
#PrivateTmp=yes
|
|
||||||
#NoNewPrivileges=true
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
Loading…
Reference in New Issue
Block a user