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
| #!/bin/sh
###############################
#Created: William Tian
#Date: 2015/8/22
#Version: 1.0.0
###############################
# This is an interactive program, we need the current locale
[ -f /etc/profile.d/lang.sh ] && . /etc/profile.d/lang.sh
# We can't Japanese on normal console at boot time, so force LANG=C.
if [ "$LANG" = "ja" -o "$LANG" = "ja_JP.eucJP" ]; then
if [ "$TERM" = "linux" ] ; then
LANG=C
fi
fi
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
Yum_Dir="/etc/yum.repos.d"
Mysql_Base_Dir="/opt/application/mysql"
Mysql_Data_Dir="/opt/data/3307"
Mysql_Socket="$Mysql_Data_Dir/mysql.sock"
Mysql_Pwd="123456"
Nginx_Dir="/opt/application/nginx"
Php_Dir="/opt/application/php"
Web_Dir="/opt/www"
###config yum###
function conf_yum() {
if [ -f CentOS6.5.repo.tar.gz ];then
mkdir $Yum_Dir/repobak
mv $Yum_Dir/*.repo $Yum_Dir/repobak
tar -zxf CentOS6.5.repo.tar.gz -C $Yum_Dir
else
echo -e "\033[33;1mCentOS6.5.repo.tar.gz package not found\033[0m"
exit
fi
}
###verify yum config isvalidate###
function verify_yum() {
Code=`curl -I -s www.qq.com|head -1|awk '{print $2}'`
if [[ $Code != "200" ]];then
echo -e "\033[33;1mPlease check your network\033[0m"
exit
fi
yum clean all && yum repolist
li=`yum repolist|grep epel|awk '{print $NF}'`
if [[ $li != "0" ]];then
echo -e "\033[34;1mYum repository EPEL Success\033[0m"
else
echo -e "\033[31;1mYum repository EPEL Failed\033[0m"
fi
}
###before install lamp, check depend on the package###
function preinstall_check() {
Count=0
while true
do
num=`rpm -q wget gcc gcc-c++ make cmake tcl re2c curl libcurl-devel libxml2 libxml2-devel\
libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel\
openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses \
ncurses-devel bison bison-devel libtool gettext gettext-devel bzip2 bzip2-devel pcre pcre-devel|grep "not installed"|wc -l`
if [ $num -ne 0 ];then
yum -y install wget gcc gcc-c++ make cmake tcl re2c curl libcurl-devel libxml2 libxml2-devel \
libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel \
openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel \
bison bison-devel libtool gettext gettext-devel bzip2 bzip2-devel pcre pcre-devel
let Count++
else
echo -e "\033[34;1mAll dependent packages installed success\033[0m"
break
fi
if [ $Count -ge 3 ];then
echo -e "\033[31;1mExceeded 3 times try install failed, please check yum configuration or check your network\033[0m"
exit
fi
done
}
###compile install mysql###
function install_mysql() {
if [ -f mysql-5.6.23.tar.gz ];then
/usr/sbin/groupadd -r -g 109 mysql
/usr/sbin/useradd -u 109 -g 109 -r mysql
mkdir -p $Mysql_Base_Dir
mkdir -p $Mysql_Data_Dir/data
chown -R mysql:mysql $Mysql_Data_Dir
tar -zxf mysql-5.6.23.tar.gz
cd mysql-5.6.23
cmake \
-DCMAKE_INSTALL_PREFIX=$Mysql_Base_Dir \
-DMYSQL_DATADIR=$Mysql_Data_Dir/data \
-DSYSCONFDIR=$Mysql_Data_Dir \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=$Mysql_Data_Dir/mysql.sock \
-DMYSQL_TCP_PORT=3307 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
$Mysql_Base_Dir/scripts/mysql_install_db --basedir=$Mysql_Base_Dir --datadir=$Mysql_Data_Dir/data --user=mysql
cd ../ && cp my.cnf mysql $Mysql_Data_Dir
chmod 700 $Mysql_Data_Dir/mysql
chmod 600 $Mysql_Data_Dir/my.cnf
rm -f $Mysql_Data_Dir/data/ib* #delete init created log file
$Mysql_Data_Dir/mysql start
sleep 5
else
echo -e "\033[33;1mmysql-5.6.23.tar.gz package not found\033[0m"
exit
fi
Port=`netstat -natp|grep 3307|grep mysqld|wc -l`
if [ $Port -ne 1 ];then
echo -e "\033[31;1mMysql start failed,please trouble shooting\033[0m"
exit
else
echo -e "\033[34;1mMysql install success\033[0m"
fi
}
###Optimization mysql###
function mysql_optimize() {
#alter root password $Mysql_Pwd
$Mysql_Base_Dir/bin/mysqladmin -uroot password "$Mysql_Pwd" -S $Mysql_Socket
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.innodb_index_stats"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.innodb_table_stats"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_master_info"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_relay_log_info"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_worker_info"
$Mysql_Data_Dir/mysql stop
rm -f $Mysql_Data_Dir/data/mysql/*.ibd
line=`ls -l $Mysql_Data_Dir/data/mysql/*.ibd|wc -l`
[ $line -eq 0 ] && $Mysql_Data_Dir/mysql start
sed -i '19ause mysql;' $Mysql_Base_Dir/share/mysql_system_tables.sql
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket < $Mysql_Base_Dir/share/mysql_system_tables.sql
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "delete from mysql.proxies_priv where Host='$HOSTNAME'"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "delete from mysql.user where password=''"
$Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop database test"
$Mysql_Data_Dir/mysql stop
sleep 2
$Mysql_Data_Dir/mysql start
}
###compile install nginx###
function install_nginx() {
if [ -f nginx-1.8.0.tar.gz ];then
groupadd -r -g 108 nginx
useradd -u 108 -g 108 -r nginx
tar -zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \
--user=nginx \
--group=nginx \
--prefix=$Nginx_Dir \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-http_gzip_static_module
make && make install
cd ../ && cp nginx /etc/init.d
chmod +x /etc/init.d/nginx
/sbin/chkconfig --add nginx && /sbin/chkconfig nginx on
#mv -f nginx.conf $Nginx_Dir/conf
mv $Nginx_Dir/conf/nginx.conf $Nginx_Dir/conf/nginx.conf.eri
cp nginx.conf $Nginx_Dir/conf
mkdir $Nginx_Dir/conf/vhosts
/etc/init.d/nginx start
Port=`netstat -natp|grep 80|grep nginx|wc -l`
if [ $Port -ne 1 ];then
echo -e "\033[31;1mNginx start failed, please check config\033[0m"
exit
fi
else
echo -e "\033[33;1mnginx-1.8.0.tar.gz package not found\033[0m"
exit
fi
}
###compile install php###
function install_php() {
if [ -f php-5.6.8.tar.gz ];then
tar -zxf php-5.6.8.tar.gz
cd php-5.6.8
./configure \
--prefix=$Php_Dir \
--with-config-file-path=$Php_Dir/etc \
--with-mysql=$Mysql_Base_Dir \
--with-mysql-sock=$Mysql_Data_Dir/mysql.sock \
--with-mysqli=$Mysql_Base_Dir/bin/mysql_config \
--with-libxml-dir \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-gd \
--with-zlib-dir \
--with-mcrypt \
--with-gettext \
--with-pdo-mysql \
--enable-fpm \
--enable-mbstring=all \
--enable-sockets \
--enable-ftp \
--enable-zip
make && make install
cp php.ini-production $Php_Dir/etc/php.ini
cd ../
else
echo -e "\e[1;33mphp-5.6.8.tar.gz package not found\e[0m"
exit
fi
}
###configuration php-fpm###
function conf_php_fpm() {
cp php-5.6.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/sbin/chkconfig --add php-fpm && /sbin/chkconfig php-fpm on
cp $Php_Dir/etc/php-fpm.conf.default $Php_Dir/etc/php-fpm.conf
#edit php-fpm.conf
sed -i 's/^pm.max_children.*$/pm.max_children = 150/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^pm.start_servers.*$/pm.start_servers = 8/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^pm.min_spare_servers.*$/pm.min_spare_servers = 5/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^pm.max_spare_servers.*$/pm.max_spare_servers = 10/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^;pm.max_requests.*$/pm.max_requests = 5000/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^;rlimit_files.*$/rlimit_files = 51200/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^user.*$/user = nginx/' $Php_Dir/etc/php-fpm.conf
sed -i 's/^group.*$/group = nginx/' $Php_Dir/etc/php-fpm.conf
#start php-fpm
/etc/init.d/php-fpm start
Foo=`netstat -natp|grep 9000|grep php-fpm|wc -l`
if [ $Foo -eq 1 ];then
echo -e "\e[1;34mphp-fpm service start success\e[0m"
else
echo -e "\e[1;31mphp-fpm service start failed\e[0m"
fi
}
###phpinfo access test###
function phpinfo_test() {
[ ! -d $Web_Dir ] && mkdir -p $Web_Dir
echo "<?php phpinfo();?>" >$Web_Dir/index.php
}
###install xcache acceleration###
function install_xcache() {
if [ -f xcache-3.2.0.tar.gz ];then
tar -zxf xcache-3.2.0.tar.gz && cd xcache-3.2.0
$Php_Dir/bin/phpize
./configure \
--enable-xcache \
--with-php-config=$Php_Dir/bin/php-config
make && make install
cat xcache.ini >> $Php_Dir/etc/php.ini
cd ../
/etc/init.d/php-fpm reload
/etc/init.d/nginx stop
sleep 2
/etc/init.d/nginx start
else
echo -e "\e[1;33mxcache-3.2.0.tar.gz package not found\e[0m"
exit
fi
}
###create phpmyadmin project###
function create_phpmyadmin_pro() {
if [ -f phpMyAdmin-4.4.6-all-languages.tar.bz2 ];then
tar -jxf phpMyAdmin-4.4.6-all-languages.tar.bz2
mv phpMyAdmin-4.4.6-all-languages $Web_Dir/phpmyadmin
[ ! -d $Nginx_Dir/conf/vhosts ] && mkdir $Nginx_Dir/conf/vhosts
cp phpmyadmin.vhost.conf $Nginx_Dir/conf/vhosts
/etc/init.d/nginx reload
else
echo -e "\e[1;33mphpMyAdmin-4.4.6-all-languages.tar.bz2 package not found\e[0m"
exit
fi
}
###judge create phpmyadmin project whether or not###
function judge_whether_create_phpmyadmin() {
while true
do
echo -e "\033[32;1m================================================\033[0m"
read -p "Do you want to install phpmyadmin project?[Yes|No] " answer
case $answer in
"Yes")
create_phpmyadmin_pro
break
;;
"No")
exit 0
;;
*)
echo -e "\033[33;1mPlease input Yes or No\033[0m"
esac
done
}
###fllow the sequence active###
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mConfig Yum Source\033[0m"
echo
conf_yum
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mVerfiy Yum Source isValidate\033[0m"
echo
verify_yum
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mCheck and Yum Install LNMP Dependent package\033[0m"
echo
preinstall_check
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mInstall Mysql......\033[0m"
echo
install_mysql
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mOptimization Mysql......\033[0m"
echo
mysql_optimize
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mInstall Nginx......\033[0m"
echo
install_nginx
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mInstall Php......\033[0m"
echo
install_php
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mConfig php-fpm......\033[0m"
echo
conf_php_fpm
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mphpinfo test......\033[0m"
echo
phpinfo_test
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mInstall Xcache......\033[0m"
echo
install_xcache
echo -e "\033[32;1m===========================================\033[0m"
echo -e "\033[32;1mJudge Whether Install phpmyadmin or not......\033[0m"
echo
judge_whether_create_phpmyadmin
|