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