首页 > 代码库 > 一键安装lnmp脚本

一键安装lnmp脚本

前段时间一直在找一个快速部署lnmp环境的方法,也没找着,就自己写了一个,结合网上的大神们的。我的方法是脚本结合源码包,很多依赖裤都是yum安装的,这都在脚本里面,需要的源码包我都下载好了,打包成压缩包,源码包+lnmp.sh文件,上传到百度云了,需要的可以download下来:

压缩包地址:

链接:http://pan.baidu.com/s/1jHCP6iM 密码:5q4c

在这里需要说明的是,脚本下载之后,打开的时候用notepad++打开,然后全选复制之后,自己在linux下,vi lnmp.sh一个新文件,把内容粘贴进去,这样就不会报windows到Linux的错误

先上传一下脚本:

  1 #!/bin/bash
  2 # by huowuzhao 2017.1.9
  3 yum -y install gcc gcc-c++ 
  4 if [ ! -d /home/tools ]
  5   then
  6     mkdir /home/tools -p
  7 fi
  8 cd /home/tools
  9 PING=`ping -c 1 www.baidu.com |grep ttl=|wc -l`
 10 if [ "$PING" -eq 0 ]
 11   then
 12     echo "Network does not work"
 13     exit 1
 14 fi
 15 if [ -e /home/tools/pcre-8.39.tar.gz ]
 16   then
 17     tar xf pcre-8.39.tar.gz
 18 else
 19     echo "no file /home/tools/pcre-8.39.tar.gz"
 20 fi
 21 cd pcre-8.39 && 22 ./configure
 23 if [ $? -ne 0 ]
 24   then
 25     echo "pcre configure is false"
 26     exit 1
 27 fi
 28 make && make install
 29 if [ $? -ne 0 ]
 30   then
 31     echo "pcre make install is false" 
 32     exit 1
 33 fi
 34 cd ..
 35 RPM=`rpm -qa|grep "openssl-"|wc -l`
 36 if [ $RPM -ne 2 ]
 37   then
 38     yum -y install openssl openssl-devel
 39   else
 40     echo "yum install openssl openssl-devel is error"
 41     exit 1
 42 fi
 43 cd /home/tools
 44 if [ ! -e nginx-1.8.0.tar.gz ]
 45   then
 46     echo " nginx-1.8.0.tar.gz is false"
 47     exit 1
 48 fi
 49 tar xf nginx-1.8.0.tar.gz
 50 cd nginx-1.8.0
 51 NGINXUSER=`cat /etc/passwd |grep nginx|wc -l`
 52 if [ "$NGINXUSER" -eq 0 ]
 53   then
 54     useradd nginx -s /sbin/nologin -M
 55 fi
 56 ./configure --user=nginx --group=nginx --prefix=/home/nginx-1.8.0 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
 57 if [ $? -eq 0 ]
 58   then
 59     make
 60   else
 61     echo "nginx configure is error"
 62     exit 1
 63 fi
 64 if [ $? -eq 0 ]
 65   then
 66     make install
 67   else
 68     echo "nginx make is error"
 69     exit 1
 70 fi
 71 if [ $? -ne 0 ]
 72   then
 73     echo "nginx make install is error"
 74     exit 1
 75 fi
 76 cd ..
 77 if [ -d /home/nginx-1.8.0/ ]
 78   then
 79     ln -s /home/nginx-1.8.0 /home/nginx
 80   else 
 81     echo "no directory /home/nginx-1.8.0/"
 82     exit 1
 83 fi
 84 if [ -f /etc/ld.so.conf ]
 85   then
 86     echo "/usr/local/lib/" >>/etc/ld.so.conf
 87   else 
 88     echo "no file /etc/ld.so.conf"
 89     exit 1
 90 fi
 91 if [ -d /lib64 ]
 92   then
 93     ln -s /usr/local/lib/libpcre.so.1 /lib64
 94   else 
 95     echo "no directory /lib64"
 96     exit 1
 97 fi
 98 /home/nginx/sbin/nginx -t
 99 if [ $? -eq 0 ]
