生产环境lnmp脚本自动安装

声明:原配置环境为张宴所写

名称:install_lnmp.tar.gz

版本:CentOS 6.3+nginx-0.8.46+php-5.2.14+MySQL-5.5.3-m3

目录结构:

---install_lnmp.sh

---soft(目录)

   ---nginx

       ---cut_nginx_log.sh  

       ---fcgi.conf  

       ---nginx.conf

       ---nginx-0.8.46.tar.gz

       ---pcre-8.10.tar.gz

   ---mysql

       ---my.cnf  

       ---mysql  

       ---mysql-5.5.3-m3.tar.gz

   ---php

       ---php-fpm.conf

       ---eaccelerator-0.9.6.1.tar.bz2  

       ---imagick-2.3.0.tgz  

       ---libmcrypt-2.5.8.tar.gz  

       ---memcache-2.2.5.tgz  

       ---PDO_MYSQL-1.0.2.tgz  

       ---php-5.2.14.tar.gz

       ---ImageMagick.tar.gz  

       ---libiconv-1.13.1.tar.gz  

       ---mcrypt-2.6.8.tar.gz mhash-0.9.9.9.tar.gz  

       ---php-5.2.14-fpm-0.5.14.diff.gz  


脚本结构:

分为六个函数

install_yum();      //yum配置

init();             //系统初始化

install_mysql();    //mysql安装

install_php();      //php安装

install_nginx();    //nginx安装

install_check();    //安装配置检查


安装包下载:

wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz

wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget
http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget
http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget
http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget
http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz


install_lnmp脚本:

#!/bin/bash

#author Dony

#blog http://linuxart.blog.51cto.com

LANG=C

soft_dir="/data0/software"

nginx_dir="/usr/local/webserver/nginx"

php_dir="/usr/local/webserver/php"

mysql_dir="/usr/local/webserver/mysql"

mysql_datadir="/data0/mysql/3306/data"

mysql_configdir="/data0/mysql/3306"

web_dir="/www"

# 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 soft"

   exit 1

fi

#Disable SeLinux

if [ -s /etc/selinux/config ]; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

fi

if [ ! -d "$soft_dir" ];then

   mkdir -p $soft_dir

fi

if [ ! -d "$soft_dir/soft" ];then

   cp -a soft $soft_dir

fi

#set up runtime

function start_time()

{

start_time="$(date +%s)"

echo "$(date) Start install!"

echo "$start_time" > /tmp/Install_lnmp_runtime

}

function end_time()

