-
Notifications
You must be signed in to change notification settings - Fork 297
/
install.sh
executable file
·216 lines (195 loc) · 9.3 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
# -------------------------------------------------------------------------------
# Filename: install.sh
# Revision: 2.0
# Date: 2018/06/21
# Author: bishenghua
# Email: [email protected]
# Description: Script to install the kubernets system
# -------------------------------------------------------------------------------
# Copyright: 2018 (c) Bishenghua
# License: GPL
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios);
#
# Credits go to Ethan Galstad for coding Nagios
# If any changes are made to this script, please mail me a copy of the changes
# -------------------------------------------------------------------------------
echo -e "\033[32m{`date`}[开始]初始化安装.............................\033[0m"
while true
do
yum -y install epel-release net-tools vim python-pip python-setuptools bzip2 unzip telnet
which pip > /dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi
done
while true
do
pip install "fabric<2"
#pip install --upgrade pip
which fab > /dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi
done
chown -R root:root ../install_k8s
#if [ ! -f "source/docker/docker_engine_packages.gz" ]; then
# tee /etc/yum.repos.d/docker.repo <<-'EOF'
#[dockerrepo]
#name=Docker Repository
#baseurl=https://yum.dockerproject.org/repo/main/centos/7/
#enabled=1
#gpgcheck=1
#gpgkey=https://yum.dockerproject.org/gpg
#EOF
# yum -y install --downloadonly --downloaddir source/docker/docker_engine_packages docker-engine
# if [[ $? -ne 0 ]]; then
# echo "下载docker失败,请重新执行"
# exit
# fi
# cd source/docker && tar zcvf docker_engine_packages.gz docker_engine_packages && rm -rf docker_engine_packages
# cd ../..
#fi
echo -e "\033[32m{`date`}[结束]初始化安装.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装基础环境.............................\033[0m"
fab install_base || exit 1
fab install_needbin || exit 1
echo -e "\033[32m{`date`}[结束]安装基础环境.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装docker.............................\033[0m"
fab install_docker || exit 1
echo -e "\033[32m{`date`}[结束]安装docker.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装docker私有仓库.............................\033[0m"
fab install_pridocker || exit 1
echo -e "\033[32m{`date`}[结束]安装docker私有仓库.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装etcd.............................\033[0m"
fab install_etcd || exit 1
echo -e "\033[32m{`date`}[结束]安装etcd.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装master节点.............................\033[0m"
fab install_master || exit 1
echo -e "\033[32m{`date`}[结束]安装master节点.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装node节点.............................\033[0m"
fab install_node || exit 1
echo -e "\033[32m{`date`}[结束]安装node节点.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装docker证书.............................\033[0m"
fab install_dockercrt || exit 1
echo -e "\033[32m{`date`}[结束]安装docker证书.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装负载均衡.............................\033[0m"
fab install_lvs || exit 1
echo -e "\033[32m{`date`}[结束]安装负载均衡.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]安装dns.............................\033[0m"
fab install_dns || exit 1
echo -e "\033[32m{`date`}[结束]安装dns.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]启动所有服务.............................\033[0m"
fab service_publish:start || exit 1
fab service_etcd:start || exit 1
fab service_etcd:restart || exit 1
sleep 10
fab service_master:start || exit 1
fab service_master:restart || exit 1
sleep 8
fab service_node:start || exit 1
fab service_node:restart || exit 1
sleep 8
fab service_dns:start || exit 1
echo -e "\033[32m{`date`}[结束]启动所有服务.............................\n\n\n\n\n\n\033[0m"
sleep 5
echo -e "\033[32m{`date`}[开始]验证k8s集群.............................\033[0m"
i=0
while true
do
sleep 1
((i++))
echo -e "\033[32m等待倒计时($i)s...\033[0m"
kubectl get nodes -o wide | grep NotReady
if [ $? -ne 0 ]; then
kubectl get nodes -o wide
break
fi
done
echo -e "\033[32m{`date`}[结束]验证k8s集群.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]初始化镜像.............................\033[0m"
fab init_images || exit 1
echo -e "\033[32m{`date`}[结束]初始化镜像.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]初始化calico.............................\033[0m"
fab init_calico || exit 1
fab kubeletcni_node || exit 1
echo -e "\033[32m{`date`}[结束]初始化calico.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]初始k8s系统镜像服务.............................\033[0m"
fab init_k8s_system || exit 1
echo -e "\033[32m{`date`}[结束]初始k8s系统镜像服务.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]初始化测试微服务.............................\033[0m"
fab init_web_test || exit 1
echo -e "\033[32m{`date`}[结束]初始化测试微服务.............................\n\n\n\n\n\n\033[0m"
echo -e "\033[32m{`date`}[开始]需要您验证测试以下说明.............................\033[0m"
i=0
while true
do
sleep 1
((i++))
echo -e "\033[32m等待kubernetes-dashboard running($i)s...\033[0m"
kubectl -n kubernetes-dashboard get pods -o wide | grep kubernetes-dashboard | grep Running
if [ $? -eq 0 ]; then
kubectl -n kubernetes-dashboard get pods -o wide | grep kubernetes-dashboard | grep Running | awk '{print "\033[31m您可以访问kubernetes-dashboard: https://"$7":30000\033[0m"}'
echo -e "\033[32m用下面输出的token登录kubernetes-dashboard\033[0m"
kubectl describe secret $(kubectl get secret -n kube-system | grep admin-token | awk '{print $1}') -n kube-system | grep token: | awk '{print $2}'
break
fi
done
i=0
while true
do
sleep 1
((i++))
echo -e "\033[32m等待monitoring-grafana running($i)s...\033[0m"
kubectl -n kube-system get pods -o wide | grep monitoring-grafana | grep Running
if [ $? -eq 0 ]; then
kubectl -n kube-system get pods -o wide | grep monitoring-grafana | grep Running | awk '{print "\033[31m您可以访问monitoring-grafana: http://"$7":30001\033[0m"}'
kubectl -n kube-system cp source/prometheus/grafana monitoring-grafana-0:/var/lib
kubectl -n kube-system delete pod monitoring-grafana-0
kubectl -n kube-system get pods -o wide | grep monitoring-grafana | grep Running | awk '{print "\033[31m您可以访问monitoring-grafana: http://"$7":30001\033[0m"}'
echo -e "\033[32m账号密码为:admin/123456\033[0m"
echo -e "\033[32m注意:需要配置一下grafana的k8s插件中的URL地址及三个认证证书(base64解码~/.kube/config中的相应证书)\033[0m"
break
fi
done
i=0
while true
do
sleep 1
((i++))
echo -e "\033[32m等待prometheus running($i)s...\033[0m"
kubectl -n kube-system get pods -o wide | grep prometheus | grep Running
if [ $? -eq 0 ]; then
kubectl -n kube-system get pods -o wide | grep prometheus | grep Running | awk '{print "\033[31m您可以访问prometheus: http://"$7":30002\033[0m"}'
break
fi
done
i=0
while true
do
sleep 1
((i++))
echo -e "\033[32m等待web-test running($i)s...\033[0m"
kubectl -n esn-system get pods -o wide | grep web-test | grep Running
if [ $? -eq 0 ]; then
chmod 600 source/esn_base/ssh/root/* source/esn_base/ssh/esn/*
kubectl -n esn-system get pods -o wide | grep web-test | grep Running | awk '{print "\033[31m您可以访问web-test: http://"$7":31000\033[0m";print "\033[31m您可以执行: ssh -i source/esn_base/ssh/root/id_rsa root@"$6" 直接登录到容器中\033[0m";print "\033[31m您也可以执行: ssh -i source/esn_base/ssh/esn/id_rsa esn@"$6" 直接登录到容器中\033[0m"}'
break
fi
done
echo -e "\033[31m您可以进入到容器中执行: ping t.test.com 看是否解析到10.10.10.10上, 或看下面测试输出\033[0m"
POD=`kubectl -n esn-system get pods | grep web-test | awk '{print $1}'`
kubectl -n esn-system exec $POD -- ping -c 5 t.test.com
echo -e "\033[32m{`date`}[结束]需要您验证测试以下说明\033[0m\033[31m[祝您好运,安全稳定的k8s集群安装完毕!]\033[0m\033[32m.............................\n\n\n\n\n\n\033[0m"