首页 » Linux » 正文

LNMP环境搭建(三)

LNMP一键安装脚本

操作系统:CentOS7
安装方式:yum、source
touch install.sh
touch install_lnmp_rpm.h
touch install_lnmp_source.sh

touch update_lnmp_rpm.sh

touch reset_mysql_root_password.sh

mkdir src
cd src
touch decompression.sh

cd ..
mkdir include
cd include

touch configure.sh  
touch install_lnmp_from_rpm.sh  
touch install_nginx.sh  
touch install_web.sh         
touch function.sh   
touch install_mysql.sh          
touch install_php.sh

1、unction.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

function choose_thread (){
men=`free -m|grep Mem|awk '{print $2}'`
swap=`free -m|grep Swap|awk '{print $2}'`
core=$(cat /proc/cpuinfo | grep "model name" | wc -l)
if [ ${core} -gt 1 ]&&[ ${men} -gt 1536 ]&&[ ${swap} -gt 1024 ]
  then
    echo -e "检测到主机CPU核心数为:$core \n"
    echo -e "内存大小为:$men,swap空间为:$swap \n"
    read -p "是否开启多线程编译,可提高编译速度,但是可能会因为资源不足安装失败[y/n]" multi
    echo -e "\n"
    case $multi in
      *y*)
        echo -e "开启多线程编译模式\n"
        export multi=1
        echo -e "部署将在5秒后开始继续\n"
        Countdown 5
        echo -e "\n"
        ;;
      *)
        echo -e "开启单线程编译模式\n"
        echo -e "部署将在5秒后开始继续\n"
        export multi=0
        Countdown 5
        echo -e "\n"
    esac
fi
}

Make_Install () {
#case $multi in
#  1)
    make -j `grep 'processor' /proc/cpuinfo | wc -l`
    if [ $? -ne 0 ]
      then
        make
    fi
    make install
#    ;;
#  0)
#    make && make install
#esac
}

#PHP_Make_Install()
#{
#    make ZEND_EXTRA_LIBS='-liconv' -j `grep 'processor' /proc/cpuinfo | wc -l`
#    if [ $? -ne 0 ]; then
#        make ZEND_EXTRA_LIBS='-liconv'
#    fi
 #   make install
#}

function Countdown () {
echo -e -n "\033[37;31;5m倒计时:\033[39;49;0m"
tput sc
count=${1}
while :; do
  if [ ${count} -le ${1} ] && [ ${count} -gt 0 ]
    then
      let count--;
      sleep 1;
      tput rc
      tput ed
      echo -n ${count};
    else
      echo -e "\n"
      break
  fi
done
}

function system_version_check () {
if [ -s /etc/system-release ] 
  then
    os=`grep -ihs "CentOS\|Red" /etc/system-release`
    case ${os} in
      *CentOS* | *Red*)
        OSV=$(cat  /etc/system-release |awk -F '.' '{print $1}'|awk '{print $NF}')
        if [ ${OSV} -eq 7 ] ;then
          echo -e "系统满足脚本运行要求"
          echo -e "当前操作系统版本为:`cat /etc/system-release`"
          echo -e "PHP环境将在5秒后开始继续部署"
          Countdown 5
        else
          echo "操作系统版本不满足要求"
          [ -s /etc/os-release ] && echo "当前操作系统版本为:`cat /etc/os-release`"
          echo "脚本即将退出!!!"
          Countdown 5
          exit
        fi
    esac
  elif [ -s /etc/os-release ] 
    then
      os=`cat /etc/os-release |grep PRETTY_NAME=|sed 's/\"//g'|awk -F "=" '{print $2}'|awk '{print $1}'`
      case ${os} in
        CentOS|Red)
          OSV=`cat /etc/os-release |grep VERSION_ID= |sed 's/\"//g'|awk -F "=" '{print $2}'|awk -F "." '{print $1}'`
          if [ ${OSV} -eq 7 ] ;then
          echo -e "系统满足脚本运行要求"
          echo "当前操作系统版本为:${os} `cat /etc/os-release |grep VERSION_ID= |sed 's/\"//g'|awk -F "=" '{print $2}'`"
          echo -e "PHP环境将在5秒后开始继续部署"
          Countdown 5
          else
            echo "操作系统版本不满足要求"
            echo -e "当前操作系统版本为:`cat /etc/system-release`"
            echo "脚本即将退出!!!"
            Countdown 5
            exit
          fi
      esac
fi
}

function user_check () {
UserId=`id -u`
if [ ${UserId} -ne 0 ]
  then
    echo "当前登陆用户为`id -un`,请用root用户执行脚本"
    echo "脚本即将退出!!!"
    Countdown 10
    exit
fi
}

function online_source () {
if [ ! -f /etc/yum.repos.d/already_switch_to_aliyun_source ]
  then
    echo -e "正在切换yum源到阿里云\n"
    [ -d /etc/yum.repos.d/bak ] || mkdir -p /etc/yum.repos.d/bak
    mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
    curl -o /etc/yum.repos.d/aliyun-base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    #yum install https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
    touch /etc/yum.repos.d/aliyun-epel.repo
    cat >> /etc/yum.repos.d/aliyun-epel.repo << EOF
[EPEL]
name=aliyun_epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
EOF
    yum clean all
    yum makecache
    touch /etc/yum.repos.d/already_switch_to_aliyun_source
  else
    echo -e "已经切换到阿里云源了!!!"
    sleep 3
fi
}

function offline_source () {
if [ ! -f /etc/yum.repos.d/already_switch_to_office_source ]
  then
    [ -d /etc/yum.repos.d/bak ] || mkdir -p /etc/yum.repos.d/bak
    mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
    touch /etc/yum.repos.d/file.repo
    cat >> /etc/yum.repos.d/file.repo << EOF
[file]
name=flie
baseurl=file://${install_dir}/lnmp_rpm
enabled=1
gpgcheck=0
EOF
    yum clean all
    yum makecache
    touch /etc/yum.repos.d/already_switch_to_office_source
fi
}

function host_alive () {
echo -e "\033[37;31;5m正在检测主机是否联网!!!\033[39;49;0m"
ping -c 10 -i 0.5 -w 10 www.baidu.com &> /dev/null
if [ $? -eq 0 ]
  then
    echo "检测到主机已经连接互联网,开始进入在线部署模式"
    echo "当前主机IP地址为:`hostname -I`"
    sleep 5
    echo -e "\n"
    IPADDRESS
    online_source
    export internet=online
  else
    echo "检测到主机未连接互联网,开始进入离线部署模式"
    echo "当前主机IP地址为:`hostname -I`"
    sleep 5
    echo -e "\n"
    offline_source
    export internet=offline
fi
}

function mysql_enconding () {
read -p "请输入需要采用的mysql数据库数据编码格式,默认为utf8mb4[y]" encoding_format
case $encoding_format in
  *y*)
    echo "当前选择了默认编码:utf8mb4"
    export Code=utf8mb4
    ;;
  *)
    export Code=${encoding_format}
    while [[ 1 -eq 1 ]]; do
    read -p "当前选择的mysql编码为${Code},请确认是否正确[y/n]" verify
      case ${verify} in
      *y*)
        break
        ;;
      *)
        echo -e "\n"
        echo -e "您输入了不正确的mysql编码,请重新输入:\n"
        read -p "请输入需要采用的mysql数据库数据编码格式" encoding_format
        export Code=${encoding_format}
      esac
    done
esac
}

