[ Agent ] [ App ] - 完全全部的离线安装脚本
This commit is contained in:
@@ -573,8 +573,16 @@ func (op *AgentOsOperator) installDocker(args []string) [][]string {
|
||||
|
||||
func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
|
||||
BasicCreateFolder("/root/install/")
|
||||
|
||||
if op.IsOsTypeUbuntu {
|
||||
|
||||
if !op.CanAccessInternet {
|
||||
// offline version
|
||||
log.InfoF("[installDockerExec] - can not access to internet, installing by offline !")
|
||||
return op.installDockerOfflineExec(args)
|
||||
}
|
||||
|
||||
installDependencyCommand := append(op.InstallCommandPrefix, []string{
|
||||
"apt-transport-https",
|
||||
"ca-certificates",
|
||||
@@ -752,6 +760,81 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDockerOfflineExec(args []string) (bool, []string) {
|
||||
|
||||
log.InfoF("[installDockerOfflineExec] - install docker 20.10.15 by offline method !")
|
||||
|
||||
// download static binary installer of docker
|
||||
var dockerOfflineFileName string
|
||||
if strings.HasPrefix(op.AgentArch, "amd") {
|
||||
dockerOfflineFileName = "docker-amd64-20.10.15.tgz"
|
||||
} else if strings.HasPrefix(op.AgentArch, "arm") {
|
||||
dockerOfflineFileName = "docker-arm64-20.10.15.tgz"
|
||||
}
|
||||
|
||||
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+dockerOfflineFileName, "/root/install/"+dockerOfflineFileName)
|
||||
if !ok {
|
||||
return false, resultLog
|
||||
}
|
||||
PureResultSingleExecute([]string{
|
||||
"tar",
|
||||
"-vxf",
|
||||
"/root/install/" + dockerOfflineFileName,
|
||||
"-C",
|
||||
"/root/install",
|
||||
})
|
||||
|
||||
resultOk, l := AllCompleteExecutor([][]string{
|
||||
{
|
||||
"chmod",
|
||||
"777",
|
||||
"-R",
|
||||
"/root/install/docker/*",
|
||||
},
|
||||
{
|
||||
"mv",
|
||||
"/root/install/docker/*",
|
||||
"/usr/bin",
|
||||
},
|
||||
})
|
||||
if !resultOk {
|
||||
return false, append(l, "[installDockerOfflineExec] - cp docker executable file error!")
|
||||
}
|
||||
|
||||
// systemd daemonize docker
|
||||
downloadOk, log2 := BasicDownloadFile(op.OssOfflinePrefix+"docker-containerd-daemon.service", "/lib/systemd/system/containerd.service")
|
||||
if !downloadOk {
|
||||
return false, append(log2, "[installDockerOfflineExec] - daemon file download error !")
|
||||
}
|
||||
|
||||
downloadOk, log2 = BasicDownloadFile(op.OssOfflinePrefix+"docker-socket-daemon.service", "/lib/systemd/system/docker.socket")
|
||||
if !downloadOk {
|
||||
return false, append(log2, "[installDockerOfflineExec] - daemon file download error !")
|
||||
}
|
||||
|
||||
downloadOk, log2 = BasicDownloadFile(op.OssOfflinePrefix+"docker-daemon.service", "/lib/systemd/system/docker.service")
|
||||
if !downloadOk {
|
||||
return false, append(log2, "[installDockerOfflineExec] - daemon file download error !")
|
||||
}
|
||||
|
||||
// run the docker
|
||||
executor, log3 := AllCommandExecutor([]string{
|
||||
"systemctl",
|
||||
"daemon-reload",
|
||||
})
|
||||
if !executor {
|
||||
return false, append(log3, "[installDockerOfflineExec] - daemon reload error !")
|
||||
}
|
||||
up, log4 := BasicSystemdUp("docker")
|
||||
if !up {
|
||||
return false, append(log4, "[installDockerOfflineExec] - start docker service error !")
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[installDockerOfflineExec] - docker offline installation success!",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDockerCompose() [][]string {
|
||||
|
||||
installDockerComposeFunc := [][]string{
|
||||
@@ -807,17 +890,16 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
|
||||
return false, []string{"离线下载OSS地址不存在! 无法安装 docker-compose"}
|
||||
}
|
||||
|
||||
DockerComposeFile := op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0"
|
||||
var DockerComposeFile string
|
||||
if strings.HasPrefix(op.AgentArch, "amd") {
|
||||
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0"
|
||||
} else if strings.HasPrefix(op.AgentArch, "arm") {
|
||||
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-aarch64-v2.18.0"
|
||||
}
|
||||
|
||||
log.InfoF("需要安装的docker版本为 => %s", DockerComposeFile)
|
||||
|
||||
ok, resultLog := AllCommandExecutor([]string{
|
||||
"curl",
|
||||
"--connect-timeout",
|
||||
"10",
|
||||
DockerComposeFile,
|
||||
"-o",
|
||||
"/usr/local/bin/docker-compose",
|
||||
})
|
||||
ok, resultLog := BasicDownloadFile(DockerComposeFile, "/usr/local/bin/docker-compose")
|
||||
if !ok {
|
||||
return false, resultLog
|
||||
}
|
||||
@@ -914,7 +996,9 @@ func (op *AgentOsOperator) installHelm() [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installHelmExec() (bool, []string) {
|
||||
return true, nil
|
||||
return true, []string{
|
||||
"[installHelmExec] - pretend to install helm success !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
|
||||
@@ -997,6 +1081,11 @@ func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string
|
||||
|
||||
func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
|
||||
if op.IsOsTypeUbuntu {
|
||||
|
||||
if !op.CanAccessInternet {
|
||||
return op.installNFSOfflineExec()
|
||||
}
|
||||
|
||||
// ubuntu
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false,
|
||||
"nfs-common", "nfs-client", "nfs")
|
||||
@@ -1013,10 +1102,58 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installNFSOfflineExec() (bool, []string) {
|
||||
|
||||
// check for version
|
||||
executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'")
|
||||
if !executor {
|
||||
return false, append(i, "[installNFSOfflineExec]- get offline package name suffix error !")
|
||||
}
|
||||
nfsClientOfflinePackageName := "nfs-client-" + op.AgentArch + "-" + i[0] + ".tar.gz"
|
||||
|
||||
// download from oss
|
||||
nfsClientOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsClientOfflinePackageName
|
||||
log.InfoF("[installNFSOfflineExec]- start to download nfs-client offline package from => %s", nfsClientOfflinePackageOSSUrl)
|
||||
ok, resultLog := BasicDownloadFile(nfsClientOfflinePackageOSSUrl, "/root/install/"+nfsClientOfflinePackageName)
|
||||
if !ok {
|
||||
return false, append(resultLog, "[installNFSOfflineExec]- download nfs-client offline package error !", nfsClientOfflinePackageOSSUrl)
|
||||
}
|
||||
// unzip
|
||||
AllCommandExecutor([]string{
|
||||
"tar",
|
||||
"-zvxf",
|
||||
"/root/install/" + nfsClientOfflinePackageName,
|
||||
"-C",
|
||||
"/root/install",
|
||||
})
|
||||
|
||||
// install
|
||||
AllCommandExecutor([]string{
|
||||
"dpkg",
|
||||
"-i",
|
||||
"/root/install/tmp/nfs-client/*.deb",
|
||||
})
|
||||
|
||||
ok, resultLog = BasicSystemdUp("nfs")
|
||||
if !ok {
|
||||
return false, append(resultLog, "[installNFSOfflineExec] - start nfs-common.service failed !")
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[installNFSOfflineExec] - install success !",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
|
||||
|
||||
// os
|
||||
if op.IsOsTypeUbuntu {
|
||||
|
||||
if !op.CanAccessInternet {
|
||||
return op.installNFSServerOfflineExec()
|
||||
}
|
||||
|
||||
// ubuntu
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-kernel-server",
|
||||
"nfs-common")
|
||||
@@ -1049,12 +1186,12 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
|
||||
{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"nfs-server",
|
||||
"nfs-kernel-server",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"nf",
|
||||
"nfs",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1069,6 +1206,84 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
|
||||
|
||||
// check for version
|
||||
executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'")
|
||||
if !executor {
|
||||
return false, append(i, "[installNFSServerOfflineExec]- get offline package name suffix error !")
|
||||
}
|
||||
nfsServerOfflinePackageName := "nfs-server-" + op.AgentArch + "-" + i[0] + ".tar.gz"
|
||||
|
||||
// download from oss
|
||||
nfsServerOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsServerOfflinePackageName
|
||||
log.InfoF("[installNFSServerOfflineExec]- start to download nfs-server offline package from => %s", nfsServerOfflinePackageOSSUrl)
|
||||
ok, resultLog := BasicDownloadFile(nfsServerOfflinePackageOSSUrl, "/root/install/"+nfsServerOfflinePackageName)
|
||||
if !ok {
|
||||
return false, append(resultLog, "[installNFSServerOfflineExec]- download nfs-server offline package error !", nfsServerOfflinePackageOSSUrl)
|
||||
}
|
||||
|
||||
// unzip
|
||||
AllCommandExecutor([]string{
|
||||
"tar",
|
||||
"-zvxf",
|
||||
"/root/install/" + nfsServerOfflinePackageName,
|
||||
"-C",
|
||||
"/root/install",
|
||||
})
|
||||
|
||||
// install
|
||||
AllCommandExecutor([]string{
|
||||
"dpkg",
|
||||
"-i",
|
||||
"/root/install/tmp/nfs-server/*.deb",
|
||||
})
|
||||
|
||||
if !PureResultSingleExecuteBatch([][]string{
|
||||
{"mkdir", "-p", nfsDataPath},
|
||||
{"chmod", "777", nfsDataPath},
|
||||
}) {
|
||||
return false, []string{
|
||||
"[installNFSServerOfflineExec]- create nfs data folder failed !",
|
||||
}
|
||||
}
|
||||
|
||||
if !BasicGrepItemInFile(nfsDataPath, "/etc/exports") {
|
||||
log.DebugF("[installNFSServerOfflineExec]- add nfs path to /etc/exports !")
|
||||
|
||||
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)"
|
||||
if !BasicAppendContentToFile(nfsExport, "/etc/exports") {
|
||||
return false, []string{
|
||||
"[installNFSServerOfflineExec]- add nfs path to /etc/exports failed !",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AllCompleteExecutor([][]string{
|
||||
{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"nfs-kernel-server",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"nfs",
|
||||
},
|
||||
})
|
||||
|
||||
ok, i = HardCodeCommandExecutor("rpcinfo -p localhost")
|
||||
if !ok {
|
||||
return false, append(i,
|
||||
"[installNFSServerOfflineExec] - rpc info error !",
|
||||
"please check nfs server installation")
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[installNFSServerOfflineExec] - install success !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installHarbor() [][]string {
|
||||
|
||||
installHarborFunc := [][]string{
|
||||
@@ -1180,6 +1395,12 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(op.AgentArch, "arm") {
|
||||
return false, []string{
|
||||
"[install harbor] - script do not support for aarch64 version of harbor installation !",
|
||||
}
|
||||
}
|
||||
|
||||
// download offline file
|
||||
harborOfflineFileURL := op.OssOfflinePrefix + "harbor-offline-installer-v2.9.0.tgz"
|
||||
log.InfoF("[install harbor] - start to download harbor offline installer from => %s !", harborOfflineFileURL)
|
||||
@@ -1531,15 +1752,9 @@ func (op *AgentOsOperator) installChronyExec() (bool, []string) {
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
//resultOk, l := AllCommandExecutor(
|
||||
// append(
|
||||
// op.RemoveCommandPrefix,
|
||||
// "systemd-timesyncd.service",
|
||||
// ),
|
||||
//)
|
||||
//if !resultOk{
|
||||
// return false, l
|
||||
//}
|
||||
if !op.IsOsTypeUbuntu || !op.CanAccessInternet {
|
||||
return op.installChronyByDockerExec()
|
||||
}
|
||||
|
||||
// install chrony
|
||||
resultOk, l := AllCommandExecutor(
|
||||
@@ -1569,7 +1784,69 @@ func (op *AgentOsOperator) installChronyExec() (bool, []string) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installChronyByDockerExec() (bool, []string) {
|
||||
|
||||
// check docker
|
||||
if !BasicCommandExistByPath("docker") {
|
||||
return false, []string{
|
||||
"[installChronyByDockerExec] - docker not installed exited !",
|
||||
}
|
||||
}
|
||||
|
||||
// check image exists
|
||||
if !BasicDockerImageExists("simonrupf/chronyd", "0.4.3") {
|
||||
return false, []string{
|
||||
"[installChronyByDockerExec] - docker image not exists !",
|
||||
}
|
||||
}
|
||||
|
||||
// run docker command
|
||||
ok, resultLog := AllCommandExecutor([]string{
|
||||
"docker",
|
||||
"run",
|
||||
"-name=chrony",
|
||||
"--restart=always",
|
||||
"--detach",
|
||||
"--publish=123:123/udp",
|
||||
"--env=NTP_SERVERS=\"ntp1.aliyun.com,ntp2.aliyun.com,ntp3.aliyun.com,ntp4.aliyun.com\"",
|
||||
"--env=LOG_LEVEL=0",
|
||||
"simonrupf/chronyd",
|
||||
})
|
||||
if !ok {
|
||||
return false, append(resultLog, "[installChronyByDockerExec] - docker chrony run error !")
|
||||
}
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"docker",
|
||||
"exec",
|
||||
"chrony",
|
||||
"chronyc",
|
||||
"tracking",
|
||||
})
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"docker",
|
||||
"exec",
|
||||
"chrony",
|
||||
"chronyc",
|
||||
"sources",
|
||||
})
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"docker",
|
||||
"exec",
|
||||
"chrony",
|
||||
"chronyc",
|
||||
"sourcestats",
|
||||
})
|
||||
|
||||
return true, []string{
|
||||
"[installChronyByDockerExec] - install success !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
|
||||
|
||||
masterInnerIP := args[0]
|
||||
|
||||
chronyToMasterFunc := [][]string{
|
||||
@@ -1607,7 +1884,16 @@ func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
|
||||
return true, nil
|
||||
|
||||
if !op.IsOsTypeUbuntu {
|
||||
return false, []string{
|
||||
"[chronyToMasterExec] - do not support none ubuntu os !",
|
||||
}
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[chronyToMasterExec] - install success !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installZSH() [][]string {
|
||||
@@ -1739,7 +2025,14 @@ func (op *AgentOsOperator) installZSH() [][]string {
|
||||
|
||||
func (op *AgentOsOperator) installZSHExec() (bool, []string) {
|
||||
|
||||
log.Info("开始安装ZSH!")
|
||||
log.Info("[installZSHExec] - 开始安装ZSH!")
|
||||
|
||||
if !op.CanAccessInternet {
|
||||
return false, []string{
|
||||
"[installZSHExec] - can not access to internet, zsh install failed !",
|
||||
}
|
||||
}
|
||||
|
||||
ok, resultLog := AllCompleteExecutor([][]string{
|
||||
{
|
||||
"rm",
|
||||
|
||||
@@ -115,6 +115,36 @@ func BasicGrepItemInFile(item string, fileName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func BasicDockerImageExists(imageName, imageVersion string) bool {
|
||||
|
||||
if !BasicCommandExistByPath("docker") {
|
||||
return false
|
||||
}
|
||||
|
||||
ok, _ := PipelineCommandExecutor([][]string{
|
||||
{
|
||||
"docker",
|
||||
"image",
|
||||
"ls",
|
||||
},
|
||||
{
|
||||
"grep",
|
||||
imageName,
|
||||
},
|
||||
{
|
||||
"grep",
|
||||
"-q",
|
||||
imageVersion,
|
||||
},
|
||||
})
|
||||
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func BasicInstallSoftwares(installPrefix []string, isStrict bool, softwares ...string) (bool, []string) {
|
||||
|
||||
var installLog []string
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -27,7 +27,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<java.version>17</java.version>
|
||||
<spring-shell.version>2.1.3</spring-shell.version>
|
||||
<spring-boot-admin.version>2.7.4</spring-boot-admin.version>
|
||||
<spring-cloud.version>Hoxton.SR12</spring-cloud.version>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<description>server</description>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
Reference in New Issue
Block a user