1 Star 0 Fork 0

OPLG / DataKit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
install.ps1.template 14.12 KB
一键复制 编辑 原始数据 按行查看 历史
tanb 提交于 2023-06-20 17:07 . feat: enable pprof by default
# DataKit install script for Windows
# Tue Aug 10 22:47:16 PDT 2021
# Author: tanb
Set-ExecutionPolicy Bypass -scope Process -Force
# See https://stackoverflow.com/a/4647985/342348
function Write-COutput($ForegroundColor) {
# save the current color
$fc = $host.UI.RawUI.ForegroundColor
# set the new color
$host.UI.RawUI.ForegroundColor = $ForegroundColor
# output
if ($args) {
Write-Output $args
}
else {
$input | Write-Output
}
# restore the original color
$host.UI.RawUI.ForegroundColor = $fc
}
# https://gist.github.com/markembling/173887
# usage: remove-host $file $args[1]
function remove-host([string]$filename, [string]$hostname) {
$c = Get-Content $filename
$newLines = @()
foreach ($line in $c) {
$bits = [regex]::Split($line, "\t+")
if ($bits.count -eq 2) {
if ($bits[1] -ne $hostname) {
$newLines += $line
}
} else {
$newLines += $line
}
}
# Write file
Clear-Content $filename
foreach ($line in $newLines) {
$line | Out-File -encoding ASCII -append $filename
}
}
##########################
# Detect variables
##########################
$installer_base_url = "https://{{.InstallBaseURL}}"
$x = [Environment]::GetEnvironmentVariable("DK_INSTALLER_BASE_URL")
if ($x -ne $null) {
$installer_base_url = $x
Write-COutput yellow "* set install base URL to $x"
}
$domain = @(
"static.guance.com"
"openway.guance.com"
"dflux-dial.guance.com"
"static.dataflux.cn"
"openway.dataflux.cn"
"dflux-dial.dataflux.cn"
"zhuyun-static-files-production.oss-cn-hangzhou.aliyuncs.com"
)
$x = [Environment]::GetEnvironmentVariable("DK_UPGRADE")
if ($x -ne $null) {
$upgrade = $x
Write-COutput green ("* set upgrade" )
}
$upgrade_manager = "0"
$x = [Environment]::GetEnvironmentVariable("DK_UPGRADE_MANAGER")
if ( ($x -ne $null) -and ($x -gt 0) ) {
$upgrade_manager = "1"
Write-COutput green ("* set upgrade_manager" )
}
$x = [Environment]::GetEnvironmentVariable("DK_UPGRADE_IP_WHITELIST")
if ($x -ne $null) {
$upgrade_ip_whitelist = $x
Write-COutput green ("* set upgrade_ip_whitelist" )
}
$x = [Environment]::GetEnvironmentVariable("DK_DATAWAY")
if ($x -ne $null) {
$dataway = $x
Write-COutput green ("* set dataway to $dataway" )
}
$http_listen = "localhost"
$x = [Environment]::GetEnvironmentVariable("DK_HTTP_LISTEN")
if ($x -ne $null) {
$http_listen = $x
Write-COutput green "* set HTTP listen to $x"
}
$http_port = 9529
$x = [Environment]::GetEnvironmentVariable("DK_HTTP_PORT")
if ($x -ne $null) {
$http_port = $x
Write-COutput green "* set HTTP port to $x"
}
$namespace=""
$x = [Environment]::GetEnvironmentVariable("DK_NAMESPACE")
if ($x -ne $null) {
$namespace = $x
Write-COutput green "* set namespace to $x"
}
$cloud_provider=""
$x = [Environment]::GetEnvironmentVariable("DK_CLOUD_PROVIDER")
if ($x -ne $null) {
$cloud_provider = $x
Write-COutput green "* set cloud provider to $x"
}
$def_inputs=""
$x = [Environment]::GetEnvironmentVariable("DK_DEF_INPUTS")
if ($x -ne $null) {
$def_inputs = $x
Write-COutput green "* set default-enabled inputs to $x"
}
$proxy=""
$x = [Environment]::GetEnvironmentVariable("HTTP_PROXY")
if ($x -ne $null) {
$proxy = $x
Write-COutput green "* set Proxy to $x"
}
$x = [Environment]::GetEnvironmentVariable("HTTPS_PROXY")
if ($x -ne $null) {
$proxy = $x
Write-COutput green "* set Proxy to $x"
}
# check nginx proxy
$proxy_type=""
$x = [Environment]::GetEnvironmentVariable("DK_PROXY_TYPE")
if ($x -ne $null) {
$proxy_type = $x
$proxy_type.ToLower()
Write-COutput green "* found Proxy Type: $proxy_type"
if ($proxy_type -eq "nginx") {
# env DK_NGINX_IP has highest priority on proxy level
$x = ""
$x = [Environment]::GetEnvironmentVariable("DK_NGINX_IP")
if ($x -ne $null -or $x -ne "") {
$proxy = $x
Write-COutput green "* got nginx Proxy $proxy"
# 更新 hosts
foreach ( $node in $domain )
{
remove-host $env:windir\System32\drivers\etc\hosts $node
Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`n$proxy`t$node" -Force
}
$proxy=""
}
}
}
$env_hostname=""
$x = [Environment]::GetEnvironmentVariable("DK_HOSTNAME")
if ($x -ne $null) {
$env_hostname=$x
Write-COutput green "* set hostname to $x"
}
$global_host_tags=""
$x = [Environment]::GetEnvironmentVariable("DK_GLOBAL_HOST_TAGS")
if ($x -ne $null) {
$global_host_tags = $x
Write-COutput green "* set global host tags $x"
}
$global_election_tags=""
$x = [Environment]::GetEnvironmentVariable("DK_GLOBAL_ELECTION_TAGS")
if ($x -ne $null) {
$global_election_tags = $x
Write-COutput green "* set global election tags $x"
}
$install_only="0"
$x = [Environment]::GetEnvironmentVariable("DK_INSTALL_ONLY")
if ($x -ne $null) {
$install_only = "1"
Write-COutput yellow "* set install only"
}
$dca_white_list=
$x = [Environment]::GetEnvironmentVariable("DK_DCA_WHITE_LIST")
if ($x -ne $null) {
$dca_white_list = $x
Write-COutput yellow "* set DCA white list $x"
}
$dca_listen=""
$x = [Environment]::GetEnvironmentVariable("DK_DCA_LISTEN")
if ($x -ne $null) {
$dca_listen = $x
Write-COutput yellow "* set DCA server listen address and port"
}
$dca_enable=
$x = [Environment]::GetEnvironmentVariable("DK_DCA_ENABLE")
if ($x -ne $null) {
$dca_enable = $x
Write-COutput yellow "* enable DCA server"
if ($dca_white_list -eq $null) {
Write-COutput red "* DCA service is enabled, but white list is not set in DK_DCA_WHITE_LIST!"
Exit
}
}
$pprof_listen=
$x = [Environment]::GetEnvironmentVariable("DK_PPROF_LISTEN")
if ($x -ne $null) {
$pprof_listen = $x
Write-COutput yellow "* set pprof listen address"
}
$install_log="install.log"
$x = [Environment]::GetEnvironmentVariable("DK_INSTALL_LOG")
if ($x -ne $null) {
$install_log = $x
Write-COutput yellow "* set install log"
}
$confd_backend=""
$confd_basic_auth=""
$confd_client_ca_keys=""
$confd_client_cert=""
$confd_client_key=""
$confd_backend_nodes=""
$confd_password=""
$confd_scheme=""
$confd_separator=""
$confd_username=""
$confd_access_key=""
$confd_secret_key=""
$confd_circle_interval=0
$confd_confd_namespace=""
$confd_pipeline_namespace=""
$confd_region=""
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_BACKEND")
if ($x -ne $null) {
$confd_backend = $x
Write-COutput yellow "* set confd backend"
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_BASIC_AUTH")
if ($x -ne $null) {
$confd_basic_auth = $x
Write-COutput yellow "* set confd_basic_auth"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_CLIENT_CA_KEYS")
if ($x -ne $null) {
$confd_client_ca_keys = $x
Write-COutput yellow "* set confd_client_ca_keys"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_CLIENT_CERT")
if ($x -ne $null) {
$confd_client_cert = $x
Write-COutput yellow "* set confd_client_cert"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_CLIENT_KEY")
if ($x -ne $null) {
$confd_client_key = $x
Write-COutput yellow "* set confd_client_key"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_BACKEND_NODES")
if ($x -ne $null) {
$confd_backend_nodes = $x
Write-COutput yellow "* set confd_backend_nodes"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_PASSWORD")
if ($x -ne $null) {
$confd_password = $x
Write-COutput yellow "* set confd_password"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_SCHEME")
if ($x -ne $null) {
$confd_scheme = $x
Write-COutput yellow "* set confd_scheme"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_SEPARATOR")
if ($x -ne $null) {
$confd_separator = $x
Write-COutput yellow "* set confd_separator"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_USERNAME")
if ($x -ne $null) {
$confd_username = $x
Write-COutput yellow "* set confd_username"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_ACCESS_KEY")
if ($x -ne $null) {
$confd_access_key = $x
Write-COutput yellow "* set confd_access_key"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_SECRET_KEY")
if ($x -ne $null) {
$confd_secret_key = $x
Write-COutput yellow "* set confd_secret_key"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_CIRCLE_INTERVAL")
if ($x -ne $null) {
$confd_circle_interval = $x
Write-COutput yellow "* set confd_circle_interval"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_CONFD_NAMESPACE")
if ($x -ne $null) {
$confd_confd_namespace = $x
Write-COutput yellow "* set confd_confd_namespace"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_PIPELINE_NAMESPACE")
if ($x -ne $null) {
$confd_pipeline_namespace = $x
Write-COutput yellow "* set confd_pipeline_namespace"
}
$x = [Environment]::GetEnvironmentVariable("DK_CONFD_REGION")
if ($x -ne $null) {
$confd_region = $x
Write-COutput yellow "* set confd_region"
}
}
$git_url=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_URL")
if ($x -ne $null) {
$git_url = $x
Write-COutput yellow "* set git url"
}
$git_key_path=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_KEY_PATH")
if ($x -ne $null) {
$git_key_path = $x
Write-COutput yellow "* set git private key path"
}
$git_key_pw=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_KEY_PW")
if ($x -ne $null) {
$git_key_pw = $x
Write-COutput yellow "* set git private key password"
}
$git_branch=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_BRANCH")
if ($x -ne $null) {
$git_branch = $x
Write-COutput yellow "* set git branch"
}
$git_pull_interval=""
$x = [Environment]::GetEnvironmentVariable("DK_GIT_INTERVAL")
if ($x -ne $null) {
$git_pull_interval = $x
Write-COutput yellow "* set git interval"
}
$enable_election=""
$x = [Environment]::GetEnvironmentVariable("DK_ENABLE_ELECTION")
if ($x -ne $null) {
$enable_election = $x
Write-COutput yellow "* set enable election"
}
$disable_404page=""
$x = [Environment]::GetEnvironmentVariable("DK_DISABLE_404PAGE")
if ($x -ne $null) {
$disable_404page = $x
Write-COutput yellow "* set 404 page disabled"
}
$rum_origin_ip_header=""
$x = [Environment]::GetEnvironmentVariable("DK_RUM_ORIGIN_IP_HEADER")
if ($x -ne $null) {
$rum_origin_ip_header = $x
Write-COutput yellow "* set rum origin IP header"
}
$log_level=""
$x = [Environment]::GetEnvironmentVariable("DK_LOG_LEVEL")
if ($x -ne $null) {
$log_level = $x
Write-COutput yellow "* set log level"
}
$log=""
$x = [Environment]::GetEnvironmentVariable("DK_LOG")
if ($x -ne $null) {
$log = $x
Write-COutput yellow "* set log"
}
$gin_Log=""
$x = [Environment]::GetEnvironmentVariable("DK_GIN_LOG")
if ($x -ne $null) {
$gin_Log = $x
Write-COutput yellow "* set gin log"
}
$ipdb_type=""
$x = [Environment]::GetEnvironmentVariable("DK_INSTALL_IPDB")
if ($x -ne $null) {
$ipdb_type = $x
Write-COutput yellow "* set ipdb type"
}
$sinker=""
$x = [Environment]::GetEnvironmentVariable("DK_SINKER")
if ($x -ne $null) {
$sinker= $x
Write-COutput yellow "* set sinker"
}
##########################
# Detect arch 32 or 64
##########################
$arch="386"
if ([Environment]::Is64BitProcess -or [Environment]::Is64BitOperatingSystem) {
$arch = "amd64"
}
$installer_url = "$installer_base_url/installer-windows-$arch-{{.Version}}.exe"
$installer=".dk-installer.exe"
##########################
# try install...
##########################
Write-COutput green "* downloading $installer_url..."
if (Test-Path $installer) {
Remove-Item $installer
}
Import-Module bitstransfer
$dl_installer_action = "start-bitstransfer -source $installer_url -destination $installer"
if ($proxy -ne "") {
$dl_installer_action = "start-bitstransfer -ProxyUsage Override -ProxyList $proxy -source $installer_url -destination $installer"
}
Invoke-Expression $dl_installer_action
if ($upgrade -ne $null) { # upgrade
$action = @(
"$installer",
"--upgrade",
"--upgrade-manager='${upgrade_manager}'", # for update DK upgrade service
"--upgrade-ip-whitelist='${upgrade_ip_whitelist}'",
"--install-log='${install_log}'",
"--proxy='${proxy}'",
"--installer_base_url='${installer_base_url}'"
)
} else { # install new datakit
$action = @(
"$installer",
"--enable-inputs='${def_inputs}'",
"--install-log='${install_log}'",
"--dataway='${dataway}'",
"--listen=${http_listen}",
"--installer_base_url='${installer_base_url}'",
"--port=${http_port}",
"--proxy='${proxy}'",
"--namespace='${namespace}'",
"--env_hostname='${env_hostname}'",
"--cloud-provider='${cloud_provider}'",
"--global-host-tags='${global_host_tags}'",
"--global-election-tags='${global_election_tags}'",
"--dca-enable='${dca_enable}'",
"--dca-listen='${dca_listen}'",
"--dca-white-list='${dca_white_list}'",
"--confd-backend='${confd_backend}'",
"--confd-basic-auth='${confd_basic_auth}'",
"--confd-client-ca-keys='${confd_client_ca_keys}'",
"--confd-client-cert='${confd_client_cert}'",
"--confd-client-key='${confd_client_key}'",
"--confd-backend-nodes='${confd_backend_nodes}'",
"--confd-password='${confd_password}'",
"--confd-scheme='${confd_scheme}'",
"--confd-separator='${confd_separator}'",
"--confd-username='${confd_username}'",
"--confd-access-key='${confd_access_key}'",
"--confd-secret-key='${confd_secret_key}'",
"--confd-circle-interval='${confd_circle_interval}'",
"--confd-confd-namespace='${confd_confd_namespace}'",
"--confd-pipeline-namespace='${confd_pipeline_namespace}'",
"--confd-region='${confd_region}'",
"--git-url='${git_url}'",
"--git-key-path='${git_key_path}'",
"--git-key-pw='${git_key_pw}'",
"--git-branch='${git_branch}'",
"--git-pull-interval='${git_pull_interval}'",
"--install-only='${install_only}'",
"--enable-election='${enable_election}'",
"--rum-origin-ip-header='${rum_origin_ip_header}'",
"--disable-404page='${disable_404page}'",
"--log-level='${log_level}'",
"--log='${log}'",
"--gin-log='${gin_log}'",
"--ipdb-type='${ipdb_type}'",
"--pprof-listen='${pprof_listen}'",
"--upgrade-ip-whitelist='${upgrade_ip_whitelist}'",
"--sinker='${sinker}'" # Do NOT add trailing `,' here!
)
}
Write-COutput green "* action: $action"
$action -join " " | Invoke-Expression
# remove installer and the script.
Remove-Item -Force -ErrorAction SilentlyContinue $installer
Remove-Item $PSCommandPath -Force
1
https://gitee.com/oplg/datakit.git
git@gitee.com:oplg/datakit.git
oplg
datakit
DataKit
main

搜索帮助