说明:
用平常的方式在Linux服务器上安装程序,需要下载安装包、进入安装包位置、给安装包文件赋予可执行权限、执行安装、设置环境变量……等等一系列复杂的操作。并且如果有关联也需要一个一个的挨着安装。耗时并且繁琐。而用shell脚本来执行这些操作,则很好的解决了这些问题!
步骤:
wget http://img006.com/badusoft/centosupNEW.sh
// 在Linux服务器上执行wget命令下载shell脚本
chmod +x centosupNEW.sh
// 给下载下来的 centosupNEW.sh 文件赋可执行权限
./centosupNEW.sh all
//执行命令安装所有程序,还可单独安装nginx、redis、tomcat等,如想单独安装resin,则执行 ./centosupNEW.sh resin 命令即可
截图:
代码:
#!/bin/bash
#version1.0
#Wangwei
#date 2015/04/02
#System Centos6.4
get_bin_tar="/bin/tar"
get_cmd_dns="/etc/resolv.conf"
get_cmd_soft="/opt/badusoft"
get_cmd_name=`/bin/uname -a | awk '{print $1,$3}'`
get_cmd_service="/usr/local/service"
get_cmd_user=`whoami`
get_cmd_cron="/var/spool/cron/"
get_cmd_url="http://img006.com/badusoft"
echo -e "System for version:e[32m$get_cmd_name e[0m
"
echo -e "Nginx for version:e[32mTengine2.1 and nginx 1.8.0e[0m
"
echo -e "Java for version:e[32mJdk 1.7e[0m
"
echo -e "Resin pro for version:e[32mResin pro 3.1e[0m
"
echo -e "Apache for tomcat version:e[32m tomcat 7e[0m
"
echo -e "Redis version:e[32m Redis 2.8e[0m
"
echo -e "Firewall:e[32moffe[0m
"
cat /dev/null > $get_cmd_dns
echo "nameserver 114.114.114.114" >> $get_cmd_dns
echo -e "NameServer:e[32m114.114.114.114e[0m
"
sleep 10
/etc/init.d/iptables stop
/sbin/chkconfig iptables off
function package(){
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
do
yum install -y $i
sleep 1
done
}
function del(){
if [ ! -d $get_cmd_soft ] && [ ! -d $get_cmd_service ]; then
mkdir /opt/badusoft >> /dev/null 2>&1
mkdir /usr/local/service/ >> /dev/null 2>&1
else
rm -rf $get_cmd_soft $get_cmd_service
cp -f /etc/profile.bak /etc/profile
mkdir /opt/badusoft >> /dev/null 2>&1
mkdir /usr/local/service/ >> /dev/null 2>&1
fi
}
function timecron(){
#date cron
if [ $get_cmd_user = "root" ];then
echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" > $get_cmd_cron/$get_cmd_user
else
if [ -f "$get_cmd_cron/root" ];then
echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" >> $get_cmd_cron/$get_cmd_user
else
echo "$get_cmd_user error"
return 0
fi
fi
}
function sysctl(){
cd $get_cmd_soft
if [ ! -f kernels_sysctl ] && [ ! -f limits.conf ];then
wget $get_cmd_url/kernels_sysctl
wget $get_cmd_url/limits.conf
if [ -f $get_cmd_soft/kernels_sysctl ] && [ -f $get_cmd_soft/limits.conf ];then
#cp -f /etc/sysctl.conf /etc/sysctl.conf.bak
#cp -f /etc/security/limits.conf /etc/security/limits.conf
cat $get_cmd_soft/kernels_sysctl > /etc/sysctl.conf
cp -f $get_cmd_soft/limits.conf /etc/security/limits.conf
/sbin/sysctl -p
if [ $? -eq 0 ];then
echo -e "e[32mcopy donee[0m
"
sleep 5
else
echo -e "e[31m copy error!!e[0m
"
exit 0
fi
else
echo -e "e[31mfile not exits[0m
"
exit 0
fi
else
echo -e "e[31mfile existse[0m
"
exit 0
fi
}
function nginx(){
cd $get_cmd_soft
if [ ! -f nginx-1.8.0.tar.gz ];then
wget $get_cmd_url/nginx-1.8.0/nginx-1.8.0.tar.gz
wget $get_cmd_url/nginx-1.8.0/nginx_upstream_check_module-master.zip
wget $get_cmd_url/nginx-1.8.0/openssl-1.0.2c.tar.gz
wget $get_cmd_url/nginx-1.8.0/ngx_cache_purge-2.3.tar.gz
wget $get_cmd_url/pcre-8.12.tar.gz
wget $get_cmd_url/zlib-1.2.5.tar.gz
if [ $? -eq 0 ];then
$get_bin_tar zxf nginx-1.8.0.tar.gz
unzip nginx_upstream_check_module-master.zip
$get_bin_tar zxf openssl-1.0.2c.tar.gz
$get_bin_tar zxf ngx_cache_purge-2.3.tar.gz
$get_bin_tar zxf pcre-8.12.tar.gz
$get_bin_tar zxf zlib-1.2.5.tar.gz
if [ $? -eq 0 ];then
cd $get_cmd_soft/nginx-1.8.0
patch -p1 < $get_cmd_soft/nginx_upstream_check_module-master/check_1.7.5+.patch
./configure --prefix=$get_cmd_service/nginx
--with-pcre=$get_cmd_soft/pcre-8.12
--with-openssl=$get_cmd_soft/openssl-1.0.2c
--with-zlib=$get_cmd_soft/zlib-1.2.5
--add-module=$get_cmd_soft/ngx_cache_purge-2.3
--with-http_realip_module
--with-http_sub_module
--with-http_flv_module
--with-http_dav_module
--with-http_gzip_static_module
--with-http_stub_status_module
--with-http_addition_module
--with-http_ssl_module
--add-module=$get_cmd_soft/nginx_upstream_check_module-master
if [ $? -eq 0 ];then
make && make install
if [ $? -eq 0 ];then
echo -e "e[32mtengine for nginx install donee[0m
"
sleep 5
else
echo -e "e[31mmake && make error!!e[0m
"
fi
else
echo -e "e[31mconfigure error!!e[0m
"
exit 0
fi
else
echo -e "e[31mtar error!!e[0m
"
exit 0
fi
else
echo -e "e[31mtengine for nginx download error!!e[0m
"
exit 0
fi
else
sleep 5
echo -e "e[31mtengine for nginx founde[0m
"
fi
}
function java(){
cd $get_cmd_soft
if [ ! -f server-jre-7u80-linux-x64.tar.gz ];then
wget $get_cmd_url/javapath
wget $get_cmd_url/server-jre-7u80-linux-x64.tar.gz
$get_bin_tar zxf server-jre-7u80-linux-x64.tar.gz
if [ $? -eq 0 ];then
mv jdk1.7.0_80 $get_cmd_service/java
cp -f /etc/profile /etc/profile.bak
cat $get_cmd_soft/javapath >> /etc/profile
source /etc/profile
if [ $? -eq 0 ];then
$get_cmd_service/java/bin/java -version
if [ $? -eq 0 ];then
echo -ne "e[32mJava install donee[0m
"
sleep 5
else
echo -ne "e[31mJava install error!!e[0m
"
exit 0
fi
else
echo -ne "e[31mJava path error!!e[0m
"
fi
else
echo -ne "e[31mJava tar error!!e[0m
"
exit 0
fi
else
echo -ne "e[31mJava download errore[0m
"
exit 0
fi
}
function resin(){
cd $get_cmd_soft
if [ ! -f resin-pro-3.1.12.tar.gz ];then
wget $get_cmd_url/licenses/004444.license
wget $get_cmd_url/resin-pro-3.1.12.tar.gz
if [ $? -eq 0 ];then
$get_bin_tar zxvf resin-pro-3.1.12.tar.gz
if [ $? -eq 0 ];then
cd $get_cmd_soft/resin-pro-3.1.12
./configure --prefix=$get_cmd_service/resin
--with-java-home=$get_cmd_service/java
--enable-64bit=yes
--enable-lfs
--enable-jni
--disable-libtool-lock
if [ $? -eq 0 ];then
make && make install
mkdir $get_cmd_service/resin/licenses
cp $get_cmd_soft/004444.license $get_cmd_service/resin/licenses
if [ $? -eq 0 ];then
echo -ne "e[32mResin install donee[0m
"
sleep 5
else
echo -ne "e[31mResin install errore[0m
"
exit 0
fi
else
echo -ne "e[31mConfigure errore[0m
"
exit 0
fi
else
echo -ne "e[31mtar errore[0m
"
exit 0
fi
else
echo -ne "e[31mdownload errore[0m
"
exit 0
fi
else
echo -ne "e[31mDircetory or Resin error!!e[0m
"
exit 0
fi
}
function tomcat(){
mkdir /usr/local/service/apache2
cd /opt/badusoft/
wget http://img006.com/badusoft/apr-1.5.2.tar.zip
wget http://img006.com/badusoft/apr-iconv-1.2.1.tar.bz2
wget http://img006.com/badusoft/apr-util-1.5.4.tar.bz2
wget http://img006.com/badusoft/tomcat-native.tar.gz
wget http://img006.com/badusoft/apache-tomcat-7.0.42.tar.gz
tar -xvf apr-1.5.2.tar.bz2
tar -xvf apr-iconv-1.2.1.tar.bz2
tar -xvf apr-util-1.5.4.tar.bz2
tar -xvf tomcat-native.tar.gz
tar -xvf apache-tomcat-7.0.42.tar.gz
mv /opt/badusoft/apache-tomcat-7.0.42 /usr/local/service/tomcat
cd /opt/badusoft/apr-1.5.2
./configure --prefix=/usr/local/service/apache2/apr
make && make install
echo "APR step over"
###############################################################
cd /opt/badushot/apr-util-1.5.4
./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr
make && make install
echo "apr-util step over"
##############################################################################
cd /opt/badusoft/tomcat-native-1.1.33-src/jni/native
./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr --with-java-home=/usr/local/service/java
make && make install
echo "tomact-native step over"
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/service/apache2/apr/lib" >> /etc/profile
source /etc/profile
cd /opt/badusoft/
wget http://img006.com/badusoft/catalina.txt
sed -i '/# limitations under the License./r catalina.txt' /usr/local/service/tomcat/bin/catalina.sh
}
function redis(){
cd $get_cmd_soft
if [ ! -f redis-2.8.12.tar.gz ];then
wget $get_cmd_url/redis-2.8.12.tar.gz
if [ $? -eq 0 ];then
tar zxf redis-2.8.12.tar.gz
if [ $? -eq 0 ];then
cd $get_cmd_soft/redis-2.8.12
make && make install
if [ $? -eq 0 ];then
mkdir $get_cmd_service/redis/
mkdir $get_cmd_service/redis/conf
mv /usr/local/bin $get_cmd_service/redis/
cp -f $get_cmd_soft/redis-2.8.12/redis.conf $get_cmd_service/redis/conf/
echo -e "e[32m Redis install donee[0m
"
sleep 5
else
echo -e "e[31m make && make install error!!e[0m
"
exit 0
fi
else
echo -e "e[31m tar errore[0m
"
exit 0
fi
else
echo -e "e[31m Download Redis error!!e[0m
"
exit 0
fi
else
echo -e "e[31m Redis file error!!e[0m
"
exit 0
fi
}
case $1 in
package)
package
;;
timecron)
package
del
timecron
;;
sysctl)
package
del
sysctl
;;
nginx)
package
del
nginx
;;
resin)
package
del
java
resin
;;
tomcat)
package
del
java
tomcat
;;
redis)
package
del
redis
;;
all)
package
del
timecron
sysctl
nginx
java
resin
tomcat
redis
;;
*)
echo -e "e[32m package timecron sysctl nginx resin tomcat redis or alle[0m
"
;;
esac
cd /opt/badusoft/
wget http://img006.com/badusoft/service.sh
chmod +x service.sh
/opt/badusoft/service.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