1. 程式人生 > 其它 >指令碼部署lnmp環境

指令碼部署lnmp環境

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

#!/bin/sh
#date:2014.8
#author:[email protected]
#system:redhatenterprise6.0
#softwaremessage:
#mysql-5.5.12.tar.gz
#nginx-1.2.1.tar.gz
#php-5.3.6.tar.bz2
#function:compileandinstallmysql,php,nginxonlinux
#/tmp/lnmp.logtracetherunningofscript
#afterrunscript,cancheckerrorvia/tmp/lnmp.log
#ifallsuccess,canusedirectly,defaultdirectoryis/usr/local/lnmp/
##[
[email protected]
lnmp]#ls #akeytolnmpmcrypt-2.6.8.tar.gznginx-1.2.1.tar.gz #libiconv-1.13.1.tar.gzmhash-0.9.9.9.tar.bz2php-5.3.6.tar.bz2 #libmcrypt-2.5.8.tar.bz2mysql-5.5.12.tar.gz #function:removealloldhttpd,mysql,phppackets RemoveOldSoftware() { #--------<checkhttpdpacket,stopservice,removepacket>--------- rpm-qhttpd>/dev/null if[$?=="0"] then pgrephttpd>/dev/null if[$?=="1"] then rpm-ehttpd>/dev/null echo"removehttpdpackets...">>/tmp/lnmp.log else /etc/init.d/httpdstop>/dev/null rpm-ehttpd>/dev/null echo"stophttpdservice...">>/tmp/lnmp.log echo"removehttpdpackets...">>/tmp/lnmp.log fi fi #--------<checkmysqldpacket,stopservice,removepacket>--------- rpm-qmysql>/dev/null if[$?=="0"] then pgrepmysqld>/dev/null if[$?=="1"] then rpm-emysql--nodeps>/dev/null echo"removemysqlpackets...">>/tmp/lnmp.log else /etc/init.d/mysqldstop>/dev/null rpm-emysql-server--nodeps>/dev/null echo"stopmysqldservice...">>/tmp/lnmp.log echo"removemysqlpackets...">>/tmp/lnmp.log fi fi #--------<checkphppacket,removepacket>--------- rpm-qphp>/dev/null if[$?=="0"] then rpm-ephp--nodeps>/dev/null echo"removephppackets...">>/tmp/lnmp.log fi } #function:installalltoolsduringcompileandinstall,andinstalllibs InstallToolsAndLib() { yuminstallcmakegccgcc-c++makencurses-develbisonopenssl-develzlib-devel-y>/dev/null echo"alltoolsandlibsneededduringcompileandinstall">>/tmp/lnmp.log } #function:compileandinstallmysql,andstartmysqldservice #notice:mysql-5.5.12.tar.gzon/lnmp MysqlPart() { #-----------<compileandinstallmysql>------------------- cd/lnmp/ tarzxfmysql-5.5.12.tar.gz cdmysql-5.5.12/ cmake-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1-DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all make&&makeinstall echo"compileandinstallmysqlfinished...">>/tmp/lnmp.log #-----------<configmysqlandstartmysqld>------------------ cd/usr/local/lnmp/mysql/ #addusermysqlwithnologinshell useradd-M-s/sbin/nologinmysql #copymysqlmodulefile cpsupport-files/my-medium.cnf/etc/my.cnf chownmysql.mysql.-R #initmysql scripts/mysql_install_db--user=mysql--basedir=/usr/local/lnmp/mysql/--datadir=/usr/local/lnmp/mysql/data/>/dev/null #changedirpemission chown-Rroot. chown-Rmysqldata #copymysqlscriptto/etc/init.d/ cpsupport-files/mysql.server/etc/init.d/mysqld #startmysqldservice /etc/init.d/mysqldstart>/dev/null if[$?=="0"] then echo"mysqldstarted" fi #不然php編譯的時候找不到mysql的庫檔案 ln-s/usr/local/lnmp/mysql/lib/usr/local/lnmp/mysql/lib64 echo"mysqlfinished...">>/tmp/lnmp.log #change~/.bash_profilefile cat>.bash_profile<<end #.bash_profile if[-f~/.bashrc];then .~/.bashrc fi PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin exportPATH end } #function:compileandinstallnginx NginxPart() { #installlibsneededtocompilenginx yuminstallopenssl-develpcre-devel-y>/dev/null cd/lnmp/ #compileandinstall tarzxfnginx-1.2.1.tar.gz cdnginx-1.2.1/ useradd-M-s/sbin/nologinnginx ./configure--user=nginx--group=nginx--prefix=/usr/local/lnmp/nginx--with-http_ssl_module--with-http_stub_status_module>/dev/null make>/dev/null&&makeinstall>/dev/null echo"nginxcompileandinstallseccess!">>/tmp/lnmp.log #startnginx cd/usr/local/lnmp/nginx/conf/ cpnginx.confnginx.conf.bak sed'2ausernginxnginx;'nginx.conf>/dev/null cd/usr/local/lnmp/nginx/sbin/ ./nginx echo"startnginxservice....">>/tmp/lnmp.log #testnginx echo"waittotest...">>/tmp/lnmp.log curlhttp://127.0.0.1 if[$?=="0"] then echo"nginxtestok!">>/tmp/lnmp.log else echo"nginxtestnotok!pleasecheck...">>/tmp/lnmp.log fi } PhpPart() { #installlibs cd/lnmp/ yuminstallnet-snmp-develcurl-devellibxml2-devellibpng-devellibjpeg-develfreetype-develgmp-developenldap-devel-y>/dev/null #compileandinstallmodules tarzxflibiconv-1.13.1.tar.gz cdlibiconv-1.13.1 ./configure--libdir=/usr/local/lib64/>/dev/null make>/dev/null&&makeinstall>/dev/null cd.. tarjxflibmcrypt-2.5.8.tar.bz2 cdlibmcrypt-2.5.8 ./configure--libdir=/usr/local/lib64/>/dev/null make>/dev/null&&makeinstall>/dev/null cdlibltdl/ ./configure--libdir=/usr/local/lib64--enable-ltdl-install>/dev/null make>/dev/null&&makeinstall>/dev/null cd../../ tarjxfmhash-0.9.9.9.tar.bz2 cdmhash-0.9.9.9 ./configure--libdir=/usr/local/lib64/>/dev/null make>/dev/null&&makeinstall>/dev/null cd.. ldconfig/usr/local/lib64/ tarzxfmcrypt-2.6.8.tar.gz cdmcrypt-2.6.8 ./configure--libdir=/usr/local/lib64/>/dev/null #注意:./configure時可能會報這個錯:/bin/rm:cannotremove`libtoolT’:Nosuchfileordirectory直接忽略 make>/dev/null&&makeinstall>/dev/null echo"allmoduleshavebeeninstalled">>/tmp/lnmp.log echo"installingphp">>/tmp/lnmp.log cd.. tarjxfphp-5.3.6.tar.bz2 cdphp-5.3.6 ./configure--prefix=/usr/local/lnmp/php\ --with-config-file-path=/usr/local/lnmp/php/etc\ --with-mysql=/usr/local/lnmp/mysql/\ --with-openssl--with-snmp--with-gd\ --with-zlib--with-curl--with-libxml-dir\ --with-png-dir--with-jpeg-dir\ --with-freetype-dir--without-pear\ --with-gettext--with-gmp--enable-inline-optimization\ --enable-soap--enable-ftp--enable-sockets\ --enable-mbstring--with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config\ --enable-fpm--with-fpm-user=nginx--with-fpm-group=nginx\ --with-libdir=lib64--with-ldap--with-ldap-sasl\ --with-mcrypt--with-mhash>/dev/null makeZEND_EXTRA_LIBS='-liconv'>/dev/null makeinstall>/dev/null echo"phpinstallfinished...">>/tmp/lnmp.log echo"configphpandstartphpservice">>/tmp/lnmp.log cd/usr/local/lnmp/php/bin/ wgethttp://pear.php.net/go-pear.phar>/dev/null echo"inputyouchioce:" yes""|./phpgo-pear.phar cd/lnmp/php-5.3.6/ cpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm chmod+x/etc/init.d/php-fpm cpphp.ini-production/usr/local/lnmp/php/etc/php.ini cd/usr/local/lnmp/php/etc/ mvphp-fpm.conf.defaultphp-fpm.conf cat>>php-fpm.conf<<end pm.max_children=5 pm.start_servers=2 pm.min_spare_servers=1 pm.max_spare_servers=3 pm.max_requests=5 end echo"startingphp....">>/tmp/lnmp.log echo"testphpservice..." /etc/init.d/php-fpmstart>/dev/null lsof-i:9000 if[$?=="0"] then echo"phpserviceok!" else echo"phpservicenotok,pleasecheck...." fi } #RemoveOldSoftwaretestsuccessful #InstallToolsAndLibtestsuccessful #MysqlParttestsuccessful #NginxParttestsuccessful #PhpParttestsuccessful echo"compileandinstallmysql,nginx,andphponRHEL6.0finished">>/tmp/lnmp.log echo"pleasechecklogfile/tmp/lnmp.log">>/tmp/lnmp.log echo"useitafterconfigservices'sconfigfile"

轉載於:https://my.oschina.net/leeypp1/blog/298447