From f735861d6508693527b3280c6eda89dffc8e4295 Mon Sep 17 00:00:00 2001 From: naiba Date: Mon, 7 Dec 2020 09:38:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(shell):=20=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20=E9=9D=A2=E6=9D=BF/RPC=20=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/agent.yml | 2 +- .github/workflows/dashboard.yml | 2 +- README.md | 2 +- script/docker-compose.yaml | 4 ++-- script/install.sh | 42 +++++++++++++++++++++++---------- script/nezha-agent.service | 2 +- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index 3bcf73c..0f25c08 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -5,7 +5,7 @@ on: paths-ignore: - "script/**" - ".gitignore" - - "README.md" + - "*.md" - "cmd/dashboard/**" - ".github/dashboard.yaml" tags: diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 4cb2439..3870c4c 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -7,7 +7,7 @@ on: paths-ignore: - "script/**" - ".gitignore" - - "README.md" + - "*.md" - "cmd/agent/**" - ".github/agent.yaml" - ".goreleaser.yml" diff --git a/README.md b/README.md index 81a9e1a..b966219 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ sudo ./nezha.sh #server_name blablabla... location /ws { - proxy_pass http://ip:8008; + proxy_pass http://ip:站点访问端口; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; diff --git a/script/docker-compose.yaml b/script/docker-compose.yaml index e6cfa22..42e1718 100644 --- a/script/docker-compose.yaml +++ b/script/docker-compose.yaml @@ -7,5 +7,5 @@ services: volumes: - ./data:/dashboard/data ports: - - 8008:80 - - 5555:5555 + - nz_site_port:80 + - nz_rpc_port:5555 diff --git a/script/install.sh b/script/install.sh index 5008363..bcb5256 100755 --- a/script/install.sh +++ b/script/install.sh @@ -146,14 +146,6 @@ install_dashboard() { echo -e "${green}Docker Compose${plain} 安装成功" fi - echo -e "正在下载 Docker 脚本" - cd $NZ_DASHBOARD_PATH - curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/docker-compose.yaml -o docker-compose.yaml >/dev/null 2>&1 - if [[ $? != 0 ]]; then - echo -e "${red}下载脚本失败,请检查本机能否连接 raw.githubusercontent.com${plain}" - return 0 - fi - modify_dashboard_config 0 if [[ $# == 0 ]]; then @@ -197,16 +189,22 @@ modify_agent_config() { fi echo "请先在管理面板上添加服务器,获取到ID和密钥" && - read -p "请输入一个解析到面板所在IP的域名(不可套CDN): " nezha_server_addr && + read -p "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_rpc_host && + read -p "请输入面板RPC端口: (5555)" nz_rpc_host && read -p "请输入Agent ID: " nezha_client_id && read -p "请输入Agent 密钥: " nezha_client_secret - if [[ -z "${nezha_server_addr}" || -z "${nezha_client_id}" || -z "${nezha_client_secret}" ]]; then + if [[ -z "${nz_rpc_host}" || -z "${nezha_client_id}" || -z "${nezha_client_secret}" ]]; then echo -e "${red}所有选项都不能为空${plain}" before_show_menu return 1 fi - sed -i "s/nezha_server_addr/${nezha_server_addr}/" ${NZ_AGENT_SERVICE} + if [[ -z "${nz_rpc_port}" ]]; then + $nz_rpc_port=5555 + fi + + sed -i "s/nz_rpc_host/${nz_rpc_host}/" ${NZ_AGENT_SERVICE} + sed -i "s/nz_rpc_port/${nz_rpc_port}/" ${NZ_AGENT_SERVICE} sed -i "s/nezha_client_id/${nezha_client_id}/" ${NZ_AGENT_SERVICE} sed -i "s/nezha_client_secret/${nezha_client_secret}/" ${NZ_AGENT_SERVICE} @@ -224,6 +222,13 @@ modify_agent_config() { modify_dashboard_config() { echo -e "> 修改面板配置" + echo -e "正在下载 Docker 脚本" + curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/docker-compose.yaml -o ${NZ_DASHBOARD_PATH}/docker-compose.yaml >/dev/null 2>&1 + if [[ $? != 0 ]]; then + echo -e "${red}下载脚本失败,请检查本机能否连接 raw.githubusercontent.com${plain}" + return 0 + fi + mkdir -p $NZ_DASHBOARD_PATH/data curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/config.yaml -o ${NZ_DASHBOARD_PATH}/data/config.yaml >/dev/null 2>&1 @@ -237,17 +242,28 @@ modify_dashboard_config() { echo "关于 GitHub Oauth2 应用:在 https://github.com/settings/developers 创建,无需审核 Callback 填 http(s)://域名或IP/oauth2/callback" && read -p "请输入 GitHub Oauth2 应用的 Client ID: " nz_github_oauth_client_id && read -p "请输入 GitHub Oauth2 应用的 Client Secret: " nz_github_oauth_client_secret && - read -p "请输入站点标题: " nz_site_title + read -p "请输入站点标题: " nz_site_title && + read -p "请输入站点访问端口: (8008)" nz_site_port && + read -p "请输入用于 Agent 接入的 RPC 端口: (5555)" nz_rpc_port if [[ -z "${nz_admin_ids}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then echo -e "${red}所有选项都不能为空${plain}" before_show_menu return 1 fi + if [[ -z "${nz_site_port}" ]]; then + $nz_site_port=8008 + fi + if [[ -z "${nz_rpc_port}" ]]; then + $nz_site_port=5555 + fi + sed -i "s/nz_admin_ids/${nz_admin_ids}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_site_title/${nz_site_title}/" ${NZ_DASHBOARD_PATH}/data/config.yaml + sed -i "s/nz_site_port/${nz_site_port}/" ${NZ_DASHBOARD_PATH}/docker-composer.yaml + sed -i "s/nz_rpc_port/${nz_rpc_port}/" ${NZ_DASHBOARD_PATH}/docker-composer.yaml echo -e "面板配置 ${green}修改成功,请稍等重启生效${plain}" @@ -265,7 +281,7 @@ restart_dashboard() { docker-compose up -d if [[ $? == 0 ]]; then echo -e "${green}哪吒面板 重启成功${plain}" - echo -e "默认管理面板地址:${yellow}域名:8008${plain}" + echo -e "默认管理面板地址:${yellow}域名:站点访问端口${plain}" else echo -e "${red}重启失败,可能是因为启动时间超过了两秒,请稍后查看日志信息${plain}" fi diff --git a/script/nezha-agent.service b/script/nezha-agent.service index 8ae874b..5b3577c 100644 --- a/script/nezha-agent.service +++ b/script/nezha-agent.service @@ -15,7 +15,7 @@ Type=simple User=root Group=root WorkingDirectory=/opt/nezha/agent/ -ExecStart=/opt/nezha/agent/nezha-agent -d -s nezha_server_addr:5555 -i nezha_client_id -p nezha_client_secret +ExecStart=/opt/nezha/agent/nezha-agent -d -s nz_rpc_host:nz_rpc_port -i nezha_client_id -p nezha_client_secret Restart=always #Environment=DEBUG=true