|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# 当前路径 |
| 4 | +workDir=$(cd `dirname $0`; pwd) |
| 5 | + |
| 6 | + |
| 7 | +echo "Scriptis front-end deployment script" |
| 8 | + |
| 9 | +source $workDir/config.sh |
| 10 | +# 前端放置目录,默认为解压目录 |
| 11 | +scriptis_basepath=$workDir |
| 12 | + |
| 13 | +#To be compatible with MacOS and Linux |
| 14 | +if [[ "$OSTYPE" == "darwin"* ]]; then |
| 15 | + # Mac OSX |
| 16 | + echo "scriptis 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 "scriptis 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 "scriptis not support Windows operating system" |
| 28 | + exit 1 |
| 29 | +elif [[ "$OSTYPE" == "win32" ]]; then |
| 30 | + echo "scriptis 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 | +# 区分版本 |
| 42 | +version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'` |
| 43 | + |
| 44 | + |
| 45 | +echo "========================================================================配置信息=======================================================================" |
| 46 | + |
| 47 | +echo "前端访问端口:${scriptis_port}" |
| 48 | +echo "后端Linkis的地址:${linkis_url}" |
| 49 | +echo "静态文件地址:${scriptis_basepath}/dist" |
| 50 | +echo "当前路径:${workDir}" |
| 51 | +echo "本机ip:${scriptis_ipaddr}" |
| 52 | + |
| 53 | +echo "========================================================================配置信息=======================================================================" |
| 54 | +echo "" |
| 55 | + |
| 56 | + |
| 57 | +# 创建文件并配置nginx |
| 58 | +scriptiConf(){ |
| 59 | + |
| 60 | + s_host='$host' |
| 61 | + s_remote_addr='$remote_addr' |
| 62 | + s_proxy_add_x_forwarded_for='$proxy_add_x_forwarded_for' |
| 63 | + s_http_upgrade='$http_upgrade' |
| 64 | + echo " |
| 65 | + server { |
| 66 | + listen $scriptis_port;# 访问端口 |
| 67 | + server_name localhost; |
| 68 | + #charset koi8-r; |
| 69 | + #access_log /var/log/nginx/host.access.log main; |
| 70 | + location / { |
| 71 | + root ${scriptis_basepath}/dist; # 静态文件目录 |
| 72 | + index index.html index.html; |
| 73 | + } |
| 74 | + location /ws { |
| 75 | + proxy_pass $linkis_url;#后端Linkis的地址 |
| 76 | + proxy_http_version 1.1; |
| 77 | + proxy_set_header Upgrade $s_http_upgrade; |
| 78 | + proxy_set_header Connection "upgrade"; |
| 79 | + } |
| 80 | +
|
| 81 | + location /api { |
| 82 | + proxy_pass $linkis_url; #后端Linkis的地址 |
| 83 | + proxy_set_header Host $s_host; |
| 84 | + proxy_set_header X-Real-IP $s_remote_addr; |
| 85 | + proxy_set_header x_real_ipP $s_remote_addr; |
| 86 | + proxy_set_header remote_addr $s_remote_addr; |
| 87 | + proxy_set_header X-Forwarded-For $s_proxy_add_x_forwarded_for; |
| 88 | + proxy_http_version 1.1; |
| 89 | + proxy_connect_timeout 4s; |
| 90 | + proxy_read_timeout 600s; |
| 91 | + proxy_send_timeout 12s; |
| 92 | + proxy_set_header Upgrade $s_http_upgrade; |
| 93 | + proxy_set_header Connection upgrade; |
| 94 | + } |
| 95 | + |
| 96 | + #error_page 404 /404.html; |
| 97 | + # redirect server error pages to the static page /50x.html |
| 98 | + # |
| 99 | + error_page 500 502 503 504 /50x.html; |
| 100 | + location = /50x.html { |
| 101 | + root /usr/share/nginx/html; |
| 102 | + } |
| 103 | + } |
| 104 | + " > /etc/nginx/conf.d/scriptis.conf |
| 105 | + |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +centos7(){ |
| 110 | + # nginx是否安装 |
| 111 | + #sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm |
| 112 | + sudo yum install -y nginx |
| 113 | + echo "nginx 安装成功" |
| 114 | + |
| 115 | + # 配置nginx |
| 116 | + scriptiConf |
| 117 | + |
| 118 | + # 解决 0.0.0.0:8888 问题 |
| 119 | + yum -y install policycoreutils-python |
| 120 | + semanage port -a -t http_port_t -p tcp $scriptis_port |
| 121 | + |
| 122 | + # 开放前端访问端口 |
| 123 | + firewall-cmd --zone=public --add-port=$scriptis_port/tcp --permanent |
| 124 | + |
| 125 | + # 重启防火墙 |
| 126 | + firewall-cmd --reload |
| 127 | + |
| 128 | + # 启动nginx |
| 129 | + systemctl restart nginx |
| 130 | + |
| 131 | + # 调整SELinux的参数 |
| 132 | + sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config |
| 133 | + # 临时生效 |
| 134 | + setenforce 0 |
| 135 | + |
| 136 | +} |
| 137 | + |
| 138 | + |
| 139 | +centos6(){ |
| 140 | + # yum |
| 141 | + S_basearch='$basearch' |
| 142 | + S_releasever='$releasever' |
| 143 | + echo " |
| 144 | + [nginx] |
| 145 | + name=nginx repo |
| 146 | + baseurl=http://nginx.org/packages/centos/$E_releasever/$S_basearch/ |
| 147 | + gpgcheck=0 |
| 148 | + enabled=1 |
| 149 | + " >> /etc/yum.repos.d/nginx.repo |
| 150 | + |
| 151 | + # install nginx |
| 152 | + yum install nginx -y |
| 153 | + |
| 154 | + # 配置nginx |
| 155 | + scriptiConf |
| 156 | + |
| 157 | + # 防火墙 |
| 158 | + S_iptables=`lsof -i:$scriptis_port | wc -l` |
| 159 | + if [ "$S_iptables" -gt "0" ];then |
| 160 | + # 已开启端口防火墙重启 |
| 161 | + service iptables restart |
| 162 | + else |
| 163 | + # 未开启防火墙添加端口再重启 |
| 164 | + iptables -I INPUT 5 -i eth0 -p tcp --dport $scriptis_port -m state --state NEW,ESTABLISHED -j ACCEPT |
| 165 | + service iptables save |
| 166 | + service iptables restart |
| 167 | + fi |
| 168 | + |
| 169 | + # start |
| 170 | + /etc/init.d/nginx start |
| 171 | + |
| 172 | + # 调整SELinux的参数 |
| 173 | + sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config |
| 174 | + |
| 175 | + # 临时生效 |
| 176 | + setenforce 0 |
| 177 | + |
| 178 | +} |
| 179 | + |
| 180 | +# centos 6 |
| 181 | +if [[ $version -eq 6 ]]; then |
| 182 | + centos6 |
| 183 | +fi |
| 184 | + |
| 185 | +# centos 7 |
| 186 | +if [[ $version -eq 7 ]]; then |
| 187 | + centos7 |
| 188 | +fi |
| 189 | + |
| 190 | + |
| 191 | +echo "请浏览器访问:http://${scriptis_ipaddr}:${scriptis_port}" |
0 commit comments