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

modify install script

parent 35468bab
...@@ -6,56 +6,77 @@ ...@@ -6,56 +6,77 @@
kibana_host="localhost:$KIBANA_PORT" kibana_host="localhost:$KIBANA_PORT"
es_host="localhost:$ES_PORT1" es_host="localhost:$ES_PORT1"
function setDefaultIndex() {
function setDefaultIndex(){ curl --location --request POST "http://$kibana_host/api/kibana/settings" \
--header 'kbn-version: 7.12.0' \
curl --location --request POST "http://$kibana_host/api/kibana/settings" \ --header 'Content-Type: application/json' \
--header 'kbn-version: 7.12.0' \ --data-raw "{\"changes\":{\"defaultIndex\":\"$1\"}}"
--header 'Content-Type: application/json' \
--data-raw "{\"changes\":{\"defaultIndex\":\"$1\"}}"
} }
function addILMPolicy() { function addILMPolicy() {
curl -XPOST "http://$es_host/_ilm/policy/service-log" \ resp=$(
--header 'Content-Type: application/json' \ curl -s -XPUT "http://$es_host/_ilm/policy/service-log" \
--data-raw '{"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"set_priority":{"priority":100}}},"delete":{"min_age":"365d","actions":{"delete":{"delete_searchable_snapshot":true}}}}}}' --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() { function addIndexTemplate() {
if [ "$(echo "$1" | grep -c "$2")" -gt 0 ]; then return 0; else return 1; fi 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() { function uploadConfig() {
resp=$(curl -s -XPOST "$kibana_host/api/saved_objects/_import?createNewCopies=true" --form "file=@kibana/export.ndjson" --header 'kbn-xsrf: true') resp=$(curl -s -XPOST "$kibana_host/api/saved_objects/_import?overwrite=true" --form "file=@kibana/export.ndjson" --header 'kbn-xsrf: true')
if contain "$resp" 'success'; then\ echo "$resp"
echo "config upload succeed"; if contain "$resp" 'success'; then
else echo "config upload failed" ; green "config upload succeed"
fi else
red "config upload failed"
fi
} }
function notHealth() { function notHealth() {
resp=$(curl -sIL -m 5 -w "%{http_code}" -o /dev/null -XGET "$kibana_host/api/features" --header 'kbn-xsrf: true') 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 if [ "$resp" == 200 ]; then
else return 0 return 1
fi else
return 0
fi
} }
start=$(date +%s) start=$(date +%s)
while notHealth while notHealth; do
do end=$(date +%s)
end=$(date +%s) take=$((end - start))
take=$(( end - start )) red "Kibana not ready yet, waiting... time: $take"
red "Kibana not ready yet, waitTime: $take" sleep 1s
sleep 1s
done done
green "=======================================" green "======================================="
green "Kibana is ready. Initialization begins." green "Kibana is ready. Initialization begins."
green "=======================================" green "======================================="
addILMPolicy addILMPolicy
addIndexTemplate
uploadConfig uploadConfig
green ""
green "========================="
green "Initialization completed." green "Initialization completed."
green "Visit the following website to discover data" green "========================="
green "http://$kibana_host/app/discover" blue "Visit the following website to discover data"
blue "http://$kibana_host/app/discover"
green "End" green "End"
...@@ -38,3 +38,7 @@ elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then ...@@ -38,3 +38,7 @@ elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
systemPackage="yum" systemPackage="yum"
systempwd="/usr/lib/systemd/system/" systempwd="/usr/lib/systemd/system/"
fi 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