diff --git a/cmd/installer/installer/dkconf.go b/cmd/installer/installer/dkconf.go index aca3bb3088..05cd730259 100644 --- a/cmd/installer/installer/dkconf.go +++ b/cmd/installer/installer/dkconf.go @@ -8,6 +8,7 @@ package installer import ( "bytes" "fmt" + "net" "os" "path/filepath" "runtime" @@ -219,10 +220,16 @@ func mergeDefaultInputs(defaultList, enabledList []string, appendDefault bool) [ func setupDefaultInputs(mc *config.Config, arg string, list []string, upgrade bool) { if upgrade { - if len(mc.DefaultEnabledInputs) == 0 { // all default inputs disabled - mc.DefaultEnabledInputs = mergeDefaultInputs(list, []string{"-"}, true) + if arg == "" { + if len(mc.DefaultEnabledInputs) == 0 { // all default inputs disabled + mc.DefaultEnabledInputs = mergeDefaultInputs(list, []string{"-"}, true) + } else { + mc.DefaultEnabledInputs = mergeDefaultInputs(list, mc.DefaultEnabledInputs, true) + } } else { - mc.DefaultEnabledInputs = mergeDefaultInputs(list, mc.DefaultEnabledInputs, true) + enabledList := strings.Split(arg, ",") + enabledList = append(enabledList, mc.DefaultEnabledInputs...) + mc.DefaultEnabledInputs = mergeDefaultInputs(list, enabledList, true) } } else { if arg == "" { @@ -338,3 +345,185 @@ func getDataway() (*dataway.Dataway, error) { return nil, fmt.Errorf("dataway is not set") } } + +func loadDKEnvCfg(mc *config.Config) *config.Config { + var err error + // prepare dataway info and check token format + if len(DatawayURLs) != 0 { + mc.Dataway, err = getDataway() + if err != nil { + l.Errorf("getDataway failed: %s", err.Error()) + l.Fatal(err) + } + + l.Infof("Set dataway to %s", DatawayURLs) + + mc.Dataway.GlobalCustomerKeys = dataway.ParseGlobalCustomerKeys(SinkerGlobalCustomerKeys) + mc.Dataway.EnableSinker = (EnableSinker != "") + + l.Infof("Set dataway global sinker customer keys: %+#v", mc.Dataway.GlobalCustomerKeys) + } + + if OTA { + mc.AutoUpdate = OTA + l.Info("set auto update(OTA enabled)") + } + + if HTTPPublicAPIs != "" { + apis := strings.Split(HTTPPublicAPIs, ",") + idx := 0 + for _, api := range apis { + api = strings.TrimSpace(api) + if api != "" { + if !strings.HasPrefix(api, "/") { + api = "/" + api + } + apis[idx] = api + idx++ + } + } + mc.HTTPAPI.PublicAPIs = apis[:idx] + l.Infof("set PublicAPIs to %s", strings.Join(apis[:idx], ",")) + } + + if DCAEnable != "" { + config.Cfg.DCAConfig.Enable = true + if DCAWhiteList != "" { + config.Cfg.DCAConfig.WhiteList = strings.Split(DCAWhiteList, ",") + } + + // check white list whether is empty or invalid + if len(config.Cfg.DCAConfig.WhiteList) == 0 { + l.Fatalf("DCA service is enabled, but white list is empty! ") + } + + for _, cidr := range config.Cfg.DCAConfig.WhiteList { + if _, _, err := net.ParseCIDR(cidr); err != nil { + if net.ParseIP(cidr) == nil { + l.Fatalf("DCA white list set error, invalid IP: %s", cidr) + } + } + } + + if DCAListen != "" { + config.Cfg.DCAConfig.Listen = DCAListen + } + + l.Infof("DCA enabled, listen on %s, whiteliste: %s", DCAListen, DCAWhiteList) + } + + if PProfListen != "" { + config.Cfg.PProfListen = PProfListen + } + l.Infof("pprof enabled? %v, listen on %s", config.Cfg.EnablePProf, config.Cfg.PProfListen) + + // Only supports linux and windows + if LimitDisabled != 1 && (runtime.GOOS == datakit.OSLinux || runtime.GOOS == datakit.OSWindows) { + mc.ResourceLimitOptions.Enable = true + + if LimitCPUMax > 0 { + mc.ResourceLimitOptions.CPUMax = LimitCPUMax + } + + if LimitMemMax > 0 { + l.Infof("resource limit set max memory to %dMB", LimitMemMax) + mc.ResourceLimitOptions.MemMax = LimitMemMax + } else { + l.Infof("resource limit max memory not set") + } + + l.Infof("resource limit enabled under %s, cpu: %f, mem: %dMB", + runtime.GOOS, mc.ResourceLimitOptions.CPUMax, mc.ResourceLimitOptions.MemMax) + } else { + mc.ResourceLimitOptions.Enable = false + l.Infof("resource limit disabled, OS: %s", runtime.GOOS) + } + + if HostName != "" { + mc.Environments["ENV_HOSTNAME"] = HostName + l.Infof("set ENV_HOSTNAME to %s", HostName) + } + + if GlobalHostTags != "" { + mc.GlobalHostTags = config.ParseGlobalTags(GlobalHostTags) + + l.Infof("set global host tags to %+#v", mc.GlobalHostTags) + } + + if GlobalElectionTags != "" { + mc.Election.Tags = config.ParseGlobalTags(GlobalElectionTags) + l.Infof("set global election tags to %+#v", mc.Election.Tags) + } + + if EnableElection != "" { + mc.Election.Enable = true + l.Infof("election enabled? %v", true) + } + + mc.Election.Namespace = ElectionNamespace + l.Infof("set election namespace to %s", mc.Election.Namespace) + + mc.HTTPAPI.Listen = fmt.Sprintf("%s:%d", HTTPListen, HTTPPort) + l.Infof("set HTTP listen to %s", mc.HTTPAPI.Listen) + + mc.InstallVer = DataKitVersion + l.Infof("install version %s", mc.InstallVer) + + if DatakitName != "" { + mc.Name = DatakitName + l.Infof("set datakit name to %s", mc.Name) + } + + if CryptoAESKey != "" || CryptoAESKeyFile != "" { + if mc.Crypto != nil { + mc.Crypto.AESKey = CryptoAESKey + mc.Crypto.AESKeyFile = CryptoAESKeyFile + l.Infof("set datakit crypto key=%s or crypto key file=%s", mc.Crypto.AESKey, mc.Crypto.AESKeyFile) + } + } + + // 一个 func 最大 230 行 + addConfdConfig(mc) + + if GitURL != "" { + mc.GitRepos = &config.GitRepost{ + PullInterval: GitPullInterval, + Repos: []*config.GitRepository{ + { + Enable: true, + URL: GitURL, + SSHPrivateKeyPath: GitKeyPath, + SSHPrivateKeyPassword: GitKeyPW, + Branch: GitBranch, + }, // GitRepository + }, // Repos + } // GitRepost + } + + if RumDisable404Page != "" { + l.Infof("set disable 404 page: %v", RumDisable404Page) + mc.HTTPAPI.Disable404Page = true + } + + if RumOriginIPHeader != "" { + l.Infof("set rum origin IP header: %s", RumOriginIPHeader) + mc.HTTPAPI.RUMOriginIPHeader = RumOriginIPHeader + } + + if LogLevel != "" { + mc.Logging.Level = LogLevel + l.Infof("set log level to %s", LogLevel) + } + + if Log != "" { + mc.Logging.Log = Log + l.Infof("set log to %s", Log) + } + + if GinLog != "" { + l.Infof("set gin log to %s", GinLog) + mc.Logging.GinLog = GinLog + } + + return mc +} diff --git a/cmd/installer/installer/install.go b/cmd/installer/installer/install.go index 1868d48a1f..529cca501c 100644 --- a/cmd/installer/installer/install.go +++ b/cmd/installer/installer/install.go @@ -8,16 +8,12 @@ package installer import ( "errors" - "fmt" - "net" - "runtime" "strings" "github.com/kardianos/service" "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/cmds" "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/config" "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/datakit" - "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/io/dataway" dkservice "gitlab.jiagouyun.com/cloudcare-tools/datakit/internal/service" ) @@ -50,181 +46,8 @@ func Install(svc service.Service, userName string) { mc := config.Cfg mc.DatakitUser = userName - // prepare dataway info and check token format - if len(DatawayURLs) != 0 { - mc.Dataway, err = getDataway() - if err != nil { - l.Errorf("getDataway failed: %s", err.Error()) - l.Fatal(err) - } - - l.Infof("Set dataway to %s", DatawayURLs) - - mc.Dataway.GlobalCustomerKeys = dataway.ParseGlobalCustomerKeys(SinkerGlobalCustomerKeys) - mc.Dataway.EnableSinker = (EnableSinker != "") - - l.Infof("Set dataway global sinker customer keys: %+#v", mc.Dataway.GlobalCustomerKeys) - } - - if OTA { - mc.AutoUpdate = OTA - l.Info("set auto update(OTA enabled)") - } - - if HTTPPublicAPIs != "" { - apis := strings.Split(HTTPPublicAPIs, ",") - idx := 0 - for _, api := range apis { - api = strings.TrimSpace(api) - if api != "" { - if !strings.HasPrefix(api, "/") { - api = "/" + api - } - apis[idx] = api - idx++ - } - } - mc.HTTPAPI.PublicAPIs = apis[:idx] - l.Infof("set PublicAPIs to %s", strings.Join(apis[:idx], ",")) - } - - if DCAEnable != "" { - config.Cfg.DCAConfig.Enable = true - if DCAWhiteList != "" { - config.Cfg.DCAConfig.WhiteList = strings.Split(DCAWhiteList, ",") - } - - // check white list whether is empty or invalid - if len(config.Cfg.DCAConfig.WhiteList) == 0 { - l.Fatalf("DCA service is enabled, but white list is empty! ") - } - - for _, cidr := range config.Cfg.DCAConfig.WhiteList { - if _, _, err := net.ParseCIDR(cidr); err != nil { - if net.ParseIP(cidr) == nil { - l.Fatalf("DCA white list set error, invalid IP: %s", cidr) - } - } - } - - if DCAListen != "" { - config.Cfg.DCAConfig.Listen = DCAListen - } - - l.Infof("DCA enabled, listen on %s, whiteliste: %s", DCAListen, DCAWhiteList) - } - - if PProfListen != "" { - config.Cfg.PProfListen = PProfListen - } - l.Infof("pprof enabled? %v, listen on %s", config.Cfg.EnablePProf, config.Cfg.PProfListen) - - // Only supports linux and windows - if LimitDisabled != 1 && (runtime.GOOS == datakit.OSLinux || runtime.GOOS == datakit.OSWindows) { - mc.ResourceLimitOptions.Enable = true - - if LimitCPUMax > 0 { - mc.ResourceLimitOptions.CPUMax = LimitCPUMax - } - - if LimitMemMax > 0 { - l.Infof("resource limit set max memory to %dMB", LimitMemMax) - mc.ResourceLimitOptions.MemMax = LimitMemMax - } else { - l.Infof("resource limit max memory not set") - } - - l.Infof("resource limit enabled under %s, cpu: %f, mem: %dMB", - runtime.GOOS, mc.ResourceLimitOptions.CPUMax, mc.ResourceLimitOptions.MemMax) - } else { - mc.ResourceLimitOptions.Enable = false - l.Infof("resource limit disabled, OS: %s", runtime.GOOS) - } - - if HostName != "" { - mc.Environments["ENV_HOSTNAME"] = HostName - l.Infof("set ENV_HOSTNAME to %s", HostName) - } - - if GlobalHostTags != "" { - mc.GlobalHostTags = config.ParseGlobalTags(GlobalHostTags) - - l.Infof("set global host tags to %+#v", mc.GlobalHostTags) - } - - if GlobalElectionTags != "" { - mc.Election.Tags = config.ParseGlobalTags(GlobalElectionTags) - l.Infof("set global election tags to %+#v", mc.Election.Tags) - } - - if EnableElection != "" { - mc.Election.Enable = true - l.Infof("election enabled? %v", true) - } - mc.Election.Namespace = ElectionNamespace - l.Infof("set election namespace to %s", mc.Election.Namespace) - - mc.HTTPAPI.Listen = fmt.Sprintf("%s:%d", HTTPListen, HTTPPort) - l.Infof("set HTTP listen to %s", mc.HTTPAPI.Listen) - - mc.InstallVer = DataKitVersion - l.Infof("install version %s", mc.InstallVer) - - if DatakitName != "" { - mc.Name = DatakitName - l.Infof("set datakit name to %s", mc.Name) - } - - if CryptoAESKey != "" || CryptoAESKeyFile != "" { - if mc.Crypto != nil { - mc.Crypto.AESKey = CryptoAESKey - mc.Crypto.AESKeyFile = CryptoAESKeyFile - l.Infof("set datakit crypto key=%s or crypto key file=%s", mc.Crypto.AESKey, mc.Crypto.AESKeyFile) - } - } - - // 一个 func 最大 230 行 - addConfdConfig(mc) - - if GitURL != "" { - mc.GitRepos = &config.GitRepost{ - PullInterval: GitPullInterval, - Repos: []*config.GitRepository{ - { - Enable: true, - URL: GitURL, - SSHPrivateKeyPath: GitKeyPath, - SSHPrivateKeyPassword: GitKeyPW, - Branch: GitBranch, - }, // GitRepository - }, // Repos - } // GitRepost - } - - if RumDisable404Page != "" { - l.Infof("set disable 404 page: %v", RumDisable404Page) - mc.HTTPAPI.Disable404Page = true - } - - if RumOriginIPHeader != "" { - l.Infof("set rum origin IP header: %s", RumOriginIPHeader) - mc.HTTPAPI.RUMOriginIPHeader = RumOriginIPHeader - } - - if LogLevel != "" { - mc.Logging.Level = LogLevel - l.Infof("set log level to %s", LogLevel) - } - - if Log != "" { - mc.Logging.Log = Log - l.Infof("set log to %s", Log) - } - - if GinLog != "" { - l.Infof("set gin log to %s", GinLog) - mc.Logging.GinLog = GinLog - } + // load DK_XXX env config + mc = loadDKEnvCfg(mc) writeDefInputToMainCfg(mc, false) diff --git a/cmd/installer/installer/upgrade.go b/cmd/installer/installer/upgrade.go index 25ca18bb87..1930dc12a7 100644 --- a/cmd/installer/installer/upgrade.go +++ b/cmd/installer/installer/upgrade.go @@ -26,12 +26,10 @@ func Upgrade() error { // load exists datakit.conf if err := mc.LoadMainTOML(datakit.MainConfPath); err == nil { - mc = upgradeMainConfig(mc) + // load DK_XXX env config + mc = loadDKEnvCfg(mc) - if OTA { - l.Debugf("set auto update(OTA enabled)") - mc.AutoUpdate = OTA - } + mc = upgradeMainConfig(mc) writeDefInputToMainCfg(mc, true) } else { diff --git a/cmd/installer/installer/upgrade_test.go b/cmd/installer/installer/upgrade_test.go index 1d37289d2e..5dbaa4e797 100644 --- a/cmd/installer/installer/upgrade_test.go +++ b/cmd/installer/installer/upgrade_test.go @@ -48,7 +48,7 @@ func Test_setupDefaultInputs(t *T.T) { "2,mem", // white list, with extra input 'mem' []string{"1", "2", "3"}, true) - assert.Equal(t, []string{"1", "2", "3", "disk"}, c.DefaultEnabledInputs) + assert.Equal(t, []string{"1", "2", "3", "disk", "mem"}, c.DefaultEnabledInputs) }) t.Run("install-with-blacklist", func(t *T.T) { diff --git a/install.template.ps1 b/install.template.ps1 index a92b8c23c7..158f8b05ee 100644 --- a/install.template.ps1 +++ b/install.template.ps1 @@ -550,13 +550,62 @@ if ($upgrade -ne $null) { # upgrade "$installer", "--upgrade", "--upgrade-manager='${upgrade_manager}'", - "--upgrade-ip-whitelist='${upgrade_ip_whitelist}'", - "--upgrade-listen='${upgrade_listen}'", + "--enable-inputs='${def_inputs}'", + "--http-public-apis='${http_public_apis}'", "--install-log='${install_log}'", + "--dataway='${dataway}'", + "--listen=${http_listen}", + "--installer_base_url='${installer_base_url}'", + "--port=${http_port}", "--proxy='${proxy}'", "--lite='${lite}'", "--elinker='${elinker}'", - "--installer_base_url='${installer_base_url}'" + "--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}'", + "--limit-disabled='${limit_disabled}'", + "--limit-cpumax='${limit_cpumax}'", + "--limit-memmax='${limit_memmax}'", + "--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}'", + "--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}'", + "--upgrade-listen='${upgrade_listen}'", + "--enable-dataway-sinker='${enable_sinker}'", + "--crypto-aes_key='${crypto_aes_key}'", + "--crypto-aes_key_file='${crypto_aes_key_file}'", + "--sinker-global-customer-keys='${global_customer_keys}'" ) } else { # install new datakit $action = @( diff --git a/install.template.sh b/install.template.sh index 37abff5751..372f1bdf2f 100755 --- a/install.template.sh +++ b/install.template.sh @@ -554,14 +554,69 @@ if [ "$upgrade" ]; then printf "* Upgrading DataKit...\n" $sudo_cmd $installer \ --install-log="$install_log" \ - --upgrade --lite="${lite}" \ + --installer_base_url="$installer_base_url" \ + --dataway="${dataway}" \ + --enable-inputs="${def_inputs}" \ + --http-public-apis="$http_public_apis" \ + --http-disabled-apis="$http_disabled_apis" \ + --install-rum-symbol-tools="$install_rum_symbol_tools" \ + --global-host-tags="${global_host_tags}" \ + --global-election-tags="${global_election_tags}" \ + --cloud-provider="${cloud_provider}" \ + --namespace="${namespace}" \ + --listen="${http_listen}" \ + --port="${http_port}" \ + --proxy="${proxy}" \ + --lite="${lite}" \ --elinker="${elinker}" \ --apm-instrumentation-enabled="${apmInstrumentation}" \ + --env_hostname="${env_hostname}" \ + --dca-enable="${dca_enable}" \ + --dca-listen="${dca_listen}" \ + --dca-white-list="${dca_white_list}" \ + --pprof-listen="${pprof_listen}" \ + --install-externals="${install_externals}" \ + --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}" \ + --limit-cpumax="${limit_cpumax}" \ + --limit-memmax="${limit_memmax}" \ + --limit-disabled="${limit_disabled}" \ + --enable-election="${enable_election}" \ + --rum-origin-ip-header="${rum_origin_ip_header}" \ + --disable-404page="${disable_404page}" \ + --log-level="${log_level}" \ + --log="${log}" \ + --ipdb-type="${ipdb_type}" \ + --sinker-global-customer-keys="${global_customer_keys}" \ + --enable-dataway-sinker="${dataway_sinker}" \ + --user-name="${user_name}" \ + --crypto-aes_key="${crypto_aes_key}" \ + --crypto-aes_key_file="${crypto_aes_key_file}" \ + --upgrade \ --upgrade-manager="${upgrade_manager}" \ --upgrade-ip-whitelist="${upgrade_ip_whitelist}" \ --upgrade-listen="${upgrade_listen}" \ - --proxy="${proxy}" \ - --installer_base_url="$installer_base_url" + --gin-log="${gin_log}" + else printf "* Installing DataKit...\n" $sudo_cmd $installer \ diff --git a/internal/config/env.go b/internal/config/env.go index 53a04773eb..874d48888f 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -627,6 +627,10 @@ func (c *Config) loadHTTPAPIEnvs() { c.HTTPAPI.RUMAppIDWhiteList = strings.Split(v, ",") } + if v := datakit.GetEnv("ENV_ALLOWED_CORS_ORIGINS"); v != "" { + c.HTTPAPI.AllowedCORSOrigins = strings.Split(v, ",") + } + if v := datakit.GetEnv("ENV_DISABLE_404PAGE"); v != "" { c.HTTPAPI.Disable404Page = true } diff --git a/internal/config/env_test.go b/internal/config/env_test.go index bd7c48e6a2..cf91b3d1f8 100644 --- a/internal/config/env_test.go +++ b/internal/config/env_test.go @@ -113,6 +113,7 @@ func TestLoadEnv(t *testing.T) { "ENV_DATAWAY_MAX_IDLE_CONNS_PER_HOST": "123", "ENV_DATAWAY_TLS_INSECURE": "on", "ENV_REQUEST_RATE_LIMIT": "1234", + "ENV_HTTP_ALLOWED_CORS_ORIGINS": "https://foo,https://bar", "ENV_DATAWAY_ENABLE_HTTPTRACE": "any", "ENV_DATAWAY_HTTP_PROXY": "http://1.2.3.4:1234", "ENV_HTTP_CLOSE_IDLE_CONNECTION": "on", @@ -145,6 +146,7 @@ func TestLoadEnv(t *testing.T) { cfg.Dataway.GlobalCustomerKeys = []string{} cfg.Dataway.GZip = true + cfg.HTTPAPI.AllowedCORSOrigins = []string{"https://foo", "https://bar"} cfg.HTTPAPI.RUMOriginIPHeader = "not-set" cfg.HTTPAPI.Listen = "localhost:9559" cfg.HTTPAPI.Disable404Page = true diff --git a/internal/export/doc/en/datakit-install.md b/internal/export/doc/en/datakit-install.md index e640b54b60..90d6352648 100644 --- a/internal/export/doc/en/datakit-install.md +++ b/internal/export/doc/en/datakit-install.md @@ -121,7 +121,7 @@ And the same as Windows: {{ InstallCmd 0 (.WithPlatform "windows") (.WithVersion "-1.2.3") }} ``` -## Additional Supported Installation Variable {#extra-envs} +## Additional Supported Environment Variable {#extra-envs} If you need to define some DataKit configuration during the installation phase, you can add environment variables to the installation command, just append them before `DK_DATAWAY` For example, append the `DK_NAMESPACE` setting: @@ -321,7 +321,7 @@ Only Linux and Windows ([:octicons-tag-24: Version-1.15.0](changelog.md#cl-1.15. | -------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `DK_INSTALL_ONLY` | `on` | Install only, not run | | `DK_HOSTNAME` | `some-host-name` | Support custom configuration hostname during installation | -| `DK_UPGRADE` | `1` | Upgrade to the latest version (Note: Once this option is turned on, all other options except `DK_UPGRADE_MANAGER` are invalid) | +| `DK_UPGRADE` | `1` | Upgrade to the latest version | | `DK_UPGRADE_MANAGER` | `on` | Whether we upgrade the **Remote Upgrade Service** when upgrading Datakit, it's used in conjunction with `DK_UPGRADE`, supported start from [1.5.9](changelog.md#cl-1.5.9) | | `DK_INSTALLER_BASE_URL` | `https://your-url` | You can choose the installation script for different environments, default to `https://static.guance.com/datakit` | | `DK_PROXY_TYPE` | - | Proxy type. The options are: `datakit` or `nginx`, both lowercase | diff --git a/internal/export/doc/en/datakit-update.md b/internal/export/doc/en/datakit-update.md index d70341c6ab..99dafa1761 100644 --- a/internal/export/doc/en/datakit-update.md +++ b/internal/export/doc/en/datakit-update.md @@ -4,6 +4,10 @@ DataKit supports both manual and automatic upgrade. +## Additional Supported Environment Variable {#extra-envs} + +From version [1.60.1](changelog.md#cl-1.60.1) onwards, the upgrade command also supports the same environment variables as the install command. For more details, refer to the [environment variables supported by the install command](datakit-install.md#extra-envs). + ## Preconditions {#req} - Automatic upgrade require DataKit version >= 1.1.6-rc1 diff --git a/internal/export/doc/zh/datakit-install.md b/internal/export/doc/zh/datakit-install.md index 0927283b67..07bfadd557 100644 --- a/internal/export/doc/zh/datakit-install.md +++ b/internal/export/doc/zh/datakit-install.md @@ -125,7 +125,7 @@ Windows 下同理: {{ InstallCmd 0 (.WithPlatform "windows") (.WithVersion "-1.2.3") }} ``` -## 额外支持的安装变量 {#extra-envs} +## 额外支持的环境变量 {#extra-envs} 如果需要在安装阶段定义一些 DataKit 配置,可在安装命令中增加环境变量,在 `DK_DATAWAY` 前面追加即可。如追加 `DK_NAMESPACE` 设置: @@ -158,8 +158,7 @@ NAME1="value1" NAME2="value2" ???+ attention - 1. [全离线安装](datakit-offline-install.md#offline)不支持这些环境变量设置。但可以通过[代理](datakit-offline-install.md#with-datakit)以及[设置本地安装地址](datakit-offline-install.md#with-nginx)方式来设置这些环境变量。 - 1. 这些环境变量只有在安装模式才能生效,升级模式下,这些环境变量都是不生效的。 + [全离线安装](datakit-offline-install.md#offline)不支持这些环境变量设置。但可以通过[代理](datakit-offline-install.md#with-datakit)以及[设置本地安装地址](datakit-offline-install.md#with-nginx)方式来设置这些环境变量。 ### 最常用环境变量 {#common-envs} @@ -344,7 +343,7 @@ NAME1="value1" NAME2="value2" | -------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | | `DK_INSTALL_ONLY` | `on` | 仅安装,不运行 | | `DK_HOSTNAME` | `some-host-name` | 支持安装阶段自定义配置主机名 | -| `DK_UPGRADE` | `1` | 升级到最新版本(注:一旦开启该选项,除 `DK_UPGRADE_MANAGER` 外其它选项均无效) | +| `DK_UPGRADE` | `1` | 升级到最新版本 | | `DK_UPGRADE_MANAGER` | `on` | 升级 Datakit 同时是否升级 **远程升级服务**,需要和 `DK_UPGRADE` 配合使用, 从 [1.5.9](changelog.md#cl-1.5.9) 版本开始支持 | | `DK_INSTALLER_BASE_URL` | `https://your-url` | 可选择不同环境的安装脚本,默认为 `https://static.guance.com/datakit` | | `DK_PROXY_TYPE` | - | 代理类型。选项有:`datakit` 或 `nginx`,均为小写 | diff --git a/internal/export/doc/zh/datakit-offline-install.md b/internal/export/doc/zh/datakit-offline-install.md index da0c8c4a4d..c2e7dd3ac2 100644 --- a/internal/export/doc/zh/datakit-offline-install.md +++ b/internal/export/doc/zh/datakit-offline-install.md @@ -206,7 +206,7 @@ ./installer-linux-amd64 --help ``` - 比如,上面我们指定 Dataway 地址就是通过 `--dataway` 方式来指定的。另外,这些额外的命令行参数设置,只有在安装模式才能生效,(离线)升级模式下,这些是不生效的。 + 比如,上面我们指定 Dataway 地址就是通过 `--dataway` 方式来指定的。另外,这些额外的命令行参数设置,只有在安装模式才能生效,(离线)模式下,这些是不生效的。 ### 高级模式 {#offline-advanced} diff --git a/internal/export/doc/zh/datakit-update.md b/internal/export/doc/zh/datakit-update.md index b9793f009f..5aa561b752 100644 --- a/internal/export/doc/zh/datakit-update.md +++ b/internal/export/doc/zh/datakit-update.md @@ -4,6 +4,10 @@ DataKit 支持手动更新和自动更新两种方式。 +## 额外支持的环境变量 {#extra-envs} + +目前在升级命令中也支持和安装命令一致的环境变量[安装命令支持的环境变量](datakit-install.md#extra-envs),从 [1.60.1](changelog.md#cl-1.60.1) 版本开始支持。 + ## 前置条件 {#req} - 远程更新要求 Datakit 版本 >= 1.5.9 diff --git a/internal/export/non_input_docs.go b/internal/export/non_input_docs.go index 27e0c0d127..bb9323a185 100644 --- a/internal/export/non_input_docs.go +++ b/internal/export/non_input_docs.go @@ -414,6 +414,15 @@ func envHTTPAPI() []*inputs.ENVInfo { Desc: "RUM app-id white list, split by `,`.", DescZh: "RUM app-id 白名单列表,以 `,` 分割。", }, + + { + ENVName: "ENV_HTTP_ALLOWED_CORS_ORIGINS", + Type: doc.List, + Default: "-", + Example: "Origin,Access-Control-Allow-Origin,Access-Control-Allow-Methods", + Desc: "Setup CORS on Datakit HTTP APIs(split by `,`) [:octicons-tag-24: Version-1.61.0](changelog.md#cl-1.61.0)", + DescZh: "设置 Datakit API CORS 属性(英文逗号分割)[:octicons-tag-24: Version-1.61.0](changelog.md#cl-1.61.0)", + }, } for idx := range infos {