Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
docker-elk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段孔乐
docker-elk
Commits
7cf3eb4a
Commit
7cf3eb4a
authored
Jul 05, 2021
by
段孔乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify install script
parent
35468bab
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
31 deletions
+56
-31
init-kibana.sh
init-kibana.sh
+52
-31
util.sh
util.sh
+4
-0
No files found.
init-kibana.sh
View file @
7cf3eb4a
...
@@ -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"
util.sh
View file @
7cf3eb4a
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment