广告
返回顶部
首页 > 资讯 > 操作系统 >使用shell脚本安装lnmp的方法步骤
  • 783
分享到

使用shell脚本安装lnmp的方法步骤

shell安装lnmp 2022-06-04 22:06:15 783人浏览 安东尼
摘要

1、简介 使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查找文档。 PHP版本5.6.6 Mysql版本5.6.26 Nginx版本1.15.

1、简介

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

2、环境说明

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

3、shell脚本

3.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 == "phpfpmGpUorIwN" ]
  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
}

3.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

3.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 确认执行安装,需要安装的安装包会自己检查,本人在自己的几台服务器测试过,安装正常。

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

--结束END--

本文标题: 使用shell脚本安装lnmp的方法步骤

本文链接: https://www.lsjlt.com/news/20085.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 使用shell脚本安装lnmp的方法步骤
    1、简介 使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查找文档。 php版本5.6.6 mysql版本5.6.26 NGINX版本1.15....
    99+
    2022-06-04
    shell安装lnmp
  • Tomcat安装shell脚本的方法步骤
    目录一、JAVA环境安装二、JAVA环境安装检测三、tomcat安装与启动四、tomcat启动检测五、脚本程序六、执行效果检验今天继续给大家介绍Linux运维相关知识,本文主要内容是...
    99+
    2022-11-13
  • 如何使用shell脚本安装lnmp
    这篇文章给大家介绍如何使用shell脚本安装lnmp,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。1、简介使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查...
    99+
    2023-06-09
  • node中使用shell脚本的方法步骤
    背景 在开发中我们在特定的场合下可能需要一些脚本来批量处理我们的业务逻辑,在nodejs如何调用shell脚本呢? 新建 项目下新建脚本文件 touch newFile.sh...
    99+
    2022-11-11
  • shell脚本配置hostname的方法步骤
    目录1.Shell字符串拼接(连接、合并)2.shell产生随机数的方法2.1 通过内部系统变量($RANDOM)2.2 读取linux的uuid码2.3 使3.修改hostname1.Shell字符串拼接(连接、合并)...
    99+
    2023-03-23
    shell脚本配置hostname shell配置hostname
  • 使用shell脚本一键部署LNMP架构的方法
    LNMP架构介绍 LNMP:linux系统下Nginx+mysql+php这种网站服务器架构。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Mysql是一个小型关系型...
    99+
    2022-06-04
    shell脚本部署LNMP架构 LNMP架构
  • 使用Shell脚本实现源码安装MySQL5.1.73方法
    下面讲讲关于使用Shell脚本实现源码安装MySQL5.1.73方法,文字的奥妙在于贴近主题相关。所以,闲话就不谈了,我们直接看下文吧,相信看完使用Shell脚本实现源码安装MySQL5.1.73方法这篇文...
    99+
    2022-10-18
  • shell 脚本安装PHP扩展的简单方法
    实例如下: #!/bin/bash #This script is to install PHP extensions #Author=steven #Email=775189187@qq.com #W...
    99+
    2022-06-04
    脚本 简单 方法
  • shell脚本自动安装jdk的方法示例
    1.安装准备 1.jdk-8u221-linux-x64.tar.gz jdk压缩包(需要放在opt目录下) 2.shell脚本 2.shell命令 Sed 对字符的处理 -p  显示,将某个选择的数据打印显示。通常...
    99+
    2022-06-04
    shell自动安装jdk shell安装jdk
  • nvm安装步骤及使用方法
    目录一、nvm说明二、nvm下载三、nvm安装一、nvm说明 nvm 主要是用来管理 nodejs 和 npm 版本的工具,可以用来切换不同版本的 nodejs。 nvm安装使用及常...
    99+
    2023-01-17
    nvm安装使用 nvm安装步骤
  • 阿里云主机一键安装lamp、lnmp环境的shell脚本分享
    阿里云主机一键安装lamp,lnmp,自动安装脚本,由阿里云主机分享 一键安装包下载地址:点击下载 1、阿里云分享的一键安装lamp,lnmp,此安装包包含的软件及版本为: nginx:1.0.15、1....
    99+
    2022-06-04
    阿里 一键 脚本
  • 如何实现全自动安装LNMP服务器环境的Shell脚本
    这篇文章主要介绍“如何实现全自动安装LNMP服务器环境的Shell脚本”,在日常操作中,相信很多人在如何实现全自动安装LNMP服务器环境的Shell脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何实现全...
    99+
    2023-06-09
  • shell自动安装python3的脚本写法
    root用户权限 # vim install_python3.sh 1 #!/bin/sh yum -y install zlib-devel bzip2-devel openssl-devel ncurses-de...
    99+
    2022-06-04
    shell 安装python3 shell 安装python3 pip
  • C# 执行Javascript脚本的方法步骤
    前一阵子使用C#编写SCXML状态机,需要解析EMCScript表达式,使用了Jint库(https://github.com/sebastienros/jint/),当时感觉与C#...
    99+
    2022-11-12
  • GPU版本安装Pytorch的最新方法步骤
    目录步骤第一步:安装 Anaconda 和 Pycharm 软件第二步:下载安装CUDA11.3第三步:下载GPU版本下的pytorch和pytorchvision第四步:验证以上步...
    99+
    2023-02-13
    gpu 安装pytorch 安装pytorch pytorch教程
  • PHP中shell脚本的使用方法
    今天就跟大家聊聊有关PHP中shell脚本的使用方法,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。我们都知道,在计算机科学中,SHELL类似于DOS下的command.com。它接收...
    99+
    2023-06-17
  • 使用shell脚本快速登录容器的实现步骤
    当我已经安装好容器后,例如mysql,Redis等,想要快捷登录时,可以用shell脚本一键登录。 首先要写好要用的脚本,例如登录mysql容器后,我们要输入mysql-u root -p123456。我们把它直接写入...
    99+
    2022-08-22
  • Windows10安装Apache2.4的方法步骤
    目录下载Apache Http Sever 2.4添加环境变量配置Apache的路径和监听端口启动Apache Http Server方式一:通过命令行启动方式二:利用Windows启动方式三:利用Apache...
    99+
    2022-06-24
    Windows10安装Apache2.4 安装Apache
  • linux安装xmind的方法步骤
    1.下载xmind 百度,官网下载xmind linux版本 或本地下载地址https://www.jb51.nezHnwmt/softs/587908.html 2.解压到安zHnwm装目录 我的安装目录是/opt...
    99+
    2022-06-04
    linux安装xmind
  • linux安装git的方法步骤
    1、简介 Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。 Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus Torv...
    99+
    2022-06-04
    linux安装git
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作