[ Agent ] [ Base ] - refresh for euler

This commit is contained in:
zeaslity
2024-01-24 17:09:48 +08:00
parent 2c1cde980c
commit 4ffd48500c
10 changed files with 111 additions and 104 deletions

View File

@@ -27,6 +27,8 @@ type AgentOsOperator struct {
IsOsTypeCentOS bool `json:"is_os_type_centos",comment:"主机操作系统是否为centos系列"` IsOsTypeCentOS bool `json:"is_os_type_centos",comment:"主机操作系统是否为centos系列"`
IsOsTypeEuler bool `json:"is_os_type_euler",comment:"主机操作系统是否为国产欧拉系列"`
IsAgentInnerWall bool `json:"is_agent_inner_wall",comment:"主机是否身处国内"` IsAgentInnerWall bool `json:"is_agent_inner_wall",comment:"主机是否身处国内"`
AgentArch string `json:"agent_arch",comment:"主机的CPU架构可选为amd64 arm64"` AgentArch string `json:"agent_arch",comment:"主机的CPU架构可选为amd64 arm64"`
@@ -353,6 +355,7 @@ func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []
// ssh-keygen -t ed25519 -C "wdd@cmii.com" // ssh-keygen -t ed25519 -C "wdd@cmii.com"
// ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa -b 4096 // ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa -b 4096
BasicCreateFolder("/root/.ssh/")
// check key exists // check key exists
if BasicFileExistAndNotNull("/root/.ssh/id_ed25519") { if BasicFileExistAndNotNull("/root/.ssh/id_ed25519") {
@@ -598,6 +601,8 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
BasicCreateFolder("/root/wdd/") BasicCreateFolder("/root/wdd/")
op.removeDockerExec()
if op.IsOsTypeUbuntu { if op.IsOsTypeUbuntu {
if !op.CanAccessInternet { if !op.CanAccessInternet {
@@ -777,11 +782,44 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
return false, append(log5, "启动docker.service失败请查明原因", "journalctl -u docker -n 100 -f") return false, append(log5, "启动docker.service失败请查明原因", "journalctl -u docker -n 100 -f")
} }
} else if op.IsOsTypeCentOS { } else if op.IsOsTypeCentOS {
if !op.CanAccessInternet { if !op.CanAccessInternet || op.IsOsTypeEuler {
// offline version // offline version
log.InfoF("[installDockerExec] - centos can not access to internet, installing by offline !") log.InfoF("[installDockerExec] - centos can not access to internet, installing by offline !")
return op.installDockerOfflineExec(args) return op.installDockerOfflineExec(args)
} }
// download
var dockerRepo string
if op.IsAgentInnerWall {
dockerRepo = "https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo"
} else {
dockerRepo = "https://download.docker.com/linux/centos/docker-ce.repo"
}
AllCommandExecutor(append(op.InstallCommandPrefix, "yum-utils"))
ok, resultLog := AllCommandExecutor(
[]string{
"yum-config-manager",
"--add-repo",
dockerRepo,
},
)
if !ok {
return false, resultLog
}
// todo 20 version
resultOk, l := AllCommandExecutor(append(op.InstallCommandPrefix, "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"))
if !resultOk {
return false, l
}
systemdUp, log2 := BasicSystemdUp("docker")
if !systemdUp {
return false, log2
}
} }
return true, []string{ return true, []string{
@@ -1995,7 +2033,7 @@ func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
if op.IsOsTypeCentOS { if op.IsOsTypeCentOS {
if !op.CanAccessInternet { if !op.CanAccessInternet {
return op.chronyToMasterCentOsOfflineExec(args) return op.chronyToMasterByDocker(args)
} }
// install ntp // install ntp
@@ -2074,9 +2112,7 @@ func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
} }
} }
func (op *AgentOsOperator) chronyToMasterCentOsOfflineExec(args []string) (bool, []string) { func (op *AgentOsOperator) chronyToMasterByDocker(args []string) (bool, []string) {
// todo
return true, nil return true, nil
} }

View File

@@ -2,23 +2,26 @@ package executor
import ( import (
"testing" "testing"
"wdd.io/agent-go/assert"
"wdd.io/agent-go/register" "wdd.io/agent-go/register"
) )
var agentOP = &AgentOsOperator{ var agentOP = &AgentOsOperator{
InstallCommandPrefix: []string{ InstallCommandPrefix: []string{
"apt-get", "install", "-y", "yum", "install", "-y",
}, },
RemoveCommandPrefix: []string{"apt", "remove", "-y"}, RemoveCommandPrefix: []string{"yum", "remove", "-y"},
CanAccessInternet: true, CanAccessInternet: true,
IsOsTypeUbuntu: true, IsOsTypeUbuntu: false,
IsOsTypeCentOS: true,
IsOsTypeEuler: true,
IsAgentInnerWall: true, IsAgentInnerWall: true,
AgentArch: "amd64", AgentArch: "amd64",
AgentOSReleaseCode: "focal", AgentOSReleaseCode: "focal",
AgentServerInfo: &register.AgentServerInfo{ AgentServerInfo: &register.AgentServerInfo{
ServerName: "", ServerName: "",
ServerIPPbV4: "", ServerIPPbV4: "",
ServerIPInV4: "192.168.0.8", ServerIPInV4: "10.250.0.147",
ServerIPPbV6: "", ServerIPPbV6: "",
ServerIPInV6: "", ServerIPInV6: "",
Location: "", Location: "",
@@ -39,23 +42,39 @@ var agentOP = &AgentOsOperator{
AgentVersion: "", AgentVersion: "",
TopicName: "", TopicName: "",
}, },
OssOfflinePrefix: "http://10.250.0.100:9000/octopus/",
} }
func TestBaseFunc(t *testing.T) { func TestBaseFunc(t *testing.T) {
//agentOP.Command("shutdownFirewall") //command := "DISABLE_SELINUX"
//agentOP.Command("modifyHostname") //command := "installDocker"
//agentOP.Command("disableSwap") //command := "installDockerCompose"
//agentOP.Command("enableSwap") command := "installHarbor"
//agentOP.Command("removeDocker")
//agentOP.Command("installDocker", "20") funcArgs := []string{
//agentOP.Command("removeDockerCompose") "10.250.0.147",
//agentOP.Command("installDockerCompose") "",
//agentOP.Command("installHelm") "",
//agentOP.Command("installHarbor") "",
//agentOP.Command("chronyToPublicNTP") }
//agentOP.Command("chronyToMaster", "192.168.0.8")
//agentOP.Command("installZSH") //agentOP.Exec("shutdownFirewall")
agentOP.Command("ok") //agentOP.Exec("modifyHostname")
//agentOP.Exec("disableSwap")
//agentOP.Exec("enableSwap")
//agentOP.Exec("removeDocker")
//agentOP.Exec("installDocker", "20")
//agentOP.Exec("removeDockerCompose")
//agentOP.Exec("installDockerCompose")
//agentOP.Exec("installHelm")
//agentOP.Exec("installHarbor")
//agentOP.Exec("chronyToMaster", "192.168.0.8")
//agentOP.Exec("installZSH")
//agentOP.Exec("ok")
exec, strings := agentOP.Exec(command, funcArgs...)
assert.Equal(t, exec, true, "exec should be true!")
t.Logf("[%s] exec result are %s", command, strings)
} }

View File

@@ -17,6 +17,7 @@ func BuildAgentOsOperator(agentInfo *status.AgentInfo, ossOfflinePrefix string)
CanAccessInternet: true, CanAccessInternet: true,
IsOsTypeUbuntu: true, IsOsTypeUbuntu: true,
IsOsTypeCentOS: false, IsOsTypeCentOS: false,
IsOsTypeEuler: false,
IsAgentInnerWall: false, IsAgentInnerWall: false,
AgentArch: "amd64", AgentArch: "amd64",
AgentOSReleaseCode: "focal", AgentOSReleaseCode: "focal",
@@ -42,21 +43,25 @@ func detectByAgentStatusInfo(agentInfo *status.AgentInfo, os *AgentOsOperator) {
bytes, _ := json.Marshal(agentInfo) bytes, _ := json.Marshal(agentInfo)
log.DebugF("[detectByAgentStatusInfo] - agent info is => %s", string(bytes)) log.DebugF("[detectByAgentStatusInfo] - agent info is => %s", string(bytes))
if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") || strings.Contains(agentInfo.HostInfo.PlatformFamily, "platformFamily") { if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") || strings.Contains(agentInfo.HostInfo.PlatformFamily, "rehl") {
// centos // centos
os.IsOsTypeUbuntu = false os.IsOsTypeUbuntu = false
os.IsOsTypeCentOS = true os.IsOsTypeCentOS = true
if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") {
os.IsOsTypeEuler = true
}
os.InstallCommandPrefix = []string{ os.InstallCommandPrefix = []string{
"yum", "install", "-y", "yum", "install", "-y",
} }
os.RemoveCommandPrefix = []string{ os.RemoveCommandPrefix = []string{
"yum", "remove", "yum", "remove", "-y",
} }
} else if strings.Contains(agentInfo.HostInfo.PlatformFamily, "debian") { } else if strings.Contains(agentInfo.HostInfo.PlatformFamily, "debian") {
// ubuntu // ubuntu
os.IsOsTypeUbuntu = true os.IsOsTypeUbuntu = true
os.IsOsTypeCentOS = false os.IsOsTypeCentOS = false
os.IsOsTypeEuler = false
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"} os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{ os.InstallCommandPrefix = []string{
"apt-get", "install", "--allow-downgrades", "-y", "apt-get", "install", "--allow-downgrades", "-y",

View File

@@ -0,0 +1,12 @@
#!/bin/bash
rm -rf go1.21.6.linux-amd64.tar.gz
wget http://10.250.0.100:9000/octopus/go1.21.6.linux-amd64.tar.gz -O go1.21.6.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
sed -i "$ a export PATH=\$PATH:/usr/local/go/bin" /root/.bashrc
source /root/.bashrc
go version
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

View File

@@ -1,40 +0,0 @@
{
"cmii-admin-data": "5.2.0",
"cmii-admin-gateway": "5.2.0",
"cmii-admin-user": "5.2.0",
"cmii-app-release": "4.2.0-validation",
"cmii-open-gateway": "5.2.0",
"cmii-suav-supervision": "5.2.0",
"cmii-uav-airspace": "5.2.0",
"cmii-uav-alarm": "5.2.0",
"cmii-uav-autowaypoint": "4.1.6-cm-0828",
"cmii-uav-brain": "5.2.0",
"cmii-uav-cloud-live": "5.2.0",
"cmii-uav-clusters": "5.2.0",
"cmii-uav-cms": "5.2.0",
"cmii-uav-data-post-process": "5.2.0",
"cmii-uav-depotautoreturn": "4.2.0",
"cmii-uav-developer": "5.2.0-25858",
"cmii-uav-device": "5.2.0",
"cmii-uav-emergency": "5.2.0",
"cmii-uav-gateway": "5.2.0",
"cmii-uav-gis-server": "5.2.0",
"cmii-uav-grid-datasource": "5.2.0-24810",
"cmii-uav-grid-engine": "5.1.0",
"cmii-uav-grid-manage": "5.1.0",
"cmii-uav-industrial-portfolio": "5.2.0-25268-12",
"cmii-uav-integration": "5.2.0-25447",
"cmii-uav-kpi-monitor": "5.2.0",
"cmii-uav-logger": "5.2.0",
"cmii-uav-material-warehouse": "5.2.0",
"cmii-uav-mission": "5.2.0-25840",
"cmii-uav-mqtthandler": "5.2.0-25340-1",
"cmii-uav-notice": "5.2.0",
"cmii-uav-oauth": "5.2.0",
"cmii-uav-process": "5.2.0",
"cmii-uav-surveillance": "5.2.0-21794",
"cmii-uav-threedsimulation": "5.2.0",
"cmii-uav-tower": "5.2.0",
"cmii-uav-user": "5.2.0",
"cmii-uav-waypoint": "5.2.0-011102"
}

View File

@@ -1,28 +0,0 @@
{
"cmii-suav-platform-supervision": "5.2.0",
"cmii-suav-platform-supervisionh5": "5.2.0",
"cmii-uav-platform": "5.2.0",
"cmii-uav-platform-ai-brain": "5.2.0",
"cmii-uav-platform-armypeople": "5.2.0-24538",
"cmii-uav-platform-base": "5.2.0",
"cmii-uav-platform-cms-portal": "5.2.0",
"cmii-uav-platform-detection": "5.2.0",
"cmii-uav-platform-emergency-rescue": "5.2.0",
"cmii-uav-platform-hljtt": "5.2.0",
"cmii-uav-platform-jiangsuwenlv": "4.1.3-jiangsu-0427",
"cmii-uav-platform-logistics": "5.2.0",
"cmii-uav-platform-media": "5.2.0",
"cmii-uav-platform-multiterminal": "5.2.0",
"cmii-uav-platform-mws": "5.2.0",
"cmii-uav-platform-oms": "5.2.0",
"cmii-uav-platform-open": "5.2.0",
"cmii-uav-platform-qingdao": "4.1.6-24238-qingdao",
"cmii-uav-platform-qinghaitourism": "4.1.0-21377-0508",
"cmii-uav-platform-security": "4.1.6",
"cmii-uav-platform-securityh5": "5.2.0",
"cmii-uav-platform-seniclive": "5.2.0",
"cmii-uav-platform-share": "5.2.0",
"cmii-uav-platform-splice": "5.2.0",
"cmii-uav-platform-threedsimulation": "5.2.0-21392",
"cmii-uav-platform-visualization": "5.2.0"
}

View File

@@ -8,7 +8,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("io.wdd.server.mapper") @MapperScan("io.wdd.server.mapper")
public class ServerApplication { public class ServerApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run( SpringApplication.run(
ServerApplication.class, ServerApplication.class,

View File

@@ -49,7 +49,6 @@ public enum BaseFunctionEnum {
), ),
INSTALL_NFS_ONLINE( INSTALL_NFS_ONLINE(
"installNfsOnline", "installNfsOnline",
"安装nfs-client online" "安装nfs-client online"
@@ -65,6 +64,11 @@ public enum BaseFunctionEnum {
"安装Chrony服务器, 废弃" "安装Chrony服务器, 废弃"
), ),
INSTALL_CHRONY_DOCKER(
"INSTALL_CHRONY_DOCKER",
"安装Chrony服务器, DOCKER版本"
),
CHRONY_TO_PUBLIC_NTP_DISCARD( CHRONY_TO_PUBLIC_NTP_DISCARD(
"chronyToPublicNTP", "chronyToPublicNTP",
"时间同步至公网NTP服务器" "时间同步至公网NTP服务器"

View File

@@ -96,8 +96,8 @@ public class BaseFuncScheduler {
List<BaseFunctionEnum> masterNodeProcedureList = List.of( List<BaseFunctionEnum> masterNodeProcedureList = List.of(
BaseFunctionEnum.DISABLE_SWAP, BaseFunctionEnum.DISABLE_SWAP,
BaseFunctionEnum.DISABLE_SELINUX,
BaseFunctionEnum.SHUTDOWN_FIREWALL, BaseFunctionEnum.SHUTDOWN_FIREWALL,
BaseFunctionEnum.CHRONY_TO_MASTER,
BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY
); );
@@ -132,11 +132,11 @@ public class BaseFuncScheduler {
} }
List<BaseFunctionEnum> masterNodeDurationTaskList = List.of( List<BaseFunctionEnum> masterNodeDurationTaskList = List.of(
BaseFunctionEnum.INSTALL_NFS_SERVER_ONLINE, // BaseFunctionEnum.INSTALL_NFS_SERVER_ONLINE,
BaseFunctionEnum.INSTALL_DOCKER, // BaseFunctionEnum.INSTALL_DOCKER,
BaseFunctionEnum.INSTALL_DOCKER_COMPOSE, // BaseFunctionEnum.INSTALL_DOCKER_COMPOSE,
BaseFunctionEnum.MODIFY_DOCKER_CONFIG, // BaseFunctionEnum.MODIFY_DOCKER_CONFIG,
BaseFunctionEnum.INSTALL_HARBOR // BaseFunctionEnum.INSTALL_HARBOR
); );
for (BaseFunctionEnum durationBaseFunc : masterNodeDurationTaskList) { for (BaseFunctionEnum durationBaseFunc : masterNodeDurationTaskList) {

View File

@@ -53,11 +53,11 @@ public class TestBaseFuncScheduler {
projectDeployContext.setMasterNode(serverInfoPO); projectDeployContext.setMasterNode(serverInfoPO);
// baseFuncScheduler.runProcedure(projectDeployContext); baseFuncScheduler.runProcedure(projectDeployContext);
harborFuncScheduler.runProcedure(projectDeployContext); // harborFuncScheduler.runProcedure(projectDeployContext);
appFuncScheduler.runProcedure(projectDeployContext); // appFuncScheduler.runProcedure(projectDeployContext);
} }
} }