deploy.sh 3.9 KB

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