Commit 7cf3eb4a authored by 段孔乐's avatar 段孔乐

modify install script

parent 35468bab
......@@ -6,56 +6,77 @@
kibana_host="localhost:$KIBANA_PORT"
es_host="localhost:$ES_PORT1"
function setDefaultIndex(){
curl --location --request POST "http://$kibana_host/api/kibana/settings" \
--header 'kbn-version: 7.12.0' \
--header 'Content-Type: application/json' \
--data-raw "{\"changes\":{\"defaultIndex\":\"$1\"}}"
function setDefaultIndex() {
curl --location --request POST "http://$kibana_host/api/kibana/settings" \
--header 'kbn-version: 7.12.0' \
--header 'Content-Type: application/json' \
--data-raw "{\"changes\":{\"defaultIndex\":\"$1\"}}"
}
function addILMPolicy() {
curl -XPOST "http://$es_host/_ilm/policy/service-log" \
--header 'Content-Type: application/json' \
--data-raw '{"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"set_priority":{"priority":100}}},"delete":{"min_age":"365d","actions":{"delete":{"delete_searchable_snapshot":true}}}}}}'
resp=$(
curl -s -XPUT "http://$es_host/_ilm/policy/service-log" \
--header 'Content-Type: application/json' \
--data-raw '{"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"set_priority":{"priority":100}}},"delete":{"min_age":"365d","actions":{"delete":{"delete_searchable_snapshot":true}}}}}}'
)
echo "$resp"
if contain "$resp" '{"acknowledged":true}'; then
green "index life cycle import success"
else
red "index life cycle import failed"
fi
}
function contain() {
if [ "$(echo "$1" | grep -c "$2")" -gt 0 ]; then return 0; else return 1; fi
function addIndexTemplate() {
resp=$(
curl -s -XPUT "http://$es_host/_index_template/service-log" \
--header 'Content-Type: application/json' \
--data-raw '{"template":{"settings":{"index":{"lifecycle":{"name":"service-log"}}},"mappings":{"_source":{"excludes":[],"includes":[],"enabled":true},"_routing":{"required":false},"dynamic":true,"numeric_detection":false,"date_detection":true,"dynamic_date_formats":["strict_date_optional_time","yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z"],"dynamic_templates":[]}},"index_patterns":["*-service-*"]}'
)
echo "$resp"
if contain "$resp" '{"acknowledged":true}'; then
green "index template import success"
else
red "index template import failed"
fi
}
function uploadConfig() {
resp=$(curl -s -XPOST "$kibana_host/api/saved_objects/_import?createNewCopies=true" --form "file=@kibana/export.ndjson" --header 'kbn-xsrf: true')
if contain "$resp" 'success'; then\
echo "config upload succeed";
else echo "config upload failed" ;
fi
resp=$(curl -s -XPOST "$kibana_host/api/saved_objects/_import?overwrite=true" --form "file=@kibana/export.ndjson" --header 'kbn-xsrf: true')
echo "$resp"
if contain "$resp" 'success'; then
green "config upload succeed"
else
red "config upload failed"
fi
}
function notHealth() {
resp=$(curl -sIL -m 5 -w "%{http_code}" -o /dev/null -XGET "$kibana_host/api/features" --header 'kbn-xsrf: true')
if [ "$resp" == 200 ]; then return 1
else return 0
fi
resp=$(curl -sIL -m 5 -w "%{http_code}" -o /dev/null -XGET "$kibana_host/api/features" --header 'kbn-xsrf: true')
if [ "$resp" == 200 ]; then
return 1
else
return 0
fi
}
start=$(date +%s)
while notHealth
do
end=$(date +%s)
take=$(( end - start ))
red "Kibana not ready yet, waitTime: $take"
sleep 1s
while notHealth; do
end=$(date +%s)
take=$((end - start))
red "Kibana not ready yet, waiting... time: $take"
sleep 1s
done
green "======================================="
green "Kibana is ready. Initialization begins."
green "======================================="
addILMPolicy
addIndexTemplate
uploadConfig
green ""
green "========================="
green "Initialization completed."
green "Visit the following website to discover data"
green "http://$kibana_host/app/discover"
green "========================="
blue "Visit the following website to discover data"
blue "http://$kibana_host/app/discover"
green "End"
......@@ -38,3 +38,7 @@ elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
fi
function contain() {
if [ "$(echo "$1" | grep -c "$2")" -gt 0 ]; then return 0; else return 1; fi
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment