说明:
用平常的方式在Linux服务器上安装程序,需要下载安装包、进入安装包位置、给安装包文件赋予可执行权限、执行安装、设置环境变量……等等一系列复杂的操作。并且如果有关联也需要一个一个的挨着安装。耗时并且繁琐。而用shell脚本来执行这些操作,则很好的解决了这些问题!
代码:
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 1#!/bin/bash
2#version1.0
3#Wangwei
4#date 2015/04/02
5#System Centos6.4
6get_bin_tar="/bin/tar"
7get_cmd_dns="/etc/resolv.conf"
8get_cmd_soft="/opt/badusoft"
9get_cmd_name=`/bin/uname -a | awk '{print $1,$3}'`
10get_cmd_service="/usr/local/service"
11get_cmd_user=`whoami`
12get_cmd_cron="/var/spool/cron/"
13get_cmd_url="http://img006.com/badusoft"
14echo -e "System for version:\e[32m$get_cmd_name \e[0m\n"
15echo -e "Nginx for version:\e[32mTengine2.1 and nginx 1.8.0\e[0m\n"
16echo -e "Java for version:\e[32mJdk 1.7\e[0m\n"
17echo -e "Resin pro for version:\e[32mResin pro 3.1\e[0m\n"
18echo -e "Apache for tomcat version:\e[32m tomcat 7\e[0m\n"
19echo -e "Redis version:\e[32m Redis 2.8\e[0m\n"
20echo -e "Firewall:\e[32moff\e[0m\n"
21cat /dev/null > $get_cmd_dns
22echo "nameserver 114.114.114.114" >> $get_cmd_dns
23echo -e "NameServer:\e[32m114.114.114.114\e[0m\n"
24sleep 10
25/etc/init.d/iptables stop
26/sbin/chkconfig iptables off
27function package(){
28 for i in wget gcc gcc-c++ make gzip autoconf automake lrzsz telnet zlib zlib-devel openssl openssl-devel pcre-devel pcre patch net-snmp
29 do
30 yum install -y $i
31 sleep 1
32 done
33}
34
35function del(){
36if [ ! -d $get_cmd_soft ] && [ ! -d $get_cmd_service ]; then
37 mkdir /opt/badusoft >> /dev/null 2>&1
38 mkdir /usr/local/service/ >> /dev/null 2>&1
39else
40 rm -rf $get_cmd_soft $get_cmd_service
41 cp -f /etc/profile.bak /etc/profile
42 mkdir /opt/badusoft >> /dev/null 2>&1
43 mkdir /usr/local/service/ >> /dev/null 2>&1
44fi
45}
46function timecron(){
47#date cron
48if [ $get_cmd_user = "root" ];then
49 echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" > $get_cmd_cron/$get_cmd_user
50else
51 if [ -f "$get_cmd_cron/root" ];then
52 echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" >> $get_cmd_cron/$get_cmd_user
53 else
54 echo "$get_cmd_user error"
55 return 0
56 fi
57fi
58}
59
60function sysctl(){
61 cd $get_cmd_soft
62 if [ ! -f kernels_sysctl ] && [ ! -f limits.conf ];then
63 wget $get_cmd_url/kernels_sysctl
64 wget $get_cmd_url/limits.conf
65 if [ -f $get_cmd_soft/kernels_sysctl ] && [ -f $get_cmd_soft/limits.conf ];then
66 #cp -f /etc/sysctl.conf /etc/sysctl.conf.bak
67 #cp -f /etc/security/limits.conf /etc/security/limits.conf
68 cat $get_cmd_soft/kernels_sysctl > /etc/sysctl.conf
69 cp -f $get_cmd_soft/limits.conf /etc/security/limits.conf
70 /sbin/sysctl -p
71 if [ $? -eq 0 ];then
72 echo -e "\e[32mcopy done\e[0m\n"
73 sleep 5
74 else
75 echo -e "\e[31m copy error!!\e[0m\n"
76 exit 0
77 fi
78 else
79 echo -e "\e[31mfile not exits\[0m\n"
80 exit 0
81 fi
82 else
83 echo -e "\e[31mfile exists\e[0m\n"
84 exit 0
85 fi
86 }
87function nginx(){
88 cd $get_cmd_soft
89 if [ ! -f nginx-1.8.0.tar.gz ];then
90 wget $get_cmd_url/nginx-1.8.0/nginx-1.8.0.tar.gz
91 wget $get_cmd_url/nginx-1.8.0/nginx_upstream_check_module-master.zip
92 wget $get_cmd_url/nginx-1.8.0/openssl-1.0.2c.tar.gz
93 wget $get_cmd_url/nginx-1.8.0/ngx_cache_purge-2.3.tar.gz
94 wget $get_cmd_url/pcre-8.12.tar.gz
95 wget $get_cmd_url/zlib-1.2.5.tar.gz
96
97 if [ $? -eq 0 ];then
98
99 $get_bin_tar zxf nginx-1.8.0.tar.gz
100 unzip nginx_upstream_check_module-master.zip
101 $get_bin_tar zxf openssl-1.0.2c.tar.gz
102 $get_bin_tar zxf ngx_cache_purge-2.3.tar.gz
103 $get_bin_tar zxf pcre-8.12.tar.gz
104 $get_bin_tar zxf zlib-1.2.5.tar.gz
105
106 if [ $? -eq 0 ];then
107 cd $get_cmd_soft/nginx-1.8.0
108
109 patch -p1 < $get_cmd_soft/nginx_upstream_check_module-master/check_1.7.5+.patch
110./configure --prefix=$get_cmd_service/nginx \
111--with-pcre=$get_cmd_soft/pcre-8.12 \
112--with-openssl=$get_cmd_soft/openssl-1.0.2c \
113--with-zlib=$get_cmd_soft/zlib-1.2.5 \
114--add-module=$get_cmd_soft/ngx_cache_purge-2.3 \
115--with-http_realip_module \
116--with-http_sub_module \
117--with-http_flv_module \
118--with-http_dav_module \
119--with-http_gzip_static_module \
120--with-http_stub_status_module \
121--with-http_addition_module \
122--with-http_ssl_module \
123--add-module=$get_cmd_soft/nginx_upstream_check_module-master
124
125 if [ $? -eq 0 ];then
126 make && make install
127 if [ $? -eq 0 ];then
128 echo -e "\e[32mtengine for nginx install done\e[0m\n"
129 sleep 5
130 else
131 echo -e "\e[31mmake && make error!!\e[0m\n"
132 fi
133 else
134 echo -e "\e[31mconfigure error!!\e[0m\n"
135 exit 0
136 fi
137 else
138 echo -e "\e[31mtar error!!\e[0m\n"
139 exit 0
140 fi
141 else
142 echo -e "\e[31mtengine for nginx download error!!\e[0m\n"
143 exit 0
144 fi
145 else
146 sleep 5
147 echo -e "\e[31mtengine for nginx found\e[0m\n"
148 fi
149}
150function java(){
151 cd $get_cmd_soft
152 if [ ! -f server-jre-7u80-linux-x64.tar.gz ];then
153 wget $get_cmd_url/javapath
154 wget $get_cmd_url/server-jre-7u80-linux-x64.tar.gz
155 $get_bin_tar zxf server-jre-7u80-linux-x64.tar.gz
156 if [ $? -eq 0 ];then
157 mv jdk1.7.0_80 $get_cmd_service/java
158 cp -f /etc/profile /etc/profile.bak
159 cat $get_cmd_soft/javapath >> /etc/profile
160 source /etc/profile
161 if [ $? -eq 0 ];then
162 $get_cmd_service/java/bin/java -version
163 if [ $? -eq 0 ];then
164 echo -ne "\e[32mJava install done\e[0m\n"
165 sleep 5
166 else
167 echo -ne "\e[31mJava install error!!\e[0m\n"
168 exit 0
169 fi
170 else
171 echo -ne "\e[31mJava path error!!\e[0m\n"
172 fi
173 else
174 echo -ne "\e[31mJava tar error!!\e[0m\n"
175 exit 0
176 fi
177
178 else
179 echo -ne "\e[31mJava download error\e[0m\n"
180 exit 0
181 fi
182
183}
184
185function resin(){
186 cd $get_cmd_soft
187 if [ ! -f resin-pro-3.1.12.tar.gz ];then
188 wget $get_cmd_url/licenses/004444.license
189 wget $get_cmd_url/resin-pro-3.1.12.tar.gz
190 if [ $? -eq 0 ];then
191 $get_bin_tar zxvf resin-pro-3.1.12.tar.gz
192 if [ $? -eq 0 ];then
193 cd $get_cmd_soft/resin-pro-3.1.12
194 ./configure --prefix=$get_cmd_service/resin \
195 --with-java-home=$get_cmd_service/java \
196 --enable-64bit=yes \
197 --enable-lfs \
198 --enable-jni \
199 --disable-libtool-lock
200
201 if [ $? -eq 0 ];then
202 make && make install
203 mkdir $get_cmd_service/resin/licenses
204 cp $get_cmd_soft/004444.license $get_cmd_service/resin/licenses
205 if [ $? -eq 0 ];then
206 echo -ne "\e[32mResin install done\e[0m\n"
207 sleep 5
208 else
209 echo -ne "\e[31mResin install error\e[0m\n"
210 exit 0
211 fi
212 else
213 echo -ne "\e[31mConfigure error\e[0m\n"
214 exit 0
215 fi
216 else
217 echo -ne "\e[31mtar error\e[0m\n"
218 exit 0
219 fi
220 else
221 echo -ne "\e[31mdownload error\e[0m\n"
222 exit 0
223 fi
224 else
225 echo -ne "\e[31mDircetory or Resin error!!\e[0m\n"
226 exit 0
227 fi
228}
229function tomcat(){
230 mkdir /usr/local/service/apache2
231
232cd /opt/badusoft/
233
234wget http://img006.com/badusoft/apr-1.5.2.tar.zip
235wget http://img006.com/badusoft/apr-iconv-1.2.1.tar.bz2
236wget http://img006.com/badusoft/apr-util-1.5.4.tar.bz2
237wget http://img006.com/badusoft/tomcat-native.tar.gz
238wget http://img006.com/badusoft/apache-tomcat-7.0.42.tar.gz
239
240
241tar -xvf apr-1.5.2.tar.bz2
242tar -xvf apr-iconv-1.2.1.tar.bz2
243tar -xvf apr-util-1.5.4.tar.bz2
244tar -xvf tomcat-native.tar.gz
245tar -xvf apache-tomcat-7.0.42.tar.gz
246
247mv /opt/badusoft/apache-tomcat-7.0.42 /usr/local/service/tomcat
248
249cd /opt/badusoft/apr-1.5.2
250
251
252./configure --prefix=/usr/local/service/apache2/apr
253
254make && make install
255
256echo "APR step over"
257
258###############################################################
259
260cd /opt/badushot/apr-util-1.5.4
261
262
263./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr
264
265make && make install
266
267echo "apr-util step over"
268##############################################################################
269
270
271cd /opt/badusoft/tomcat-native-1.1.33-src/jni/native
272
273./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr --with-java-home=/usr/local/service/java
274
275
276make && make install
277
278echo "tomact-native step over"
279
280
281echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/service/apache2/apr/lib" >> /etc/profile
282
283source /etc/profile
284
285cd /opt/badusoft/
286
287wget http://img006.com/badusoft/catalina.txt
288
289sed -i '/# limitations under the License./r catalina.txt' /usr/local/service/tomcat/bin/catalina.sh
290
291 }
292function redis(){
293 cd $get_cmd_soft
294 if [ ! -f redis-2.8.12.tar.gz ];then
295 wget $get_cmd_url/redis-2.8.12.tar.gz
296 if [ $? -eq 0 ];then
297 tar zxf redis-2.8.12.tar.gz
298 if [ $? -eq 0 ];then
299 cd $get_cmd_soft/redis-2.8.12
300 make && make install
301 if [ $? -eq 0 ];then
302 mkdir $get_cmd_service/redis/
303 mkdir $get_cmd_service/redis/conf
304 mv /usr/local/bin $get_cmd_service/redis/
305 cp -f $get_cmd_soft/redis-2.8.12/redis.conf $get_cmd_service/redis/conf/
306 echo -e "\e[32m Redis install done\e[0m\n"
307 sleep 5
308 else
309 echo -e "\e[31m make && make install error!!\e[0m\n"
310 exit 0
311 fi
312 else
313 echo -e "\e[31m tar error\e[0m\n"
314 exit 0
315 fi
316
317 else
318 echo -e "\e[31m Download Redis error!!\e[0m\n"
319 exit 0
320 fi
321 else
322 echo -e "\e[31m Redis file error!!\e[0m\n"
323 exit 0
324 fi
325}
326
327case $1 in
328
329package)
330 package
331;;
332
333timecron)
334
335 package
336 del
337 timecron
338;;
339
340sysctl)
341
342 package
343 del
344 sysctl
345;;
346
347
348nginx)
349 package
350 del
351 nginx
352;;
353
354resin)
355 package
356 del
357 java
358 resin
359
360;;
361tomcat)
362
363 package
364 del
365 java
366tomcat
367
368;;
369redis)
370 package
371 del
372 redis
373;;
374
375all)
376 package
377 del
378 timecron
379 sysctl
380 nginx
381 java
382 resin
383 tomcat
384 redis
385;;
386
387*)
388 echo -e "\e[32m package timecron sysctl nginx resin tomcat redis or all\e[0m\n"
389;;
390esac
391
392cd /opt/badusoft/
393
394wget http://img006.com/badusoft/service.sh
395
396chmod +x service.sh
397
398
399/opt/badusoft/service.sh
400
401