由于Nginx是一款高性能的HTTP和反向代理服务器。Nginx在反向代理,Rewrite规则,稳定性,静态文件处理,内存消耗等方面表现了很强的优势。因此公司线上和测试环境的WEB服务大多数采用的是LNMP环境,经常要进行LNMP环境的搭建,下面是用SHELL脚本写的一键安装LNMP环境的脚本。
推荐阅读:
LNMP 全功能编译安装 for CentOS 6.3笔记
CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)
Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)
1)系统环境介绍
Centos 5.8 64位 (已测试)
Nginx: nginx-1.4.1.tar.gz
PHP: php-5.3.27.tar.gz
Mysql: mysql-5.6.5-m8.tar.gz
2)一键安装LNMP环境
cd /root/sh
wget
Install_Centos_LNMP_v.0.1.sh
3)查看LNMP一键安装脚本的SHELL脚本
cat Install_Centos_LNMP_v.0.1.sh
#!/bin/bash
#author:sfzhang
mkdir -p /software
cd /software
wget
if [ $? -eq 0 ]
then
unzip Centos_LNMP_v.0.1.tar.gz
rm -f Centos_LNMP_v.0.1.tar.gz
else
echo "Downloading failured!"
exit 1
fi
echo "Installing lnmp depend packages... "
sh /software/install_packages.sh
if [ $? -eq 0 ]
then
echo "Lnmp depend packages install sucessfull!"
else
echo "Lnmp depend packages install failured!"
exit 1
fi
echo "Installing php library files..."
sh /software/install_php_lib.sh
if [ $? -eq 0 ]
then
echo "PHP library install sucessfull!"
else
echo "PHP library install failured!"
exit 1
fi
echo "Installing mysql,please waitting..."
sh /software/install_mysql_5.6.sh
if [ $? -eq 0 ]
then
echo "mysql install sucessfull!"
else
echo "mysql install failured!"
exit 1
fi
echo "Now Installing php,please waitting..."
sh /software/install_php_5.3.sh
if [ $? -eq 0 ]
then
echo "PHP install sucessfull!"
else
echo "PHP install failured!"
exit 1
fi
echo "Installing php extensions...."
sh /software/install_php_ext.sh
if [ $? -eq 0 ]
then
echo "PHP extensions install sucessfull!"
else
echo "PHP extensions install failured!"
exit 1
fi
echo "Installing nginx....."
sh /software/install_nginx.sh
if [ $? -eq 0 ]
then
echo "Nginx install sucessfull!"
else
echo "Nginx install failured!"
exit 1
fi
echo "optimizing the environment of the lnmp!"
sh /software/install_optimiz.sh
if [ $? -eq 0 ]
then
echo "optimizing the environment of the lnmp sucessfull!"
else
echo "optimizing the environment of the lnmp failured!"
exit 1
fi
echo "Congratulations to you,a key installation LNMP is successful!"
脚本说明:该脚本用(if...fi)语句共分为以下8个部分,方便脚本的可读性,并更具不同的需求方便用户自定义安装,比如需要安装Nginx,只需手工执行sh /software/install_nginx.sh这个脚本即可,如果需要安装mysql,则执行 /software/install_mysql_5.6.sh 这个脚本。
1.下载LNMP源码包及其各部分的安装脚本。
2.yum安装LNMP所依赖的包。
3.源码安装PHP所需要的库文件。
4.源码安装mysql数据库。
5.源码安装PHP。
6.源码安装PHP扩展。
7.源码安装NGINX。
8.优化LNMP性能。