Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

init-kibana.sh 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # unset http proxy which maybe set by docker daemon
  3. export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""
  4. echo "Elasticsearch built-in user: elastic:${ELASTIC_PASSWORD}"
  5. # Wait Elasticsearch be healthy
  6. while true; do
  7. response=$(curl -s -v -w "\n%{http_code}" -u "elastic:${ELASTIC_PASSWORD}" "http://es01:9200")
  8. exit_code=$?
  9. status=$(echo "$response" | tail -n1)
  10. if [ $exit_code -eq 0 ] && [ "$status" = "200" ]; then
  11. echo "Elasticsearch is healthy"
  12. break
  13. else
  14. echo "Elasticsearch is unhealthy: $exit_code $status"
  15. echo "$response"
  16. sleep 5
  17. fi
  18. done
  19. # Create new role with all privileges to all indices
  20. # https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html#privileges-list-indices
  21. echo "Going to create Elasticsearch role own_indices with all privileges to all indices"
  22. while true; do
  23. response=$(curl -s -v -w "\n%{http_code}" -u "elastic:${ELASTIC_PASSWORD}" -X POST http://es01:9200/_security/role/own_indices -H 'Content-Type: application/json' -d '{"indices": [{"names": ["*"], "privileges": ["all"]}]}')
  24. exit_code=$?
  25. status=$(echo "$response" | tail -n1)
  26. if [ $exit_code -eq 0 ] && [ "$status" = "200" ]; then
  27. echo "Elasticsearch role own_indices created"
  28. break
  29. else
  30. echo "Elasticsearch role own_indices failure: $exit_code $status"
  31. echo "$response"
  32. sleep 5
  33. fi
  34. done
  35. echo "Elasticsearch role own_indices:"
  36. curl -u "elastic:${ELASTIC_PASSWORD}" -X GET "http://es01:9200/_security/role/own_indices"
  37. echo ""
  38. PAYLOAD="{\"password\": \"${KIBANA_PASSWORD}\", \"roles\": [\"kibana_admin\", \"kibana_system\", \"own_indices\"], \"full_name\": \"${KIBANA_USER}\", \"email\": \"${KIBANA_USER}@example.com\"}"
  39. echo "Going to create Elasticsearch user ${KIBANA_USER}: ${PAYLOAD}"
  40. # Create new user
  41. while true; do
  42. response=$(curl -s -v -w "\n%{http_code}" -u "elastic:${ELASTIC_PASSWORD}" -X POST http://es01:9200/_security/user/${KIBANA_USER} -H "Content-Type: application/json" -d "${PAYLOAD}")
  43. exit_code=$?
  44. status=$(echo "$response" | tail -n1)
  45. if [ $exit_code -eq 0 ] && [ "$status" = "200" ]; then
  46. echo "Elasticsearch user ${KIBANA_USER} created"
  47. break
  48. else
  49. echo "Elasticsearch user ${KIBANA_USER} failure: $exit_code $status"
  50. echo "$response"
  51. sleep 5
  52. fi
  53. done
  54. echo "Elasticsearch user ${KIBANA_USER}:"
  55. curl -u "elastic:${ELASTIC_PASSWORD}" -X GET "http://es01:9200/_security/user/${KIBANA_USER}"
  56. echo ""
  57. exit 0