哪吒探针使用教程

官方地址

一个开源、轻量的服务器和网站监控、运维工具

准备条件

  1. GitHub账号
  2. 服务器一台
  3. 域名一个,并已做好解析

如果域名托管到了Cloudflare,记得 tls 设置那里要选择完全/完全(严格),要不然后面反代访问时会报错的

实现目标:用 https://tz.xxx.com 即可访问探针地址

搭建步骤

1. 安装docker,以ubuntu为例

其他版本请参考 这里

apt-get remove docker docker-engine docker.io containerd runc
apt-get update && apt-get install -y ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
curl -L https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

2.创建OAuth Apps

  1. 进入这个网址 Developer applications (github.com) ,并点击右上角的 New OAuth App

  2. 输入以下信息后,点击 Register application

    Application nameHomepage URLAuthorization callback URL
    随意输入,例如:探针https://tz.xxx.comhttps://tz.xxx.com/oauth2/callback
  3. 保存页面中的 Client ID,然后点击 Generate a new client secret,创建一个新的 Client Secret,新建的密钥仅会显示一次,请妥善保存

3.搭建哪吒面板

  • 在面板服务器中,运行安装脚本:
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh  -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh
  • 等待脚本跑完后,分别输入以下值:

    • OAuth提供商 - 选择 Github
    • Client ID - 之前保存的 Client ID
    • Client Secret - 之前保存的 Client secrets
    • 用户名 - github用户名,一定要正确的用户名
    • 站点标题 - 自定义站点标题
    • 访问端口 - 公开访问端口,可自定义,默认 8008,反代之后可以不用打开
    • Agent的通信端口 - Agent与Dashboard的通信端口,默认 5555,反代之后一定要打开
  • 输入完成后,等待拉取镜像 安装结束后,如果一切正常,此时你可以访问域名+端口号,如 “http://tz.xxx.com:8008” 来查看面板

4.申请ssl证书

  1. 安装acme脚本

    apt update && apt install -y cron socat && curl https://get.acme.sh | sh
    
  2. 注册账户

    .acme.sh/acme.sh --register-account -m abcd@qq.com
    
  3. 用80端口申请域名证书,也可以用其他方式

    .acme.sh/acme.sh --issue --standalone -d tz.xxx.com
    
  4. 安装申请好的证书

    [ -d /ssl/tz.xxx.com ] || mkdir -p /ssl/tz.xxx.com
    .acme.sh/acme.sh --installcert -d tz.xxx.com --fullchain-file /ssl/tz.xxx.com/cret.crt --key-file /ssl/tz.xxx.com/private.key
    chmod +r /ssl/tz.xxx.com/cret.crt && chmod +r /ssl/tz.xxx.com/private.key
    
  5. 设置acme脚本自动更新证书

    .acme.sh/acme.sh --upgrade --auto-upgrade
    

5.设置nginx反向代理

  • 创建一个目录,用于存放nginx的docker配置文件

    mkdir /docker/nginx -p
    
  • 配置nginx的docker启动文件

    cd /docker/nginx
    
    cat > docker-compose.yml <<EOF
    services:
      nginx:
        container_name: nginx 
        image: nginx:stable-alpine3.17-slim
        restart: always
        network_mode: "host"
        volumes:
          - /ssl:/ssl:ro
          - ./log:/var/log/nginx
          - ./conf/:/etc/nginx/conf.d/:ro
          - ./html:/usr/share/nginx/html
    EOF
    
  • 配置反代的配置文件

    mkdir conf
    cat > conf/nezha.conf <<\EOF
    server {
            listen  80;
            server_name     tz.xxx.com;
            if ($server_port !~ 443){
                    rewrite ^(/.*)$ https://$host$1 permanent;
            }
    }
    server {
            listen  443 ssl http2;
            server_name     tz.xxx.com;
            #ssl
            ssl_protocols TLSv1.2 TLSv1.3;
            ssl_certificate      /ssl/tz.xxx.com/cret.crt;
            ssl_certificate_key  /ssl/tz.xxx.com/private.key;
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
            ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;
            location / {
                proxy_pass http://172.17.0.1:8008;
                proxy_set_header Host $http_host;
                proxy_set_header      Upgrade $http_upgrade;
    
            }
            location ~ ^/(ws|terminal/.+)$  {
                proxy_pass http://172.17.0.1:8008;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header Host $http_host;
            }   
    }
    EOF
    
  • 启动nginx

    docker-compose up -d
    
  • 这时就可以通过访问 https://tz.xxx.com 来访问哪吒面板

美化哪吒

目的:在原探针的基础上美化主题并增加了cpu等信息的显示

步骤如下

1.更改默认主题配置文件

  • 进入哪吒的volume数据卷路径
cd `docker inspect dashboard-dashboard-1|grep "/var/lib/docker/overlay2/"|grep MergedDir|grep -oE "/var.*merged"`/dashboard/resource/template/theme-default
  • 把原来的文件打包,做一个压缩包
tar -zcf backup.tar.gz ./* && rm -rf home.html
  • 下载新的文件
wget https://raw.githubusercontent.com/psmtnhljs/vps-test/main/home.html && wget https://raw.githubusercontent.com/psmtnhljs/vps-test/main/header.html
  • 重启面板
docker restart dashboard-dashboard-1

2.更改css

  • 登录探针面板后台,将以下代码填入 自定义代码(style、script 都可以) 后保存
  • 此处提供一种css,更多主题请自行谷歌寻找,别直接ctrl c+v,自己看着改图片链接
<style>
/* 屏幕适配 */
@media only screen and (min-width: 1200px) {
    .ui.container {
    width: 80% !important;
}
}
 
@media only screen and (max-width: 767px) {
    .ui.card>.content>.header:not(.ui), .ui.cards>.card>.content>.header:not(.ui) {
        margin-top: 0.4em !important;
    }
}
 
/* 整体图标 */
i.icon {
    color: #000;
    width: 1.2em !important;
}
 
/* 背景图片 */
body {
    content: " " !important;
    background: fixed !important;
    z-index: -1 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    background-position: top !important;
    background-repeat: no-repeat !important;
    background-size: cover !important;
/*
每日一图: "https://api.dujin.org/bing/1920.php"
随机风景: "https://api.cyrilstudio.top/bing/image.php/bing?rand=true"
随机动漫: "https://img.xjh.me/random_img.php?type=bg&return=302"
必应: "https://tuapi.eees.cc/api.php?category=biying&type=302"
*/
    background-image: url(https://bing.yuji2022.tk/?rand=true) !important;
    font-family: Arial,Helvetica,sans-serif !important;
}
 
/* 导航栏 */
.ui.large.menu {
    border: 0 !important;
    border-radius: 0px !important;
    background-color: rgba(255, 255, 255, 55%) !important;
}
 
/* 首页按钮 */
.ui.menu .active.item {
    background-color: transparent !important;
}
 
/* 导航栏下拉框 */
.ui.dropdown .menu {
    border: 0 !important;
    border-radius: 0 !important;
    background-color: rgba(255, 255, 255, 80%) !important;
}
 
/* 登陆按钮 */
.nezha-primary-btn {
    background-color: transparent !important;
    color: #000 !important;
}
 
/* 大卡片 */
#app .ui.fluid.accordion {
    background-color: #fbfbfb26 !important;
    border-radius: 1rem !important;
}
 
/* 小卡片 */
.ui.four.cards>.card {
    border-radius: 1rem !important;
    background-color: #fafafaa3 !important;
}
 
.status.cards .wide.column {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    height: 3.3rem !important;
}
 
.status.cards .three.wide.column {
    padding-right: 0rem !important;
}
 
.status.cards .wide.column:nth-child(1) {
    margin-top: 2rem !important;
}
 
.status.cards .wide.column:nth-child(2) {
    margin-top: 2rem !important;
}
 
.status.cards .description {
    padding-bottom: 0 !important;
}
 
/* 小鸡名 */
.status.cards .flag {
    margin-right: 0.5rem !important;
}
 
/* 弹出卡片图标 */
.status.cards .header > .info.icon {
    margin-right: 0 !important;
}
 
.nezha-secondary-font {
    color: #21ba45 !important;
}
 
/* 进度条 */
.ui.progress {
    border-radius: 50rem !important;
}
.ui.progress .bar {
    min-width: 1.8em !important;
    border-radius: 15px !important;
    line-height: 1.65em !important;
    color:black
}
.ui.fine.progress> .bar {
    background-color: #ba45ac !important;
}
.ui.progress> .bar {
    background-color: #000 !important;
}
 
.ui.progress.fine .bar {
    background-image: linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%);!important;
}
 
