[agent-go] [Bastion] - basic accomplished !
This commit is contained in:
@@ -233,11 +233,13 @@ func (op *AgentOsOperator) shutdownFirewallExec() (bool, []string) {
|
||||
{"iptables", "-F"},
|
||||
}
|
||||
// 忽略错误
|
||||
_, resultLog := AllCompleteExecutor(shutdownFunc)
|
||||
AllCompleteExecutor(shutdownFunc)
|
||||
|
||||
// centos
|
||||
|
||||
return true, resultLog
|
||||
return true, []string{
|
||||
"[shutdownFirewallExec] - 关闭防火墙成功!",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) modifyHostname(args []string) [][]string {
|
||||
@@ -258,15 +260,45 @@ func (op *AgentOsOperator) modifyHostnameExec(args []string) (bool, []string) {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) modifySystemConfigExec() (bool, []string) {
|
||||
sysctlConfigFile := "/etc/sysctl.d/wdd-k8s.conf"
|
||||
|
||||
// ssh config
|
||||
// system redirection
|
||||
if !BasicFileExistAndNotNull(sysctlConfigFile) {
|
||||
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+"systemctl-config-template.txt", "", "", "", sysctlConfigFile)
|
||||
if !ok {
|
||||
return false, resultLog
|
||||
}
|
||||
}
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"sysctl",
|
||||
"-p",
|
||||
sysctlConfigFile,
|
||||
})
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) ModifySysConfigBastion() (bool, []string) {
|
||||
return op.modifySystemConfigExec()
|
||||
|
||||
sysctlConfigFile := "/etc/sysctl.d/wdd-k8s.conf"
|
||||
|
||||
if !BasicAppendOverwriteContentToFile(beans.SysctlConfig, sysctlConfigFile) {
|
||||
return false, []string{
|
||||
"[ModifySysConfigBastion] - error appending sysctl config to sysctl.d !",
|
||||
}
|
||||
}
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"sysctl",
|
||||
"-p",
|
||||
sysctlConfigFile,
|
||||
})
|
||||
|
||||
return true, []string{
|
||||
"[ModifySysConfigBastion] - success !",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) enableSwap() [][]string {
|
||||
@@ -370,7 +402,9 @@ func (op *AgentOsOperator) disableSELinuxExec() (bool, []string) {
|
||||
"0",
|
||||
})
|
||||
|
||||
return true, []string{}
|
||||
return true, []string{
|
||||
"[disableSELinuxExec] - success",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) DisableSelinuxBastion() (bool, []string) {
|
||||
@@ -417,7 +451,9 @@ func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []
|
||||
|
||||
// check
|
||||
if BasicGrepItemInFile("wdd@cmii.com", "/root/.ssh/authorized_keys") {
|
||||
return true, nil
|
||||
return true, []string{
|
||||
"[installDefaultSSHKeyExec] - authorized_keys contain the ssh-pub key !",
|
||||
}
|
||||
}
|
||||
|
||||
return false, []string{
|
||||
@@ -444,7 +480,7 @@ func (op *AgentOsOperator) InstallDefaultSshBastion() (bool, []string) {
|
||||
"[installDefaultSSHKeyExec] - error appending private ssh key to authorized_keys !",
|
||||
}
|
||||
}
|
||||
if !BasicAppendOverwriteContentToFile(beans.Ed25519PublicKey, "/root/.ssh/id_ed25519.pu") {
|
||||
if !BasicAppendOverwriteContentToFile(beans.Ed25519PublicKey, "/root/.ssh/id_ed25519.pub") {
|
||||
return false, []string{
|
||||
"[installDefaultSSHKeyExec] - error appending public ssh key to authorized_keys !",
|
||||
}
|
||||
@@ -466,7 +502,9 @@ func (op *AgentOsOperator) InstallDefaultSshBastion() (bool, []string) {
|
||||
// check
|
||||
if BasicGrepItemInFile("wdd@cmii.com", "/root/.ssh/authorized_keys") {
|
||||
log.Info("installDefaultSSHKeyExec - authorized_keys contain the ssh-pub key !")
|
||||
return true, nil
|
||||
return true, []string{
|
||||
"[InstallDefaultSshBastion] - install success !",
|
||||
}
|
||||
}
|
||||
|
||||
return false, []string{
|
||||
@@ -504,6 +542,12 @@ func (op *AgentOsOperator) removeDocker() [][]string {
|
||||
|
||||
func (op *AgentOsOperator) removeDockerExec() (bool, []string) {
|
||||
|
||||
if !BasicCommandExistByPath("docker") {
|
||||
return true, []string{
|
||||
"[removeDockerExec] - docker is not installed !",
|
||||
}
|
||||
}
|
||||
|
||||
dockerServiceStopCommand := [][]string{
|
||||
{
|
||||
"systemctl",
|
||||
@@ -1236,13 +1280,13 @@ func (op *AgentOsOperator) InstallDockerComposeBastion() (bool, []string) {
|
||||
|
||||
var DockerComposeFile string
|
||||
if strings.HasPrefix(op.AgentArch, "amd") {
|
||||
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0"
|
||||
DockerComposeFile = OctopusAgentInstallPrefix + "docker-compose-linux-x86_64-v2.18.0"
|
||||
} else if strings.HasPrefix(op.AgentArch, "arm64") {
|
||||
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-aarch64-v2.18.0"
|
||||
DockerComposeFile = OctopusAgentInstallPrefix + "docker-compose-linux-aarch64-v2.18.0"
|
||||
}
|
||||
|
||||
// check file exits
|
||||
if !BasicFileExistInFolder(DockerComposeFile) {
|
||||
if !BasicFileExistAndNotNull(DockerComposeFile) {
|
||||
sprintf := fmt.Sprintf("docker-compose 离线安装文件不存在! => %s", DockerComposeFile)
|
||||
return false, []string{
|
||||
sprintf,
|
||||
@@ -1250,6 +1294,11 @@ func (op *AgentOsOperator) InstallDockerComposeBastion() (bool, []string) {
|
||||
}
|
||||
|
||||
AllCompleteExecutor([][]string{
|
||||
{
|
||||
"mv",
|
||||
DockerComposeFile,
|
||||
"/usr/local/bin/docker-compose",
|
||||
},
|
||||
{
|
||||
"chmod", "+x", "/usr/local/bin/docker-compose",
|
||||
},
|
||||
@@ -1259,6 +1308,12 @@ func (op *AgentOsOperator) InstallDockerComposeBastion() (bool, []string) {
|
||||
})
|
||||
log.Info("docker-compose安装成功!")
|
||||
|
||||
if !BasicCommandExistByPath("docker-compose") {
|
||||
return false, []string{
|
||||
"[InstallDockerComposeBastion] - docker-compose 安装失败!",
|
||||
}
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[InstallDockerComposeBastion] - docker-compose offline installation from local success!",
|
||||
}
|
||||
@@ -1378,12 +1433,46 @@ func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
|
||||
}
|
||||
func (op *AgentOsOperator) ModifyDockerConfigBastion() (bool, []string) {
|
||||
|
||||
argList := []string{
|
||||
"127.0.0.1",
|
||||
dockerDaemonFile := "/etc/docker/daemon.json"
|
||||
// check docker daemon json exist
|
||||
if BasicFileExistAndNotNull(dockerDaemonFile) {
|
||||
AllCommandExecutor([]string{
|
||||
"mv",
|
||||
dockerDaemonFile,
|
||||
"/etc/docker/daemon-json.backup",
|
||||
})
|
||||
}
|
||||
return op.modifyDockerConfigExec(argList)
|
||||
}
|
||||
|
||||
// download new
|
||||
if !BasicAppendOverwriteContentToFile(beans.DockerDeamonConfig, dockerDaemonFile) {
|
||||
return false, []string{
|
||||
"[ModifyDockerConfigBastion] - modify docker daemon config error !",
|
||||
}
|
||||
}
|
||||
|
||||
if !BasicReplace(dockerDaemonFile, "DockerRegisterDomain", op.AgentServerInfo.ServerIPInV4) {
|
||||
return false, []string{
|
||||
"[ModifyDockerConfigBastion] - modify docker daemon config error !",
|
||||
}
|
||||
}
|
||||
log.InfoF("[ModifyDockerConfigBastion] - 修改docker配置成功! => %s", op.AgentServerInfo.ServerIPInV4)
|
||||
|
||||
// restart docker
|
||||
if !PureResultSingleExecute([]string{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"docker.service",
|
||||
}) {
|
||||
return false, []string{
|
||||
"[ModifyDockerConfigBastion] - restart docker.service error !",
|
||||
}
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[ModifyDockerConfigBastion] - 修改docker配置成功!",
|
||||
}
|
||||
|
||||
}
|
||||
func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string) {
|
||||
|
||||
dockerDaemonFile := "/etc/docker/daemon.json"
|
||||
@@ -1438,7 +1527,7 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
|
||||
if op.IsOsTypeUbuntu {
|
||||
|
||||
// ubuntu
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false,
|
||||
installOk, installLog := BasicInstallSoftware(op.InstallCommandPrefix, false,
|
||||
"nfs-common", "nfs-client", "nfs")
|
||||
if !installOk {
|
||||
return false, installLog
|
||||
@@ -1451,7 +1540,7 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
|
||||
} else if op.IsOsTypeCentOS {
|
||||
|
||||
// centos
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false,
|
||||
installOk, installLog := BasicInstallSoftware(op.InstallCommandPrefix, false,
|
||||
"nfs-utils")
|
||||
if !installOk {
|
||||
return false, installLog
|
||||
@@ -1547,7 +1636,7 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
|
||||
// os
|
||||
if op.IsOsTypeUbuntu {
|
||||
// ubuntu
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-kernel-server",
|
||||
installOk, installLog := BasicInstallSoftware(op.InstallCommandPrefix, true, "nfs-kernel-server",
|
||||
"nfs-common")
|
||||
if !installOk {
|
||||
return false, installLog
|
||||
@@ -1563,7 +1652,7 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
|
||||
|
||||
} else if op.IsOsTypeCentOS {
|
||||
// ubuntu
|
||||
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-utils")
|
||||
installOk, installLog := BasicInstallSoftware(op.InstallCommandPrefix, true, "nfs-utils")
|
||||
if !installOk {
|
||||
return false, installLog
|
||||
}
|
||||
@@ -1762,7 +1851,7 @@ func (op *AgentOsOperator) installHarbor() [][]string {
|
||||
}
|
||||
func (op *AgentOsOperator) checkHarborInstallExec() (bool, []string) {
|
||||
// check docker-compose
|
||||
if !BasicCommandExistByPath("/usr/local/bin/docker-compose") {
|
||||
if !BasicCommandExistByPath("docker-compose") {
|
||||
return false, []string{
|
||||
"[install harbor] - docker-compose uninstalled ! can't install harbor!",
|
||||
}
|
||||
@@ -1809,7 +1898,9 @@ func (op *AgentOsOperator) checkHarborInstallExec() (bool, []string) {
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return true, []string{
|
||||
"[install harbor] - check harbor installation environment success !",
|
||||
}
|
||||
}
|
||||
|
||||
// installHarborExec install harbor offline
|
||||
@@ -1912,7 +2003,8 @@ func (op *AgentOsOperator) InstallHarborBastion() (bool, []string) {
|
||||
|
||||
// local file check exists
|
||||
if !BasicFileExistAndNotNull("/root/wdd/harbor-offline-installer-v2.9.0.tgz") {
|
||||
return false, []string{"[InstallHarborBastion] - harbor offline installer not exists !"}
|
||||
sprintf := fmt.Sprintf("[InstallHarborBastion] - harbor offline installer not exists ! => %s", "/root/wdd/harbor-offline-installer-v2.9.0.tgz")
|
||||
return false, []string{sprintf}
|
||||
}
|
||||
|
||||
// unzip
|
||||
@@ -2350,7 +2442,7 @@ func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
|
||||
}
|
||||
|
||||
// install ntp
|
||||
installSoftwares, i := BasicInstallSoftwares(op.InstallCommandPrefix, true, "ntp")
|
||||
installSoftwares, i := BasicInstallSoftware(op.InstallCommandPrefix, true, "ntp")
|
||||
if !installSoftwares {
|
||||
msg := "[chronyToMasterExec] - centos install ntp error!"
|
||||
log.ErrorF(msg)
|
||||
|
||||
Reference in New Issue
Block a user