-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcentos7-docker-install.sh
458 lines (383 loc) · 12.3 KB
/
centos7-docker-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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#!/bin/sh
#------------------------------------------
# Centos7 Install Helper
# copyright https://github.com/cjy37
# email: [email protected]
#------------------------------------------
function showMenu()
{
clear
echo
echo "--------------------------------------------------------------"
echo "| Centos7 Install Helper |"
echo "| 版权所有 https://github.com/cjy37 |"
echo "--------------------------------------------------------------"
echo "| a. 安装 Docker 运行环境 |"
echo "| b. 安装 Rancher (Docker控制台) |"
echo "| # c. 安装 MySQL 服务 (不推荐, 建议Docker方式) |"
echo "| # d. 安装 MongoDB 服务 (不推荐, 建议Docker方式) |"
echo "| # e. 安装 MQTT 服务 (不推荐, 建议Docker方式) |"
echo "| # f. 安装 Redis 服务 (不推荐, 建议Docker方式) |"
echo "| # g. 安装 Nginx 服务 (不推荐, 建议Docker方式) |"
echo "| # h. 安装 Haproxy 服务 (不推荐, 建议Docker方式) |"
echo "| i. 安装 NFS 共享存储 |"
echo "| x. 退出 |"
echo "--------------------------------------------------------------"
echo
return 0
}
function selectCmd()
{
alias cp='cp'
showMenu
echo "请选择要安装的字母序号 [a-x]:"
read -n 1 M
echo
if [ "$M" = "x" ]; then
exit 1
elif [ "$M" = "a" ]; then
echo "安装 Docker 运行环境"
echo "------------------------------------"
setupDocker
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "b" ]; then
echo "安装 Rancher 服务"
echo "------------------------------------"
setupRancher
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "c" ]; then
echo "安装 MySQL 服务"
echo "------------------------------------"
setupMysql
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "d" ]; then
echo "安装 MongoDB 服务"
echo "------------------------------------"
setupMongodb
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "e" ]; then
echo "安装 MQTT 服务(Mosquitto)"
echo "------------------------------------"
setupMosquitto
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "f" ]; then
echo "安装 Redis 服务"
echo "------------------------------------"
setupRedis
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "g" ]; then
echo "安装 Nginx 服务"
echo "------------------------------------"
setupNginx
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "h" ]; then
echo "安装 Haproxy 服务"
echo "------------------------------------"
setupHaproxy
read -n 1 -p "按 <Enter> 继续..."
elif [ "$M" = "i" ]; then
echo "安装 NFS 共享存储"
echo "------------------------------------"
setupNFS
read -n 1 -p "按 <Enter> 继续..."
else
echo "选择错误!"
read -n 1 -p "按 <Enter> 继续..."
fi
selectCmd
return 0
}
function setupDocker()
{
# 删除旧的组件
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
# 安装依赖
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo tee /etc/security/limits.conf <<-'EOF'
#增加如下内容
root soft nofile 102400
root hard nofile 102400
* soft nofile 102400
* hard nofile 102400
EOF
sudo tee /etc/sysctl.conf <<-'EOF'
#增加如下内容
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_max_syn_backlog=1024
net.ipv4.tcp_synack_retries=2
#net.ipv6.conf.all.disable_ipv6=1
#net.ipv6.conf.default.disable_ipv6=1
#net.ipv6.conf.lo.disable_ipv6=1
net.ipv4.conf.lo.arp_announce=2
vm.swappiness=10
vm.vfs_cache_pressure=50
vm.overcommit_memory=1
net.core.somaxconn=65535
net.netfilter.nf_conntrack_max=655350
net.netfilter.nf_conntrack_tcp_timeout_established=1200
#增加NFS挂载服务并发数
sunrpc.tcp_slot_table_entries=128
EOF
#使修改马上生效
sudo sysctl -p
systemctl start firewalld.service
# 基础端口
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --permanent --add-port=1883/tcp
firewall-cmd --permanent --add-port=27017/tcp
firewall-cmd --permanent --add-port=9200/tcp
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=3306/udp
#firewall-cmd --permanent --zone=public --add-service=docker-proxy
firewall-cmd --reload
# 安装Docker
curl https://releases.rancher.com/install-docker/17.03.sh | sh
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://y1q9bgae.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
return $?
}
function setupRancher()
{
echo "install rancher"
echo "------------------------------------"
systemctl start firewalld.service
# Rancher基础端口
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=500/tcp
firewall-cmd --permanent --add-port=500/udp
firewall-cmd --permanent --add-port=4500/tcp
firewall-cmd --permanent --add-port=4500/udp
firewall-cmd --permanent --add-port=4789/tcp
firewall-cmd --permanent --add-port=4789/udp
firewall-cmd --reload
sudo docker run -d --restart=unless-stopped -p 8080:8080 -v /wwwroot/rancher_db:/var/lib/mysql rancher/server
return $?
}
function setupMysql()
{
echo "安装 mysql"
echo "------------------------------------"
echo '# MariaDB 10.0 CentOS repository list - created 2014-10-18 16:58 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1' > /etc/yum.repos.d/MariaDB.repo
yum -y install MariaDB-server MariaDB-client MariaDB-devel
cp /usr/share/mysql/my-innodb-heavy-4G.cnf /etc/my.cnf
#sudo sed -i 's/# generic configuration options/user = mysql/g' /etc/my.cnf
sudo sed -i '/\[mysqld\]/a user = mysql' /etc/my.cnf
chkconfig --level 2345 mysql on
service mysql start
mysql -V
echo "------------------------------------"
echo "Mysql: Please Ender user(root) password"
read -e PWD
mysqladmin -uroot password "$PWD"
return $?
}
function setupMongodb()
{
echo "install Mongodb"
echo "------------------------------------"
yum -y install mongodb mongodb-server
echo "Install mongodb completed. info:"
mongod --version
echo "------------------------------------"
return $?
}
function setupMosquitto()
{
echo "install Mosquitto"
echo "------------------------------------"
echo '[home_oojah_mqtt]
name=mqtt (CentOS_CentOS-7)
type=rpm-md
baseurl=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7/repodata/repomd.xml.key
enabled=1
' > /etc/yum.repos.d/Mosquitto.repo
yum -y install mosquitto mosquitto-clients libmosquitto1 libmosquitto-devel libmosquittopp1 libmosquittopp-devel python-mosquitto
mosquitto -h
echo "------------------------------------"
return $?
}
function setupRedis()
{
echo "install redis"
echo "------------------------------------"
yum -y install redis
echo "Install Redis completed. info:"
redis-server -v
echo "------------------------------------"
return $?
}
function setupNginx()
{
echo "install nginx"
echo "------------------------------------"
echo '[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1' > /etc/yum.repos.d/nginx.repo
yum -y install nginx
chkconfig --level 2345 nginx on
service nginx start
nginx -v
echo "------------------------------------"
return $?
}
function setupHaproxy()
{
echo "install haproxy"
echo "------------------------------------"
yum -y install haproxy
echo "Install haproxy completed. info:"
haproxy -v
echo "------------------------------------"
return $?
}
function setupNFS()
{
echo "install nfs"
echo "------------------------------------"
yum install -y nfs-utils rpcbind
echo " 检查rpcbind是否开机启动"
systemctl list-unit-files | grep rpcbind.service
systemctl enable rpcbind.service
echo "启动rpcbind服务"
systemctl restart rpcbind.service
echo " 查看rpc"
netstat -lntup|grep rpcbind
echo " 查看nfs服务向rpc注册的端口信息"
rpcinfo -p localhost
echo
echo " 检查NFS是否开机启动"
systemctl list-unit-files | grep nfs.service
systemctl enable nfs.service
echo "启动NFS服务"
echo "/wwwroot 172.16.7.0/24(rw,sync,all_squash,anonuid=0,anongid=0)" > /etc/exports
#chown -R nfsnobody.nfsnobody /wwwroot
systemctl restart nfs.service
exportfs -rv
echo '
RQUOTAD_PORT=1001
# 去掉下面语句前面的“#”号
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662' >> /etc/sysconfig/nfs
systemctl start firewalld.service
# NFS 基础端口
firewall-cmd --permanent --add-port=111/tcp
firewall-cmd --permanent --add-port=111/udp
firewall-cmd --permanent --add-port=2049/tcp
firewall-cmd --permanent --add-port=2049/udp
firewall-cmd --permanent --add-port=1001/tcp
firewall-cmd --permanent --add-port=1001/udp
# NFS服务端口2
firewall-cmd --permanent --add-port=32803/tcp
firewall-cmd --permanent --add-port=32803/udp
firewall-cmd --permanent --add-port=32769/tcp
firewall-cmd --permanent --add-port=32769/udp
firewall-cmd --permanent --add-port=892/tcp
firewall-cmd --permanent --add-port=892/udp
firewall-cmd --permanent --add-port=662/tcp
firewall-cmd --permanent --add-port=662/udp
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --reload
rpcinfo -p
# 下载配置文件
echo "下载配置文件"
cd /wwwroot/
wget https://github.com/cjy37/linux-asp.net-installScript/raw/master/config.tar.bz2
tar xjf config.tar.bz2
cp -rf config/jenkins_home ./
rm -f config.tar.bz2
echo "====== 后续操作: ======"
echo "vim /etc/exports"
echo 'exports文件配置格式:
NFS共享的目录 NFS客户端地址1(参数1,参数2,...) 客户端地址2(参数1,参数2,...)
要用绝对路径,可被nfsnobody读写。
例如:
# /wwwroot 172.16.7.0/24(rw,sync,all_squash)
'
return $?
}
function setupOs7Epel()
{
echo "Install Centos7_64bit EPEL repository"
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
sudo yum -y install yum-priorities
return $?
}
function setupOs6Epel()
{
echo "Install Centos6_64bit EPEL repository"
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum -y install yum-priorities
return $?
}
function setupOs5Epel()
{
echo "Install Centos5_64bit EPEL repository"
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
yum -y install yum-priorities
return $?
}
function setupFedoraEpel()
{
vers=`cat /etc/redhat-release | awk -F'release' '{print $2}' | awk -F'.' '{print $1}' | awk -F' ' '{print $1}'`
if [ "$vers" = "7" ]; then
setupOs7Epel
elif [ "$vers" = "6" ]; then
setupOs6Epel
elif [ "$vers" = "5" ]; then
setupOs5Epel
fi
sudo yum -y update
sudo yum -y groupinstall "Development Tools"
echo "安装Docker..."
echo "------------------------------------"
if [ ! -d /wwwroot ]; then
mkdir -pv /wwwroot
fi
return $?
}
cd /tmp
read -n 1 -p "按任意键安装Docker组件. 按 [Ctrl + C] 取消安装."
setupFedoraEpel
selectCmd