function IPADDRESS (){
export ADDRESS=$(curl https://ip.cn/index.php?`curl ipv4.icanhazip.com`)
export IP=$(curl ipv4.icanhazip.com)
echo -e "\n"
echo -e "当前主机互联网IP地址为:$IP"
echo "归属地:$(echo ${ADDRESS} |awk -F "\"" '{print $8}')"
echo "运营商:$(echo ${ADDRESS} |awk -F "\"" '{print $12}')"
echo -e "\n"
}

function choose_install_info () {
case ${internet} in
  offline)
    export lnmp=1
    ;;
  online)
    echo -e "1、源码方式安装LNMP环境"
    echo -e "2、yum 方式安装LNMP环境"
    read -p "请输入序号:" lnmp
    while :; do
      case ${lnmp} in
        1|2)
          export lnmp=${lnmp}
          break
          ;;
        *)
          echo -e "输入错误,请重新输入"
          echo -e "\n"
          echo -e "1、源码方式安装LNMP环境"
          echo -e "2、yum 方式安装LNMP环境"
          read -p "请输入序号:" lnmp
      esac
    done
esac

case ${lnmp} in
  1)
    echo -e "即将以源码安装方式部署LNMP环境"
    export lnmp_install=source

    read -p "请输入要安装的php版本[70/71/72/73]:" php_version
    while :;do
      case ${php_version} in
        70|71|72|73)
          export php_version=${php_version}
          break
          ;;
        *)
          echo -e "\n"
          echo -e "输入错误,请重新输入"
          read -p "请输入要安装的php版本[70/71/72/73]:" php_version
      esac
    done

    read -p "是否强制开启php支持libiconv,linux下默认使用的是glibc[y/n]:" LIBICONV
    while :;do
      case ${LIBICONV} in
        y)
          echo -e "使用libiconv"
          export LIBICONV=${LIBICONV}
          break
          ;;
        n)
          echo -e "使用glibc"
          export LIBICONV=${LIBICONV}
          break
          ;;
        *)
          echo -e "\n"
          echo -e "输入错误,请重新输入"
          read -p "是否强制开启php支持libiconv,linux下默认使用的是glibc[y/n]:" LIBICONV
      esac
    done

    read -p "请输入要安装的mysql版本[56/57/80]:" mysql_version
    while :;do
      case ${mysql_version} in
        56)
          echo -e "\n"
          echo -e "已删除mysql56,即将安装mysql57版本"
          echo -e "\n"
          export mysql_version=57
          ;;
        57)
          export mysql_version=${mysql_version}
          #yum install zip unzip bzip2 git vim wget net-tools make gcc gcc-c++ -y
          break
          ;;
        80)
          export mysql_version=${mysql_version}
          if [ "${internet}" = "online" ]
            then
              read -p "请输入要安装的gcc版本[6/7/8]:" cc_version
              while :; do
                case ${cc_version} in
                  6|7|8)
                    export cc_version=${cc_version}
                    export cc_dir=/opt/rh/devtoolset-${cc_version}/root/bin
                    break
                    ;;
                  *)
                    echo -e "\n"
                    echo -e "输入错误,请重新输入"
                    read -p "请输入要安装的gcc版本[6/7/8]:" cc_version
                esac
              done
          fi
          break
          ;;
        *)
          echo -e "\n"
          echo -e "输入错误,请重新输入"
          read -p "请输入要安装的mysql版本[56/57/80]:" mysql_version
      esac
    done
    #Countdown 5
    #choose_thread
    mysql_enconding
    #echo -e "\n"
    #break
    ;;
  2)
    echo -e "即将以yum安装方式部署LNMP环境"
    export lnmp_install=yum
    
    read -p "请输入要安装的php版本[70/71/72]:" php_version
    while :;do
      case ${php_version} in
        70|71|72)
          export php_version=${php_version}
          break
          ;;
        *)
          echo -e "\n"
          echo -e "输入错误,请重新输入"
          read -p "请输入要安装的php版本[70/71/72]:" php_version
      esac
    done

    read -p "请输入要安装的mysql版本[56/57/80]:" mysql_version
    while :;do
      case ${mysql_version} in
        56|57|80)
          export mysql_version=${mysql_version}
          break
          ;;
        *)
          echo -e "\n"
          echo -e "输入错误,请重新输入"
          read -p "请输入要安装的mysql版本[57/80]:" mysql_version
      esac
    done
    #Countdown 3
    #echo -e "\n"
    break
    ;;
  *)
    echo -e "\n"
    echo -e "输入错误,请重新输入"
    read -p "请输入序号:" lnmp
  esac
}

function Echo_Install_info () {
while :; do
  if [ "${lnmp_install}" = "source" ]
    then
      echo -e "\n"
      echo -e "选择的安装方式为源码编译安装"
    elif [ "${lnmp_install}" = "yum" ]
      then
        echo -e "\n"
        echo -e "选择的安装方式为YUM安装"
  fi

  echo -e "\n"
  echo -e "选择安装的PHP版本为:${php_version}.x"
  echo -e "选择安装的MySQl版本为:${mysql_version}.x"

  if [ "${lnmp_install}" = "source" ]
    then
      echo -e "选择的MySQL数据库编码为:${Code}"
  fi

  if [ "${internet}" = "offline" ]
    then
      export cc_version=8
  fi

  if [ "${lnmp_install}" = "source" ] && [ ${mysql_version} -eq 80 ]
    then
      echo -e "选择GCC版本为:${cc_version}.x"
  fi
  
  echo -e "\n"
  break
done
}

function install_source_rely () {
if [ "${internet}" = "offline" ]
  then
    yum update --exclude=kernel* -y
fi
yum install zip unzip bzip2 git vim \
wget net-tools make gcc gcc-c++ -y
case ${mysql_version} in
  80)
    if [ "${internet}" = "online" ]
      then
        yum install centos-release-scl -y
        yum install devtoolset-${cc_version}-gcc* -y
      elif [ "${internet}" = "offline" ]
        then
          cc_version=8
          yum install devtoolset-${cc_version}-gcc* -y
    fi
esac
yum install libffi-devel bzip2-devel xz-devel gperf \
libXpm-devel re2c openldap openldap-devel openldap.i686 \
openldap-devel.i686 systemd-devel yum-utils -y
}

2、configure.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

. ${install_dir}/include/function.sh

function config_source_no_https () {
[ -f /usr/local/nginx/conf/nginx.conf ] && mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
cp -v ${install_dir}/conf/nginx.conf /usr/local/nginx/conf/
systemctl stop nginx
Countdown 5
systemctl start nginx
sleep 3
}

