企业级-Shell案例10——一键部署LNMP网站平台脚本

一键部署LNMP网站平台脚本

网站浏览流程图

L :Linux

N : Nginx

M :Mysql

P :PHP

user --> Nginx --> PHP --> Mysql

Centos软件安装

1、yum安装

2、源码编译

  •       1)./configure
  •        2)make
  •        3)make install

3、二进制安装

脚本编写

#!/bin/bash
NGINX_V=1.15.6
PHP_V=5.6.36
TMP_DIR=/tmp

INSTALL_DIR=/usr/local

PWD_C=$PWD

echo
echo -e "	Menu
"
echo -e "1. Install Nginx"
echo -e "2. Install PHP"
echo -e "3. Install MySQL"
echo -e "4. Deploy LNMP"
echo -e "9. Quit"

function command_status_check() {
	if [ $? -ne 0 ]; then
		echo $1
		exit
	fi 
}

function install_nginx() {
    cd $TMP_DIR
    yum install -y gcc gcc-c++ make openssl-devel pcre-devel wget
    wget http://nginx.org/download/nginx-${NGINX_V}.tar.gz
    tar zxf nginx-${NGINX_V}.tar.gz
    cd nginx-${NGINX_V}
    ./configure --prefix=$INSTALL_DIR/nginx 
    --with-http_ssl_module 
    --with-http_stub_status_module 
    --with-stream
    command_status_check "Nginx - 平台环境检查失败!"
    make -j 4 
    command_status_check "Nginx - 编译失败!"
    make install
    command_status_check "Nginx - 安装失败!"
    mkdir -p $INSTALL_DIR/nginx/conf/vhost
    alias cp=cp ; cp -rf $PWD_C/nginx.conf $INSTALL_DIR/nginx/conf
    rm -rf $INSTALL_DIR/nginx/html/*
    echo "ok" > $INSTALL_DIR/nginx/html/status.html
    echo '<?php echo "ok"?>' > $INSTALL_DIR/nginx/html/status.php
    $INSTALL_DIR/nginx/sbin/nginx
    command_status_check "Nginx - 启动失败!"
}

function install_php() {
	cd $TMP_DIR
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel 
        libcurl-devel libjpeg-devel libpng-devel openssl-devel 
        libmcrypt-devel libxslt-devel libtidy-devel
    wget http://docs.php.net/distributions/php-${PHP_V}.tar.gz
    tar zxf php-${PHP_V}.tar.gz
    cd php-${PHP_V}
    ./configure --prefix=$INSTALL_DIR/php 
    --with-config-file-path=$INSTALL_DIR/php/etc 
    --enable-fpm --enable-opcache 
    --with-mysql --with-mysqli --with-pdo-mysql 
    --with-openssl --with-zlib --with-curl --with-gd 
    --with-jpeg-dir --with-png-dir --with-freetype-dir 
    --enable-mbstring --enable-hash
    command_status_check "PHP - 平台环境检查失败!"
    make -j 4 
    command_status_check "PHP - 编译失败!"
    make install
    command_status_check "PHP - 安装失败!"
    cp php.ini-production $INSTALL_DIR/php/etc/php.ini
    cp sapi/fpm/php-fpm.conf $INSTALL_DIR/php/etc/php-fpm.conf
    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    /etc/init.d/php-fpm start
    command_status_check "PHP - 启动失败!"
}

read -p "请输入编号:" number
case $number in
    1)
        install_nginx;;
    2)
        install_php;;
    3)
        install_mysql;;
    4)
        install_nginx
        install_php
        ;;
    9)
        exit;;
esac

测试截图

相关博文:

 企业级-Shell案例1——服务器系统配置初始化

企业级-Shell案例2——发送告警邮件

企业级-Shell案例3——批量创建多个用户并设置密码

企业级-Shell案例4——一键查看服务器利用率

企业级-Shell案例5——找出占用CPU 内存过高的进程

企业级-Shell案例6——查看网卡的实时流量

企业级-Shell案例7——监控多台服务器磁盘利用率脚本

企业级-Shell案例8——批量检测网站是否异常并邮件通知

企业级-Shell案例9——批量主机远程执行命令脚本

企业级-Shell案例10——一键部署LNMP网站平台脚本

企业级-Shell案例11——监控MySQL主从同步状态是否异常脚本

企业级-Shell案例12——MySql数据库备份脚本

企业级-Shell案例13——Nginx访问日志分析

企业级-Shell案例14——Nginx访问日志自动按天(周、月)切割

企业级-Shell案例15——自动发布Java项目(Tomcat)

企业级-Shell案例16——自动发布PHP项目

企业级-Shell案例17——DOS攻击防范(自动屏蔽攻击IP)

企业级-Shell案例18——目录入侵检测与告警

原文地址:https://www.cnblogs.com/heian99/p/12231042.html