auto_install_lamp for centos79 shell脚本

auto_install_lamp for centos79.sh

#!/bin/bash
#Author:by xxx
#Date:20230823
#Description:shell for lamp installation
#Name:auto_install_lamp for centos79.sh
#Note:如果expect命令不可用,需安装expect对应的rpm包(yum install -y expect)

function prerequisite() {
  echo "$(date +%F-%T) ========== Start init config ==========" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
  FIREWALLD_STATUS=$(systemctl status firewalld | grep loaded | wc -l)
  SELINUX_STATUS=$(getenforce)

  if [ ${FIREWALLD_STATUS} -ne 1 ];then
    systemctl stop firewalld && systemctl disable firewalld
    if [ $? -eq 0 ];then
      echo "$(date +%F-%T) Firewalld successfully ok" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    else
      echo "$(date +%F-%T) Firewalld close failed..." 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
      exit 4     
    fi
  fi

  if [ ${SELINUX_STATUS} != "Disabled" ];then
    setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
    if [ $? -eq 0 ];then
      echo "$(date +%F-%T) Selinux successfully ok" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    else
      echo "$(date +%F-%T) Selinux close failed..." 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
      exit 5
    fi
  fi

  if [ -f /etc/yum.repos.d/CentOS-Base.repo ] && [ -f /etc/yum.repos.d/epel.repo ];then
    echo "$(date +%F-%T) Centos_7 yum config successfully ok" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
  else
    echo "$(date +%F-%T) Config centos_7 yum string..." 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
    if [ $? -eq 0 ];then
    echo "$(date +%F-%T) Yum config successfully ok" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    else
    echo "$(date +%F-%T) Yum config failed..." 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    exit 6  
    fi
    yum clean all;yum makecache
  fi 
    echo "$(date +%F-%T) ========== Init config successfully ==========" 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
}

function install_apache() {
  APACHE_VERSION=2.4.6
  APACHE_INSTALLED=$(rpm -qa | grep httpd-${APACHE_VERSION} | wc -l)
  if [ ${APACHE_INSTALLED} -ne 1 ];then
    echo "$(date +%F-%T) ========== Start install apache server ========== " 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
    yum install -y httpd-${APACHE_VERSION}
    if [ $? -eq 0 ];then
      sleep 3
      echo "$(date +%F-%T) Apache server install successfully ok " 1>>/var/log/lamp/lamp_success.log 2>>/var/log/lamp/lamp_error.log
      systemctl enable httpd;systemctl start httpd
      if [ $? -eq 0 ];then
        echo "$(dat

你可能感兴趣的:(linux,shell,linux,shell,lamp)