-
Notifications
You must be signed in to change notification settings - Fork 0
/
lnmp.sh
585 lines (500 loc) · 22.2 KB
/
lnmp.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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/bin:/sbin
export PATH
# Check if Directory existed.if not,create it!
echo "Please input LNMP Work Directory:"
read -p "(Default LNMP Work Directory:/opt/lnmp):" LNMP_DIR
if [ "$LNMP_DIR" = "" ]; then
LNMP_DIR="/opt/lnmp"
if [ -d $LNMP_DIR ];then
printf "LNMP Work Directory has existed!\n"
fi
else
mkdir -pv $LNMP_DIR && echo "LNMP Work Directory created"
fi
echo "==========================="
echo LNMP Work Directory:="$LNMP_DIR"
echo "==========================="
mkdir -pv $LNMP_DIR/src
NMP_SRC_DIR=$LNMP_DIR/src
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
echo "Auto-compile & install Nginx+MySQL+PHP on Linux by Jerry "
#Optimize the system kernel parameters
cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
eof
cat >>/etc/sysctl.conf<<eof
fs.file-max=262140
vm.swappiness = 0
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 = 8192
net.ipv4.tcp_synack_retries = 2
net.ipv4.conf.lo.arp_announce=2
vm.overcommit_memory = 1
net.core.somaxconn = 4096
net.ipv4.tcp_tw_reuse = 1
kernel.threads-max = 254737
eof
#set main domain name
domain="www.jerry.vip"
echo "Please input domain:"
read -p "(Default domain: www.jerry.vip):" domain
if [ "$domain" = "" ]; then
domain="www.jerry.vip"
fi
echo "==========================="
echo domain="$domain"
echo "==========================="
#set mysql root password
echo "==========================="
mysqlrootpwd="root123"
echo "Please input the root password of mysql:"
read -p "(Default password: root123):" mysqlrootpwd
if [ "$mysqlrootpwd" = "" ]; then
mysqlrootpwd="root123"
fi
echo "==========================="
echo mysqlrootpwd="$mysqlrootpwd"
echo "==========================="
#Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Update time
yum install -y ntp
ntpdate -u time3.aliyun.com
date
#Uninstall the same installation package that exists in the system
rpm -qa|grep httpd
rpm -e httpd
rpm -qa|grep mysql
rpm -e mysql
rpm -qa|grep php
rpm -e php
yum -y remove httpd*
yum -y remove php*
yum -y remove mysql-server mysql
yum -y remove php-mysql
yum -y remove boost*
yum -y install yum-fastestmirror
yum -y remove httpd
#yum -y update
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
Print_Sys_Info()
{
eval echo "${DISTRO} \${${DISTRO}_Version}"
cat /etc/issue
cat /etc/*-release
uname -a
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo "Memory is: ${MemTotal} MB "
df -h
}
MySQL_Opt()
{
if [[ ${MemTotal} -gt 1024 && ${MemTotal} -lt 2048 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 32M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 128#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 768K#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 768K#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 8M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 16#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 16M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 32M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 32M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 1000" $LNMP_DIR/mysql/conf/my.cnf
elif [[ ${MemTotal} -ge 2048 && ${MemTotal} -lt 4096 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 256#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 1M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 1M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 16M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 32#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 32M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 2000" $LNMP_DIR/mysql/conf/my.cnf
elif [[ ${MemTotal} -ge 4096 && ${MemTotal} -lt 8192 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 512#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 2M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 2M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 32M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 64#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 512M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 4000" $LNMP_DIR/mysql/conf/my.cnf
elif [[ ${MemTotal} -ge 8192 && ${MemTotal} -lt 16384 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 1024#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 4M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 4M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 64M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 128#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 1024M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 6000" $LNMP_DIR/mysql/conf/my.cnf
elif [[ ${MemTotal} -ge 16384 && ${MemTotal} -lt 32768 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 512M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 2048#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 8M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 8M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 128M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 256#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 2048M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 512M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 8000" $LNMP_DIR/mysql/conf/my.cnf
elif [[ ${MemTotal} -ge 32768 ]]; then
sed -i "s#^key_buffer_size.*#key_buffer_size = 1024M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^table_open_cache.*#table_open_cache = 4096#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^sort_buffer_size.*#sort_buffer_size = 16M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^read_buffer_size.*#read_buffer_size = 16M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 256M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^thread_cache_size.*#thread_cache_size = 512#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^query_cache_size.*#query_cache_size = 512M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^tmp_table_size.*#tmp_table_size = 512M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 4096M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 1024M#" $LNMP_DIR/mysql/conf/my.cnf
sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 10000" $LNMP_DIR/mysql/conf/my.cnf
fi
}
cp /etc/yum.conf /etc/yum.conf.lnmp
sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf
#Installation dependency package
for packages in make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel patch wget crontabs libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel libicu-devel libxslt libxslt-devel xz pcre-devel libticonv.x86_64 libticonv-devel.x86_64 php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel vim-minimal nano fonts-chinese;
do yum -y install $packages; done
mv -f /etc/yum.conf.lnmp /etc/yum.conf
#Check the source installation package
#Donwload file from Sohu.com Open Source Mirror Site and soft.vpser.net
echo "=======================Check the source installation package================================="
cd $NMP_SRC_DIR
if [ -s mysql-boost-5.7.18.tar.gz ]; then
echo "mysql-boost-5.7.18.tar.gz [found]"
else
echo "Error: mysql-boost-5.7.18.tar.gz not found!!!download now......"
wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.18.tar.gz -P $NMP_SRC_DIR
fi
if [ -s boost_1_59_0.tar.gz ]; then
echo "boost_1_59_0.tar.gz [found]"
else
echo "Error: boost_1_59_0.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/lib/boost/boost_1_59_0.tar.gz -P $NMP_SRC_DIR
fi
if [ -s phpMyAdmin-4.7.1-all-languages.tar.xz ]; then
echo "phpMyAdmin-4.7.1-all-languages.tar.xz [found]"
else
echo "Error: phpMyAdmin-4.7.1-all-languages.tar.xz not found!!!download now......"
wget -c http://soft.vpser.net/datebase/phpmyadmin/phpMyAdmin-4.7.1-all-languages.tar.xz -P $NMP_SRC_DIR
fi
if [ -s nginx-1.12.1.tar.gz ]; then
echo "nginx-1.12.1.tar.gz [found]"
else
echo "Error: nginx-1.12.1.tar.gz not found!!!download now......"
wget -c http://nginx.org/download/nginx-1.12.1.tar.gz -P $NMP_SRC_DIR
fi
if [ -s php-5.6.30.tar.bz2 ]; then
echo "php-5.6.30.tar.bz2 [found]"
else
echo "Error: php-5.6.30.tar.bz2 not found!!!download now......"
wget -c http://soft.vpser.net/web/php/php-5.6.30.tar.bz2 -P $NMP_SRC_DIR
fi
#Install MySQL 5.7
echo "============================Install MySQL 5.7.18=================================="
cd $NMP_SRC_DIR
rm -f /etc/my.cnf
tar zxvf mysql-boost-5.7.18.tar.gz
cd mysql-5.7.18/
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
mkdir -pv $LNMP_DIR/mysql/{conf,data,log}
cmake -DCMAKE_INSTALL_PREFIX=$LNMP_DIR/mysql -DMYSQL_DATADIR=$LNMP_DIR/mysql/data -DSYSCONFDIR=$LNMP_DIR/mysql/conf -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=$LNMP_DIR/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=$NMP_SRC_DIR -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNODB_MEMCACHED=on
make -j $(cat /proc/cpuinfo| grep "processor"|wc -l) && make install > $NMP_SRC_DIR/mysqlinstall
mysqltempwd=$(tail -1 $NMP_SRC_DIR/mysqlinstall | awk '{print $NF}')
#rm -f $NMP_SRC_DIR/mysqlinstall
cd $LNMP_DIR/mysql
./bin/mysqld --initialize --user=mysql --basedir=$LNMP_DIR/mysql --datadir=$LNMP_DIR/mysql/data --explicit_defaults_for_timestamp
chown -R mysql $LNMP_DIR/mysql
chgrp -R mysql $LNMP_DIR/mysql/.
cat > $LNMP_DIR/mysql/conf/my.cnf<<EOF
[client]
#password = your_password
port = 3306
socket = $LNMP_DIR/mysql/mysql.sock
[mysqld]
port = 3306
socket = $LNMP_DIR/mysql/mysql.sock
datadir = $LNMP_DIR/mysql/data
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
performance_schema_max_table_instances = 500
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
early-plugin-load = ""
#loose-innodb-trx=0
#loose-innodb-locks=0
#loose-innodb-lock-waits=0
#loose-innodb-cmp=0
#loose-innodb-cmp-per-index=0
#loose-innodb-cmp-per-index-reset=0
#loose-innodb-cmp-reset=0
#loose-innodb-cmpmem=0
#loose-innodb-cmpmem-reset=0
#loose-innodb-buffer-page=0
#loose-innodb-buffer-page-lru=0
#loose-innodb-buffer-pool-stats=0
#loose-innodb-metrics=0
#loose-innodb-ft-default-stopword=0
#loose-innodb-ft-inserted=0
#loose-innodb-ft-deleted=0
#loose-innodb-ft-being-deleted=0
#loose-innodb-ft-config=0
#loose-innodb-ft-index-cache=0
#loose-innodb-ft-index-table=0
#loose-innodb-sys-tables=0
#loose-innodb-sys-tablestats=0
#loose-innodb-sys-indexes=0
#loose-innodb-sys-columns=0
#loose-innodb-sys-fields=0
#loose-innodb-sys-foreign=0
#loose-innodb-sys-foreign-cols=0
default_storage_engine = InnoDB
#innodb_file_per_table = 1
#innodb_data_home_dir = $LNMP_DIR/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = $LNMP_DIR/mysql/data
#innodb_buffer_pool_size = 16M
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqld_safe]
log-error=$LNMP_DIR/mysql/log/mysqld_err.log
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
sed -i 's:^#innodb:innodb:g' $LNMP_DIR/mysql/conf/my.cnf
touch $LNMP_DIR/mysql/log/mysqld_err.log
chown -R mysql:mysql $LNMP_DIR/mysql/log/mysqld_err.log
MySQL_Opt
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
sed -i "s:mysqld_pid_file_path=:mysqld_pid_file_path=$LNMP_DIR/mysql/mysqld.pid:g" /etc/init.d/mysql
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf $LNMP_DIR/mysql/lib/mysql /usr/lib/mysql
ln -sf $LNMP_DIR/mysql/include/mysql /usr/include/mysql
ln -sf $LNMP_DIR/mysql/bin/mysql /usr/bin/mysql
ln -sf $LNMP_DIR/mysql/bin/mysqldump /usr/bin/mysqldump
ln -sf $LNMP_DIR/mysql/bin/myisamchk /usr/bin/myisamchk
ln -sf $LNMP_DIR/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
/etc/init.d/mysql start >$NMP_SRC_DIR/mysqlstart
$LNMP_DIR/mysql/bin/mysqladmin -u root -p$mysqltempwd -h localhost password $mysqlrootpwd
#cat > /tmp/mysql_sec_script<<EOF
#use mysql;
#update user set authentication_string=password('$mysqlrootpwd') where user='root';
#delete from user where not (user='root') ;
#delete from user where user='root' and password='';
#drop database test;
#DROP USER ''@'%';
#flush privileges;
#EOF
#$LNMP_DIR/mysql/bin/mysql -u root -p$mysqltempwd -h localhost < /tmp/mysql_sec_script
#rm -f /tmp/mysql_sec_script
/etc/init.d/mysql restart
chkconfig --add mysql
chkconfig mysql on
#Install Nginx
echo "========================Starting install Nginx=================================="
cd $NMP_SRC_DIR
tar zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1/
groupadd nginx
useradd -s /sbin/nologin -M -g nginx nginx
mkdir -pv $LNMP_DIR/nginx
./configure --prefix=$LNMP_DIR/nginx --with-select_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module
make -j $(cat /proc/cpuinfo| grep "processor"|wc -l) && make install
echo "====================Setup Nginx initd========================"
cat > /etc/init.d/nginx<<EOF
#!/bin/bash
# nginx This shell script takes care of starting and stopping
# nginx
#
# chkconfig: - 13 68
# description: nginx is a web server
### BEGIN INIT INFO
# Provides: $named
# Short-Description: start|stop|status|restart|configtest
### END INIT INFO
#variables
NGINX_BIN="$LNMP_DIR/nginx/sbin/nginx"
NGINX_CONF="$LNMP_DIR/nginx/conf/nginx.conf"
NGINX_PID="$LNMP_DIR/nginx/logs/nginx.pid"
NETSTAT="/bin/netstat"
alter=$1
prog=nginx
#load system function
. /etc/rc.d/init.d/functions
#function:echo ok or error
function if_no {
if [ $2 == 0 ]; then
echo -n $"$1 ${prog}:" && success && echo
else
echo -n $"$1 ${prog}:" && failure && echo
fi
}
#start nginx
function start {
if [ -s ${NGINX_PID} ]; then
echo "nginx already running"
else
if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then
rm -f ${NGINX_PID} 2>/dev/null
${NGINX_BIN} -c ${NGINX_CONF}
if_no start $?
else
${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1 > ${NGINX_PID}
if_no start $?
fi
fi
}
#stop nginx
function stop {
if [ -s ${NGINX_PID} ]; then
cat ${NGINX_PID} | xargs kill -QUIT
if_no stop $?
else
if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then
rm -f ${NGINX_PID} 2>/dev/null
if_no stop 0
else
rm -f ${NGINX_PID} 2>/dev/null
kill `${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1`
if_no stop $?
fi
fi
}
function restart {
if [ -s ${NGINX_PID} ]; then
cat ${NGINX_PID} | xargs kill -HUP
if_no restart $?
else
stop
sleep 1
start
fi
}
function status {
${NETSTAT} -tnpl | grep nginx | grep LISTEN
[ $? == 0 ] && echo "nginx is running" || echo "nginx is not running"
}
function configtest {
${NGINX_BIN} -t
}
case $alter in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
configtest)
configtest
;;
*)
echo "use:${NGINX} {start|stop|restart|status|configtest}"
;;
esac
EOF
chkconfig --add nginx
chkconfig nginx on
echo "============================php install======================"
cd $NMP_SRC_DIR
yum -y install gd zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libticonv.x8664 libticonv-devel.x8664 php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel
tar jxvf php-5.6.30.tar.bz2
cd php-5.6.30/
./configure --prefix=$LNMP_DIR/php --sysconfdir=$LNMP_DIR/php/etc --enable-fpm --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-shared --enable-mbstring --enable-xml --enable-opcache --enable-bcmath --enable-soap --enable-zip --with-mysqli=$LNMP_DIR/mysql/bin/mysql_config --with-mysql=$LNMP_DIR/mysql --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-iconv --with-mhash --with-mcrypt --with-config-file-path=$LNMP_DIR/php/etc --with-config-file-scan-dir=$LNMP_DIR/php/etc/php.d --with-bz2 --with-curl --with-gettext --with-gd
make -j $(cat /proc/cpuinfo| grep "processor"|wc -l) && make install
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm && chkconfig php-fpm on
cd $LNMP_DIR/php/etc/
cp php-fpm.conf.default php-fpm.conf
cat >>$LNMP_DIR/php/etc/php-fpm.conf<<eof
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
eof
service php-fpm start
echo "====================================php install completed=================================================="
echo "========================Integrating Nginx and PHP5========================================================="
cd $LNMP_DIR/nginx/conf
sed -i '/pass the PHP scripts to FastCGI server/'a\ 'location ~ \\.php$ {'\\nroot\ html\;\\nfastcgi\_pass\ 127\.0\.0\.1\:9000\;\\nfastcgi\_index\ index\.php\;\\nfastcgi\_param\ SCRIPT\_FILENAME\ \/\$document\_root\$fastcgi\_script\_name\;\\ninclude\ fastcgi\_params\;\\n\} nginx.conf
sed -i "s/^[[:space:]]*index/index index.php/" nginx.conf
cat >>$LNMP_DIR/nginx/html/index.php<<eof
<?php
phpinfo();
?>
eof
service nginx configtest
service nginx force-reload
echo "========================Completely Integrating Nginx and PHP5==================================="