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
|
echo
"It will install 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"
-o $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
$1already installed.
fi
}
##install some packges.
for
p
in
gcc gcc-c++ wget perl perl-devel libaiolibaio-devel pcre-devel zlib-devel openssl openssl-devel ncurses ncurses-devellibxml2 libxml2-devel
bzip2
bzip2
-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libtool-ltdl-devel
do
myum $p
done
##install epel.
if
rpm -qa epel-release >
/dev/null
then
rpm -e epel-release
check_ok
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 install mysqld
install_mysqld() {
echo
"Install mysql version 5.1.72"
cd
/usr/local/src
[ -f mysql-5.1.72.
tar
.gz ] || wget http:
//mirrors
.sohu.com
/mysql/MySQL-5
.1
/mysql-5
.1.72.
tar
.gz
check_ok
[ -d mysql-5.1.72] ||
tar
-zvxf mysql-5.1.72.
tar
.gz
[ -d
/usr/local/mysql
] &&
/bin/mv/usr/local/mysql
/usr/local/mysql_
`
date
+%s`
cd
mysql-5.1.72
sed
-i ’s/$RM
"$cfgfile"
/
#$RM "$cfgfile"/’ configure
.
/configure
--prefix=
/usr/local/mysql
--with-unix-socket-path=
/tmp/mysql
.sock--with-client-ldflags=-static
'CFLAGS=-g -O3'
'CXXFLAGS=-g -O3'
--with-extra-charsets=gbk,utf8,ascii,big5,latin1,binary--
enable
-assembler --
enable
-
local
-infile --
enable
-profiling --
enable
-thread-safe-client
check_ok
make
&&
make
install
check_ok
if
!
grep
'^mysql:'
/etc/passwd
then
useradd
-M mysql -s
/sbin/nologin
check_ok
fi
if
!
grep
'^php-fpm'
/etc/passwd
then
useradd
-M php-fpm -s
/sbin/nologin
check_ok
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
/usr/local/mysql/bin/mysql_install_db--user
=mysql --datadir=
/data/mysql
check_ok
cd
/usr/local/src/mysql-5
.1.72
[ -f
/etc/my
.cnf ] ||
/bin/cp
support-files
/my-medium
.cnf.
/etc/my
.cnf
[ -f
/etc/init
.d
/mysqld
] ||
/bin/cp
support-files
/mysql
.server
/etc/inid
.d
/mysqld
#sed -i 's/^port =@MYSQL_TCP_PORT@ /port= 3306/' /etc/my.cnf
#sed -i 's#^socket=@MYSQL_UNIX_ADDR@#socket=/tmp/mysql.sock#' /etc/my.cnf
#sed -i 's/^user=@MYSQLD_USER@/user=mysql/’ /etc/init.d/mysqld
#sed -i 's# basedir=@prefix@# basedir=/usr/local/mysql#’ /etc/init.d/mysqld
#sed -i 's# bindir=@bindir@# bindir=/usr/local/mysql/bin#’ /etc/init.d/mysqld
#sed -i 's# datadir=@localstatedir@#datadir=/usr/local/mysql/var#’ /etc/init.d/mysqld
#sed -i 's#sbindir=@sbindir@#sbindir=/usr/local/mysql/sbin#’ /etc/init.d/mysqld
#sed -i 's#libexecdir=@libexecdir@#libexecdir=/usr/local/mysql/libexec#’ /etc/init.d/mysqld
sed
-i
's#^basedir=#basedir=/usr/local/mysql#'
/etc/init
.d
/mysqld
sed
-i
's#^datadir=#datadir=/data/mysql#'
/etc/init
.d
/mysqld
#sed-i 's#@HOSTNAME@# /bin/hostname# ' /etc/init.d/mysqld
chmod755
/etc/init
.d
/mysqld
chkconfig --add mysqld
chkconfig mysqld on
if
ps
aux |
grep
mysql
then
pkill mysql
service mysqld start
fi
check_ok
}
install_mysqld
##function of install php_libmcrypt.
install_php_libmcrypt(){
cd
/usr/local/src
[ -f libmcrypt-2.5.7.
tar
.gz ] || wgethttp:
//down1
.chinaunix.net
/distfiles/libmcrypt-2
.5.7.
tar
.gz
[-d libmcrypt-2.5.7 ] ||
tar
-zxf libmcrypt-2.5.7.
tar
.gz
check_ok
cd
libmcrypt-2.5.7
.
/configure
--prefix=
/usr/local/libmcrypt
check_ok
make
&&
make
install
check_ok
}
install_php_libmcrypt
##function of install php.
install_php(){
cd
/usr/local/src
[ -f php-5.5.32.
tar
.gz ] || wget http:
//cn2
.php.net
/distributions/php-5
.5.32.
tar
.gz
yum
install
-y php-mcrypt libmcrypt libmcrypt-devel
[-d php-5.5.32 ] ||
tar
-zxf php-5.5.32.
tar
.gz
[ -d
/usr/local/php
] &&
/bin/mv
/usr/local/php
/usr/local/php_
`
date
+%s`
cd
php-5.5.32
.
/configure
--prefix=
/usr/local/php
--
enable
-fpm--with-fpm-user=php-fpm --with-fpm-group=php-fpm--with-config-
file
-path=
/usr/local/php/etc
--with-mysql=
/usr/local/mysql
--with-mysqli=
/usr/local/mysql/bin/mysql_config--with-mysql-sock
=
/tmp/mysql
.sock --with-libxml-
dir
=
/usr/local
--
enable
-xml --with-gd --with-jpeg-
dir
--with-png-
dir
--with-freetype-
dir
=
/usr/include/freetype2/freetype
--with-iconv-
dir
=
/usr/local
--with-zlib-
dir
--with-bz2 --with-openssl --with-mcrypt --
enable
-soap --
enable
-gd-native-ttf --
enable
-mbstring --
enable
-sockets--
enable
-exif --
enable
-bcmath --
enable
-shmop --
enable
-sysvsem --disable-ipv6
check_ok
make
&&
make
install
check_ok
}
install_php
[ -f
/usr/local/php/etc/php
.ini ] ||
/bin/cpphp
.ini-production
/usr/local/php-fpm/etc/php
.ini
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-fpm/etc/php
.ini
sed
-i
's#listen = /tmp/php-fcgi.sock#listen = /tmp/php-fpm.sock#'
/usr/local/php/etc/php-fpm
.conf
check_ok
fi
[ -f
/usr/local/php/etc/php-fpm
.conf ]|| curl http:
//www
.apelearn.com
/study_v2/
.phpfpm_conf -o
/usr/local/php/etc/php-fpm
.conf
[ -f
/etc/init
.d
/phpfpm
] ||
/bin/cp
sapi
/fpm/init
.d.php-fpm
/etc/init
.d
/phpfpm
chmod755
/etc/init
.d
/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
##function of check service is running or not, examplenginx, 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
"$1service is already started."
else
if
[ -f
/etc/init
.d/$1 ]
then
/etc/init
.d/$1 start
check_ok
else
install_$1
fi
fi
}
check_service
##function of install nginx.
install_nginx() {
echo
"Install nginx version 2.2."
cd
/usr/local/src
[ -f nginx-1.8.0.
tar
.gz ] || wget http:
//nginx
.org
/download/nginx-1
.8.0.
tar
.gz
[ -d nginx-1.8.0 ] ||
tar
-zxf nginx-1.8.0.
tar
.gz
[ -d
/usr/local/nginx
] &&
/bin/mv
/usr/local/nginx/
usr
/local/nginx_
`
date
+%s`
cd
nginx-1.8.0
myum pcre-devel
.
/configure
--prefix=
/usr/local/nginx
check_ok
make
&& makeinstall
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
}
install_nginx
##function of install lnmp
lnmp() {
check_service mysqld
check_service nginx
check_service phpfpm
echo
"The lnmp done, Please use 'http://yourip/index.php' to access."
}
lnmp
|
本文转自wsw26 51CTO博客,原文链接:lnmp一键编译安装的脚本,如需转载请自行联系原作者