Commit 35468bab authored by 段孔乐's avatar 段孔乐

add install script

parent cf53da7e
kibana_host="127.0.0.1:15601"
es_host="127.0.0.1:19200"
#!/bin/bash
. util.sh
. .env
kibana_host="localhost:$KIBANA_PORT"
es_host="localhost:$ES_PORT1"
function setDefaultIndex(){
......@@ -10,55 +16,46 @@ curl --location --request POST "http://$kibana_host/api/kibana/settings" \
}
function addTestData() {
curl --location --request POST "http://$es_host/$1/_doc/testdata" \
function addILMPolicy() {
curl -XPOST "http://$es_host/_ilm/policy/service-log" \
--header 'Content-Type: application/json' \
--data-raw '{
"message": test data
}'
--data-raw '{"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"set_priority":{"priority":100}}},"delete":{"min_age":"365d","actions":{"delete":{"delete_searchable_snapshot":true}}}}}}'
}
function addIndexPattern(){
serviceName="${1}"
index="${serviceName#\*}"
index="${index%\*}"
addTestData "$index"
resp=$(curl -XPOST "http://$kibana_host/api/saved_objects/index-pattern" \
--header 'kbn-version: 7.12.0' \
--header 'Content-Type: application/json' \
--data-raw "{\"attributes\":{\"title\":\"$1\",\"timeFieldName\":\"@timestamp\"}}")
if [ "$(echo "$resp" | grep -c '{"type":"index-pattern","id":"')" -lt 1 ]; then echo "addIndexPattern failed, resp:$resp"; exit; fi
id="${resp##*id\":\"}"
id="${id%%\"*}"
function contain() {
if [ "$(echo "$1" | grep -c "$2")" -gt 0 ]; then return 0; else return 1; fi
}
return "$id"
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
}
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
}
id=addIndexPattern "*-service*"
setDefaultIndex "$id"
id=addIndexPattern "*-service-v1*"
id=addIndexPattern "*-service-v2*"
id=addIndexPattern "auth-service-v1*"
id=addIndexPattern "department-service-v2*"
id=addIndexPattern "file-service-v1*"
id=addIndexPattern "gateway-service-v1*"
id=addIndexPattern "gateway-service-v2*"
id=addIndexPattern "notify-service-v1*"
id=addIndexPattern "others*"
id=addIndexPattern "pay-service-v1*"
id=addIndexPattern "process-service-v2*"
id=addIndexPattern "proof-service-v1*"
id=addIndexPattern "role-service-v2*"
id=addIndexPattern "swagger-service-v1*"
id=addIndexPattern "swagger-service-v2*"
id=addIndexPattern "template-service-v2*"
id=addIndexPattern "trace-service-v2*"
id=addIndexPattern "tx-service-v1*"
id=addIndexPattern "user-service-v1*"
start=$(date +%s)
while notHealth
do
end=$(date +%s)
take=$(( end - start ))
red "Kibana not ready yet, waitTime: $take"
sleep 1s
done
green "======================================="
green "Kibana is ready. Initialization begins."
green "======================================="
addILMPolicy
uploadConfig
green "Initialization completed."
green "Visit the following website to discover data"
green "http://$kibana_host/app/discover"
green "End"
#!/bin/bash
. start.sh
. init-kibana.sh
\ No newline at end of file
{"attributes":{"buildNum":39309,"dateFormat":"YYYY-MM-DD HH:mm:ss.SSS","dateFormat:dow":"Monday","dateFormat:tz":"Asia/Shanghai","dateNanosFormat":"YYYY-MM-DD HH:mm:ss.SSSSSSSSS","defaultColumns":["message"],"defaultIndex":"3dd09b40-b302-11eb-8677-fd4740a7c42a"},"coreMigrationVersion":"7.12.0","id":"7.12.0","migrationVersion":{"config":"7.12.0"},"references":[],"type":"config","updated_at":"2021-07-02T05:10:07.453Z","version":"Wzc3NjUxLDExXQ=="}
{"attributes":{"fieldAttrs":"{}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"role-service*"},"coreMigrationVersion":"7.12.0","id":"a26fc570-b6d7-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-05-17T06:18:02.439Z","version":"WzYwMjE4LDExXQ=="}
{"attributes":{"fieldAttrs":"{}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"notify-service-v1*"},"coreMigrationVersion":"7.12.0","id":"cf0150c0-bf9e-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-05-28T10:23:56.364Z","version":"WzY0Mjc1LDExXQ=="}
{"attributes":{"fieldAttrs":"{\"service.version\":{\"count\":2}}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"others*"},"coreMigrationVersion":"7.12.0","id":"cb829560-b3d9-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-05-31T02:53:05.046Z","version":"WzcxMjI4LDExXQ=="}
{"attributes":{"fieldAttrs":"{\"json.content\":{\"count\":13},\"json.duration\":{\"count\":7},\"json.level\":{\"count\":5},\"json.span\":{\"count\":4},\"json.trace\":{\"count\":4},\"log.file.path\":{\"count\":4},\"message\":{\"count\":10},\"service.name\":{\"count\":1},\"service.version\":{\"count\":2}}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"*-service*"},"coreMigrationVersion":"7.12.0","id":"3dd09b40-b302-11eb-8677-fd4740a7c42a","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-06-22T02:40:13.017Z","version":"Wzc1ODg4LDExXQ=="}
{"attributes":{"fieldAttrs":"{\"json.content\":{\"count\":2},\"message\":{\"count\":11},\"_id\":{\"count\":8},\"_type\":{\"count\":1},\"json.level\":{\"count\":6}}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"trace-service-v2*"},"coreMigrationVersion":"7.12.0","id":"d2394ae0-c1ba-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-06-30T07:33:22.471Z","version":"Wzc2OTk3LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"auth-service-v1*"},"coreMigrationVersion":"7.12.0","id":"66aa7500-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:20.432Z","version":"Wzc3NTQ2LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"*-service-v1*"},"coreMigrationVersion":"7.12.0","id":"65763ac0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:18.412Z","version":"Wzc3NTQyLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"*-service-v2*"},"coreMigrationVersion":"7.12.0","id":"661030d0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:19.421Z","version":"Wzc3NTQ0LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"department-service-v2*"},"coreMigrationVersion":"7.12.0","id":"67441cf0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:21.439Z","version":"Wzc3NTQ4LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"gateway-service-v2*"},"coreMigrationVersion":"7.12.0","id":"69105170-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:24.455Z","version":"Wzc3NTU0LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"gateway-service-v1*"},"coreMigrationVersion":"7.12.0","id":"687c9cf0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:23.487Z","version":"Wzc3NTUyLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"process-service-v2*"},"coreMigrationVersion":"7.12.0","id":"6c104b00-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:29.489Z","version":"Wzc3NTY0LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"file-service-v1*"},"coreMigrationVersion":"7.12.0","id":"67dc8c60-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:22.438Z","version":"Wzc3NTUwLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"pay-service-v1*"},"coreMigrationVersion":"7.12.0","id":"6b7606d0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:28.477Z","version":"Wzc3NTYyLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"proof-service-v1*"},"coreMigrationVersion":"7.12.0","id":"6ca9cbe0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:30.494Z","version":"Wzc3NTY2LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"swagger-service-v2*"},"coreMigrationVersion":"7.12.0","id":"6faef590-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:35.561Z","version":"Wzc3NTc0LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"template-service-v2*"},"coreMigrationVersion":"7.12.0","id":"704198a0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:36.522Z","version":"Wzc3NTc2LDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"swagger-service-v1*"},"coreMigrationVersion":"7.12.0","id":"6f14ff80-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:34.552Z","version":"Wzc3NTcyLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"tx-service-v1*"},"coreMigrationVersion":"7.12.0","id":"7173d710-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:38.529Z","version":"Wzc3NTgwLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"user-service-v1*"},"coreMigrationVersion":"7.12.0","id":"720e4250-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:39.541Z","version":"Wzc3NTgyLDExXQ=="}
{"attributes":{"timeFieldName":"@timestamp","title":"role-service-v2*"},"coreMigrationVersion":"7.12.0","id":"6e7e8be0-daf2-11eb-bdce-75a994460910","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern","updated_at":"2021-07-02T05:00:33.566Z","version":"Wzc3NTcwLDExXQ=="}
{"attributes":{"columns":["json.content","json.duration","json.level","json.span","json.trace"],"description":"","hits":0,"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[{\"meta\":{\"alias\":null,\"negate\":false,\"disabled\":false,\"type\":\"exists\",\"key\":\"json.content\",\"value\":\"exists\",\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index\"},\"exists\":{\"field\":\"json.content\"},\"$state\":{\"store\":\"appState\"}}],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"},"sort":[["@timestamp","desc"]],"title":"json","version":1},"coreMigrationVersion":"7.12.0","id":"df93aa50-b30f-11eb-8677-fd4740a7c42a","migrationVersion":{"search":"7.9.3"},"references":[{"id":"3dd09b40-b302-11eb-8677-fd4740a7c42a","name":"kibanaSavedObjectMeta.searchSourceJSON.index","type":"index-pattern"},{"id":"3dd09b40-b302-11eb-8677-fd4740a7c42a","name":"kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index","type":"index-pattern"}],"type":"search","updated_at":"2021-05-12T10:50:32.181Z","version":"WzU1NTYxLDExXQ=="}
{"exportedCount":23,"missingRefCount":0,"missingReferences":[]}
\ No newline at end of file
#!/bin/bash
# 字体颜色
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
. ./util.sh
. ./.env
function checkPort(){
......@@ -43,7 +33,6 @@ function checkPS(){
if [ "$(docker ps | grep -c 'docker-elk' )" -gt 0 ]; then
red "======================="
red "ELK are already started"
red "======================="
exit
fi
......
#!/bin/bash
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
if [[ -f /etc/redhat-release ]]; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "debian"; then
release="debian"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
release="ubuntu"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "debian"; then
release="debian"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "ubuntu"; then
release="ubuntu"
systemPackage="apt-get"
systempwd="/lib/systemd/system/"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
systempwd="/usr/lib/systemd/system/"
fi
\ No newline at end of file
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