deploy.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #./bin/bash
  2. # 定义颜色
  3. BLUE_COLOR="\033[36m"
  4. RED_COLOR="\033[31m"
  5. GREEN_COLOR="\033[32m"
  6. VIOLET_COLOR="\033[35m"
  7. RES="\033[0m"
  8. echo -e "${BLUE_COLOR}# ######################################################################${RES}"
  9. echo -e "${BLUE_COLOR}# Docker ELK Deploy Script #${RES}"
  10. echo -e "${BLUE_COLOR}# ######################################################################${RES}"
  11. # 创建目录
  12. echo -e "${BLUE_COLOR}---> create [elasticsearch]directory start.${RES}"
  13. if [ ! -d "./elasticsearch/" ]; then
  14. mkdir -p ./elasticsearch/master/conf ./elasticsearch/master/data ./elasticsearch/master/logs \
  15. ./elasticsearch/slave1/conf ./elasticsearch/slave1/data ./elasticsearch/slave1/logs \
  16. ./elasticsearch/slave2/conf ./elasticsearch/slave2/data ./elasticsearch/slave2/logs
  17. fi
  18. echo -e "${RED_COLOR}---> create [kibana]directory start.${RES}"
  19. if [ ! -d "./kibana/" ]; then
  20. mkdir -p ./kibana/conf ./kibana/logs
  21. fi
  22. echo -e "${GREEN_COLOR}---> create [logstash]directory start.${RES}"
  23. if [ ! -d "./logstash/" ]; then
  24. mkdir -p ./logstash/conf ./logstash/logs
  25. fi
  26. echo -e "${GREEN_COLOR}---> create [filebeat]directory start.${RES}"
  27. if [ ! -d "./filebeat/" ]; then
  28. mkdir -p ./filebeat/conf ./filebeat/logs ./filebeat/data
  29. fi
  30. echo -e "${VIOLET_COLOR}---> create [nginx]directory start.${RES}"
  31. if [ ! -d "./nginx/" ]; then
  32. mkdir -p ./nginx/conf ./nginx/logs ./nginx/www
  33. fi
  34. echo -e "${BLUE_COLOR}===> create directory success.${RES}"
  35. # 目录授权(data/logs 都要授读/写权限)
  36. echo -e "${BLUE_COLOR}---> directory authorize start.${RES}"
  37. if [ -d "./elasticsearch/" ]; then
  38. chmod 777 ./elasticsearch/master/data/ ./elasticsearch/master/logs/ \
  39. ./elasticsearch/slave1/data/ ./elasticsearch/slave1/logs/ \
  40. ./elasticsearch/slave2/data/ ./elasticsearch/slave2/logs
  41. fi
  42. if [ -d "./filebeat/" ]; then
  43. chmod 777 ./filebeat/data/ ./filebeat/logs/
  44. fi
  45. echo -e "${BLUE_COLOR}===> directory authorize success.${RES}"
  46. # 移动配置文件
  47. echo -e "${BLUE_COLOR}---> move [elasticsearch]config file start.${RES}"
  48. if [ -f "./es-master.yml" ] && [ -f "./es-slave1.yml" ] && [ -f "./es-slave2.yml" ]; then
  49. mv ./es-master.yml ./elasticsearch/master/conf
  50. mv ./es-slave1.yml ./elasticsearch/slave1/conf
  51. mv ./es-slave2.yml ./elasticsearch/slave2/conf
  52. fi
  53. echo -e "${RED_COLOR}---> move [kibana]config file start.${RES}"
  54. if [ -f "./kibana.yml" ]; then
  55. mv ./kibana.yml ./kibana/conf
  56. fi
  57. echo -e "${GREEN_COLOR}---> move [logstash]config file start.${RES}"
  58. if [ -f "./logstash.yml" ] && [ -f "./logstash-filebeat.conf" ]; then
  59. mv ./logstash-filebeat.conf ./logstash/conf
  60. mv ./logstash.yml ./logstash/conf
  61. fi
  62. echo -e "${GREEN_COLOR}---> move [filebeat]config file start.${RES}"
  63. if [ -f "./filebeat.yml" ]; then
  64. mv ./filebeat.yml ./filebeat/conf
  65. fi
  66. echo -e "${VIOLET_COLOR}---> move [nginx]config file start.${RES}"
  67. if [ -f "./nginx.conf" ]; then
  68. mv ./nginx.conf ./nginx/conf
  69. fi
  70. echo -e "${BLUE_COLOR}===> move config files success.${RES}"
  71. echo -e "${GREEN_COLOR}>>>>>>>>>>>>>>>>>> The End <<<<<<<<<<<<<<<<<<${RES}"
  72. # 部署项目
  73. echo -e "${BLUE_COLOR}==================> Docker deploy Start <==================${RES}"
  74. docker-compose up --build -d