deploy.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. #使用说明,用来提示输入参数
  3. usage() {
  4. echo "Usage: sh 执行脚本.sh [port|mount|base|monitor|modules|prometheus|alertmanager|stop|rm|rmiNoneTag]"
  5. exit 1
  6. }
  7. #开启所需端口
  8. port(){
  9. #gateway
  10. firewall-cmd --add-port=88/tcp --permanent
  11. #web
  12. firewall-cmd --add-port=8000/tcp --permanent
  13. #nacos
  14. firewall-cmd --add-port=8848/tcp --permanent
  15. firewall-cmd --add-port=9848/tcp --permanent
  16. firewall-cmd --add-port=9849/tcp --permanent
  17. #sentinel
  18. firewall-cmd --add-port=8858/tcp --permanent
  19. #grafana
  20. firewall-cmd --add-port=3000/tcp --permanent
  21. #mysql
  22. firewall-cmd --add-port=3306/tcp --permanent
  23. #redis
  24. firewall-cmd --add-port=3379/tcp --permanent
  25. #admin
  26. firewall-cmd --add-port=7002/tcp --permanent
  27. #turbine
  28. firewall-cmd --add-port=7003/tcp --permanent
  29. #ureport
  30. firewall-cmd --add-port=8108/tcp --permanent
  31. #zipkin
  32. firewall-cmd --add-port=9411/tcp --permanent
  33. #prometheus
  34. firewall-cmd --add-port=9090/tcp --permanent
  35. #swagger
  36. firewall-cmd --add-port=18000/tcp --permanent
  37. #firewalld
  38. service firewalld restart
  39. }
  40. ##放置挂载文件
  41. mount(){
  42. #挂载配置文件
  43. if test ! -f "/docker/nginx/api/nginx.conf" ;then
  44. mkdir -p /docker/nginx/api
  45. cp nginx/api/nginx.conf /docker/nginx/api/nginx.conf
  46. fi
  47. if test ! -f "/docker/nginx/web/nginx.conf" ;then
  48. mkdir -p /docker/nginx/web
  49. cp nginx/web/nginx.conf /docker/nginx/web/nginx.conf
  50. cp -r nginx/web/html /docker/nginx/web/html
  51. fi
  52. if test ! -f "/docker/nacos/init.d/custom.properties" ;then
  53. mkdir -p /docker/nacos/init.d
  54. cp nacos/init.d/custom.properties /docker/nacos/init.d/custom.properties
  55. fi
  56. if test ! -f "/docker/prometheus/prometheus.yml" ;then
  57. mkdir -p /docker/prometheus
  58. cp prometheus/config/prometheus.yml /docker/prometheus/prometheus.yml
  59. fi
  60. if test ! -f "/docker/prometheus/rules/alert_rules.yml" ;then
  61. mkdir -p /docker/prometheus/rules
  62. cp prometheus/config/alert_rules.yml /docker/prometheus/rules/alert_rules.yml
  63. fi
  64. if test ! -f "/docker/grafana/grafana.ini" ;then
  65. mkdir -p /docker/grafana
  66. cp prometheus/config/grafana.ini /docker/grafana/grafana.ini
  67. fi
  68. if test ! -f "/docker/alertmanager/alertmanager.yml" ;then
  69. mkdir -p /docker/alertmanager
  70. cp prometheus/config/alertmanager.yml /docker/alertmanager/alertmanager.yml
  71. fi
  72. if test ! -f "/docker/alertmanager/templates/wechat.tmpl" ;then
  73. mkdir -p /docker/alertmanager/templates
  74. cp prometheus/config/wechat.tmpl /docker/alertmanager/templates/wechat.tmpl
  75. fi
  76. if test ! -f "/docker/webhook_dingtalk/dingtalk.yml" ;then
  77. mkdir -p /docker/webhook_dingtalk
  78. cp prometheus/config/dingtalk.yml /docker/webhook_dingtalk/dingtalk.yml
  79. fi
  80. #增加目录权限
  81. chmod -R 777 /docker/prometheus
  82. chmod -R 777 /docker/grafana
  83. chmod -R 777 /docker/alertmanager
  84. }
  85. #启动基础模块
  86. base(){
  87. docker-compose up -d nacos sentinel seata-server web-nginx blade-nginx blade-redis
  88. }
  89. #启动监控模块
  90. monitor(){
  91. docker-compose up -d blade-admin blade-turbine
  92. }
  93. #启动程序模块
  94. modules(){
  95. docker-compose up -d blade-gateway1 blade-gateway2 blade-auth1 blade-auth2 blade-swagger blade-report blade-user blade-desk blade-system blade-log blade-flow blade-resource
  96. }
  97. #启动普罗米修斯模块
  98. prometheus(){
  99. docker-compose up -d prometheus node-exporter mysqld-exporter cadvisor grafana
  100. }
  101. #启动监听模块
  102. alertmanager(){
  103. docker-compose up -d alertmanager webhook-dingtalk
  104. }
  105. #关闭所有模块
  106. stop(){
  107. docker-compose stop
  108. }
  109. #删除所有模块
  110. rm(){
  111. docker-compose rm
  112. }
  113. #删除Tag为空的镜像
  114. rmiNoneTag(){
  115. docker images|grep none|awk '{print $3}'|xargs docker rmi -f
  116. }
  117. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  118. case "$1" in
  119. "port")
  120. port
  121. ;;
  122. "mount")
  123. mount
  124. ;;
  125. "base")
  126. base
  127. ;;
  128. "monitor")
  129. monitor
  130. ;;
  131. "modules")
  132. modules
  133. ;;
  134. "prometheus")
  135. prometheus
  136. ;;
  137. "alertmanager")
  138. alertmanager
  139. ;;
  140. "stop")
  141. stop
  142. ;;
  143. "rm")
  144. rm
  145. ;;
  146. "rmiNoneTag")
  147. rmiNoneTag
  148. ;;
  149. *)
  150. usage
  151. ;;
  152. esac