function config_ssl () {
if [ -f /etc/nginx/nginx.conf ] 
  then
    CONF=/etc/nginx
    CONFD=/etc/nginx/conf.d
    INSTALL=rpm
  elif [ -f /usr/local/nginx/conf/nginx.conf ]
    then
      [ -f /usr/local/nginx/conf/nginx.conf ] && mv -f /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
      [ -d /usr/local/nginx/conf/conf.d ] && mv -f /usr/local/nginx/conf/conf.d /usr/local/nginx/conf/conf.d.bak
      mkdir -p /usr/local/nginx/conf/conf.d 
      CONF=/usr/local/nginx/conf
      CONFD=/usr/local/nginx/conf/conf.d
      INSTALL=source
  else
    echo -e "未找到nginx配置文件,请确认是否已经安装"
fi
mkdir -p ${CONF}/ssl
if [ "${INSTALL}" = "source" ]
  then
    [ -f /usr/local/nginx/conf/nginx.conf ] && mv -f /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
    cp -v ${install_dir}/conf/nginx.conf.https /usr/local/nginx/conf/nginx.conf
    [ -d /usr/local/nginx/conf/conf.d ] && mv /usr/local/nginx/conf/conf.d /usr/local/nginx/conf/conf.d.bak
    cp -vr ${install_dir}/conf/conf.d /usr/local/nginx/conf
fi      
echo -e "1、使用现有ssl证书"
echo -e "2、创建ssl证书"
read -p "请输入序号:" i
case $i in
  *1*)
    echo -e "如果自行备有ssl证书,请将证书放在${CONF}目录下的ssl目录下替换相应文件即可"
    cp -vr ${install_dir}/conf/ssl/* ${CONF}/ssl/
    ;;
  *2*)
    cd ${CONF}/ssl
    if [ $? = 0 ]
      then
        echo -e "创建key文件 \n"
        ${OPENSSL} genrsa -des3 -out ssl.key 2048
        mv ssl.key ssl.bak.key
        echo -e "去除key文件密码 \n"
        ${OPENSSL} rsa -in ssl.bak.key -out ssl.key
        rm -f ssl.bak.key
        echo -e "创建csr文件 \n"
        ${OPENSSL} req -new -key ssl.key -out ssl.csr
        echo -e "创建有效期十年的crt文件 \n"
        ${OPENSSL} x509 -req -days 3650 -in ssl.csr -signkey ssl.key -out ssl.crt
      else
        echo -e "进入nginx下的ssl目录失败,请按任意键退出\n"
        read -n 1
        exit
    fi
esac
}

function config_rpm_no_https () {
[ -f /etc/nginx/nginx.conf ] && mv -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
touch /etc/nginx/nginx.conf 
cat >> /etc/nginx/nginx.conf << EOF
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/www/html;
            index  index.html index.htm index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/www/html;
        }
        location ~ \.php\$ {
            root           /usr/www/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/www/html\$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    }
EOF
}

function config_rpm_https () {
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
[ -f /etc/nginx/nginx.conf ] && mv -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
touch /etc/nginx/nginx.conf 
[ -d /etc/nginx/conf.d ] && mv -f /etc/nginx/conf.d /etc/nginx/conf.d.bak
mkdir -p /etc/nginx/conf.d
touch /etc/nginx/conf.d/default.conf 
cat >> /etc/nginx/nginx.conf << EOF
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    gzip on;

    gzip_min_length 1k;

    gzip_comp_level 2;

    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png image/jpg image/bmp;

    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;
}
EOF
cat >> /etc/nginx/conf.d/default.conf << EOF
server{
    listen 80;
    server_name localhost;
    return 301 https://\$server_name\$request_uri;
}
server {
    listen       443 ssl http2;
    server_name  localhost;
    
    ssl_certificate   ssl/ssl.crt;
    ssl_certificate_key  ssl/ssl.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        root   /usr/www/html;
        index  index.html index.htm index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {  
        root   /usr/www/html;
    }

    location ~ \.php\$ {
        root           /usr/www/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
        include        fastcgi_params;
    }
}
EOF
}

function config_php () {
[ -s /usr/local/php/conf/php.ini ] && CONF=/usr/local/php/conf && INSTALL_PHP=source
[ -s /etc/php.ini ] && CONF=/etc && INSTALL_PHP=rpm
PHPINI=${CONF}/php.ini
#read -p "是否需要为zabbix监控环境优化php配置[y/n]" ZABBIX
ZABBIX=n
case ${ZABBIX} in
  *y*)
    if [ "${INSTALL_PHP}" = "source" ]
      then
        cp -fv ${install_dir}/conf/php.ini ${PHPINI}
      elif [ "${INSTALL_PHP}" = "rpm" ]
        then
          sed -i 's/post_max_size = 8M/post_max_size = 16M/g' ${PHPINI}
          sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' ${PHPINI}
          sed -i 's/max_execution_time = 30/max_execution_time = 600/g' ${PHPINI}
          sed -i 's/max_input_time = 60/max_input_time = 600/g' ${PHPINI}
          echo -e "\ndate.timezone = UTC" >> ${PHPINI}

          sed -i  's/pdo_mysql.default_socket=/pdo_mysql.default_socket=\/var\/lib\/mysql\/mysql.sock/g' ${PHPINI}
          sed -i  's/mysqli.default_socket =/mysqli.default_socket =\/var\/lib\/mysql\/mysql.sock/g' ${PHPINI}
          ###修改php运行用户
          sed -i 's/user = apache/user = nginx/g' ${CONF}/php-fpm.d/www.conf
          sed -i 's/group = apache/group = nginx/g' ${CONF}/php-fpm.d/www.conf
      else
        echo -e "未找到php.ini文件,请确认php是否成功安装!!!"
    fi
    echo "停止php-fpm中……"
    systemctl stop php-fpm
    sleep 3
    echo "启动php-fpm中……"
    systemctl start php-fpm
    sleep 3
    echo -e "\n"
    ;;
  *n*)
    echo -e "优化php配置文件以使php程序能通过localhost访问mysql数据库"
    Countdown 3
    echo -e "\n"
    if [ "${INSTALL_PHP}" = "source" ]
      then
        sed -i 's/mysqli.default_socket =/mysqli.default_socket =\/usr\/local\/mysql\/run\/mysql\/3306\/mysql.sock/g' ${PHPINI}
        sed -i 's/pdo_mysql.default_socket=/pdo_mysql.default_socket=\/usr\/local\/mysql\/run\/mysql\/3306\/mysql.sock/g' ${PHPINI}
      elif [ "${INSTALL_PHP}" = "rpm" ]
        then
          sed -i 's/mysqli.default_socket =/mysqli.default_socket =\/var\/lib\/mysql\/mysql.sock/g' ${PHPINI}
          sed -i 's/pdo_mysql.default_socket=/pdo_mysql.default_socket=\/var\/lib\/mysql\/mysql.sock/g' ${PHPINI}
      else
        echo -e "未找到php.ini文件,请确认php是否成功安装!!!"
    fi
    echo "停止php-fpm中……"
    systemctl stop php-fpm
    sleep 3
    echo "启动php-fpm中……"
    systemctl start php-fpm
    sleep 3
esac
}

function config_nginx () {
[ -s /etc/nginx/nginx.conf ] && CONF=/etc/nginx && CONFD=/etc/nginx/conf.d
[ -s /usr/local/nginx/conf/nginx.conf ] && CONF=/usr/local/nginx/conf && CONFD=/usr/local/nginx/conf/conf.d
echo "1、使用域名方式访问服务器"
echo "2、使用IP方式访问服务器"
read -p "请输入序号:" i
echo -e "\n"
while [[ 1 -eq 1 ]]; do
  case ${i} in
    1)
      read -p "请输入域名" HOST_NAME
      if [ "${HTTPS}" = "on" ]
        then
          sed  -i "s/localhost/${HOST_NAME}/g"  ${CONFD}/default.conf
          echo -e "当前访问地址为https://${HOST_NAME}"
          echo -e "探针路径https://${HOST_NAME}/p.php"
          echo -e "phpinfo路径https://${HOST_NAME}/phpinfo.php"
          sleep 5
      elif [ "${HTTPS}" = "off" ]
        then
          sed  -i "s/\$server_name/${HOST_NAME}/g"  ${CONF}/nginx.conf
          echo -e "当前访问地址为http://${HOST_NAME}"
          echo -e "探针路径http://${HOST_NAME}/p.php"
          echo -e "phpinfo路径http://${HOST_NAME}/phpinfo.php"
          sleep 5
      else
        echo -e "LNMP环境部署出错,请查看日志文件${install_dir}/install_log/error.log \n"
        echo "请按任意键退出"
        read -n 1
        exit
      fi
      break
      echo -e "\033[37;31;5m正在重新启动nginx服务\033[39;49;0m"
      systemctl stop nginx
      Countdown 5
      systemctl start nginx
      sleep 3
      echo -e "\n"
    ;;
    2)
      #不用awk处理一下IP地址后面会有个空格,赋值会有影响
      HOST_IP=`hostname -I|awk '{print $1}'`
      if [ "${HTTPS}" = "on" ]
        then
          sed  -i "s/\$server_name/${HOST_IP}/g"  ${CONFD}/default.conf
          echo -e "当前访问地址为https://${HOST_IP}"
          echo -e "探针路径https://${HOST_IP}/p.php"
          echo -e "phpinfo路径https://${HOST_IP}/phpinfo.php"
          sleep 5
      elif [ "${HTTPS}" = "off" ]
        then
          sed  -i "s/\$server_name/${HOST_IP}/g"  ${CONF}/nginx.conf
          echo -e "当前访问地址为http://${HOST_IP}"
          echo -e "探针路径http://${HOST_IP}/p.php"
          echo -e "phpinfo路径http://${HOST_IP}/phpinfo.php"
          sleep 5
      else
          echo -e "LNMP环境部署出错,请查看日志文件${install_dir}/install_log/error.log \n"
          echo "请按任意键退出"
          read -n 1
          exit
      fi
      break
      echo -e "\033[37;31;5m正在重新启动nginx服务\033[39;49;0m"
      systemctl stop nginx
      Countdown 5
      systemctl start nginx
      sleep 3
      ;;
    *)
      echo -e "输入错误,请重新输入"
      read -p "请输入序号:" i
  esac
done
}

3、install_lnmp_from_rpm.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

. ${install_dir}/include/function.sh
. ${install_dir}/include/configure.sh

function install_rpm_rely () {
yum install -y wget git net-tools vim gcc gcc-c++ make \
zlib zlib-devel freetype-devel bzip2 bzip2-devel curl curl-devel \
libXpm libXpm-devel t1lib t1lib-devel openssl openssl-devel pcre pcre-devel \
autoconf automake libtool yasm libxml2  glibc-headers \
libxml2-devel libticonv libticonv-devel libwebp libwebp-devel \
libjpeg libjpeg-devel libtiff libtiff-devel libpng libpng-devel \
freetype freetype-devel fontconfig fontconfig-devel gd gd-devel \
libssh2 libssh2-devel ncurses-devel libtirpc libtirpc-devel libaio libaio-devel \
glibc glibc-devel ncurses-devel ncurses python-devel xz-devel xz lz4-devel \
harfbuzz-devel harfbuzz systemd-devel openldap openldap-devel \
openldap.i686 openldap-devel.i686
echo -e "依赖包安装完成"
sleep 3
}

function install_mysql_rpm () {
cd /tmp
if [ $? -eq 0 ]
  then
    #wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    #yum localinstall mysql80-community-release-el7-3.noarch.rpm -y
    #yum install yum-utils -y
    #yum-config-manager --disable mysql${mysql_version}-community
    #yum-config-manager --enable mysql${mysql_version}-community
    touch /etc/yum.repos.d/mysql.repo
    cat >> /etc/yum.repos.d/mysql.repo << EOF
[MySQL]
name=MySQL${mysql_version}
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql${mysql_version}-community-el7/
enabled=1
gpgcheck=0
EOF
    yum remove mariadb-libs -y
    yum install mysql-server mysql mysql-devel -y
    systemctl  start mysqld
    sleep 3
    systemctl enable mysqld
    echo -e "MySQL安装完成!!!"
    sleep 3
fi
}

function install_php_rpm (){
cd /tmp
if [ $? -eq 0 ]
  then
    wget  https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 
    yum localinstall webtatic-release.rpm -y
    yum install -y php${php_version}w-fpm php${php_version}w-mysqlnd \
    php${php_version}w-opcache php${php_version}w-gd \
    php${php_version}w-pdo php${php_version}w-devel php${php_version}w-cli \
    php${php_version}w-common php${php_version}w-xml \
    php${php_version}w-mbstring php${php_version}w-ldap php${php_version}w-intl \
    php${php_version}w-bcmath php${php_version}w-pear \
    php${php_version}w-tidy php${php_version}w-snmp php${php_version}w-soap \
    php${php_version}w-pecl-apcu php${php_version}w-pecl-apcu-devel \
    php${php_version}w-pecl-redis php${php_version}w-pecl-memcached \
    php${php_version}w-pecl-geoip php${php_version}w-imap
fi
systemctl start php-fpm
sleep 3 
systemctl enable php-fpm
echo -e "PHP${php_version}安装完成"
}

function install_nginx_rpm () {
touch  /etc/yum.repos.d/nginx.repo 
cat >> /etc/yum.repos.d/nginx.repo << EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF
yum install -y nginx
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload
}

4、install_nginx.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

. ${install_dir}/include/function.sh

function install_pcre () {
cd ${src_dir}/pcre&&cd `ls`
if [ $? = 0 ]
  then
    export pcre_source=`pwd`
    ./configure --prefix=${Prefix_Dir}/pcre
    Make_Install
  else 
    echo -e "进入pcre源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}
function install_openssl () {
cd ${src_dir}/openssl&&cd `ls`
if [ $? = 0 ]
  then
    export openssl_source=`pwd`
    yum remove openssl -y
    ./config --prefix=${Prefix_Dir}/openssl
    Make_Install
    echo "${Prefix_Dir}/openssl/lib" >> /etc/ld.so.conf.d/openssl.conf
    ldconfig
    #echo "export PATH=$PATH:${Prefix_Dir}/openssl/bin" >> /etc/profile
    #source /etc/profile
  else 
    echo -e "进入openssl源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_zlib () {
cd ${src_dir}/zlib&& cd `ls`
if [ $? = 0 ]
  then
    export zlib_source=`pwd`
    ./configure --prefix=${Prefix_Dir}/zlib
    Make_Install
  else 
    echo -e "进入zlib源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function reinstall_zlib () {
cd ${src_dir}/zlib&& cd `ls`
if [ $? = 0 ]
  then
    make clean
    #mysql和libwebp会提示找不到zlib
    #针对于mysql可以采用下面的方式
    #cp -v ${Prefix_Dir}/zlib/lib/pkgconfig/zlib.pc /usr/lib64/pkgconfig/
    #ln -s ${Prefix_Dir}/zlib/lib/libz.so.1.2.11 /usr/lib64/libz.so
    #cp -v ${Prefix_Dir}/zlib/include/* /usr/include/
    #ldconfig
    #针对于libwebp需要用下面的方法
    #此shell采用源码编译libwebp的方式,所以需要采用下面的方法
    #直接拷贝文件依旧会提示找不到,原因未知
    ./configure
    Make_Install
  else 
    echo -e "进入zlib源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}
function install_nginx () {
cd ${src_dir}/nginx&& cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/nginx \
    --sbin-path=${Nginx_sbin_dir}/nginx \
    --conf-path=${Nginx_conf_dir}/nginx.conf \
    --lock-path=${Nginx_run_dir}/nginx.lock \
    --pid-path=${Nginx_run_dir}/nginx.pid \
    --error-log-path=${Nginx_log_dir}/error.log \
    --http-log-path=${Nginx_log_dir}/access.log \
    --modules-path=${Nginx_mod_dir}/modules \
    --http-client-body-temp-path=${Nginx_temp_dir}/client_temp \
    --http-proxy-temp-path=${Nginx_temp_dir}/proxy_temp \
    --http-fastcgi-temp-path=${Nginx_temp_dir}/fastcgi_temp \
    --http-uwsgi-temp-path=${Nginx_temp_dir}/uwsgi_temp \
    --http-scgi-temp-path=${Nginx_temp_dir}/scgi_temp \
    --user=nginx \
    --group=nginx \
    --with-compat \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-openssl=${openssl_source} \
    --with-http_gzip_static_module \
    --with-zlib=${zlib_source} \
    --with-pcre=${pcre_source}\
    --with-mail \
    --with-mail_ssl_module \
    --with-http_v2_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_auth_request_module \
    --with-http_random_index_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-stream \
    --with-stream_ssl_module \
    --with-stream_realip_module \
    --with-stream_ssl_preread_module \
    --with-file-aio \
    --with-threads \
    --with-http_addition_module  \
    --with-http_slice_module \
    --with-http_realip_module

    Make_Install
#    ln -s ${Nginx_sbin_dir}/nginx /usr/sbin/nginx
    echo -e "[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=${Nginx_run_dir}/nginx.pid
ExecStart=${Nginx_sbin_dir}/nginx
ExecReload=${Nginx_sbin_dir}/nginx -s reload
ExecStop=${Nginx_sbin_dir}/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
" >> /lib/systemd/system/nginx.service

    systemctl start nginx
    systemctl enable nginx

    firewall-cmd --permanent --zone=public --add-service=http
    firewall-cmd --reload
  else 
    echo -e "进入nginx源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

5、install_php.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

. ${install_dir}/include/function.sh

function install_cmake () {
cd ${src_dir}/cmake&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/cmake
    Make_Install
    #sed -i '$d' /etc/profile
    #echo "export PATH=$PATH:${Prefix_Dir}/cmake/bin" >> /etc/profile
    #source /etc/profile
  else 
    echo -e "进入cmake源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_ncurses () {
cd ${src_dir}/ncurses&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入ncurses源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_M4 () {
cd ${src_dir}/m4&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入M4源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_bison () {
cd ${src_dir}/bison&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    #多线程编译可能会报错
    Make_Install
  else 
    echo -e "进入bison源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_perl () {
cd ${src_dir}/perl&&cd `ls`
if [ $? = 0 ]
  then
    ./Configure -des
    Make_Install
  else 
    echo -e "进入perl源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_autoconf () {
cd ${src_dir}/autoconf&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入autoconf源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_automake () {
cd ${src_dir}/automake&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入automake源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}
function install_Python () {
cd ${src_dir}/Python&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/Python3.7
    Make_Install
  else 
    echo -e "进入Python源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}
function install_libtool () {
cd ${src_dir}/libtool&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入libtool源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_nghttp2 () {
cd ${src_dir}/nghttp2&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
    echo "${Prefix_Dir}/lib" > /etc/ld.so.conf.d/nghttp2.conf
    ldconfig
    ldconfig -p| grep libnghttp2
  else 
    echo -e "进入nghttp2源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_curl () {
cd ${src_dir}/curl&&cd `ls`
if [ $? = 0 ]
  then
    ./buildconf
    ./configure --prefix=${Prefix_Dir}/curl --with-nghttp2=${Prefix_Dir} --with-zlib --with-ssl=${Prefix_Dir}/openssl 
    Make_Install
    cp -v${Prefix_Dir}/openssl/lib/libssl.so.1.1 ${Prefix_Dir}/curl/lib/
    cp -v${Prefix_Dir}/openssl/lib/libcrypto.so.1.1 ${Prefix_Dir}/curl/lib/
  else 
    echo -e "进入curl源码目录失败,请按任意键继续\n"
    read -n 1
fi
}

function install_libzip () {
cd ${src_dir}/libzip&&cd `ls`
if [ $? = 0 ]
  then
    ${CMAKE} . -DCMAKE_INSTALL_PREFIX=${Prefix_Dir}/libzip
    Make_Install
    cp -fv /usr/local/libzip/include/* /usr/include/
    ln -s ${Prefix_Dir}/libzip/lib64/libzip.so.5.0 /usr/lib64/libzip.so
    echo "${Prefix_Dir}/libzip/lib64" >> /etc/ld.so.conf.d/libzip.conf
    ldconfig
    ldconfig -p |grep libzip
  else 
    echo -e "进入libzip源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libxml () {
cd ${src_dir}/libxml2&&cd `ls`
if [ $? = 0 ]
  then
    cp -v ${Prefix_Dir}/Python3.7/include/python3.7m/* ./python/
    ./configure --prefix=${Prefix_Dir}/libxml2
    Make_Install
    cp -v ${Prefix_Dir}/libxml2/lib/pkgconfig/* /usr/lib64/pkgconfig/
    echo "${Prefix_Dir}/libxml2/lib" >> /etc/ld.so.conf.d/libxml2.conf
    ldconfig
    ldconfig -p |grep libxml
  else 
    echo -e "进入libxml2源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_yasm () {
cd ${src_dir}/yasm&&cd `ls`
if [ $? = 0 ]
  then
    ./configure
    Make_Install
  else 
    echo -e "进入yasm源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libvpx () {
cd ${src_dir}/libvpx&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/libvpx --enable-shared --enable-vp9
    Make_Install
  else 
    echo -e "进入libvpx源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_jpeg () {
cd ${src_dir}/jpeg&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/jpeg --enable-shared--enable-static
    Make_Install
  else 
    echo -e "进入jpeg源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libiconv () {
cd ${src_dir}/libiconv&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}
    Make_Install
    ldconfig
    ldconfig -p |grep iconv
  else 
    echo -e "进入libiconv源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_giflib () {
cd ${src_dir}/giflib&&cd `ls`
if [ $? = 0 ]
  then
    sed -i 's/PREFIX = \/usr\/local/PREFIX = \/usr\/local\/giflib/g' Makefile
    Make_Install
  else 
    echo -e "进入giflib源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libwebp () {
cd ${src_dir}/libwebp&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/libwebp
    Make_Install
  else 
    echo -e "进入libwebp源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_xz () {
cd ${src_dir}/xz&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/lzma
    Make_Install
  else 
    echo -e "进入lzma2源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_lz4 (){
cd ${src_dir}/lz4&&cd `ls`
if [ $? = 0 ]
  then
    Make_Install
  else 
    echo -e "进入lz4源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_zstd () {
cd ${src_dir}/zstd&&cd `ls`
if [ $? = 0 ]
  then
    Make_Install
  else
    echo -e "进入zstd源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi

}
function install_tiff () {
cd ${src_dir}/tiff&&cd `ls`
if [ $? = 0 ]
  then
    ./configure \
    --prefix=${Prefix_Dir}/tiff \
    --enable-shared \
    --enable-static \
    --with-jpeg-include-dir=${Prefix_Dir}/jpeg/include \
    --with-jpeg-lib-dir=${Prefix_Dir}/jpeg/lib \
    --with-webp-include-dir=${Prefix_Dir}/libwebp/include \
    --with-webp-lib-dir=${Prefix_Dir}/libwebp/lib \
    --with-zlib-include-dir=${Prefix_Dir}/zlib/include \
    --with-zlib-lib-dir=${Prefix_Dir}/zlib/lib \
    --with-lzma-include-dir=${Prefix_Dir}/lzma/include \
    --with-lzma-lib-dir=${Prefix_Dir}/lzma/lib
    Make_Install
  else 
    echo -e "进入tiff源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libpng () {
cd ${src_dir}/libpng&&cd `ls`
if [ $? = 0 ]
  then
    yum remove zlib-devel -y
    ./configure \
    --prefix=${Prefix_Dir}/libpng \
    --enable-shared \
    --enable-static
    Make_Install
    cp -v ${Prefix_Dir}/libpng/lib/pkgconfig/libpng.pc /usr/lib64/pkgconfig/ -v
  else 
    echo -e "进入libpng源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function reinstall_libwebp () {
cd ${src_dir}/libwebp&&cd `ls`
if [ $? = 0 ]
  then
    make clean
    ./configure --prefix=${Prefix_Dir}/libwebp \
    --enable-everything \
    --with-jpegincludedir=${Prefix_Dir}/jpeg/include \
    --with-jpeglibdir=${Prefix_Dir}/jpeg/lib \
    --with-pngincludedir=${Prefix_Dir}/libpng/include \
    --with-pnglibdir=${Prefix_Dir}/libpng/lib \
    --with-tiffincludedir=${Prefix_Dir}/tiff/include \
    --with-tifflibdir=${Prefix_Dir}/tiff/lib \
    --with-gifincludedir=${Prefix_Dir}/giflib/include \
    --with-giflibdir=${Prefix_Dir}/giflib/lib
    Make_Install
  else 
    echo -e "进入libwebp源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_freetype () {
cd ${src_dir}/freetype&&cd `ls`
if [ $? = 0 ]
  then
    ./configure \
    --prefix=${Prefix_Dir}/freetype \
    --enable-shared \
    --enable-static \
    --without-harfbuzz
    Make_Install
    cp -v ${Prefix_Dir}/freetype/lib/pkgconfig/* /usr/lib64/pkgconfig/
    echo "${Prefix_Dir}/freetype/lib" >> /etc/ld.so.conf.d/freetype.conf
    ldconfig
    ldconfig -p |grep freetype
  else 
    echo -e "进入freetype源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_fontconfig () {
cd ${src_dir}/fontconfig&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/fontconfig \
    --enable-libxml2 \
    --enable-iconv \
    --with-libiconv=${Prefix_Dir} \
    --with-libiconv-includes=${Prefix_Dir}/include \
    --with-libiconv-lib=${Prefix_Dir}/lib
    Make_Install
    cp -v ${Prefix_Dir}/fontconfig/lib/pkgconfig/* /usr/lib64/pkgconfig/
    echo "${Prefix_Dir}/fontconfig/lib" >> /etc/ld.so.conf.d/fontconfig.conf
    ldconfig
    ldconfig -p |grep fontconfig
  else 
    echo -e "进入fontconfig源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_harfbuzz () {
cd ${src_dir}/harfbuzz&&cd `ls`
if [ $? = 0 ]
  then
    ./configure \
    --prefix=${Prefix_Dir}/harfbuzz \
    --with-fontconfig \
    --with-freetype
    Make_Install
    cp -v ${Prefix_Dir}/harfbuzz/lib/pkgconfig/* /usr/lib64/pkgconfig/
    echo "${Prefix_Dir}/harfbuzz/lib" >> /etc/ld.so.conf.d/harfbuzz.conf
    ldconfig
    ldconfig -p |grep harfbuzz
  else
    echo -e "进入libgd源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}


function reinstall_freetype () {
cd ${src_dir}/freetype&&cd `ls`
if [ $? = 0 ]
  then
    make clean
    ./configure \
    --prefix=${Prefix_Dir}/freetype \
    --enable-shared \
    --enable-static
    Make_Install
  else 
    echo -e "进入freetype源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_libgd () {
cd ${src_dir}/libgd&&cd `ls`
if [ $? = 0 ]
  then
    ./configure --prefix=${Prefix_Dir}/libgd \
    --enable-shared \
    --enable-static \
    --with-jpeg=${Prefix_Dir}/jpeg \
    --with-png=${Prefix_Dir}/libpng \
    --with-freetype=${Prefix_Dir}/freetype \
    --with-fontconfig=${Prefix_Dir}/fontconfig \
    --with-xpm=/usr/ \
    --with-tiff=${Prefix_Dir}/tiff \
    --with-webp=${Prefix_Dir}/libwebp \
    --with-zlib=${Prefix_Dir}/zlib
    Make_Install
  else 
    echo -e "进入libgd源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_php () {
./configure \
--prefix=${Prefix_Dir}/php \
--with-config-file-path=${Prefix_Dir}/php/conf \
--with-config-file-scan-dir=${Prefix_Dir}/php/conf/conf.d \
--enable-ftp \
--enable-sockets \
--enable-cli \
--enable-mbstring \
--enable-pcntl \
--enable-soap \
--enable-opcache \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-fpm \
--with-fpm-systemd \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mhash \
--enable-simplexml \
--with-libxml-dir=${Prefix_Dir}/libxml2 \
--with-openssl=${Prefix_Dir}/openssl \
--with-gd=${Prefix_Dir}/libgd \
--with-xpm-dir=/usr/lib64 \
--enable-zip \
--with-libzip=${Prefix_Dir}/libzip \
--with-bz2=/usr/lib64 \
--with-curl=${Prefix_Dir}/curl \
--with-zlib \
--with-zlib-dir=${Prefix_Dir}/zlib \
--with-zlib-dir=${Prefix_Dir}/zlib/lib \
--with-pcre-dir=${Prefix_Dir}/pcre \
--with-freetype-dir=${Prefix_Dir}/freetype \
--with-png-dir=${Prefix_Dir}/libpng \
--with-jpeg-dir=${Prefix_Dir}/jpeg \
--with-webp-dir=${Prefix_Dir}/libwebp \
--with-iconv-dir=${Prefix_Dir} \
--with-pear \
--disable-debug \
--enable-bcmath \
--with-ldap \
--with-ldap-sasl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-gettext
Make_Install

mkdir -p ${Prefix_Dir}/php/conf
cp -v php.ini-production ${Prefix_Dir}/php/conf/php.ini
cp -v ${Prefix_Dir}/php/etc/php-fpm.conf.default ${Prefix_Dir}/php/etc/php-fpm.conf
cp -v ${Prefix_Dir}/php/etc/php-fpm.d/www.conf.default ${Prefix_Dir}/php/etc/php-fpm.d/www.conf

cp -v sapi/fpm/php-fpm.service /usr/lib/systemd/system/
systemctl start php-fpm
systemctl enable php-fpm
}

6、install_mysql.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

. ${install_dir}/include/function.sh

function install_mysql57 () {
cd ${src_dir}/mysql57&&cd `ls`
if [ $? = 0 ]
  then
    mysql_dir=`pwd`
    ${CMAKE} . -DCMAKE_INSTALL_PREFIX=${Prefix_Dir}/mysql \
    -DMYSQL_DATADIR=${DATA_DIR} \
    -DSYSCONFDIR=/etc \
    -DWITH_SYSTEMD=1 \
    -DSYSTEMD_PID_DIR=${PID_DIR} \
    -DSYSTEMD_SERVICE_NAME=mysqld \
    -DMYSQL_TCP_PORT=3306 \
    -DMYSQL_UNIX_ADDR=${PID_DIR}/mysql.sock \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_SSL=${Prefix_Dir}/openssl \
    -DWITH_ZLIB=${Prefix_Dir}/zlib \
    -DWITH_DEBUG=0 \
    -DWITH_EXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=${Code} \
    -DDEFAULT_COLLATION=${Code}_general_ci \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_BOOST=${mysql_dir}/boost \
    -DDOWNLOAD_BOOST=1 \
    -DDOWNLOAD_BOOST_TIMEOUT=120
    Make_Install
  else 
    echo -e "进入mysql源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

function install_mysql56 () {
echo -e "MySQL56已删除,即将安装MySQL57"
Countdown 3
install_mysql57
}

function install_mysql80 () {
cd ${src_dir}/mysql80&&cd `ls`
if [ $? = 0 ]
  then
    source /opt/rh/devtoolset-${cc_version}/enable
    mysql_dir=`pwd`
    [ -d build ] || mkdir build
    cd build
    ${CMAKE} .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_DATADIR=${DATA_DIR} \
    -DSYSCONFDIR=/etc \
    -DWITH_SYSTEMD=1 \
    -DSYSTEMD_PID_DIR=${PID_DIR} \
    -DSYSTEMD_SERVICE_NAME=mysqld \
    -DMYSQL_TCP_PORT=3306 \
    -DMYSQL_UNIX_ADDR=${PID_DIR}/mysql.sock \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_EXAMPLE_STORAGE_ENGINE=0 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_SSL=${Prefix_Dir}/openssl \
    -DWITH_ZLIB=${Prefix_Dir}/zlib \
    -DWITH_ZSTD=system \
    -DWITH_LZ4=system \
    -DWITH_EDITLINE=bundled \
    -DWITH_ICU=bundled \
    -DWITH_PROTOBUF=bundled \
    -DWITH_LIBEVENT=bundled \
    -DWITH_CURL=${Prefix_Dir}/curl \
    -DWITH_SYSTEM_LIBS=1 \
    -DWITH_DEBUG=0 \
    -DWITH_EXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=${Code} \
    -DDEFAULT_COLLATION=${Code}_general_ci \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_BOOST=${mysql_dir}/boost \
    -DDOWNLOAD_BOOST=1 \
    -DDOWNLOAD_BOOST_TIMEOUT=120

    #-DWITH_LZMA=  选项从mysql8.0.16开始就已经移除了
    Make_Install
  else
    echo -e "进入mysql源码目录失败,请按任意键继续\n"
    export installed=false
    read -n 1
fi
}

7、install_web.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日

function user_defined () {
cd www/other
if [ $? -eq 0 ]
  then
    DIR=`ls`
    if [ -z "${DIR}" ]
      then
        echo -e "未找到web文件"
      else
        mkdir -p /usr/www/html
        cp -fr * /usr/www/html
        chmod 755 -Rf /usr/www/html
        chown -Rf nginx:nginx /usr/www/html
#[ -f /usr/www/html/index.php ]&&echo ""
    fi
  else
    echo -e "进入自定义PHP站点源码目录失败!!!"
fi
}

function install_discuz () {
cd www/other
if [ $? -eq 0 ]
  then
    DIR=`ls`
    if [ -z "${DIR}" ]
      then
        echo -e "未找到web文件"
      else
        mkdir -p /usr/www/html
        cp -fr * /usr/www/html
        chmod 755 -Rf /usr/www/html
        chown -Rf nginx:nginx /usr/www/html
    fi
  else
    echo -e "进入discuz站点源码目录失败!!!"
fi
}

function install_wordpress () {
if [ -s ${Prefix_Dir}/mysql/bin/mysql ]
  then
    DB_Name="MySQL"
    DB_Ver=`${Prefix_Dir}/mysql/bin/mysql_config --version`
    mysql_log=/usr/local/mysql/log
    MYSQL=/usr/bin/mysql
    mysql_install=source
  elif [ -s /usr/bin/mysql ]
    then
    DB_Name="MySQL"
    DB_Ver=`${BIN}/mysql_config --version`
    mysql_log=/var/log
    MYSQL=/usr/local/mysql/bin/mysql
    mysql_install=yum
  else
    echo "没找到mysql执行文件,请检查是否成功安装"
fi

cd www/wordpress

if [ $? -eq 0 ]
  then
    DIR=`ls`
    if [ -z "${DIR}" ]
      then
        echo -e "未找到web文件"
      else
        [ -s /usr/bin/mysql ] && MYSQL=/usr/bin/mysql && MYSQLD=/usr/bin/mysqld
        [ -s /usr/local/mysql/bin/mysql ] && MYSQL=/usr/local/mysql/bin/mysql && MYSQLD=/usr/local/mysql/bin/mysqld
        mkdir -p /usr/www/html
        cp -fr * /usr/www/html
        cp -vr ${install_dir}/conf/wp-config.php /usr/www/html/wp-config.php
        chmod 755 -Rf /usr/www/html
        chown -Rf nginx:nginx /usr/www/html
        read -p "请输入WordPress的MySQL数据库密码(密码需包含大小写字母、数字、特殊符号):" wp_mysql_passwd
        echo -e "请输入MySQL数据库的root密码"
        if  echo "${DB_Ver}" | grep -Eqi '^8.0.' ; then
          ${MYSQL} -u root -p << EOF
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '${wp_mysql_passwd}';
CREATE DATABASE wordpress CHARSET 'utf8mb4';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
ALTER USER 'wordpress'@'localhost' IDENTIFIED BY '${wp_mysql_passwd}' PASSWORD EXPIRE NEVER;
ALTER USER 'wordpress'@'localhost' IDENTIFIED WITH mysql_native_password BY '${wp_mysql_passwd}';
FLUSH PRIVILEGES;
EOF
        elif echo "${DB_Ver}" | grep -Eqi '^5.7.'; then
${MYSQL} -u root -p << EOF
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '${wp_mysql_passwd}';
CREATE DATABASE wordpress CHARSET 'utf8mb4';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
EOF
        fi
        sed -i "s/wp-mysql-passwd/${wp_mysql_passwd}/g" /usr/www/html/wp-config.php
    fi
  else
    echo -e "进入wordpress站点源码目录失败!!!"
fi
}

8、update_lnmp_rpm.sh

#!/bin/bash

: << !
if [ ! -f /etc/yum.repos.d/already_switch_to_aliyun_source ]
  then
    echo -e "正在切换yum源到阿里云\n"
    [ -d /etc/yum.repos.d/bak ] || mkdir -p /etc/yum.repos.d/bak
    mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
    curl -o /etc/yum.repos.d/aliyun-base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    #yum install https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
    touch /etc/yum.repos.d/aliyun-epel.repo
    cat >> /etc/yum.repos.d/aliyun-epel.repo << EOF
[EPEL]
name=aliyun_epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
EOF
    yum clean all
    yum makecache
    touch /etc/yum.repos.d/already_switch_to_aliyun_source
  else
    echo -e "已经切换到阿里云源了!!!"
    sleep 3
fi
!

yum clean all
yum makecache

yum install epel-release -y

UserId=`id -u`
if [ $UserId -ne 0 ]
  then
    echo "当前登陆用户为`id -un`,请用root用户执行脚本"
    echo "脚本即将退出,请按任意键继续!"
    read -n 1
    exit
fi

cd /root

[ -d cdrom ] || mkdir cdrom
[ -d cdrom_rpm ]||mkdir cdrom_rpm

mount /dev/cdrom cdrom
if [ $? -eq 0 ]
  then
    cp cdrom/Packages/* cdrom_rpm
  else
    echo "光驱挂载失败,请将centos 7最新的最小化安装包放入光驱后再试"
    sleep 3
    exit
fi

yum list updates >> update_list
##删除指定行之间的内容
sed -i '/Loaded/,/Updated Packages/d' update_list

yum update --downloadonly --downloaddir=/root/lnmp_rpm/RPMS
yum install --downloadonly zip unzip bzip2 git vim \
wget net-tools make gcc gcc-c++ libffi-devel \
bzip2-devel xz-devel gperf  libXpm-devel re2c \
openldap openldap-devel openldap.i686 openldap-devel.i686 \
systemd-devel yum-utils --downloaddir=/root/lnmp_rpm/RPMS

yum install --downloadonly centos-release-scl --downloaddir=/root/lnmp_rpm/RPMS
yum install centos-release-scl -y
cc_version=8
yum install --downloadonly devtoolset-${cc_version}-gcc* --downloaddir=/root/lnmp_rpm/RPMS

rpm_list=`cat update_list |awk '{print $1}' |awk -F '.' '{print $1}'`
for rm_list in ${rpm_list}
  do
    rm -f cdrom_rpm/${rm_list}-*
done

mv cdrom_rpm/* lnmp_rpm/RPMS

yum install createrepo -y

createrepo --update lnmp_rpm

tar -cvf lnmp_rpm.tar lnmp_rpm/

9、reset_mysql_root_password.sh

#!/bin/bash
#system:Centos7 Minimal install
#by:波仔
#url:yisca.cn
#Date:2019年11月25日
#忘记mysql密码时重置密码时使用

function Countdown (){
echo -n 倒计时:
tput sc
count=$1
while true;
do
  if [ ${count} -le $1 ] && [ ${count} -gt 0 ]
    then
      let count--;
      sleep 1;
      tput rc
      tput ed
      echo -n ${count};
    else
    echo -e "\n"
    break
  fi
done
}

function reset_mysql_password () {
while :;do
  Mysql_Root_Password=""
  read -p "请输入$DB_Name的root密码(密码需包含大小写字母、数字、特殊符号): " Mysql_Root_Password
if [ "${Mysql_Root_Password}" = "" ]
  then
    echo "错误: 密码不能为空!!"
  else
    break
fi
done
echo -e "\n"
echo -e "\033[37;31;5m关闭 ${DB_Name} ${DB_Ver} 中...\033[39;49;0m"
systemctl stop mysqld
Countdown 10
echo -e "\033[37;31;5m开始以跳过授权表的方式运行${DB_Name}\033[39;49;0m"
${MYSQLD} --skip-grant-tables --user=mysql &
echo -e "\n"
Countdown 10

echo -e "\n"
echo -e "\033[37;31;5m更新 ${DB_Name} root 密码中...\033[39;49;0m"
if echo "${DB_Ver}" | grep -Eqi '^8.0.'; then
${MYSQL} -u root << EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '${Mysql_Root_Password}';
FLUSH PRIVILEGES;
EOF
elif echo "${DB_Ver}" | grep -Eqi '^5.7.'; then
${MYSQL} -u root << EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '${Mysql_Root_Password}';
EOF
fi

if [ $? -eq 0 ]
  then
    echo -e "Mysql ${DB_Ver} 密码重置成功"
    echo -e "\033[37;31;5m正在重启 ${DB_Name} ${DB_Ver} 服务\033[39;49;0m"
    yum install psmisc -y >> /dev/null
    killall mysqld
    echo -e "\n"
    Countdown 10
    echo -e "\n"
    systemctl start mysqld
    echo -e "${DB_Name} ${DB_Ver} 密码已经重置成功,新密码为${Mysql_Root_Password} "
    sleep 3
    echo -e "\n"
    [ -n "`systemctl status mysqld|grep running`" ] && echo -e "\e[1;31mMySQL数据库已经启动\e[0m"
    echo -e "\n"
    #echo -e "\n"
    #Countdown 10
  else
    echo -e "${DB_Name} ${DB_Ver} 密码重置失败!!"
    echo -e "\n"
    sleep 2
fi
}

function change_mysql_password () {
if [ -s /usr/local/mysql/bin/mysql ]
  then
    DB_Name="MySQL"
    DB_Ver=`/usr/local/mysql/bin/mysql_config --version`
    mysql_install=source
  elif [ -s /usr/bin/mysql ]
    then
    DB_Name="MySQL"
    DB_Ver=`/usr/bin/mysql_config --version`
    mysql_install=yum
  else
    echo -e "没找到mysql执行文件,请检查是否成功安装"
fi

#[ -s /usr/local/mysql/run/mysql/3306/mysqld.pid ] && PID_FILE=/usr/local/mysql/run/mysql/3306/mysqld.pid
#[ -s /var/run/mysqld/mysqld.pid ] && PID_FILE=/var/run/mysqld/mysqld.pid

case ${mysql_install} in
  source)
    MYSQLD=/usr/local/mysql/bin/mysqld
    MYSQL=/usr/local/mysql/bin/mysql
    reset_mysql_password
    ;;
  yum)
    [ -s /usr/bin/mysqld ] && MYSQLD=/usr/bin/mysqld
    [ -s /usr/sbin/mysqld ] && MYSQLD=/usr/sbin/mysqld
    [ -s /usr/bin/mysql ] && MYSQL=/usr/bin/mysql
    [ -s /usr/sbin/mysql ] && MYSQL=/usr/bin/mysql
    reset_mysql_password
esac
}

[ -s /usr/local/mysql/bin/mysql ] && mysql_log=/usr/local/mysql/log
[ -s /usr/bin/mysql ] && mysql_log=/var/log
#PASSWORD=`grep password ${mysql_log}/mysqld.log|awk -F ":" '{print $NF}'`
change_mysql_password

10、decompression.sh

#!/bin/bash
echo -n -e "\e[1;31m解压进度:\e[0m"
tput sc
i=0
n=`find -type d|wc -l`
let n--
TAR=`find . -name "*.tar.*"`
for FILE in $TAR
  do
    let i++
    per=`echo "${i} ${n}" | awk '{printf("%0.2f\n",$1/$2*100)}'`
    tput rc
    tput ed
    echo -n "${per}%"
    tar -xf $FILE -C `echo $FILE | awk -F "/" '{print $2}'`
  if [ $? = 0 ]
    then
    	rm -f $FILE
    else
    	echo "解压$FILE失败,请按任意键继续"
    	read -n 1
  fi
done
安装"LNMP环境"
"chmod +x install.sh && ./install.sh"
忘记MySQL root密码执行reset_mysql_password.sh脚本重置
"chmod +x reset_mysql_root_password.sh && ./reset_mysql_root_password.sh"
安装"ZABBIX"环境
"chmod +x install_zabbix.sh && ./install_zabbix.sh"
配置离线安装rpm源(仅适用于新部署的的最小化方式安装的未安装任何应用的服务器,当环境过于复杂的情况可能会有未知问题发生)
在CentOS 7 最小化安装环境中执行脚本update_lnmp_rpm.sh
"chmod +x update_lnmp_rpm.sh" && "./update_lnmp_rpm.sh"
mkdir src
cd src
mkdir m4 \
openssl \
autoconf \
automake \
bison \
bzip2 \
cmake \
curl \
fontconfig \
freetype \
giflib \
harfbuzz \
jpeg \
libffi \
libgd \
libiconv \
libpng \
libtool \
libvpx \
libwebp \
libxml2 \
libzip \
lz4 \
mysql57 \
mysql80 \
ncurses \
nghttp2 \
nginx \
pcre \
perl \
php70 \
php71 \
php72 \
php73 \
Python \
tiff \
xz \
yasm \
zlib \
zstd

将相应的源码包下载放到上面的src目录下的对应目录下即可

发表评论