Skip to content

Instantly share code, notes, and snippets.

@bferg314
Last active January 25, 2019 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bferg314/478c438b167ef6aa6d450916e152986f to your computer and use it in GitHub Desktop.
Save bferg314/478c438b167ef6aa6d450916e152986f to your computer and use it in GitHub Desktop.
Download and Install ELK on Windows
# This install script will...
# Download and install ELK
# Install X-Pack
# Launch Elastic
# Run the set password script for elastic
# Change the version and the install path to whatever you want
$elk_version = "6.2.0"
$install_path = "c:/apps"
Add-Type -AssemblyName System.IO.Compression.FileSystem
Import-Module BitsTransfer
function Unzip
{
param([string]$zipfile, [string]$outpath)
Write-Host "Unziping $zipfile to $outpath"
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
Write-Host "$zipfile successfully unzipped to $outpath"
Write-Host ""
}
function dl{
param([string]$url, [string]$path)
if (!(Test-Path $path)) {
Write-Host "Downloading $url to $path"
Start-BitsTransfer -Source $url -Destination $path
# Invoke-WebRequest -Uri $url -OutFile $path
Write-Host "Successfully dowloaded $url to $path"
}
else {
Write-Host "$path already exists, skipping..."
}
Write-Host ""
}
Write-Host "Beginning to gather ELK & X-pack"
# Create the install path
if (!(Test-Path $install_path)) {
New-Item -ItemType directory -Path $install_path
}
# Set the proxy if required
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
# Set some paths
$file = "elasticsearch-$elk_version.zip"
$e_path = Join-Path $install_path $file
$url = "https://artifacts.elastic.co/downloads/elasticsearch/$file"
dl $url $e_path
$file = "logstash-$elk_version.zip"
$l_path = Join-Path $install_path $file
$url = "https://artifacts.elastic.co/downloads/logstash/$file"
dl $url $l_path
$file = "kibana-$elk_version-windows-x86_64.zip"
$k_path = Join-Path $install_path $file
$url = "https://artifacts.elastic.co/downloads/kibana/$file"
dl $url $k_path
$file = "x-pack-$elk_version.zip"
$x_path = Join-Path $install_path $file
$url = "https://artifacts.elastic.co/downloads/packs/x-pack/$file"
dl $url $x_path
Write-Host ""
Write-Host "File gathering complete... Unzipping."
Write-Host ""
$paths = $e_path, $l_path, $k_path
foreach ($path in $paths) {
$dir = Join-Path $install_path ([System.Io.Path]::GetFileNameWithoutExtension($path))
if (!(Test-Path $dir)) {
Unzip $path $install_path
}
else {
Write-Host "$dir already exists, skip unzip."
}
}
Write-Host ""
Write-Host "Unzipped... Installing X-Pack."
Write-Host ""
if (!(Test-Path (Join-Path $install_path "logstash-$elk_version\vendor\bundle\jruby\2.3.0\gems\x-pack-$elk_version-java"))) {
Write-Host "Installing LogStash X-Pack"
Set-Location (Join-Path $install_path "logstash-$elk_version\bin")
& .\logstash-plugin.bat install "file:///$install_path/x-pack-$elk_version.zip"
Write-Host "LogStash X-Pack Install Complete"
}
else {
Write-Host "LogStash already has X-Pack installed!"
}
if (!(Test-Path (Join-Path $install_path "kibana-$elk_version-windows-x86_64\plugins\x-pack"))) {
Write-Host "Installing Kibana X-Pack"
Set-Location (Join-Path $install_path "kibana-$elk_version-windows-x86_64\bin")
& .\kibana-plugin.bat install "file:///$install_path/x-pack-$elk_version.zip"
Write-Host "Kibana X-Pack Install Complete"
}
else {
Write-Host "Kibana already has X-Pack installed!"
}
if (!(Test-Path (Join-Path $install_path "elasticsearch-$elk_version\plugins\x-pack"))) {
Write-Host "Installing Elastic X-Pack"
Set-Location (Join-Path $install_path "elasticsearch-$elk_version\bin")
& .\elasticsearch-plugin.bat install --batch "file:///$install_path/x-pack-$elk_version.zip"
Write-Host "Elastic X-Pack Install Complete... Starting Elastic so you can configure security."
Write-Host "Launching Elastic in an external process..."
& Set-Location (Join-Path $install_path "elasticsearch-$elk_version\bin")
Start-Process "elasticsearch.bat"
Read-Host 'Wait for Elastic to start, the press enter to configure security...'
Write-Host "======================================"
Write-Host ""
& Set-Location (Join-Path $install_path "elasticsearch-$elk_version\bin\x-pack")
& .\setup-passwords.bat interactive
}
else {
Write-Host "Elastic already has X-Pack installed!"
}
Write-Host "DON'T FORGET TO UPDATE kibana.yml WITH THE APPROPRIATE USERNAME AND PASSWORD!"
Write-Host ""
Write-Host "Install completed..."
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment