1 Star 0 Fork 0

OPLG / DataKit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
install.sh.template 11.45 KB
一键复制 编辑 原始数据 按行查看 历史
张义 提交于 2023-06-20 20:50 . Feat:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
# DataKit install script for UNIX-like OS
# Wed Aug 11 11:35:28 CST 2021
# Author: tanb@jiagouyun.com
# https://stackoverflow.com/questions/19339248/append-line-to-etc-hosts-file-with-shell-script/37824076
# usage: updateHosts ip domain1 domain2 domain3 ...
updateHosts() {
for n in "$@"
do
if [ "$n" != "$1" ]; then
# echo $n
ip_address=$1
host_name=$n
# find existing instances in the host file and save the line numbers
matches_in_hosts="$(grep -n "$host_name" /etc/hosts | cut -f1 -d:)"
host_entry="${ip_address} ${host_name}"
if [ -n "$matches_in_hosts" ]
then
# iterate over the line numbers on which matches were found
while read -r line_number; do
# replace the text of each line with the desired host entry
if [[ "$OSTYPE" == "darwin"* ]]; then
$sudo_cmd sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
else
$sudo_cmd sed -i "${line_number}s/.*/${host_entry} /" /etc/hosts
fi
done <<< "$matches_in_hosts"
else
echo "$host_entry" | $sudo_cmd tee -a /etc/hosts > /dev/null
fi
fi
done
}
set -e
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"
)
# detect root user
if [ "$UID" = "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
##################
# colors
##################
RED="\033[31m"
CLR="\033[0m"
errorf() {
msg=$1
shift
printf "${RED}[E] $msg ${CLR}\n" "$@" >&2
}
##################
# Set Variables
##################
# Detect OS/Arch
arch=
case $(uname -m) in
"x86_64")
arch="amd64"
;;
"i386" | "i686")
arch="386"
;;
"aarch64")
arch="arm64"
;;
"arm" | "armv7l")
arch="arm"
;;
"arm64")
arch="arm64"
;;
*)
# shellcheck disable=SC2059
printf "${RED}[E] Unsupported arch $(uname -m) ${CLR}\n"
exit 1
;;
esac
os="linux"
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ $arch != "amd64" ]] && [[ $arch != "arm64" ]]; then # Darwin only support amd64 and arm64
# shellcheck disable=SC2059
printf "${RED}[E] Darwin only support amd64/arm64.${CLR}\n"
exit 1;
fi
os="darwin"
# NOTE: under darwin, for arm64 and amd64, both use amd64
arch="amd64"
fi
# Select installer
installer_base_url="https://{{.InstallBaseURL}}"
if [ -n "$DK_INSTALLER_BASE_URL" ]; then
installer_base_url=$DK_INSTALLER_BASE_URL
printf "* base url = %s\n" "$installer_base_url"
fi
installer_file="installer-${os}-${arch}-{{.Version}}"
# shellcheck disable=SC2059
printf "Detect installer ${installer_file}\n"
installer_url="${installer_base_url}/${installer_file}"
installer=/tmp/dk-installer
dataway=
if [ -n "$DK_DATAWAY" ]; then
dataway=$DK_DATAWAY
fi
upgrade=
if [ -n "$DK_UPGRADE" ]; then
upgrade=$DK_UPGRADE
fi
upgrade_manager=0
if [ -n "$DK_UPGRADE_MANAGER" ]; then
upgrade_manager=$DK_UPGRADE_MANAGER
fi
upgrade_ip_whitelist=
if [ -n "$DK_UPGRADE_IP_WHITELIST" ]; then
upgrade_ip_whitelist=$DK_UPGRADE_IP_WHITELIST
fi
def_inputs=
if [ -n "$DK_DEF_INPUTS" ]; then
def_inputs=$DK_DEF_INPUTS
fi
install_rum_symbol_tools=0
if [ -n "$DK_INSTALL_RUM_SYMBOL_TOOLS" ]; then
install_rum_symbol_tools=1
fi
http_public_apis=""
if [ -n "$DK_HTTP_PUBLIC_APIS" ]; then
http_public_apis="$DK_HTTP_PUBLIC_APIS"
fi
http_disabled_apis=""
if [ -n "$DK_HTTP_DISABLED_APIS" ]; then
http_disabled_apis="$DK_HTTP_DISABLED_APIS"
fi
global_host_tags=
if [ -n "$DK_GLOBAL_HOST_TAGS" ]; then
global_host_tags=$DK_GLOBAL_HOST_TAGS
fi
global_election_tags=
if [ -n "$DK_GLOBAL_ELECTION_TAGS" ]; then
global_election_tags=$DK_GLOBAL_ELECTION_TAGS
fi
cloud_provider=
if [ -n "$DK_CLOUD_PROVIDER" ]; then
cloud_provider=$DK_CLOUD_PROVIDER
fi
namespace=
if [ -n "$DK_NAMESPACE" ]; then
namespace=$DK_NAMESPACE
fi
http_listen="localhost"
if [ -n "$DK_HTTP_LISTEN" ]; then
http_listen=$DK_HTTP_LISTEN
fi
http_port=9529
if [ -n "$DK_HTTP_PORT" ]; then
http_port=$DK_HTTP_PORT
fi
install_only=0
if [ -n "$DK_INSTALL_ONLY" ]; then
install_only=1
fi
dca_white_list=""
if [ -n "$DK_DCA_WHITE_LIST" ]; then
dca_white_list=$DK_DCA_WHITE_LIST
fi
dca_listen=""
if [ -n "$DK_DCA_LISTEN" ]; then
dca_listen=$DK_DCA_LISTEN
fi
dca_enable=""
if [ -n "$DK_DCA_ENABLE" ]; then
dca_enable="$DK_DCA_ENABLE"
if [ -z "$dca_white_list" ]; then
printf "${RED}[E] DCA service is enabled, but white list is not set in DK_DCA_WHITE_LIST!${CLR}\n"
exit 1;
fi
fi
pprof_listen=""
if [ -n "$DK_PPROF_LISTEN" ]; then
pprof_listen=$DK_PPROF_LISTEN
fi
ipdb_type=""
if [ -n "$DK_INSTALL_IPDB" ]; then
ipdb_type=$DK_INSTALL_IPDB
fi
install_externals=""
if [ -n "$DK_INSTALL_EXTERNALS" ]; then
install_externals=$DK_INSTALL_EXTERNALS
fi
if [ -n "$HTTP_PROXY" ]; then
proxy=$HTTP_PROXY
fi
if [ -n "$HTTPS_PROXY" ]; then
proxy=$HTTPS_PROXY
fi
# check nginx proxy
proxy_type=""
if [ -n "$DK_PROXY_TYPE" ]; then
proxy_type=$DK_PROXY_TYPE
proxy_type=$(echo "$proxy_type" | tr '[:upper:]' '[:lower:]') # to lowercase
printf "\n* found Proxy Type: %s\n" "$proxy_type"
if [ "$proxy_type" = "nginx" ]; then
# env DK_NGINX_IP has the highest priority on proxy level
if [ -n "$DK_NGINX_IP" ]; then
proxy=$DK_NGINX_IP
if [ "$proxy" != "" ]; then
printf "\n* got nginx Proxy: %s\n" "$proxy"
for i in "${domain[@]}"; do
updateHosts "$proxy" "$i"
done
fi
proxy=""
fi
fi
fi
env_hostname=
if [ -n "$DK_HOSTNAME" ]; then
env_hostname=$DK_HOSTNAME
fi
limit_cpumax=30
if [ -n "$DK_LIMIT_CPUMAX" ]; then
limit_cpumax=$DK_LIMIT_CPUMAX
fi
limit_cpumin=5
if [ -n "$DK_LIMIT_CPUMIN" ]; then
limit_cpumin=$DK_LIMIT_CPUMIN
fi
limit_memmax=4096
if [ -n "$DK_LIMIT_MEMMAX" ]; then
limit_memmax=$DK_LIMIT_MEMMAX
fi
cgroup_disabled=0
if [ -n "$DK_CGROUP_DISABLED" ]; then
cgroup_disabled=1
fi
install_log=/var/log/datakit/install.log
if [ -n "$DK_INSTALL_LOG" ]; then
install_log=$DK_INSTALL_LOG
fi
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=""
if [ -n "$DK_CONFD_BACKEND" ]; then
confd_backend=$DK_CONFD_BACKEND
fi
if [ -n "$DK_CONFD_BASIC_AUTH" ]; then
confd_basic_auth=$DK_CONFD_BASIC_AUTH
fi
if [ -n "$DK_CONFD_CLIENT_CA_KEYS" ]; then
confd_client_ca_keys=$DK_CONFD_CLIENT_CA_KEYS
fi
if [ -n "$DK_CONFD_CLIENT_CERT" ]; then
confd_client_cert=$DK_CONFD_CLIENT_CERT
fi
if [ -n "$DK_CONFD_CLIENT_KEY" ]; then
confd_client_key=$DK_CONFD_CLIENT_KEY
fi
if [ -n "$DK_CONFD_BACKEND_NODES" ]; then
confd_backend_nodes=$DK_CONFD_BACKEND_NODES
fi
if [ -n "$DK_CONFD_PASSWORD" ]; then
confd_password=$DK_CONFD_PASSWORD
fi
if [ -n "$DK_CONFD_SCHEME" ]; then
confd_scheme=$DK_CONFD_SCHEME
fi
if [ -n "$DK_CONFD_SEPARATOR" ]; then
confd_separator=$DK_CONFD_SEPARATOR
fi
if [ -n "$DK_CONFD_USERNAME" ]; then
confd_username=$DK_CONFD_USERNAME
fi
if [ -n "$DK_CONFD_ACCESS_KEY" ]; then
confd_role=$DK_CONFD_ACCESS_KEY
fi
if [ -n "$DK_CONFD_SECRET_KEY" ]; then
confd_role=$DK_CONFD_SECRET_KEY
fi
if [ -n "$DK_CONFD_CIRCLE_INTERVAL" ]; then
confd_role=$DK_CONFD_CIRCLE_INTERVAL
fi
if [ -n "$DK_CONFD_CONFD_NAMESPACE" ]; then
confd_role=$DK_CONFD_CONFD_NAMESPACE
fi
if [ -n "$DK_CONFD_PIPELINE_NAMESPACE" ]; then
confd_role=$DK_CONFD_PIPELINE_NAMESPACE
fi
if [ -n "$DK_CONFD_REGION" ]; then
confd_role=$DK_CONFD_REGION
fi
git_url=""
if [ -n "$DK_GIT_URL" ]; then
git_url=$DK_GIT_URL
fi
git_key_path=""
if [ -n "$DK_GIT_KEY_PATH" ]; then
git_key_path=$DK_GIT_KEY_PATH
fi
git_key_pw=""
if [ -n "$DK_GIT_KEY_PW" ]; then
git_key_pw=$DK_GIT_KEY_PW
fi
git_branch=""
if [ -n "$DK_GIT_BRANCH" ]; then
git_branch=$DK_GIT_BRANCH
fi
git_pull_interval=""
if [ -n "$DK_GIT_INTERVAL" ]; then
git_pull_interval=$DK_GIT_INTERVAL
fi
enable_election=""
if [ -n "$DK_ENABLE_ELECTION" ]; then
enable_election=$DK_ENABLE_ELECTION
fi
rum_origin_ip_header=""
if [ -n "$DK_RUM_ORIGIN_IP_HEADER" ]; then
rum_origin_ip_header=$DK_RUM_ORIGIN_IP_HEADER
fi
disable_404page=""
if [ -n "$DK_DISABLE_404PAGE" ]; then
disable_404page=$DK_DISABLE_404PAGE
fi
log_level=""
if [ -n "$DK_LOG_LEVEL" ]; then
log_level=$DK_LOG_LEVEL
fi
log=""
if [ -n "$DK_LOG" ]; then
log=$DK_LOG
fi
gin_log=""
if [ -n "$DK_GIN_LOG" ]; then
gin_log=$DK_GIN_LOG
fi
sinker=""
if [ -n "$DK_SINKER" ]; then
sinker=$DK_SINKER
fi
user_name=""
if [ -n "$DK_USER_NAME" ]; then
user_name=$DK_USER_NAME
fi
##################
# Try install...
##################
# shellcheck disable=SC2059
printf "\n* Downloading installer ${installer}\n"
rm -rf $installer
if [ "$proxy" ]; then # add proxy for curl
# shellcheck disable=SC2086
curl -s -x "$proxy" --fail --progress-bar $installer_url > $installer
else
# shellcheck disable=SC2086
curl --fail --progress-bar $installer_url > $installer
fi
# Set executable
chmod +x $installer
if [ "$upgrade" ]; then
# shellcheck disable=SC2059
printf "\n* Upgrading DataKit...\n"
$sudo_cmd $installer \
--install-log="$install_log" \
--upgrade --upgrade-manager="${upgrade_manager}" --upgrade-ip-whitelist="${upgrade_ip_whitelist}" --proxy="${proxy}" --installer_base_url="$installer_base_url"
else
printf "\n* Installing DataKit...\n"
$sudo_cmd $installer \
--install-log="${install_log}" \
--install-only="${install_only}" \
--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}" \
--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-cpumin="${limit_cpumin}" \
--limit-mem="${limit_memmax}" \
--cgroup-disabled="${cgroup_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="${sinker}" \
--user-name="${user_name}" \
--upgrade-ip-whitelist="${upgrade_ip_whitelist}" \
--gin-log="${gin_log}"
fi
rm -rf $installer
# install completion
$sudo_cmd datakit tool --setup-completer-script
1
https://gitee.com/oplg/datakit.git
git@gitee.com:oplg/datakit.git
oplg
datakit
DataKit
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891