拓展版的LNMP安装包(适合批量部署)

最近的一个任务是写个一键安装LNMP的脚本,运行的平台是Ubuntu12.04,命令那些跟之前的RHEL和Centos 有一点点区别,这里做个记录。

#!/bin/bash############################################## Fuction: Install LNMP automaticlly. ## Date: 2014-03-17## Contact Infomation## Q: 303228632## T: ***********## Designed by Pmghong############################################### Configuration Argumentsworkpath=”/usr/local/src”install_path=”/usr/local”mysql=”mysql-5.5.29″php=”php-5.4.11″nginx=”nginx-1.2.6″# Install basic softwareecho -e “\e[1;31m Installing basic software… \e[0m”apt-get install -y gcc g++ make cmakeecho -e “\e[1;32m Complete \e[0m”# Install mysqlecho -e “\e[1;31m Installing mysql… \e[0m”apt-get install -y libncurses5-dev build-essential bisongroupadd mysqluseradd -r -g mysql mysqlcd ${workpath}tar xf ${mysql}.tar.gzcd ${mysql}cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DMYSQL_USER=mysql -DWITH_DEBUG=0make && make installecho -e “\e[1;32m Complete!!! \e[0m”# Configure mysqlecho -e “\e[1;31m Confuring mysql… \e[0m”cd ${install_path}/mysqlscripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/datachown -R mysql.mysql .cp support-files/my-medium.cnf /etc/my.cnfsed -i “27i datadir = ${install_path}\/mysql\/data” /etc/my.cnfsed -i “27i basedir = ${install_path}\/mysql” /etc/my.cnfsed -i “27i user = mysql” /etc/my.cnfsed -i “30i character_set_server = utf8” /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqldsed -i “46s#basedir=#basedir=${install_path}\/mysql#” /etc/init.d/mysqldsed -i “47s#datadir=#datadir=${install_path}\/mysql\/data#” /etc/init.d/mysqldln -s /usr/local/mysql/bin/* /usr/bin//etc/init.d/mysqld startecho -e “\e[1;32m Complete!!! \e[0m”# Install phpecho -e “\e[1;31m Installing php… \e[0m”apt-get install -y libltdl-dev libssl-dev sendmail libjpeg8 libjpeg8-dev libpng12-0 libpng12-dev libxml2-dev libcurl4-openssl-dev libmcrypt-devcd ${workpath}tar xf ${php}.tar.bz2cd ${php}./configure –prefix=/usr/local/php –enable-fpm –with-fpm-user=www-data –with-fpm-group=www-data –with-curl –with-mcrypt –enable-mbstring –enable-pdo –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –with-mysql=mysqlnd –with-openssl –with-imap-ssl –with-gd –with-jpeg-dir=/usr/lib/ –with-png-dir=/usr/lib/ –enable-exif –enable-zipmake && make installcp php.ini-production /usr/local/php/lib/php.inicd ${install_path}/php/etccp -a php-fpm.conf.default php-fpm.confuseradd -s /sbin/nologin -M fpmuser${install_path}/php/sbin/php-fpmecho -e “\e[1;32m Complete!!! \e[0m”# Install nginxecho -e “\e[1;31m Installing nginx… \e[0m”apt-get install -y libpcre3 libpcre3-dev zlib1g-dev libncurses5-devuseradd -s /sbin/nologin -M wwwcd ${workpath}tar xf ${nginx}.tar.gzcd ${nginx}./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_modulemake && make installln -s /usr/local/nginx/sbin/nginx /etc/init.d//etc/init.d/nginxecho -e “\e[1;32m Complete!!! \e[0m”# Configure nginxecho -e “\e[1;31m Configuringing nginx… \e[0m”sed -i “s/#user nobody;/user www www;/” ${install_path}/nginx/conf/nginx.confIP=`ifconfig eth0|grep “\&;inet\&;”|cut -d’:’ -f2|sed -n ‘s/ Bcast//p’`sed -i “37s/server_name localhost;/server_name ${IP};/” ${install_path}/nginx/conf/nginx.confsed -i ’45s/index /& index.php/’ ${install_path}/nginx/conf/nginx.confsed -i ‘65,71s/#//’ ${install_path}/nginx/conf/nginx.confsed -i ‘s#\/scripts$fastcgi_script_name;#$document_root$fastcgi_script_name;#’ ${install_path}/nginx/conf/nginx.conf# Create a test pagecat << EOF >> ${install_path}/nginx/html/index.php<?phpphpinfo();?>EOF/etc/init.d/nginx -s reloadecho -e “\e[1;32m Totally Complete!!! Now you can test the LNMP system. \e[0m”

打包:

需要打包有4个目录:

tar cPf mysql.tar.gz /usr/local/mysql

tar cPf nginx.tar.gz /usr/local/nginx

tar cPf php.tar.gz /usr/local/php

tar cPf php_lib.gz /usr/local/src/lib

另外,把安装包发布到新的机器上后,,还需要通过脚本对系统进行一些初始化:

脚本一:

这个脚本的主要功能是解压nginx、php、mysql等,并对系统进行初始化

#!/bin/bashcat << EOF###############################################################Welcome to AutoLNMP!## Fuction: This script will install LNMP automaticlly. ## Date: 2014-03-19## Contact Infomation## T: ***********##Designed by Pmghong###############################################################Script is running please wait for a minune…EOF# Unzip packagestar xPf nginx.tar.gz -C /usr/local/ 2> /dev/nulltar xPf mysql.tar.gz -C /usr/local/ 2> /dev/nulltar xPf php.tar.gz -C /usr/local/ 2> /dev/nullmkdir -p /usr/local/src/libtar xPf php_lib.tar.gz -C /usr/local/src/ 2> /dev/nullapt-get install expect -y > /dev/null 2>&1# Add service usersgroupadd mysqluseradd -r -g mysql mysqluseradd -s /sbin/nologin -M fpmuseruseradd -s /sbin/nologin -M www# Configure Mysqlcd /usr/local/mysqlchown mysql.mysql . -Rscripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data > /dev/nullcp mysqld /etc/init.d/ln -s /usr/local/mysql/bin/* /usr/bin/# Start services/usr/local/nginx/sbin/nginx/etc/init.d/mysqld start > /dev/null/usr/local/php/sbin/php-fpmechoecho “Work complete!”echo “Now you can test the page ‘http://IP’.”echo “If you want to install wordpress.Follow this step: 1.Run expect.sh. 2.Run LNMP_tester.sh”

脚本二:

往往为了自己的不能失败,而处心积虑前怕狼后怕虎,

拓展版的LNMP安装包(适合批量部署)

相关文章:

你感兴趣的文章:

标签云: