install-escheduler-ui.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/bash
  2. # 当前路径
  3. esc_basepath=$(cd `dirname $0`; pwd)
  4. menu(){
  5. cat <<END
  6. =================================================
  7. 1.CentOS6安装
  8. 2.CentOS7安装
  9. 3.Ubuntu安装
  10. 4.退出
  11. =================================================
  12. END
  13. }
  14. # 创建文件并配置nginx
  15. eschedulerConf(){
  16. E_host='$host'
  17. E_remote_addr='$remote_addr'
  18. E_proxy_add_x_forwarded_for='$proxy_add_x_forwarded_for'
  19. E_http_upgrade='$http_upgrade'
  20. echo "
  21. server {
  22. listen $1;# 访问端口
  23. server_name localhost;
  24. #charset koi8-r;
  25. #access_log /var/log/nginx/host.access.log main;
  26. location / {
  27. root ${esc_basepath}/dist; # 静态文件目录
  28. index index.html index.html;
  29. }
  30. location /escheduler {
  31. proxy_pass $2; # 接口地址
  32. proxy_set_header Host $E_host;
  33. proxy_set_header X-Real-IP $E_remote_addr;
  34. proxy_set_header x_real_ipP $E_remote_addr;
  35. proxy_set_header remote_addr $E_remote_addr;
  36. proxy_set_header X-Forwarded-For $E_proxy_add_x_forwarded_for;
  37. proxy_http_version 1.1;
  38. proxy_connect_timeout 300s;
  39. proxy_read_timeout 300s;
  40. proxy_send_timeout 300s;
  41. proxy_set_header Upgrade $E_http_upgrade;
  42. proxy_set_header Connection "upgrade";
  43. }
  44. #error_page 404 /404.html;
  45. # redirect server error pages to the static page /50x.html
  46. #
  47. error_page 500 502 503 504 /50x.html;
  48. location = /50x.html {
  49. root /usr/share/nginx/html;
  50. }
  51. }
  52. " >> /etc/nginx/conf.d/escheduler.conf
  53. }
  54. ubuntu(){
  55. #更新源
  56. apt-get update
  57. #安装nginx
  58. apt-get install -y nginx
  59. # 配置nginx
  60. eschedulerConf $1 $2
  61. # 启动nginx
  62. /etc/init.d/nginx start
  63. sleep 1
  64. if [ $? -ne 0 ];then
  65. /etc/init.d/nginx start
  66. fi
  67. nginx -s reload
  68. }
  69. centos7(){
  70. rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  71. yum install -y nginx
  72. # 配置nginx
  73. eschedulerConf $1 $2
  74. # 解决 0.0.0.0:8888 问题
  75. yum -y install policycoreutils-python
  76. semanage port -a -t http_port_t -p tcp $esc_proxy
  77. # 开放前端访问端口
  78. firewall-cmd --zone=public --add-port=$esc_proxy/tcp --permanent
  79. # 启动nginx
  80. systemctl start nginx
  81. sleep 1
  82. if [ $? -ne 0 ];then
  83. systemctl start nginx
  84. fi
  85. nginx -s reload
  86. # 调整SELinux的参数
  87. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  88. # 临时生效
  89. setenforce 0
  90. }
  91. centos6(){
  92. rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  93. # install nginx
  94. yum install nginx -y
  95. # 配置nginx
  96. eschedulerConf $1 $2
  97. # 启动nginx
  98. /etc/init.d/nginx start
  99. sleep 1
  100. if [ $? -ne 0 ];then
  101. /etc/init.d/nginx start
  102. fi
  103. nginx -s reload
  104. # 调整SELinux的参数
  105. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  106. # 临时生效
  107. setenforce 0
  108. }
  109. function main(){
  110. echo "欢迎使用easy scheduler前端部署脚本,目前前端部署脚本仅支持CentOS,Ubuntu"
  111. echo "请在 escheduler-ui 目录下执行"
  112. #To be compatible with MacOS and Linux
  113. if [[ "$OSTYPE" == "darwin"* ]]; then
  114. # Mac OSX
  115. echo "Easy Scheduler ui install not support Mac OSX operating system"
  116. exit 1
  117. elif [[ "$OSTYPE" == "linux-gnu" ]]; then
  118. # linux
  119. echo "linux"
  120. elif [[ "$OSTYPE" == "cygwin" ]]; then
  121. # POSIX compatibility layer and Linux environment emulation for Windows
  122. echo "Easy Scheduler ui not support Windows operating system"
  123. exit 1
  124. elif [[ "$OSTYPE" == "msys" ]]; then
  125. # Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
  126. echo "Easy Scheduler ui not support Windows operating system"
  127. exit 1
  128. elif [[ "$OSTYPE" == "win32" ]]; then
  129. echo "Easy Scheduler ui not support Windows operating system"
  130. exit 1
  131. elif [[ "$OSTYPE" == "freebsd"* ]]; then
  132. # ...
  133. echo "freebsd"
  134. else
  135. # Unknown.
  136. echo "Operating system unknown, please tell us(submit issue) for better service"
  137. exit 1
  138. fi
  139. # 配置前端访问端口
  140. read -p "请输入nginx代理端口,不输入,则默认8888 :" esc_proxy_port
  141. if [ -z "${esc_proxy_port}" ];then
  142. esc_proxy_port="8888"
  143. fi
  144. read -p "请输入api server代理ip,必须输入,例如:192.168.xx.xx :" esc_api_server_ip
  145. if [ -z "${esc_api_server_ip}" ];then
  146. echo "api server代理ip不能为空."
  147. exit 1
  148. fi
  149. read -p "请输入api server代理端口,不输入,则默认12345 :" esc_api_server_port
  150. if [ -z "${esc_api_server_port}" ];then
  151. esc_api_server_port="12345"
  152. fi
  153. # api server后端地址
  154. esc_api_server="http://$esc_api_server_ip:$esc_api_server_port"
  155. # 本机ip地址
  156. esc_ipaddr=$(ip a | grep inet | grep -v inet6 | grep -v 127 | sed 's/^[ \t]*//g' | cut -d ' ' -f2 | head -n 1 | awk -F '/' '{print $1}')
  157. # 提示信息
  158. menu
  159. read -p "请输入安装编号(1|2|3|4):" num
  160. case $num in
  161. 1)
  162. centos6 ${esc_proxy_port} ${esc_api_server}
  163. ;;
  164. 2)
  165. centos7 ${esc_proxy_port} ${esc_api_server}
  166. ;;
  167. 3)
  168. ubuntu ${esc_proxy_port} ${esc_api_server}
  169. ;;
  170. 4)
  171. echo $"Usage :sh $0"
  172. exit 1
  173. ;;
  174. *)
  175. echo $"Usage :sh $0"
  176. exit 1
  177. esac
  178. echo "请浏览器访问:http://${esc_ipaddr}:${esc_proxy_port}"
  179. }
  180. main