install(线上环境).sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/bash
  2. echo "escheduler-ui-install.sh"
  3. echo "escheduler-ui目录下执行"
  4. # 配置前端访问端口
  5. esc_proxy="8888"
  6. # 配置代理后端接口
  7. esc_proxy_port="http://192.168.220.154:12345"
  8. # 当前路径
  9. esc_basepath=$(cd `dirname $0`; pwd)
  10. # 本机ip
  11. esc_ipaddr='172.0.0.1'
  12. esc_ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
  13. # 区分版本
  14. version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
  15. echo "========================================================================配置信息======================================================================="
  16. echo "前端访问端口:${esc_proxy}"
  17. echo "后端代理接口地址:${esc_proxy_port}"
  18. echo "静态文件地址:${esc_basepath}/dist"
  19. echo "当前路径:${esc_basepath}"
  20. echo "本机ip:${esc_ipaddr}"
  21. echo "========================================================================配置信息======================================================================="
  22. echo ""
  23. # 创建文件并配置nginx
  24. eschedulerConf(){
  25. E_host='$host'
  26. E_remote_addr='$remote_addr'
  27. E_proxy_add_x_forwarded_for='$proxy_add_x_forwarded_for'
  28. E_http_upgrade='$http_upgrade'
  29. echo "
  30. server {
  31. listen $esc_proxy;# 访问端口
  32. server_name localhost;
  33. #charset koi8-r;
  34. #access_log /var/log/nginx/host.access.log main;
  35. location / {
  36. root ${esc_basepath}/dist; # 静态文件目录
  37. index index.html index.html;
  38. }
  39. location /escheduler {
  40. proxy_pass ${esc_proxy_port}; # 接口地址
  41. proxy_set_header Host $E_host;
  42. proxy_set_header X-Real-IP $E_remote_addr;
  43. proxy_set_header x_real_ipP $E_remote_addr;
  44. proxy_set_header remote_addr $E_remote_addr;
  45. proxy_set_header X-Forwarded-For $E_proxy_add_x_forwarded_for;
  46. proxy_http_version 1.1;
  47. proxy_connect_timeout 4s;
  48. proxy_read_timeout 30s;
  49. proxy_send_timeout 12s;
  50. proxy_set_header Upgrade $E_http_upgrade;
  51. proxy_set_header Connection "upgrade";
  52. }
  53. #error_page 404 /404.html;
  54. # redirect server error pages to the static page /50x.html
  55. #
  56. error_page 500 502 503 504 /50x.html;
  57. location = /50x.html {
  58. root /usr/share/nginx/html;
  59. }
  60. }
  61. " >> /etc/nginx/conf.d/escheduler.conf
  62. }
  63. centos7(){
  64. # nginx是否安装
  65. sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  66. sudo yum install -y nginx
  67. echo "nginx 安装成功"
  68. # 配置nginx
  69. eschedulerConf
  70. # 解决 0.0.0.0:8888 问题
  71. yum -y install policycoreutils-python
  72. semanage port -a -t http_port_t -p tcp $esc_proxy
  73. # 开放前端访问端口
  74. firewall-cmd --zone=public --add-port=$esc_proxy/tcp --permanent
  75. # 重启防火墙
  76. firewall-cmd --reload
  77. # 启动nginx
  78. systemctl start nginx
  79. # 调整SELinux的参数
  80. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  81. # 临时生效
  82. setenforce 0
  83. }
  84. centos6(){
  85. # yum
  86. E_basearch='$basearch'
  87. E_releasever='$releasever'
  88. echo "
  89. [nginx]
  90. name=nginx repo
  91. baseurl=http://nginx.org/packages/centos/$E_releasever/$E_basearch/
  92. gpgcheck=0
  93. enabled=1
  94. " >> /etc/yum.repos.d/nginx.repo
  95. # install nginx
  96. yum install nginx -y
  97. # 配置nginx
  98. eschedulerConf
  99. # 防火墙
  100. E_iptables=`lsof -i:$esc_proxy | wc -l`
  101. if [ "$E_iptables" -gt "0" ];then
  102. # 已开启端口防火墙重启
  103. service iptables restart
  104. else
  105. # 未开启防火墙添加端口再重启
  106. iptables -I INPUT 5 -i eth0 -p tcp --dport $esc_proxy -m state --state NEW,ESTABLISHED -j ACCEPT
  107. service iptables save
  108. service iptables restart
  109. fi
  110. # start
  111. /etc/init.d/nginx start
  112. # 调整SELinux的参数
  113. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  114. # 临时生效
  115. setenforce 0
  116. }
  117. # centos 6
  118. if [[ $version -eq 6 ]]; then
  119. centos6
  120. fi
  121. # centos 7
  122. if [[ $version -eq 7 ]]; then
  123. centos7
  124. fi
  125. echo "请浏览器访问:http://${esc_ipaddr}:${esc_proxy}"