{

end_time="$(date +%s)"

total_s=$(($end_time - $start_time))

total_m=$(($total_s / 60))

if [ $total_s -lt 60 ]; then

       time_en="${total_s} Seconds"

else

       time_en="${total_m} Minutes"

fi

echo "$(date) Finish install!"

#!/bin/bash

#author amwytai

#blog http://linuxart.blog.51cto.com

LANG=C

soft_dir="/data0/software"

nginx_dir="/usr/local/webserver/nginx"

php_dir="/usr/local/webserver/php"

mysql_dir="/usr/local/webserver/mysql"

mysql_datadir="/data0/mysql/3306/data"

mysql_configdir="/data0/mysql/3306"

web_dir="/www"

# 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 soft"

   exit 1

fi

#Disable SeLinux

if [ -s /etc/selinux/config ]; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

fi

if [ ! -d "$soft_dir" ];then

   mkdir -p $soft_dir

fi

if [ ! -d "$soft_dir/soft" ];then

   cp -a soft $soft_dir

fi

#set up runtime

function start_time()

{

start_time="$(date +%s)"

echo "$(date) Start install!"

echo "$start_time" > /tmp/Install_lnmp_runtime

}

function end_time()

{

end_time="$(date +%s)"

total_s=$(($end_time - $start_time))

total_m=$(($total_s / 60))

if [ $total_s -lt 60 ]; then

       time_en="${total_s} Seconds"

else

       time_en="${total_m} Minutes"

fi

echo "$(date) Finish install!"

#!/bin/bash

#author amwytai

#blog http://linuxart.blog.51cto.com

LANG=C

soft_dir="/data0/software"

nginx_dir="/usr/local/webserver/nginx"

php_dir="/usr/local/webserver/php"

mysql_dir="/usr/local/webserver/mysql"

mysql_datadir="/data0/mysql/3306/data"

mysql_configdir="/data0/mysql/3306"

web_dir="/www"

# 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 soft"

   exit 1

fi

#Disable SeLinux

if [ -s /etc/selinux/config ]; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

fi

if [ ! -d "$soft_dir" ];then

   mkdir -p $soft_dir

fi

if [ ! -d "$soft_dir/soft" ];then

   cp -a soft $soft_dir

fi

#set up runtime

function start_time()

{

start_time="$(date +%s)"

echo "$(date) Start install!"

echo "$start_time" > /tmp/Install_lnmp_runtime

}

function end_time()

{

end_time="$(date +%s)"

total_s=$(($end_time - $start_time))

total_m=$(($total_s / 60))

if [ $total_s -lt 60 ]; then

       time_en="${total_s} Seconds"

else

       time_en="${total_m} Minutes"

fi

echo "$(date) Finish install!"

echo "Install_lnmp.sh runtime: ${time_en} "> /tmp/Install_lnmp_runtime

echo "Total runtime: ${time_en}"

}

#if yum fail,please use install_yum to solve.

function install_yum()

{

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm

wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.i386.rpm

rpm --import RPM-GPG-KEY.dag.txt

yum -y install yum-fastestmirror yum-presto

}

#init set up Library

function init()

{

yum -y install yum-fastestmirror yum-presto

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers patch perl-CPAN vixie-cron

}

#install mysql

function install_mysql()

{

cd $soft_dir/soft/php/

tar xzf libiconv-1.13.1.tar.gz

cd libiconv-1.13.1

./configure --prefix=/usr/local

make && make install

cd ../

tar xzf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make && make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make && make install

cd ../../

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

cd ../

if [ -e "/lib64" ];then

   ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la

   ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so

   ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4

   ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8

   ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a

   ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la

   ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so

   ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2

   ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1

   ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

else

   ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

   ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

   ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

   ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

   ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

   ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

   ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

   ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

   ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

   ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

fi

tar xzf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

/sbin/ldconfig

./configure

make && make install

cd ../

cd $soft_dir/soft/mysql/

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

tar zxvf mysql-5.5.3-m3.tar.gz

cd mysql-5.5.3-m3/

./configure --prefix=$mysql_dir --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg

make && make install

chmod +w $mysql_dir

chown -R mysql:mysql $mysql_dir

mkdir -p $mysql_datadir

mkdir $mysql_configdir/relaylog

mkdir $mysql_configdir/binlog

chown mysql.mysql -R $mysql_configdir

chown mysql.mysql -R $mysql_datadir

$mysql_dir/bin/mysql_install_db --basedir=$mysql_dir --datadir=$mysql_datadir --user=mysql

rm -f $mysql_configdir/my.cnf

rm -f $mysql_configdir/mysql

cp $soft_dir/soft/mysql/my.cnf $mysql_configdir/my.cnf

cp $soft_dir/soft/mysql/mysql $mysql_configdir/mysql

chmod +x $mysql_configdir/mysql

/data0/mysql/3306/mysql start

sleep 30

/usr/local/webserver/mysql/bin/mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';"

/usr/local/webserver/mysql/bin/mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';"

$mysql_configdir/mysql restart

echo "mysql install success!"

}

#install php

function install_php()

{

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

cd $soft_dir/soft/php

rm -f /usr/lib/libjpeg*

rm -f /usr/lib/libpng*

rm -f /usr/lib/libldap*

cp -frp /usr/lib64/libjpeg* /usr/lib/

cp -frp /usr/lib64/libpng* /usr/lib/

cp -frp /usr/lib64/libldap* /usr/lib/

tar zxf php-5.2.14.tar.gz

gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1

cd php-5.2.14/

./configure --prefix=$php_dir --with-config-file-path=$php_dir/etc --with-mysql=$mysql_dir --with-mysqli=$mysql_dir/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

make ZEND_EXTRA_LIBS='-liconv'

make install

rm -f $php_dir/etc/php.ini

cp php.ini-dist $php_dir/etc/php.ini

cd ../

tar xzf memcache-2.2.5.tgz

cd memcache-2.2.5

$php_dir/bin/phpize

./configure --with-php-config=$php_dir/bin/php-config

make && make install

cd ../

tar xjf eaccelerator-0.9.6.1.tar.bz2

cd eaccelerator-0.9.6.1

$php_dir/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=$php_dir/bin/php-config

make && make install

cd ../

tar xzf PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2

$php_dir/bin/phpize

./configure --with-php-config=$php_dir/bin/php-config --with-pdo-mysql=$mysql_dir

make && make install

cd ../

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.5.1-2/

./configure

make

make install

cd ../

tar xzf imagick-2.3.0.tgz

cd imagick-2.3.0

$php_dir/bin/phpize

./configure --with-php-config=$php_dir/bin/php-config

make && make install

cd ../

#Modiry php.ini

sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' $php_dir/etc/php.ini

sed -i 's#output_buffering = Off#output_buffering = On#' $php_dir/etc/php.ini

sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" $php_dir/etc/php.ini

sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" $php_dir/etc/php.ini

echo '[eaccelerator]

zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"' >>/$php_dir/etc/php.ini

rm -f $php_dir/etc/php-fpm.conf

cp $soft_dir/soft/php/php-fpm.conf $php_dir/etc/php-fpm.conf

ulimit -SHn 65535

$php_dir/sbin/php-fpm start

echo "$php_dir/sbin/php-fpm" >> /etc/rc.local

echo "php install success!"

}

#install nginx

function install_nginx()

{

mkdir /www

chown www:www /www

cd $soft_dir/soft/nginx

tar zxvf pcre-8.10.tar.gz

cd pcre-8.10/

./configure

make && make install

cd ../

tar zxvf nginx-0.8.46.tar.gz

cd nginx-0.8.46/

./configure --user=www --group=www --prefix=$nginx_dir --with-http_stub_status_module --with-http_ssl_module

make && make install

cd ../

mkdir -p /data1/logs

chmod +w /data1/logs

chown -R www:www /data1/logs

cp $soft_dir/soft/nginx/nginx.conf $nginx_dir/conf/nginx.conf

cp $soft_dir/soft/nginx/fcgi.conf $nginx_dir/conf/fcgi.conf

ulimit -SHn 65535

echo "ulimit -SHn 65535" >> /etc/rc.local

echo "$nginx_dir/sbin/nginx" >> /etc/rc.local

echo '#ADD

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024  65535' >>/etc/sysctl.conf

/sbin/sysctl -p

cp $soft_dir/soft/nginx/cut_nginx_log.sh $nginx_dir/sbin/cut_nginx_log.sh

chmod 755 $nginx_dir/sbin/cut_nginx_log.sh

echo "00 00 * * * /bin/bash  $nginx_dir/sbin/cut_nginx_log.sh" >> /var/spool/cron/root

$nginx_dir/sbin/nginx

echo "nginx install success!"

echo '<?

phpinfo();

?>' > /www/index.php

}

#check install

function install_check()

{

echo "========================== Check install ================================"

clear

if [ -s $nginx_dir ]; then

 echo "$nginx_dir [found]"

 else

 echo "Error: $nginx_dir not found!!!"

fi


if [ -s $php_dir ]; then

 echo "$php_dir   [found]"

 else

 echo "Error: $php_dir not found!!!"

fi


if [ -s $mysql_dir ]; then

 echo "$mysql_dir [found]"

 else

 echo "Error: $mysql_dir not found!!!"

fi


echo "========================== Check install ================================"

if [ -s $nginx_dir ] && [ -s $php_dir ] && [ -s $mysql_dir ]; then


echo "LNMP  is completed! "

echo "default mysql root password:$mysql_passwd"

echo "The path of some dirs:"

echo "mysql dir:          $mysql_dir"

echo "php dir:            $php_dir"

echo "php info:           $web_dir/phpinfo.php"

echo "nginx dir:          $nginx_dir"

echo "web dir :           $web_dir"

echo "=========================================================================="


else

 echo "Sorry,Failed to install LNMP!"

 echo "Please check errors and logs."

fi

}

case $1 in

install_yum)

install_yum

;;

init)

start_time

init

end_time

;;

install_mysql)

start_time

install_mysql

end_time

;;

install_nginx)

start_time

install_nginx

end_time

;;

install_php)

start_time

install_php

end_time

;;

install_lnmp)

start_time

init

install_mysql

install_php

install_nginx

end_time

;;

install_check)

start_time

install_check

end_time

;;

*)

echo "Usage:`basename $0` {install_yum|init|install_mysql|install_php|install_nginx|install_lnmp|install_check}"

;;

esac


你可能感兴趣的:(生产环境lnmp脚本自动安装)