.ui.progress.warning .bar {
    background-image: linear-gradient(to right, #fa709a 0%, #fee140 100%); !important;
}
 
.ui.progress.error .bar {
    background-image: linear-gradient(to top, #ff0844 0%, #ffb199 100%);important;
}
 
.ui.progress.offline .bar {
    background-image: linear-gradient(to top, #e6e9f0 0%, #eef1f5 100%); !important;
}
 
/* 上传下载 */
.status.cards .outline.icon {
    margin-right: 1px !important;
}
 
i.arrow.alternate.circle.down.outline.icon {
    color: #21ba45 !important;
}
 
i.arrow.alternate.circle.up.outline.icon {
    color: red !important;
}
 
/* 弹出卡片小箭头 */
.ui.right.center.popup {
    margin: -3px 0 0 0.914286em !important;
    -webkit-transform-origin: left 50% !important;
    transform-origin: left 50% !important;
}
 
.ui.bottom.left.popup {
    margin-left: 1px !important;
    margin-top: 3px !important;
}
 
.ui.top.left.popup {
    margin-left: 0 !important;
    margin-bottom: 10px !important;
}
 
.ui.top.right.popup {
    margin-right: 0 !important;
    margin-bottom: 8px !important;
}
 
.ui.left.center.popup {
    margin: -3px .91428571em 0 0 !important;
    -webkit-transform-origin: right 50% !important;
    transform-origin: right 50% !important;
}
 
.ui.right.center.popup:before,
.ui.left.center.popup:before {
    border: 0px solid #fafafaeb !important;
    background: #fafafaeb !important;
}
.ui.top.popup:before {
    border-color: #fafafaeb transparent transparent !important;
}
 
.ui.popup:before {
    border-color: #fafafaeb transparent transparent !important;
}
 
.ui.bottom.left.popup:before {
    border-radius: 0 !important;
    border: 1px solid transparent !important;
    border-color: #fafafaeb transparent transparent !important;
    background: #fafafaeb !important;
    -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important;
    box-shadow: 0px 0px 0 0 #fafafaeb !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0) !important;
}
 
.ui.bottom.right.popup:before {
    border-radius: 0 !important;
    border: 1px solid transparent !important;
    border-color: #fafafaeb transparent transparent !important;
    background: #fafafaeb !important
    -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important;
    box-shadow: 0px 0px 0 0 #fafafaeb !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0) !important;
}
 
.ui.top.left.popup:before {
    border-radius: 0 !important;
    border: 1px solid transparent !important;
    border-color: #fafafaeb transparent transparent !important;
    background: #fafafaeb !important;
    -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important;
    box-shadow: 0px 0px 0 0 #fafafaeb !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0) !important;
}
 
.ui.top.right.popup:before {
    border-radius: 0 !important;
    border: 1px solid transparent !important;
    border-color: #fafafaeb transparent transparent !important;
    background: #fafafaeb !important;
    -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important;
    box-shadow: 0px 0px 0 0 #fafafaeb !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0) !important;
}
 
.ui.left.center.popup:before {
    border-radius: 0 !important;
    border: 1px solid transparent !important;
    border-color: #fafafaeb transparent transparent !important;
    background: #fafafaeb !important;
    -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important;
    box-shadow: 0px 0px 0 0 #fafafaeb !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0) !important;
}
 
/* 弹出卡片 */
.status.cards .ui.content.popup {
    min-width: 20rem !important;
    line-height: 2rem !important;
    border-radius: 1rem !important;
    border: 1px solid transparent !important;
    background-color: #fafafaeb !important;
    font-family: Arial,Helvetica,sans-serif !important;
}
 
.ui.content {
    margin: 0 !important;
    padding: 1em !important;
}
 
/* 服务页 */
.ui.table {
    background: RGB(225,225,225,0.6) !important;
}
 
.ui.table thead th {
    background: transparent !important;
}
 
/* 服务页进度条 */
 
/* 版权 */
.ui.inverted.segment, .ui.primary.inverted.segment {
    color: #000 !important;
    font-weight: bold !important;
    background-color: #fafafaa3 !important;
}
</style>
 
<script>
    window.onload = function(){
    var avatar=document.querySelector(".item img")
    var footer=document.querySelector("div.is-size-7")
    document.querySelector("[rel='shortcut icon']").href = "https://s1.yesimg.com/2022/d2087fb7236f3.png"
    footer.innerHTML="うずまきナルトのクラウドサーバー"
    footer.style.visibility="visible"
    avatar.src="https://s1.yesimg.com/2022/d2087fb7236f3.png"
    avatar.style.visibility="visible"
    }
</script>

哪吒数据的备份

  1. 停止原来的哪吒
  2. 把旧哪吒的数据备份到新哪吒即可,数据目录在 /opt/nezha/ ,也就是把这个目录原封不动地拷贝过去既可以了
  3. 进入新哪吒的网页端后台,设置 未接入CDN的面板服务器域名/IP ,只有这个设置对了,才能迁移成功。
  4. 未接入CDN的面板服务器域名/IP 这个设置如果用域名的话,不能开CDN

哪吒的其他设置

Q.E.D.