100   then
101     echo "nginx is ok"
102   else
103     echo "nginx is false"
104     exit 1
105 fi
106 /home/nginx/sbin/nginx
107 chown -R nginx.nginx /home/nginx/*
108 clear
109 echo "==================nginx install is all finish=================="
110 sleep 2
111 cd /home/tools
112 echo "=====================starting cmake install======================="
113 tar xf cmake-3.7.1.tar.gz
114 cd cmake-3.7.1
115 ./configure
116 if [ $? -ne 0 ]
117   then
118     echo "cmake configure is error"
119     exit 1
120 fi
121 gmake
122 if [ $? -ne 0 ]
123   then
124     echo " cmake gmake is error" 
125     exit 1
126 fi
127 gmake install
128 if [ $? -ne 0 ]
129   then
130      echo " cmake gmake install is error" 
131      exit 1
132 fi
133 cd ../
134 PING=`ping -c 1 www.baidu.com |grep ttl=|wc -l`
135 if [ "$PING" -ne 1 ]
136   then
137     echo "Network does not work"
138     exit 1
139 fi
140 echo "=====================starting ncurses-devel install======================="
141 RPM=`rpm -qa |grep ncurses-devel |wc -l`
142 if [ $RPM -ne 1 ]
143   then
144     yum install ncurses-devel -y
145 fi
146 echo "=====================next is install mysql...======================="
147 cd /home/tools/
148 if [ -e /home/tools/mysql-5.6.34.tar.gz ]
149   then
150     tar zxf mysql-5.6.34.tar.gz 
151   else
152     echo "no file /home/tools/mysql-5.6.34.tar.gz"
153 fi
154 NGINXUSER=`cat /etc/passwd |grep mysql|wc -l`
155 if [ "$NGINXUSER" -eq 0 ]
156   then
157     useradd mysql -s /sbin/nologin -M
158 fi    
159 cd mysql-5.6.34
160 cmake . -DCMAKE_INSTALL_PREFIX=/home/mysql-5.6.34 161 -DMYSQL_DATADIR=/home/mysql-5.6.34/data 162 -DMYSQL_UNIX_ADDR=/home/mysql-5.6.34/tmp/mysql.sock 163 -DDEFAULT_CHARSET=utf8 164 -DDEFAULT_COLLATION=utf8_general_ci 165 -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 166 -DENABLED_LOCAL_INFILE=ON 167 -DWITH_INNOBASE_STORAGE_ENGINE=1 168 -DWITH_FEDERATED_STORAGE_ENGINE=1 169 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 170 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 171 -DWITH_FAST_MUTEXES=1 172 -DWITH_ZLIB=bundled 173 -DENABLED_LOCAL_INFILE=1 174 -DWITH_READLINE=1 175 -DWITH_EMBEDDED_SERVER=1 176 -DWITH_DEBUG=0
177 if [ $? -ne 0 ]
178   then
179     echo "mysql cmake is error"
180     exit 1
181 fi
182 make
183 if [ $? -ne 0 ]
184   then
185      echo "mysql make is error"
186      exit 1
187 fi
188 make install
189 if [ $? -ne 0 ]
190   then
191      echo "mysql make install is error"
192      exit 1
193 fi
194 echo "=====================configuration mysql======================="
195 if [ -d /home/mysql-5.6.34 ]
196   then
197      ln -s /home/mysql-5.6.34/ /home/mysql
198   else
199      echo "no directory /home/mysql-5.6.34/"
200      exit 1
201 fi
202 cd /home/mysql
203 cp /home/tools/my.cnf /etc/my.cnf
204 chown -R mysql.mysql /home/mysql/
205 chown -R mysql.mysql /tmp
206 echo "=====================mysql is INIT======================="
207 /home/mysql/scripts/mysql_install_db --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql
208 INIT=`/home/mysql/scripts/mysql_install_db --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql|grep OK|wc -l`
209 if [ "$INIT" -eq 2 ]
210   then
211     echo "=====================mysql INIT is ok====================="
212 fi
213 if [ -f /home/mysql/support-files/mysql.server ]
214   then
215     cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld
216   else
217     echo "no file /home/mysql/support-files/mysql.server"
218 fi
219 chmod +x /etc/init.d/mysqld
220 /etc/init.d/mysqld start
221 echo ‘PATH=/home/mysql/bin/:$PATH‘ >>/etc/profile
222 . /etc/profile
223 chkconfig mysqld on
224 mysqladmin -u root password ‘123456‘
225 MYSQLLOGIN=`mysql -uroot -p123456 -e "select version();"|wc -l`
226 if [ $MYSQLLOGIN -ne 0 ]
227   then 
228     echo "mysql is installed and mysql login is ok..."
229   else 
230     echo "mysql don‘t login..."
231 fi
232 clear
233 echo "Pls input user@localhost and password login!!!!!"
234 sleep 1
235 clear
236 echo "==============other installation package=============="
237 cd /home/tools/
238 yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libtool-ltdl-devel -y
239 yum install libxslt libxslt-devel -y
240 YUM=`rpm -qa zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel|wc -l`
241 if [ $YUM -lt 3 ]
242   then
243     echo "yum bag is error,bag is lack..."
244     exit 1
245 fi
246 if [ ! -e libiconv-1.9.2.tar.gz ]
247   then
248     echo "no gz libiconv-1.9.2.tar.gz"
249      exit 1
250 fi
251 tar zxf libiconv-1.9.2.tar.gz
252 cd libiconv-1.9.2
253 ./configure --prefix=/usr/local/libiconv
254 if [ $? -ne 0 ]
255   then
256     echo "libiconv-1.9.2 configure is error"
257      exit 1
258 fi
259 make&&make install
260 if [ $? -ne 0 ]
261   then
262      echo "libiconv-1.9.2 make&&make install is error"
263      exit 1
264 fi
265 cd ../
266 if [ ! -e libmcrypt-2.5.8.tar.gz ]
267   then
268      echo "no gz libmcrypt-2.5.8.tar.gz"
269      exit 1
270 fi
271 tar zxf libmcrypt-2.5.8.tar.gz 
272 cd libmcrypt-2.5.8
273 ./configure
274 if [ $? -ne 0 ]
275   then
276      echo "libmcrypt-2.5.8 configure is error"
277      exit 1
278 fi
279 make&&make install
280 if [ $? -ne 0 ]
281   then
282      echo "libmcrypt-2.5.8 make&&make install is error"
283      exit 1
284 fi
285 sleep 2
286 /sbin/ldconfig
287 cd libltdl/
288 ./configure --enable-ltdl-install
289 if [ $? -ne 0 ]
290   then
291      echo "libmcrypt-2.5.8/libltdl configure is error"
292      exit 1
293 fi
294 make&&make install
295 if [ $? -ne 0 ]
296   then
297      echo "libmcrypt-2.5.8/libltdl make&&make install is error"
298      exit 1
299 fi
300 cd ../../ 
301 if [ ! -e mhash-0.9.9.9.tar.gz ]
302   then
303      echo "no gz mhash-0.9.9.9.tar.gz"
304      exit 1
305 fi
306 tar zxf mhash-0.9.9.9.tar.gz
307 cd mhash-0.9.9.9/
308 ./configure
309 if [ $? -ne 0 ]
310   then
311      echo "mhash-0.9.9.9 configure is error"
312      exit 1
313 fi
314 make&&make install
315 if [ $? -ne 0 ]
316   then
317      echo "mhash-0.9.9.9 make&&make install is error"
318      exit 1
319 fi
320 sleep 2
321 cd ../ 
322 rm -f /usr/lib64/libmcrypt.*
323 rm -f /usr/lib64/libmhash*
324 ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la
325 ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so
326 ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
327 ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
328 ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a
329 ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la
330 ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so
331 ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2
332 ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
333 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config 
334 if [ ! -e mcrypt-2.6.8.tar.gz ]
335   then
336      echo "no gz mcrypt-2.6.8.tar.gz"
337      exit 1
338 fi
339 tar zxf mcrypt-2.6.8.tar.gz
340 cd mcrypt-2.6.8/
341 /sbin/ldconfig
342 ./configure LD_LIBRARY_PATH=/usr/local/lib
343 if [ $? -ne 0 ]
344   then
345      echo "mcrypt-2.6.8 configure is error"
346      exit 1
347 fi
348 make&&make install
349 if [ $? -ne 0 ]
350   then
351      echo "mcrypt-2.6.8 make&&make install is error"
352      exit 1
353 fi
354 cd ../
355 clear
356 echo "==============other installation package is ok=============="
357 sleep 2
358 echo "==================starting install php===================="
359 if [ ! -e php-5.6.11.tar.gz ]
360   then
361      echo "no gz php-5.6.11.tar.gz"
362     exit 1
363 fi
364 tar xf php-5.6.11.tar.gz
365 cd php-5.6.11
366 echo "/home/mysql-5.6.25/lib/" >>/etc/ld.so.conf
367 ldconfig
368 ./configure 369 --prefix=/home/php-5.6.11 370 --with-mysql=/home/mysql 371 --with-iconv-dir=/usr/local/libiconv 372 --with-freetype-dir 373 --with-jpeg-dir 374 --with-png-dir 375 --with-zlib 376 --with-libxml-dir=/usr 377 --enable-xml 378 --disable-rpath 379 --enable-bcmath 380 --enable-shmop 381 --enable-sysvsem 382 --enable-inline-optimization 383 --with-curl 384 --enable-mbregex 385 --enable-fpm 386 --enable-mbstring 387 --with-mcrypt 388 --with-gd 389 --enable-gd-native-ttf 390 --with-openssl 391 --with-mhash 392 --enable-pcntl 393 --enable-sockets 394 --with-xmlrpc 395 --enable-zip 396 --enable-soap 397 --enable-short-tags 398 --enable-static 399 --with-xsl 400 --with-fpm-user=nginx 401 --with-fpm-group=nginx 402 --enable-ftp
403 if [ $? -ne 0 ]
404   then
405      echo "php-5.6.11.tar.gz configure is error"
406     exit 1
407 fi
408 make
409 if [ $? -eq 0 ]
410   then
411     make install
412   else
413     echo "make is error"
414     exit 1
415 fi
416 ln -s /home/php-5.6.11/ /home/php
417 cp php.ini-production /home/php/lib/php.ini
418 cd /home/php/etc/
419 cp /home/tools/php-fpm.conf ./
420 CONF=`ls php-fpm.conf|wc -l`
421 if [ $CONF -ne 1 ]
422   then
423         echo "no file /home/php/etc/php-fpm.conf"
424     exit 1
425 fi
426 clear
427 echo "=====================php install is ok========================"
428 sleep 1
429 /home/php/sbin/php-fpm
430 PHPSTART=`ss -luntp |grep php-fpm|wc -l`
431 if [ $PHPSTART -eq 0 ]
432   then
433     echo "php-fpm is stopped..."
434 fi
435 clear
436 echo "===========lnmp all install is ok============="
437 echo "==============!!!!happy!!!!================"
438 echo "         *   *     *       *           "
439 echo "         *   *   *   *   *   *         "
440 echo "         *****   *   *   *   *         "
441 echo "         *   *   *   *   *   *         "
442 echo "         *   *     *  *    *           "
443 echo "==============!!!!happy!!!!================"

 

一键安装lnmp脚本