Linux 一键安装命令

This commit is contained in:
naiba 2021-08-10 20:04:58 +08:00
parent 4740a41e36
commit 985ecc7c65
9 changed files with 62 additions and 110 deletions

View File

@ -452,6 +452,7 @@ type settingForm struct {
EnableIPChangeNotification string
IgnoredIPNotification string
Oauth2Type string
GRPCHost string
Cover uint8
}
@ -466,6 +467,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
}
dao.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on"
dao.Conf.Cover = sf.Cover
dao.Conf.GRPCHost = sf.GRPCHost
dao.Conf.IgnoredIPNotification = sf.IgnoredIPNotification
dao.Conf.Site.Brand = sf.Title
dao.Conf.Site.Theme = sf.Theme

View File

@ -2,7 +2,6 @@ package main
import (
"context"
"github.com/naiba/nezha/util"
"log"
"time"
@ -47,9 +46,6 @@ func init() {
if dao.Conf.GRPCPort == 0 {
dao.Conf.GRPCPort = 5555
}
if dao.Conf.GRPCHost == "" {
dao.Conf.GRPCHost = util.FetchGeoIP(false).IP
}
dao.Cache = cache.New(5*time.Minute, 10*time.Minute)
initSystem()

View File

@ -174,8 +174,6 @@ function addOrEditServer(server, conf) {
modal.find(".secret.field").attr("style", "");
modal.find(".command.field").attr("style", "");
modal.find(".command.hostSecret").text(server.Secret);
modal.find(".command.GRPCHost").text(conf.GRPCHost);
modal.find(".command.GRPCPort").text(conf.GRPCPort);
modal.find("input[name=secret]").val(server.Secret);
} else {
modal.find(".secret.field").attr("style", "display:none");

View File

@ -9,7 +9,7 @@
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.1/dist/semantic.min.js"></script>
<script src="/static/semantic-ui-alerts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.min.js"></script>
<script src="/static/main.js?v20210806"></script>
<script src="/static/main.js?v20210810"></script>
</body>
</html>

View File

@ -26,14 +26,15 @@
</div>
<div class="command field">
<label>Agent 安装命令</label>
<label>Linux 一键安装</label>
<div class="ui message">
<div class="header">
systemd
</div>
<div class="ui segment">
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh install_agent <code class="command GRPCHost"></code> <code class="command GRPCPort"></code> <code class="command hostSecret"></code>
</div>
{{if .Conf.GRPCHost}}
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod
+x nezha.sh && sudo ./nezha.sh install_agent <code class="command">{{.Conf.GRPCHost}}</code> <code
class="command">{{.Conf.GRPCPort}}</code> <code class="command hostSecret"></code>
{{else}}
请先在设置页面配置 未接入CDN的面板服务器域名/IP
{{end}}
</div>
</div>
</form>

View File

@ -19,6 +19,7 @@
<th>IP</th>
<th>版本号</th>
<th>密钥</th>
<th>一键安装</th>
<th>备注</th>
<th>管理</th>
</tr>
@ -32,10 +33,24 @@
<td>{{$server.Host.IP}}</td>
<td>{{$server.Host.Version}}</td>
<td>{{$server.Secret}}</td>
<td>
<button class="ui icon green mini button"
data-clipboard-text="{{if $.Conf.GRPCHost}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod
+x nezha.sh && sudo ./nezha.sh install_agent {{$.Conf.GRPCHost}} {{$.Conf.GRPCPort}} {{$server.Secret}}{{else}}请先在设置页面配置 未接入CDN的面板服务器域名/IP{{end}}"
data-tooltip="点击复制安装命令">
<i class="linux icon"></i>
</button>
<button class="ui icon mini button" data-tooltip="尚未支持请下载release手动安装">
<i class="windows icon"></i>
</button>
<button class="ui icon mini button" data-tooltip="尚未支持请下载release手动安装">
<i class="apple icon"></i>
</button>
</td>
<td style="word-break: break-word;">{{$server.Note}}</td>
<td>
<div class="ui mini icon buttons">
<button class="ui button" onclick="addOrEditServer({{$server.Marshal}},{{$.Conf}})">
<button class="ui button" onclick="addOrEditServer({{$server.Marshal}})">
<i class="edit icon"></i>
</button>
<button class="ui button"
@ -50,6 +65,10 @@
</table>
</div>
</div>
{{template "component/server"}}
{{template "component/server" .}}
{{template "common/footer" .}}
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
<script>
var clipboard = new ClipboardJS('.ui.icon.green.mini.button');
</script>
{{end}}

View File

@ -40,6 +40,10 @@
<label>前台查看密码</label>
<input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}">
</div>
<div class="field">
<label>未接入CDN的面板服务器域名/IP</label>
<input type="text" name="GRPCHost" placeholder="" value="{{.Conf.GRPCHost}}">
</div>
<div class="field">
<label>IP 变更提醒</label>
</div>
@ -70,40 +74,41 @@
{{template "common/footer" .}}
<script>
$('#settingForm').submit(function () {
$.post('/api/setting', $('#settingForm').serialize()).then((resp) => {
if (resp.code == 200) {
$.post('/api/setting', $('#settingForm').serialize())
.then((resp) => {
if (resp.code == 200) {
$.suiAlert({
title: '',
description: '修改成功',
type: 'success',
time: '3',
position: 'top-center',
});
} else {
$.suiAlert({
title: '',
description: resp.message,
type: 'error',
time: '3',
position: 'top-center',
});
}
}).catch(err => {
$.suiAlert({
title: '',
description: '修改成功',
type: 'success',
time: '3',
position: 'top-center',
});
} else {
$.suiAlert({
title: '',
description: resp.message,
description: err,
type: 'error',
time: '3',
position: 'top-center',
});
}
}).error(err => {
$.suiAlert({
title: '',
description: err,
type: 'error',
time: '3',
position: 'top-center',
});
})
})
return false;
})
$('.checkbox').checkbox()
$('#settingForm').find("select[name=Cover]")
.val({{.Conf.Cover}});
{{ if .Conf.EnableIPChangeNotification}}
.val({{.Conf.Cover }});
{{if .Conf.EnableIPChangeNotification}}
$('.checkbox').checkbox('set checked')
{{ end }}
</script>
{{end}}
{{end}}

View File

@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha"
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
NZ_VERSION="v0.6.5"
NZ_VERSION="v0.6.6"
red='\033[0;31m'
green='\033[0;32m'

View File

@ -1,69 +0,0 @@
package util
import (
"encoding/json"
"io/ioutil"
"net/http"
"strings"
"time"
"github.com/naiba/nezha/pkg/utils"
)
type geoIP struct {
CountryCode string `json:"country_code,omitempty"`
IP string `json:"ip,omitempty"`
Query string `json:"query,omitempty"`
}
var (
geoIPApiList = []string{
"https://api.ip.sb/geoip",
"https://ip.seeip.org/geoip",
"https://ipapi.co/json",
"https://freegeoip.app/json/",
"http://ip-api.com/json/",
"https://extreme-ip-lookup.com/json/",
}
cachedIP, cachedCountry string
httpClientV4 = utils.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false)
httpClientV6 = utils.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true)
)
func FetchGeoIP(isV6 bool) geoIP {
servers := geoIPApiList
var ip geoIP
var resp *http.Response
var err error
for i := 0; i < len(servers); i++ {
if isV6 {
resp, err = httpClientV6.Get(servers[i])
} else {
resp, err = httpClientV4.Get(servers[i])
}
if err == nil {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
continue
}
resp.Body.Close()
err = json.Unmarshal(body, &ip)
if err != nil {
continue
}
if ip.IP == "" && ip.Query != "" {
ip.IP = ip.Query
}
// 没取到 v6 IP
if isV6 && !strings.Contains(ip.IP, ":") {
continue
}
// 没取到 v4 IP
if !isV6 && !strings.Contains(ip.IP, ".") {
continue
}
return ip
}
}
return ip
}