-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanmp.sh
480 lines (455 loc) · 14.5 KB
/
lanmp.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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/bin/bash
## written by aming.
## 2015-06-24.
#######Begin########
echo "It will install lamp or lnmp."
sleep 1
##check last command is OK or not.
check_ok() {
if [ $? != 0 ]
then
echo "Error, Check the error log."
exit 1
fi
}
##get the archive of the system,i686 or x86_64.
ar=`arch`
##close seliux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s == "enforcing" ]
then
setenforce 0
fi
##close iptables
iptables-save > /etc/sysconfig/iptables_`date +%s`
iptables -F
service iptables save
##if the packge installed ,then omit.
myum() {
if ! rpm -qa|grep -q "^$1"
then
yum install -y $1
check_ok
else
echo $1 already installed.
fi
}
## install some packges.
for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel
do
myum $p
done
##install epel.
if rpm -qa epel-release >/dev/null
then
rpm -e epel-release
fi
if ls /etc/yum.repos.d/epel-6.repo* >/dev/null 2>&1
then
rm -f /etc/yum.repos.d/epel-6.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
##function of installing mysqld.
install_mysqld() {
case $mysql_v in
5.1)
cd /usr/local/src
[ -f mysql-5.1.72-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gz
tar zxf mysql-5.1.72-linux-$ar-glibc23.tar.gz
check_ok
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`
mv mysql-5.1.72-linux-$ar-glibc23 /usr/local/mysql
check_ok
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
check_ok
fi
myum compat-libstdc++-33
[ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s`
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
check_ok
/bin/cp support-files/my-huge.cnf /etc/my.cnf
check_ok
sed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf
/bin/cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
check_ok
break
;;
5.6)
cd /usr/local/src
[ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
tar zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
check_ok
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_bak
mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
fi
myum compat-libstdc++-33
[ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_bak
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
check_ok
/bin/cp support-files/my-default.cnf /etc/my.cnf
check_ok
sed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf
/bin/cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
check_ok
break
;;
*)
echo "only 1(5.1) or 2(5.6)"
exit 1
;;
esac
}
##function of install httpd.
install_httpd() {
echo "Install apache version 2.2."
cd /usr/local/src
[ -f httpd-2.2.16.tar.gz ] || wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zxf httpd-2.2.16.tar.gz && cd httpd-2.2.16
check_ok
./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
check_ok
make && make install
check_ok
}
##function of install lamp's php.
install_php() {
echo -e "Install php.\nPlease chose the version of php."
case $php_v in
5.4)
cd /usr/local/src/
[ -f php-5.4.45.tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4.45.tar.bz2
tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done
check_ok
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
check_ok
make && make install
check_ok
[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini
break
;;
5.6)
cd /usr/local/src/
[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar zxf php-5.6.6.tar.gz && cd php-5.6.6
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
check_ok
make && make install
check_ok
[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini
break
;;
*)
echo "only 1(5.4) or 2(5.6)"
;;
esac
}
##function of apache and php configue.
join_apa_php() {
sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' /usr/local/apache2/conf/httpd.conf
check_ok
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' /usr/local/apache2/conf/httpd.conf
check_ok
cat > /usr/local/apache2/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
if /usr/local/php/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php/etc/php.ini
fi
/usr/local/apache2/bin/apachectl restart
check_ok
}
##function of check service is running or not, example nginx, httpd, php-fpm.
check_service() {
if [ "$1" == "phpfpm" ]
then
s="php-fpm"
else
s=$1
fi
n=`ps aux |grep "$s"|wc -l`
if [ $n -gt 1 ]
then
echo "$1 service is already started."
else
if [ -f /etc/init.d/$1 ]
then
/etc/init.d/$1 start
check_ok
else
install_$1
fi
fi
}
##function of install lamp
lamp() {
check_service mysqld
check_service httpd
install_php
join_apa_php
echo "LAMP done,Please use 'http://your ip/index.php' to access."
}
##function of install nginx
install_nginx() {
cd /usr/local/src
[ -f nginx-1.8.0.tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
myum pcre-devel
./configure --prefix=/usr/local/nginx
check_ok
make && make install
check_ok
if [ -f /etc/init.d/nginx ]
then
/bin/mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s`
fi
curl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginx
check_ok
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
curl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.conf
check_ok
service nginx start
check_ok
echo -e "<?php\n phpinfo();\n?>" > /usr/local/nginx/html/index.php
check_ok
}
##function of install php-fpm
install_phpfpm() {
echo -e "Install php.\nPlease chose the version of php."
case $php_v in
5.4)
cd /usr/local/src/
[ -f php-5.4.45.tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4.45.tar.bz2
tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done
if ! grep -q '^php-fpm:' /etc/passwd
then
useradd -M -s /sbin/nologin php-fpm
check_ok
fi
./configure \
--prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--enable-zend-multibyte \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
check_ok
make && make install
check_ok
[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini
if /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.ini
check_ok
fi
[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
chmod 755 /etc/init.d/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
break
;;
5.6)
cd /usr/local/src/
[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar zxf php-5.6.6.tar.gz && cd php-5.6.6
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done
if ! grep -q '^php-fpm:' /etc/passwd
then
useradd -M -s /sbin/nologin php-fpm
fi
check_ok
./configure \
--prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
check_ok
make && make install
check_ok
[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini
if /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.ini
check_ok
fi
[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
check_ok
[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
chmod 755 /etc/init.d/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
break
;;
*)
echo 'only 1(5.4) or 2(5.6)'
;;
esac
}
##function of install lnmp
lnmp() {
check_service mysqld
check_service nginx
check_service phpfpm
echo "The lnmp done, Please use 'http://your ip/index.php' to access."
}
read -p "Please chose which type env you install, (lamp|lnmp)? " t
case $t in
lamp)
read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v
read -p "Please chose the version of php. (5.4|5.6)" php_v
lamp
;;
lnmp)
read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v
read -p "Please chose the version of php. (5.4|5.6)" php_v
lnmp
;;
*)
echo "Only 'lamp' or 'lnmp' your can input."
;;
esac
##111111
##########end##############