commit
						2f7fd589bf
					
				@ -1,7 +1,7 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#========================================================
 | 
					#========================================================
 | 
				
			||||||
#   System Required: CentOS 7+ / Debian 8+ / Ubuntu 16+ /
 | 
					#   System Required: CentOS 7+ / Debian 8+ / Ubuntu 16+ / Alpine 3+ /
 | 
				
			||||||
#     Arch 未测试
 | 
					#     Arch 未测试
 | 
				
			||||||
#   Description: 哪吒监控安装脚本
 | 
					#   Description: 哪吒监控安装脚本
 | 
				
			||||||
#   Github: https://github.com/naiba/nezha
 | 
					#   Github: https://github.com/naiba/nezha
 | 
				
			||||||
@ -20,13 +20,10 @@ plain='\033[0m'
 | 
				
			|||||||
export PATH=$PATH:/usr/local/bin
 | 
					export PATH=$PATH:/usr/local/bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
os_arch=""
 | 
					os_arch=""
 | 
				
			||||||
 | 
					[ -e /etc/os-release ] && cat /etc/os-release | grep -i "PRETTY_NAME" | grep -qi "alpine" && os_alpine='1'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pre_check() {
 | 
					pre_check() {
 | 
				
			||||||
    command -v systemctl >/dev/null 2>&1
 | 
					    [ "$os_alpine" != 1 ] && ! command -v systemctl >/dev/null 2>&1 && echo "不支持此系统:未找到 systemctl 命令" && exit 1
 | 
				
			||||||
    if [[ $? != 0 ]]; then
 | 
					 | 
				
			||||||
        echo "不支持此系统:未找到 systemctl 命令"
 | 
					 | 
				
			||||||
        exit 1
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # check root
 | 
					    # check root
 | 
				
			||||||
    [[ $EUID -ne 0 ]] && echo -e "${red}错误: ${plain} 必须使用root用户运行此脚本!\n" && exit 1
 | 
					    [[ $EUID -ne 0 ]] && echo -e "${red}错误: ${plain} 必须使用root用户运行此脚本!\n" && exit 1
 | 
				
			||||||
@ -133,7 +130,8 @@ install_soft() {
 | 
				
			|||||||
    (command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
 | 
					    (command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
 | 
				
			||||||
        (command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
 | 
					        (command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
 | 
				
			||||||
        (command -v pacman >/dev/null 2>&1 && pacman -Syu $*) ||
 | 
					        (command -v pacman >/dev/null 2>&1 && pacman -Syu $*) ||
 | 
				
			||||||
        (command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y)
 | 
					        (command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
 | 
				
			||||||
 | 
					        (command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install_dashboard() {
 | 
					install_dashboard() {
 | 
				
			||||||
@ -186,12 +184,14 @@ install_dashboard() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
selinux(){
 | 
					selinux(){
 | 
				
			||||||
    #判断当前的状态
 | 
					    #判断当前的状态
 | 
				
			||||||
    getenforce | grep '[Ee]nfor'
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    if [ $? -eq 0 ];then
 | 
					      getenforce | grep '[Ee]nfor'
 | 
				
			||||||
        echo -e "SELinux是开启状态,正在关闭!" 
 | 
					      if [ $? -eq 0 ];then
 | 
				
			||||||
        setenforce 0 &>/dev/null
 | 
					          echo -e "SELinux是开启状态,正在关闭!" 
 | 
				
			||||||
        find_key="SELINUX="
 | 
					          setenforce 0 &>/dev/null
 | 
				
			||||||
        sed -ri "/^$find_key/c${find_key}disabled" /etc/selinux/config
 | 
					          find_key="SELINUX="
 | 
				
			||||||
 | 
					          sed -ri "/^$find_key/c${find_key}disabled" /etc/selinux/config
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -247,10 +247,12 @@ install_agent() {
 | 
				
			|||||||
modify_agent_config() {
 | 
					modify_agent_config() {
 | 
				
			||||||
    echo -e "> 修改Agent配置"
 | 
					    echo -e "> 修改Agent配置"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    if [[ $? != 0 ]]; then
 | 
					      wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
 | 
				
			||||||
        echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
 | 
					      if [[ $? != 0 ]]; then
 | 
				
			||||||
        return 0
 | 
					          echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [ $# -lt 3 ]; then
 | 
					    if [ $# -lt 3 ]; then
 | 
				
			||||||
@ -272,21 +274,30 @@ modify_agent_config() {
 | 
				
			|||||||
        nz_client_secret=$3
 | 
					        nz_client_secret=$3
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
 | 
					      sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
    sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
 | 
					      sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					      sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    shift 3
 | 
					      shift 3
 | 
				
			||||||
    if [ $# -gt 0 ]; then
 | 
					      if [ $# -gt 0 ]; then
 | 
				
			||||||
        args=" $*"
 | 
					          args=" $*"
 | 
				
			||||||
        sed -i "/ExecStart/ s/$/${args}/" ${NZ_AGENT_SERVICE}
 | 
					          sed -i "/ExecStart/ s/$/${args}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo "@reboot nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} >/dev/null 2>&1 &" >> /etc/crontabs/root
 | 
				
			||||||
 | 
					      crond
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
 | 
					    echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    systemctl daemon-reload
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    systemctl enable nezha-agent
 | 
					      systemctl daemon-reload
 | 
				
			||||||
    systemctl restart nezha-agent
 | 
					      systemctl enable nezha-agent
 | 
				
			||||||
 | 
					      systemctl restart nezha-agent
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} >/dev/null 2>&1 &
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [[ $# == 0 ]]; then
 | 
					    if [[ $# == 0 ]]; then
 | 
				
			||||||
        before_show_menu
 | 
					        before_show_menu
 | 
				
			||||||
@ -477,10 +488,15 @@ show_agent_log() {
 | 
				
			|||||||
uninstall_agent() {
 | 
					uninstall_agent() {
 | 
				
			||||||
    echo -e "> 卸载Agent"
 | 
					    echo -e "> 卸载Agent"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    systemctl disable nezha-agent.service
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    systemctl stop nezha-agent.service
 | 
					      systemctl disable nezha-agent.service
 | 
				
			||||||
    rm -rf $NZ_AGENT_SERVICE
 | 
					      systemctl stop nezha-agent.service
 | 
				
			||||||
    systemctl daemon-reload
 | 
					      rm -rf $NZ_AGENT_SERVICE
 | 
				
			||||||
 | 
					      systemctl daemon-reload
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      sed -i "/nezha-agent/d" /etc/crontabs/root
 | 
				
			||||||
 | 
					      pkill nezha
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rm -rf $NZ_AGENT_PATH
 | 
					    rm -rf $NZ_AGENT_PATH
 | 
				
			||||||
    clean_all
 | 
					    clean_all
 | 
				
			||||||
@ -652,4 +668,4 @@ if [[ $# > 0 ]]; then
 | 
				
			|||||||
    esac
 | 
					    esac
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
    show_menu
 | 
					    show_menu
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#========================================================
 | 
					#========================================================
 | 
				
			||||||
#   System Required: CentOS 7+ / Debian 8+ / Ubuntu 16+ /
 | 
					#   System Required: CentOS 7+ / Debian 8+ / Ubuntu 16+ / Alpine 3+ /
 | 
				
			||||||
#     Arch not tested
 | 
					#     Arch not tested
 | 
				
			||||||
#   Description: Nezha Monitoring Install Script
 | 
					#   Description: Nezha Monitoring Install Script
 | 
				
			||||||
#   Github: https://github.com/naiba/nezha
 | 
					#   Github: https://github.com/naiba/nezha
 | 
				
			||||||
@ -20,13 +20,10 @@ plain='\033[0m'
 | 
				
			|||||||
export PATH=$PATH:/usr/local/bin
 | 
					export PATH=$PATH:/usr/local/bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
os_arch=""
 | 
					os_arch=""
 | 
				
			||||||
 | 
					[ -e /etc/os-release ] && cat /etc/os-release | grep -i "PRETTY_NAME" | grep -qi "alpine" && os_alpine='1'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pre_check() {
 | 
					pre_check() {
 | 
				
			||||||
    command -v systemctl >/dev/null 2>&1
 | 
					    [ "$os_alpine" != 1 ] && ! command -v systemctl >/dev/null 2>&1 && echo "This system is not supported: systemctl not found" && exit 1
 | 
				
			||||||
    if [[ $? != 0 ]]; then
 | 
					 | 
				
			||||||
        echo "This system is not supported: systemctl not found"
 | 
					 | 
				
			||||||
        exit 1
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # check root
 | 
					    # check root
 | 
				
			||||||
    [[ $EUID -ne 0 ]] && echo -e "${red}ERROR: ${plain} This script must be run with the root user!\n" && exit 1
 | 
					    [[ $EUID -ne 0 ]] && echo -e "${red}ERROR: ${plain} This script must be run with the root user!\n" && exit 1
 | 
				
			||||||
@ -103,7 +100,8 @@ install_soft() {
 | 
				
			|||||||
    (command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
 | 
					    (command -v yum >/dev/null 2>&1 && yum makecache && yum install $* selinux-policy -y) ||
 | 
				
			||||||
        (command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
 | 
					        (command -v apt >/dev/null 2>&1 && apt update && apt install $* selinux-utils -y) ||
 | 
				
			||||||
        (command -v pacman >/dev/null 2>&1 && pacman -Syu $*) ||
 | 
					        (command -v pacman >/dev/null 2>&1 && pacman -Syu $*) ||
 | 
				
			||||||
        (command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y)
 | 
					        (command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* selinux-utils -y) ||
 | 
				
			||||||
 | 
					        (command -v apk >/dev/null 2>&1 && apk update && apk add $* -f)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install_dashboard() {
 | 
					install_dashboard() {
 | 
				
			||||||
@ -155,12 +153,14 @@ install_dashboard() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
selinux(){
 | 
					selinux(){
 | 
				
			||||||
    #Check SELinux
 | 
					    #Check SELinux
 | 
				
			||||||
    getenforce | grep '[Ee]nfor'
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    if [ $? -eq 0 ];then
 | 
					      getenforce | grep '[Ee]nfor'
 | 
				
			||||||
        echo -e "SELinux running,closing now!" 
 | 
					      if [ $? -eq 0 ];then
 | 
				
			||||||
        setenforce 0 &>/dev/null
 | 
					          echo -e "SELinux running,closing now!" 
 | 
				
			||||||
        find_key="SELINUX="
 | 
					          setenforce 0 &>/dev/null
 | 
				
			||||||
        sed -ri "/^$find_key/c${find_key}disabled" /etc/selinux/config
 | 
					          find_key="SELINUX="
 | 
				
			||||||
 | 
					          sed -ri "/^$find_key/c${find_key}disabled" /etc/selinux/config
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -216,10 +216,12 @@ install_agent() {
 | 
				
			|||||||
modify_agent_config() {
 | 
					modify_agent_config() {
 | 
				
			||||||
    echo -e "> Modify Agent Configuration"
 | 
					    echo -e "> Modify Agent Configuration"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    if [[ $? != 0 ]]; then
 | 
					      wget -t 2 -T 10 -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
 | 
				
			||||||
        echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
 | 
					      if [[ $? != 0 ]]; then
 | 
				
			||||||
        return 0
 | 
					          echo -e "${red}Fail to download service, please check if the network can link ${GITHUB_RAW_URL}${plain}"
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [ $# -lt 3 ]; then
 | 
					    if [ $# -lt 3 ]; then
 | 
				
			||||||
@ -241,21 +243,30 @@ modify_agent_config() {
 | 
				
			|||||||
        nz_client_secret=$3
 | 
					        nz_client_secret=$3
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
 | 
					      sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
    sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
 | 
					      sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					      sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    shift 3
 | 
					      shift 3
 | 
				
			||||||
    if [ $# -gt 0 ]; then
 | 
					      if [ $# -gt 0 ]; then
 | 
				
			||||||
        args=" $*"
 | 
					          args=" $*"
 | 
				
			||||||
        sed -i "/ExecStart/ s/$/${args}/" ${NZ_AGENT_SERVICE}
 | 
					          sed -i "/ExecStart/ s/$/${args}/" ${NZ_AGENT_SERVICE}
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo "@reboot nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} >/dev/null 2>&1 &" >> /etc/crontabs/root
 | 
				
			||||||
 | 
					      crond
 | 
				
			||||||
    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}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    systemctl daemon-reload
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    systemctl enable nezha-agent
 | 
					      systemctl daemon-reload
 | 
				
			||||||
    systemctl restart nezha-agent
 | 
					      systemctl enable nezha-agent
 | 
				
			||||||
 | 
					      systemctl restart nezha-agent
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      nohup ${NZ_AGENT_PATH}/nezha-agent -s ${nz_grpc_host}:${nz_grpc_port} -p ${nz_client_secret} >/dev/null 2>&1 &
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [[ $# == 0 ]]; then
 | 
					    if [[ $# == 0 ]]; then
 | 
				
			||||||
        before_show_menu
 | 
					        before_show_menu
 | 
				
			||||||
@ -445,10 +456,15 @@ show_agent_log() {
 | 
				
			|||||||
uninstall_agent() {
 | 
					uninstall_agent() {
 | 
				
			||||||
    echo -e "> Uninstall Agent"
 | 
					    echo -e "> Uninstall Agent"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    systemctl disable nezha-agent.service
 | 
					    if [ "$os_alpine" != 1 ];then
 | 
				
			||||||
    systemctl stop nezha-agent.service
 | 
					      systemctl disable nezha-agent.service
 | 
				
			||||||
    rm -rf $NZ_AGENT_SERVICE
 | 
					      systemctl stop nezha-agent.service
 | 
				
			||||||
    systemctl daemon-reload
 | 
					      rm -rf $NZ_AGENT_SERVICE
 | 
				
			||||||
 | 
					      systemctl daemon-reload
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      sed -i "/nezha-agent/d" /etc/crontabs/root
 | 
				
			||||||
 | 
					      pkill nezha
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rm -rf $NZ_AGENT_PATH
 | 
					    rm -rf $NZ_AGENT_PATH
 | 
				
			||||||
    clean_all
 | 
					    clean_all
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user