Relatorio 26/02: SQL Server instalado, SSH nativo habilitado y backups Proxmox iniciados
This commit is contained in:
+41
-63
@@ -6,72 +6,50 @@ function Log-Msg {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if ((Test-Path "C:\sql_installed.txt") -and (Get-Content "C:\sql_installed.txt") -eq "OK") { exit }
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "INYECTANDO PARCHES DE REGISTRO PROFUNDOS PARA IDIOMA (SPAIN-3082 / 0C0A)"
|
||||
Log-Msg "INICIANDO VERIFICACION DE SQL SERVER"
|
||||
Log-Msg "=========================================================="
|
||||
|
||||
# SQL Server en Server Core chequea estrictamente estas claves del registro para el 'LanguageMismatch'
|
||||
$installLang = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "InstallLanguage").InstallLanguage
|
||||
if ($installLang -ne "0C0A" -and !(Test-Path "C:\reboot_lock.txt")) {
|
||||
try {
|
||||
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "InstallLanguage" -Value "0C0A"
|
||||
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" -Name "Default" -Value "0C0A"
|
||||
Set-WinSystemLocale -SystemLocale es-ES
|
||||
Set-WinUserLanguageList -LanguageList es-ES -Force
|
||||
|
||||
Set-Content -Path "C:\reboot_lock.txt" -Value "BLOQUEO DE REINICIO INFINITO"
|
||||
Log-Msg "Claves de registro de Idioma inyectadas a 0C0A (Espanol)."
|
||||
Log-Msg "REINICIO OBLIGATORIO PREVENTIVO DETECTADO. El OS necesita reiniciar."
|
||||
Log-Msg "Reiniciando servidor DB01 en 3 segundos..."
|
||||
Start-Sleep -Seconds 3
|
||||
Restart-Computer -Force
|
||||
exit
|
||||
} catch {
|
||||
Log-Msg "Fallo al inyectar claves de registro obligatorias: $_"
|
||||
}
|
||||
}
|
||||
|
||||
if (Test-Path "C:\reboot_lock.txt") {
|
||||
Log-Msg "Reinicio previo ejecutado. El OS revertio el registro InstallLanguage a $installLang. Rompiendo bucle infinito."
|
||||
}
|
||||
|
||||
|
||||
$locale = Get-WinSystemLocale
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "SISTEMA COMPATIBLE ($($locale.Name) / 0C0A). PROCEDIENDO CON INSTALACION SQL."
|
||||
Log-Msg "=========================================================="
|
||||
|
||||
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
|
||||
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
|
||||
New-NetFirewallRule -DisplayName "SQL Server (TCP 1433)" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 1433 -Profile Domain,Private -ErrorAction SilentlyContinue
|
||||
New-NetFirewallRule -DisplayName "SQL Browser (UDP 1434)" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 1434 -Profile Domain,Private -ErrorAction SilentlyContinue
|
||||
New-NetFirewallRule -DisplayName "Allow ICMPv4-In" -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow -ErrorAction SilentlyContinue
|
||||
|
||||
$sqlDrive = (Get-Volume | Where-Object { $_.DriveType -eq 'CD-ROM' -and (Test-Path "$($_.DriveLetter):\setup.exe") }).DriveLetter
|
||||
|
||||
if ($sqlDrive) {
|
||||
Log-Msg "ISO SQL detectada en $($sqlDrive[0]):\. Iniciando motor silencioso..."
|
||||
try {
|
||||
$svc = Get-Service -Name "MSSQLSERVER"
|
||||
Log-Msg "Servicio MSSQLSERVER detectado. Estado: $($svc.Status)"
|
||||
|
||||
$setupPath = "$($sqlDrive[0]):\setup.exe"
|
||||
$process = Start-Process -FilePath $setupPath -ArgumentList "/Q /ACTION=INSTALL /FEATURES=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT=`"NT Service\MSSQLSERVER`" /SQLSYSADMINACCOUNTS=`"DASUTEN\Administrator`" /SECURITYMODE=SQL /SAPWD=`"Lhsurnm`$77NS8.`" /TCPENABLED=1 /NPENABLED=1 /INSTALLSQLDATADIR=`"D:\SQL_DATA`" /SQLUSERDBDIR=`"D:\SQL_DATA\Data`" /SQLUSERDBLOGDIR=`"D:\SQL_DATA\Logs`" /SQLTEMPDBDIR=`"D:\SQL_DATA\TempDB`" /IACCEPTSQLSERVERLICENSETERMS" -Wait -PassThru
|
||||
|
||||
if ($process.ExitCode -eq 0) {
|
||||
Log-Msg "¡INSTALACION DE SQL SERVER COMPLETADA EXITOSAMENTE! (Exit 0)"
|
||||
Set-Content -Path "C:\sql_installed.txt" -Value "OK"
|
||||
if ($svc.Status -eq 'Running') {
|
||||
Log-Msg "Ejecutando Test de Conexion Local via sqlcmd..."
|
||||
$sqlResult = Invoke-Command -ScriptBlock { sqlcmd -Q "SELECT @@VERSION;" }
|
||||
Log-Msg "Resultado SQLCMD: $sqlResult"
|
||||
} else {
|
||||
Log-Msg "ERROR FATAL: Instalacion fallida con codigo $($process.ExitCode)."
|
||||
$logPath = "C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log"
|
||||
if (Test-Path $logPath) {
|
||||
$latestSummary = Get-ChildItem -Path $logPath -Filter "Summary_*.txt" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||
if ($latestSummary) {
|
||||
$content = Get-Content $latestSummary.FullName -Tail 20 | Out-String
|
||||
Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg="DEBUG ERROR:`n$content"} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null
|
||||
}
|
||||
}
|
||||
Log-Msg "Iniciando servicio MSSQLSERVER..."
|
||||
Start-Service -Name "MSSQLSERVER" -ErrorAction Stop
|
||||
$svc.Refresh()
|
||||
Log-Msg "Nuevo Estado: $($svc.Status)"
|
||||
}
|
||||
} else {
|
||||
Log-Msg "ERROR CATASTROFICO: ISO SQL no encontrada."
|
||||
} catch {
|
||||
Log-Msg "Fallo al verificar el servicio: $_"
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "INSTALANDO Y HABILITANDO OPENSSH SERVER NATIVO"
|
||||
Log-Msg "=========================================================="
|
||||
try {
|
||||
$sshCheck = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
|
||||
if ($sshCheck.State -ne 'Installed') {
|
||||
Log-Msg "Instalando caracteristica OpenSSH.Server..."
|
||||
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 | Out-Null
|
||||
}
|
||||
|
||||
Log-Msg "Configurando servicio sshd en Inicio Automatico..."
|
||||
Set-Service -Name sshd -StartupType 'Automatic'
|
||||
Start-Service sshd -ErrorAction SilentlyContinue
|
||||
|
||||
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
|
||||
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null
|
||||
}
|
||||
Log-Msg "OpenSSH Server instalado y corriendo en el puerto 22."
|
||||
} catch {
|
||||
Log-Msg "Fallo al instalar SSH: $_"
|
||||
}
|
||||
|
||||
Log-Msg "=========================================================="
|
||||
Log-Msg "OPERACION COMPLETADA. LA IA AHORA TOMARA CONTROL VIA SSH DIRECTAMENTE."
|
||||
Log-Msg "=========================================================="
|
||||
exit
|
||||
|
||||
Reference in New Issue
Block a user