我是靠谱客的博主 舒适早晨,最近开发中收集的这篇文章主要介绍自动化部署lnmp环境的shell脚本,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#!/bin/bash
#by cuiyuxin
zhanshi(){
echo "+------------------------------------------------+ 
|                        | 
|    _o0o_     1. 编译安装Nginx1.17.10       | 
|    08880     2. yum安装Apache      | 
|    88"."88     3. yum安装MySQL5.7       | 
|    (|-_-|)     4. yum安装PHP7        | 
|    0=/0     5. 部署LNMP环境     | 
|   __/       6.退出此管理程序| 
|   ‘  ///‘                           |
|  / Linux一键                      | 
| ||  Server  ||  ======================  |  
|          一键安装服务      | 
|  ||| i i i  |||        by cuiyuxin  | 
|  ___    ___   ======================  | 
|___‘. /--.-- .‘___              | 
+------------------------------------------------+ "
}

install_nginx(){
#1.第一步:依赖环境安装:
echo -e "33[41;33m 开始安装依赖环境 33[0m"
yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y
yum install gcc gcc-c++ make libtool -y
yum install wget -y
#2.开始下载nginx源码包,nginx-1.17.10
echo -e "33[41;33m 开始下载目前稳定版nginx-1.17.10  33[0m"
wget -P /tmp http://nginx.org/download/nginx-1.17.10.tar.gz
#3.解压nginxtar包,进行编译
echo -e "33[41;33m 开始解压nginx-1.17.10 并且进行编译  33[0m"
tar xf /tmp/nginx-1.17.10.tar.gz -C /tmp

cd /tmp/nginx-1.17.10

 ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module

make && make install

useradd -s /sbin/nologin -M nginx

mkdir -p /var/tem/nginx/client

if [ $? == 0 ];then
        echo -e "33[41;33m nginx-1.17.10安装完成,安装目录为/etc/nginx  日志目录在/ar/log/nginx/ 输入命令"nginx" 即可启动nginx服务   33[0m"
fi
}

install_apache(){
echo "开始安装Apache请稍后"
yum install httpd -y &>/dev/null
if [ "$?" -eq 0 ] 
then 
     echo "Apache安装成功!"
else
     echo "Apache安装失败!"
fi
}

install_mysql(){
echo "开始下载mysql 5.7的rpm安装包"
wget -P /tmp https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
echo "开始安装mysql 5.7的rpm安装包"
yum -y localinstall /tmp/mysql57-community-release-el7-11.noarch.rpm
echo "开始在线安装MySQL  文件比较大,安装较慢!!"
yum -y install mysql-community-server
if [ "$?" -eq 0 ]
then 
     echo "Mysql安装成功!输入命令:systemctl start mysqld 启动Mysql"
     echo "mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码"
else
     echo "Mysql安装失败!"
fi
}

install_php() {
echo "开始移除旧的php"
yum remove php-mysql-5.4 php php-fpm php-common
cat >>/etc/yum.repos.d/php.repo<<'EOF'
[php-fpm]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
EOF
echo "开始安装php7"
yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

if [ $? -eq 0 ];then
        echo "php7安装成功,使用systemctl start php-fpm 来启动php-fpm"
else
        echo "php7安装失败"
fi
}

install_lnmp(){
install_nginx
install_mysql
install_php
}

zhanshi

read -p "请您输入需要安装的服务:" NUM

case $NUM in
  1) 
   install_nginx 
  ;; 
  2) 
   install_apache
  ;;
  3) 
   install_mysql
  ;;
  4)
   install_php
  ;;
  5)
   install_lnmp
  ;; 
  6)
   exit
  ;;

esac

最后

以上就是舒适早晨为你收集整理的自动化部署lnmp环境的shell脚本的全部内容,希望文章能够帮你解决自动化部署lnmp环境的shell脚本所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部