install(线上环境).sh 3.7 KB

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