install-escheduler-ui.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/bin/bash
  2. # 当前路径
  3. esc_basepath=$(cd `dirname $0`; pwd)
  4. echo "欢迎使用easy scheduler前端部署脚本,目前前端部署脚本仅支持Centos"
  5. echo "请在 escheduler-ui 目录下执行"
  6. # 配置前端访问端口
  7. esc_proxy="8888"
  8. # 配置代理后端接口
  9. esc_proxy_port="http://192.168.xx.xx:12345"
  10. # 本机ip
  11. esc_ipaddr='127.0.0.1'
  12. esc_ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
  13. #To be compatible with MacOS and Linux
  14. if [[ "$OSTYPE" == "darwin"* ]]; then
  15. # Mac OSX
  16. echo "Easy Scheduler ui install not support Mac OSX operating system"
  17. exit 1
  18. elif [[ "$OSTYPE" == "linux-gnu" ]]; then
  19. # linux
  20. echo "linux"
  21. elif [[ "$OSTYPE" == "cygwin" ]]; then
  22. # POSIX compatibility layer and Linux environment emulation for Windows
  23. echo "Easy Scheduler ui not support Windows operating system"
  24. exit 1
  25. elif [[ "$OSTYPE" == "msys" ]]; then
  26. # Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
  27. echo "Easy Scheduler ui not support Windows operating system"
  28. exit 1
  29. elif [[ "$OSTYPE" == "win32" ]]; then
  30. echo "Easy Scheduler ui not support Windows operating system"
  31. exit 1
  32. elif [[ "$OSTYPE" == "freebsd"* ]]; then
  33. # ...
  34. echo "freebsd"
  35. else
  36. # Unknown.
  37. echo "Operating system unknown, please tell us(submit issue) for better service"
  38. exit 1
  39. fi
  40. # 区分版本
  41. version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
  42. echo "========================================================================配置信息======================================================================="
  43. echo "前端访问端口:${esc_proxy}"
  44. echo "后端代理接口地址:${esc_proxy_port}"
  45. echo "静态文件地址:${esc_basepath}/dist"
  46. echo "当前路径:${esc_basepath}"
  47. echo "本机ip:${esc_ipaddr}"
  48. echo "========================================================================配置信息======================================================================="
  49. echo ""
  50. # 创建文件并配置nginx
  51. eschedulerConf(){
  52. E_host='$host'
  53. E_remote_addr='$remote_addr'
  54. E_proxy_add_x_forwarded_for='$proxy_add_x_forwarded_for'
  55. E_http_upgrade='$http_upgrade'
  56. echo "
  57. server {
  58. listen $esc_proxy;# 访问端口
  59. server_name localhost;
  60. #charset koi8-r;
  61. #access_log /var/log/nginx/host.access.log main;
  62. location / {
  63. root ${esc_basepath}/dist; # 静态文件目录
  64. index index.html index.html;
  65. }
  66. location /escheduler {
  67. proxy_pass ${esc_proxy_port}; # 接口地址
  68. proxy_set_header Host $E_host;
  69. proxy_set_header X-Real-IP $E_remote_addr;
  70. proxy_set_header x_real_ipP $E_remote_addr;
  71. proxy_set_header remote_addr $E_remote_addr;
  72. proxy_set_header X-Forwarded-For $E_proxy_add_x_forwarded_for;
  73. proxy_http_version 1.1;
  74. proxy_connect_timeout 4s;
  75. proxy_read_timeout 30s;
  76. proxy_send_timeout 12s;
  77. proxy_set_header Upgrade $E_http_upgrade;
  78. proxy_set_header Connection "upgrade";
  79. }
  80. #error_page 404 /404.html;
  81. # redirect server error pages to the static page /50x.html
  82. #
  83. error_page 500 502 503 504 /50x.html;
  84. location = /50x.html {
  85. root /usr/share/nginx/html;
  86. }
  87. }
  88. " >> /etc/nginx/conf.d/escheduler.conf
  89. }
  90. centos7(){
  91. # nginx是否安装
  92. sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  93. sudo yum install -y nginx
  94. echo "nginx 安装成功"
  95. # 配置nginx
  96. eschedulerConf
  97. # 解决 0.0.0.0:8888 问题
  98. yum -y install policycoreutils-python
  99. semanage port -a -t http_port_t -p tcp $esc_proxy
  100. # 开放前端访问端口
  101. firewall-cmd --zone=public --add-port=$esc_proxy/tcp --permanent
  102. # 重启防火墙
  103. firewall-cmd --reload
  104. # 启动nginx
  105. systemctl start nginx
  106. # 调整SELinux的参数
  107. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  108. # 临时生效
  109. setenforce 0
  110. }
  111. centos6(){
  112. # yum
  113. E_basearch='$basearch'
  114. E_releasever='$releasever'
  115. echo "
  116. [nginx]
  117. name=nginx repo
  118. baseurl=http://nginx.org/packages/centos/$E_releasever/$E_basearch/
  119. gpgcheck=0
  120. enabled=1
  121. " >> /etc/yum.repos.d/nginx.repo
  122. # install nginx
  123. yum install nginx -y
  124. # 配置nginx
  125. eschedulerConf
  126. # 防火墙
  127. E_iptables=`lsof -i:$esc_proxy | wc -l`
  128. if [ "$E_iptables" -gt "0" ];then
  129. # 已开启端口防火墙重启
  130. service iptables restart
  131. else
  132. # 未开启防火墙添加端口再重启
  133. iptables -I INPUT 5 -i eth0 -p tcp --dport $esc_proxy -m state --state NEW,ESTABLISHED -j ACCEPT
  134. service iptables save
  135. service iptables restart
  136. fi
  137. # start
  138. /etc/init.d/nginx start
  139. # 调整SELinux的参数
  140. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  141. # 临时生效
  142. setenforce 0
  143. }
  144. # centos 6
  145. if [[ $version -eq 6 ]]; then
  146. centos6
  147. fi
  148. # centos 7
  149. if [[ $version -eq 7 ]]; then
  150. centos7
  151. fi
  152. echo "请浏览器访问:http://${esc_ipaddr}:${esc_proxy}"