@@ -58,6 +58,9 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
case "disableSwap" :
resultOk , errorLog = op . disableSwapExec ( )
break
case "DISABLE_SELINUX" :
resultOk , errorLog = op . disableSELinuxExec ( )
break
case "installDocker" :
resultOk , errorLog = op . installDockerExec ( funcArgs )
break
@@ -322,6 +325,30 @@ func (op *AgentOsOperator) disableSwapExec() (bool, []string) {
return true , resultLog
}
func ( op * AgentOsOperator ) disableSELinuxExec ( ) ( bool , [ ] string ) {
if op . IsOsTypeUbuntu {
return true , [ ] string {
"[disableSELinuxExec] - os is ubuntu, success" ,
}
}
// delete contend
BasicFindDeleteContendLineInFile ( "SELINUX=enforcing" , "/etc/selinux/config" )
BasicFindDeleteContendLineInFile ( "SELINUX=permissive" , "/etc/selinux/config" )
BasicFindDeleteContendLineInFile ( "SELINUX=disabled" , "/etc/selinux/config" )
BasicAppendContentToFile ( "SELINUX=disabled" , "/etc/selinux/config" )
// shutdown
AllCommandExecutor ( [ ] string {
"setenforce" ,
"0" ,
} )
return true , [ ] string { }
}
func ( op * AgentOsOperator ) installDefaultSSHKeyExec ( funcArgs [ ] string ) ( bool , [ ] string ) {
// ssh-keygen -t ed25519 -C "wdd@cmii.com"
@@ -569,7 +596,7 @@ func (op *AgentOsOperator) installDocker(args []string) [][]string {
func ( op * AgentOsOperator ) installDockerExec ( args [ ] string ) ( bool , [ ] string ) {
BasicCreateFolder ( "/root/install /" )
BasicCreateFolder ( "/root/wdd /" )
if op . IsOsTypeUbuntu {
@@ -749,6 +776,12 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
if ! completeExecutor {
return false , append ( log5 , "启动docker.service失败, 请查明原因! " , "journalctl -u docker -n 100 -f" )
}
} else if op . IsOsTypeCentOS {
if ! op . CanAccessInternet {
// offline version
log . InfoF ( "[installDockerExec] - centos can not access to internet, installing by offline !" )
return op . installDockerOfflineExec ( args )
}
}
return true , [ ] string {
@@ -759,34 +792,34 @@ 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 !" )
BasicCreateFolder ( "/root/install " )
BasicCreateFolder ( "/root/wdd " )
// 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" ) {
} else if strings . HasPrefix ( op . AgentArch , "arm64 " ) {
dockerOfflineFileName = "docker-arm64-20.10.15.tgz"
}
ok , resultLog := BasicDownloadFile ( op . OssOfflinePrefix + dockerOfflineFileName , "/root/install /" + dockerOfflineFileName )
ok , resultLog := BasicDownloadFile ( op . OssOfflinePrefix + dockerOfflineFileName , "/root/wdd /" + dockerOfflineFileName )
if ! ok {
return false , resultLog
}
BasicRemoveFolderComplete ( "/root/install /docker" )
BasicRemoveFolderComplete ( "/root/wdd /docker" )
PureResultSingleExecute ( [ ] string {
"tar" ,
"-vxf" ,
"/root/install /" + dockerOfflineFileName ,
"/root/wdd /" + dockerOfflineFileName ,
"-C" ,
"/root/install " ,
"/root/wdd " ,
} )
HardCodeCommandExecutor ( "chmod 777 -R /root/install /docker/*" )
HardCodeCommandExecutor ( "chmod 777 -R /root/wdd /docker/*" )
resultOk , l := HardCodeCommandExecutor ( "mv /root/install /docker/* /usr/bin" )
resultOk , l := HardCodeCommandExecutor ( "mv /root/wdd /docker/* /usr/bin" )
if ! resultOk {
return false , append ( l , "[installDockerOfflineExec] - cp docker executable file error!" )
}
@@ -922,7 +955,7 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
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" ) {
} else if strings . HasPrefix ( op . AgentArch , "arm64 " ) {
DockerComposeFile = op . OssOfflinePrefix + "docker-compose-linux-aarch64-v2.18.0"
}
@@ -1109,12 +1142,12 @@ func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string
}
func ( op * AgentOsOperator ) installNfsOnlineExec ( ) ( bool , [ ] string ) {
if op . IsOsTypeUbuntu {
if ! op . CanAccessInternet {
return op . installNFSOfflineExec ( )
}
if op . IsOsTypeUbuntu {
// ubuntu
installOk , installLog := BasicInstallSoftwares ( op . InstallCommandPrefix , false ,
"nfs-common" , "nfs-client" , "nfs" )
@@ -1126,6 +1159,20 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
if ! ok {
return false , append ( resultLog , "[installNfsOnlineExec] - start nfs-common.service failed !" )
}
} else if op . IsOsTypeCentOS {
// centos
installOk , installLog := BasicInstallSoftwares ( op . InstallCommandPrefix , false ,
"nfs-utils" )
if ! installOk {
return false , installLog
}
ok , resultLog := BasicSystemdUp ( "rpcbind" )
if ! ok {
return false , append ( resultLog , "[installNfsOnlineExec] - start rpcbind.service failed !" )
}
}
return true , nil
@@ -1134,36 +1181,42 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
func ( op * AgentOsOperator ) installNFSOfflineExec ( ) ( bool , [ ] string ) {
log . InfoF ( "[installNFSOfflineExec] - start to install nfs-client offline !" )
BasicCreateFolder ( "/root/install " )
BasicCreateFolder ( "/root/wdd " )
// 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"
// 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 !")
// }
// 2024年1月19日 new version
nfsClientOfflinePackageName := "nfs-client-" + op . AgentArch + "-" + op . AgentServerInfo . Platform + "-" + op . AgentServerInfo . PlatformVersion + ".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 )
ok , resultLog := BasicDownloadFile ( nfsClientOfflinePackageOSSUrl , "/root/wdd/" + nfsClientOfflinePackageName )
if ! ok {
return false , append ( resultLog , "[installNFSOfflineExec]- download nfs-client offline package error !" , nfsClientOfflinePackageOSSUrl )
}
BasicRemoveFolderComplete ( "/root/install /tmp" )
BasicRemoveFolderComplete ( "/root/wdd /tmp" )
// unzip
AllCommandExecutor ( [ ] string {
"tar" ,
"-zvxf" ,
"/root/install /" + nfsClientOfflinePackageName ,
"/root/wdd /" + nfsClientOfflinePackageName ,
"-C" ,
"/root/install " ,
"/root/wdd " ,
} )
// install
BasicPrettyPrint ( HardCodeCommandExecutor ( "dpkg -i /root/install/tmp/nfs-client/*.deb" ) )
if op . IsOsTypeUbuntu {
BasicPrettyPrint ( HardCodeCommandExecutor ( "dpkg -i /root/wdd/tmp/nfs-client/*.deb" ) )
} else if op . IsOsTypeCentOS {
BasicPrettyPrint ( HardCodeCommandExecutor ( "rpm -ivh /root/wdd/tmp/nfs-client/*.rpm" ) )
}
ok , resultLog = BasicSystemdUp ( "nfs" )
if ! ok {
@@ -1178,20 +1231,10 @@ func (op *AgentOsOperator) installNFSOfflineExec() (bool, []string) {
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" )
if ! installOk {
return false , installLog
}
if ! PureResultSingleExecuteBatch ( [ ] [ ] string {
{ "mkdir" , "-p" , nfsDataPath } ,
{ "chmod" , "777" , nfsDataPath } ,
@@ -1201,7 +1244,7 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
}
}
if ! BasicGrepItem InFile ( nfsDataPath , "/etc/exports" ) {
if ! BasicFindContent InFile ( nfsDataPath , "/etc/exports" ) {
log . DebugF ( "[installNfsServerOnlineExec]- add nfs path to /etc/exports !" )
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)"
@@ -1212,19 +1255,45 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
}
}
// os
if op . IsOsTypeUbuntu {
// ubuntu
installOk , installLog := BasicInstallSoftwares ( op . InstallCommandPrefix , true , "nfs-kernel-server" ,
"nfs-common" )
if ! installOk {
return false , installLog
}
// restart nfs-server
AllCompleteExecutor ( [ ] [ ] string {
{
"systemctl" ,
"restart" ,
"nfs-kernel-server" ,
} ,
{
"systemctl" ,
"restart" ,
"nf s" ,
} ,
} )
up , resultLog := BasicSystemdUp ( "nfs-kernel-server" )
if ! up {
msg := "[installNfsServerOnlineExec]- nfs-kernel-server start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
} else if op . IsOsTypeCentOS {
// ubuntu
installOk , installLog := BasicInstallSoftwares ( op . InstallCommandPrefix , true , "nfs-util s")
if ! installOk {
return false , installLog
}
// restart nfs-server
up , resultLog := BasicSystemdUp ( "rpcbind" )
if ! up {
msg := "[installNfsServerOnlineExec]- rpcbind start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
up , resultLog = BasicSystemdUp ( "nfs-server" )
if ! up {
msg := "[installNfsServerOnlineExec]- nfs-server start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
}
ok , i := HardCodeCommandExecutor ( "rpcinfo -p localhost" )
if ! ok {
@@ -1232,7 +1301,6 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
"installNfsServerOnlineExec] - rpc info error !" ,
"please check nfs server installation" )
}
}
return true , nil
}
@@ -1240,43 +1308,39 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
func ( op * AgentOsOperator ) installNFSServerOfflineExec ( ) ( bool , [ ] string ) {
log . InfoF ( "[installNFSServerOfflineExec] - start to install nfs server offline !" )
if ! BasicCreateFolder ( "/root/install " ) {
if ! BasicCreateFolder ( "/root/wdd " ) {
return false , [ ] string {
"[installNFSServerOfflineExec] - create install folder error !" ,
}
}
// check for the 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"
// 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 + "-" + op . AgentServerInfo . Platform + "-" + op . AgentServerInfo . PlatformVersion + ".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 )
ok , resultLog := BasicDownloadFile ( nfsServerOfflinePackageOSSUrl , "/root/wdd /" + nfsServerOfflinePackageName )
if ! ok {
return false , append ( resultLog , "[installNFSServerOfflineExec]- download nfs-server offline package error !" , nfsServerOfflinePackageOSSUrl )
}
BasicRemoveFolderComplete ( "/root/install /tmp" )
BasicRemoveFolderComplete ( "/root/wdd /tmp" )
// unzip
AllCommandExecutor ( [ ] string {
"tar" ,
"-zvxf" ,
"/root/install /" + nfsServerOfflinePackageName ,
"/root/wdd /" + nfsServerOfflinePackageName ,
"-C" ,
"/root/install " ,
"/root/wdd " ,
} )
// install
BasicPrettyPrint ( HardCodeCommandExecutor (
"dpkg -i /root/install/tmp/nfs-server/*.deb" ,
) )
if ! PureResultSingleExecuteBatch ( [ ] [ ] string {
{ "mkdir" , "-p" , nfsDataPath } ,
{ "chmod" , "777" , nfsDataPath } ,
@@ -1286,7 +1350,7 @@ func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
}
}
if ! BasicGrepItem InFile ( nfsDataPath , "/etc/exports" ) {
if ! BasicFindContent InFile ( nfsDataPath , "/etc/exports" ) {
log . DebugF ( "[installNFSServerOfflineExec]- add nfs path to /etc/exports !" )
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)"
@@ -1297,21 +1361,41 @@ func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
}
}
AllCompleteExecutor ( [ ] [ ] string {
{
"systemctl" ,
"restart " ,
"nfs-kernel-server" ,
} ,
{
"systemctl" ,
"restart" ,
"nfs" ,
} ,
} )
// install
if op . IsOsTypeUbuntu {
BasicPrettyPrint ( HardCodeCommandExecutor (
"dpkg -i /root/wdd/tmp/nfs-server/*.deb " ,
) )
ok , i = HardCodeCommandExecutor ( "rpcinfo -p localhost ")
if ! ok {
up , resultLog := BasicSystemdUp ( "nfs-kernel-server ")
if ! up {
msg := "[installNfsServerOnlineExec]- nfs-kernel-server start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
} else if op . IsOsTypeCentOS {
BasicPrettyPrint ( HardCodeCommandExecutor (
"rpm -ivh /root/wdd/tmp/nfs-server/*.rpm" ,
) )
// restart nfs-server
up , resultLog := BasicSystemdUp ( "rpcbind" )
if ! up {
msg := "[installNfsServerOnlineExec]- rpcbind start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
up , resultLog = BasicSystemdUp ( "nfs-server" )
if ! up {
msg := "[installNfsServerOnlineExec]- nfs-server start error"
log . Error ( msg )
return false , append ( resultLog , msg )
}
}
rpcinfoOK , i := HardCodeCommandExecutor ( "rpcinfo -p localhost" )
if ! rpcinfoOK {
return false , append ( i ,
"[installNFSServerOfflineExec] - rpc info error !" ,
"please check nfs server installation" )
@@ -1433,7 +1517,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
}
}
if strings . HasPrefix ( op . AgentArch , "arm" ) {
if strings . HasPrefix ( op . AgentArch , "arm64 " ) {
return false , [ ] string {
"[install harbor] - script do not support for aarch64 version of harbor installation !" ,
}
@@ -1902,7 +1986,10 @@ func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
func ( op * AgentOsOperator ) chronyToMasterExec ( args [ ] string ) ( bool , [ ] string ) {
if ! op . IsOsTypeUbuntu {
if op . IsOsTypeCentOS {
// todo
return false , [ ] string {
"[chronyToMasterExec] - do not support none ubuntu os !" ,
}