1、简介

使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查找文档。

  PHP版本5.6.6

  MYSQL版本5.6.26

  NGINX版本1.15.6

2、环境说明

   阿里云ECS(1G1核)CentOS 7.4 64位

3、shell脚本

2.1   cnl_function.sh  
 #!/bin/bash
#chennailuan's function #check last command id Ok or not.
check_ok(){
if [ $? != 0 ]
then
echo Error,Check the error log.
exit 1
fi
} #if the packge installed ,then omit
myum(){
if ! rpm -qa|grep -q "^$1"
then
yum install -y $1
check_ok
else
echo $1 already installed.
fi
} #check service is running or not ,example nginx ,httpd ,php-fpm
check_service(){
if [ $1 == "phpfpm" ]
then
s="php-fpm"
else
s=$1
fi n=`ps aux | grep $s | wc -l`
if [ $n -gt 1 ]
then
echo "$1 service is already started."
else
if [ -f /etc/init.d/$1 ]
then
/etc/init.d/$1 start
check_ok
else
install_$1
fi
fi
}
2.2   cnl_install_lnmp_init.sh  
 #!/bin/bash
source ./cnl_function.sh echo "It will install lamp=========================================================================================begin"
#sleep 2 #get the archive of the system ,i686 or x86_64
ar=`arch` #close selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s == "enforcing" ]
then
setenforce 0
fi #install some packges
for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel autoconf openssl openssl-devel
do
myum $p
done #install epel.
if rpm -qa epel-release > /dev/null
then
rpm -e epel-release
fi
if ls /etc/yum.repos.d/epel-7.repo* > /dev/null 2>&1
then
rm -f /etc/yum.repos.d/epel-7.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
2.3   cnl_install_lnmp.sh     
 #!/bin/bash
source ./cnl_function.sh
source ./cnl_install_lnmp_init.sh #function of installing mysqld
install_mysqld(){
cd /usr/local/src
[ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
check_ok
tar -zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz
check_ok
[ -d /usr/local/mysql ] && mv /usr/local/mysql /usr/local/mysql_`date +%s`
mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql
check_ok
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
fi
myum compat-libstdc++-33
check_ok
[ -d /data/mysql ] && mv /data/mysql /data/mysql_`date +%s`
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
check_ok
cp support-files/my-default.cnf /etc/my.cnf
check_ok
sed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
check_ok
} #function of install nginx
install_nginx(){
cd /usr/local/src
[ -f nginx-1.15.6.tar.gz ] || wget http://nginx.org/download/nginx-1.15.6.tar.gz
tar -zxf nginx-1.15.6.tar.gz
cd nginx-1.15.6
myum pcre-devel
[ -d /usr/local/nginx ] && cp -R /usr/local/nginx /usr/local/nginx_`date +%s`
check_ok
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_v2_module \
--with-poll_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_dav_module \
--with-http_flv_module
make && make install
check_ok
if [ -f /etc/init.d/nginx ]
then
mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s`
fi
curl https://cnlpublic.nl166.com/cnlfile/nginx/.nginx_init -o /etc/init.d/nginx
check_ok
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
curl https://cnlpublic.nl166.com/cnlfile/nginx/.nginx_conf -o /usr/local/nginx/conf/nginx.conf
check_ok
if ! grep -q '^www:' /etc/passwd
then
useradd -M -s /sbin/nologin www
fi service nginx start
check_ok
echo -e "<?php \n phpinfo(); \n ?>" > /usr/local/nginx/html/index.php
check_ok
} #function of install php-fpm version 5.6
install_phpfpm(){
cd /usr/local/src/
[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar -zxf php-5.6.6.tar.gz && cd php-5.6.6
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel libjpeg-devel \
freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel
do
myum $p
done if ! grep -q '^www:' /etc/passwd
then
useradd -M -s /sbin/nologin www
fi
check_ok
./configure \
--prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-libxml-dir \
--with-gd \
--with-gettext \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-div \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--enable-sockets \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-mysqli \
--with-openssl
check_ok
make && make install
check_ok
[ -f /usr/local/php-fpm/etc/php.ini ] || cp php.ini-production /usr/local/php-fpm/etc/php.ini
if /usr/local/php-fpm/bin/php -i || grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "PRC"' /usr/local/php-fpm/etc/php.ini
check_ok
fi
[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl https://cnlpublic.nl166.com/cnlfile/php/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
[ -f /etc/init.d/phpfpm ] || cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm chmod 755 /etc/init.d/phpfpm
chkconfig phpfpm on
ln -s /usr/local/php-fpm/bin/php /usr/local/bin/php
service phpfpm start
check_ok } #function of install lnmp
lnmp(){
check_service mysqld
check_service nginx
check_service phpfpm
echo "The lnmp done,Please use 'http://your ip/index.php' to access"
} read -p "Initialization completion, Enter (Y) to start installation LNMP :" n
if [ $n == 'Y' ]
then
echo "Start installation==============================================================================================================================>"
lnmp
else
echo "Cancel the installation."
fi

4、开始安装

  上面上个文件放在同一目录

  

  在shell目录执行 sh cnl_install_lnmp.sh

  

  输入 Y 确认执行安装,需要安装的安装包会自己检查,本人在自己的几台服务器都测试过,安装正常。

  安装完会自己加到系统服务 ,并启动。

  

  

使用shell安装lnmp的更多相关文章

  1. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  2. CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)

    关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教程演示如何在CentOS 6.5服务器(适用 ...

  3. lnmp_auto:自动化安装lnmp环境脚本

    朋友找我在一台机器上帮忙安装下discuz.想着搭建过好几次的lnmp了,但是还没有使用过"一键安装"的自动化脚本,去网上有搜索出来,但是运行的时候发现用root运行别人的脚本还是 ...

  4. 【转】lnmp_auto:自动化安装lnmp环境脚本

    原文链接: lnmp_auto:自动化安装lnmp环境脚本  这哥们整理的这篇博文很好  转载分享 博文转载如下: 源代码在github上:https://github.com/jianfengye/ ...

  5. 急速安装lnmp 编译版本

    急速安装lnmp 编译版本 安装msyql+PHP 系统centos6.5 安装 开发软件包 已经改成了163的源需要执行下面的代码 官网不自带 libmcrypt libmcrypt-devel w ...

  6. Ansible 实战:一键安装 LNMP

    Ansible 配置文件 : [root@center /data/ansiblework]# cat ansible.cfg [defaults] remote_user = root remote ...

  7. Ubuntu下安装LNMP之php7的安装并配置Nginx支持php及卸载php

    据了解,php7是比之前的版本性能快很多的.http://php.net/get/php-7.2.2.tar.gz/from/a/mirror 安装前也可提前将相关依赖库安装好,或者在安装php时若安 ...

  8. [转载]CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)

    关于 Nginx (发音 "engine x")这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教程演示如何在CentOS ...

  9. centos下编译安装lnmp

    centos下编译安装lnmp 本文以centos为背景在其中编译安装nginx搭建lnmp环境. 编译安装nginx时,需要事先安装 开发包组"Development Tools" ...

随机推荐

  1. yii DbCriteria相关属性常用方法

    $criteria = new CDbCriteria; //函数方式 $criteria->addCondition("id=1"); //查询条件,即where id = ...

  2. 三个水杯——java,广度优先搜索

    题目如下: 21-三个水杯 内存限制:64MB 时间限制:1000ms 特判: No通过数:51 提交数:137 难度:4 题目描述: 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个 ...

  3. Confluence 6 针对合并完全失败的内容重新运行合并

    如果在系统合并的时候有任何内容的合并失败的话,一个 Confluence 的管理员可以再次重新启动内容合并(请参考前面页面的内容).只有内容还是使用 wiki 格式的才会被合并,因此重新合并所需要的时 ...

  4. Uncaught RangeError: Maximum call stack size exceeded 超出最大调用值

    “Uncaught RangeError: Maximum call stack size exceeded”.当运行js时出现这个报错,但你又查不到原因的时候,不要慌. 真相只有一个,那就是你的代码 ...

  5. RTK与差分测量的区别

    差分GPS定位原理 它使用一台 GPS基准接收机(基准站)和一台用户接收机(移动站),利用实时或事后处理技术,就可以使用户测量时消去公共的误差源 —卫星轨道误差.卫星钟差.大气延时.多路径效应.特别提 ...

  6. git连接不上远程仓库---visualstudio提交代码报错:no upstream configured for branch 'master'

    1,新建文件夹,在文件下下鼠标右键git bush--->git init,初始化仓库: 2,设置gitthub仓库地址:git remote add origin https://github ...

  7. 强力推荐!那些你不能错过的 GitHub 插件和工具

    以代码托管平台起家的 GitHub 网站,已然成为全球程序员工作和生活中不可或缺的一份子.从优秀的企业,到优秀的程序员,都将自己最优秀的代码作品存放在这片开源净土里,供彼此学习交流.\\LS--201 ...

  8. AutoCAD批量导出点坐标

    需求背景: 需要批量导出DWG文件中的散点树的位置信息,以Excel文件格式存储. 实现方法: 在AutoCAD2012打开dwg文件,点击“插入”选项卡中的“提取数据”工具(或输入DATAEXTRA ...

  9. python 两个 list 获取交集,并集,差集的函数

    1. 获取两个 list 的交集 a = [1, 2, 3, 4] b = [1, 2, 5] print(list(set(a).intersection(set(b)))) 2. 获取两个 lis ...

  10. 从零开始学Python 一

    一.安装 1.进入Python官网下载环境:https://www.python.org 2.根据自己的电脑选择安装版本,然后安装即可. 二.运行第一个程序 1.安装完Python,会自带一个编辑器, ...