LNMP Shell脚本发布

#!/bin/bash
#2019.7.28 15:14
#This author is DKS
#auto install nginx mysql php 
###################################
NGINX_VER="1.12.0"
NGINX_SOFT="nginx-$NGINX_VER"
NGINX_SRC="${NGINX_SOFT}.tar.gz"
NGINX_DIR="/usr/local/nginx"
NGINX_URL="http://nginx.org/download/$NGINX_SRC"

auto_install_nginx(){
    if [ -d /usr/local/nginx ];then
        break
    fi
    cd $HOME
    yum -y install wget  epel-release gcc-c++ zlib zlib-devel openssl-devel openssl pcre-devel curl-devel
    wget -c $NGINX_URL
    tar -xzvf $NGINX_SRC
    cd $NGINX_SOFT
    ./configure --prefix=$NGINX_DIR 
    make  
    make install
    systemctl stop firewalld.service
    setenforce 0
    /usr/local/nginx/sbin/nginx
}
#####################################################
MYSQL_SOFT="mysql-5.5.61"
MYSQL_SRC="${MYSQL_SOFT}.tar.gz"
MYSQL_DIR="/usr/local/mysql5"
MYSQL_URL="http://mirrors.163.com/mysql/Downloads/MySQL-5.5/mysql-5.5.61.tar.gz"
MYSQL_DATA="/data/mysql"

auto_install_mysql(){
    if [ -d /usr/local/mysql5 ];then
        break
    fi
    cd $HOME
    yum -y install cmake gcc-c++  ncurses-devel bison-devel cmake nucrses
    wget -c $MYSQL_URL
    tar -xzvf $MYSQL_SRC
    cd $MYSQL_SOFT
    mkdir -p $MYSQL_DATA
    touch /tmp/mysql.sock
    cmake . -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
    -DMYSQL_DATADIR=$MYSQL_DATA \
    -DSYSCONFDIR=/etc \
    -DMYSQL_USER=mysql \
    -DMYSQL_TCP_PORT=3306 \
    -DWITH_XTRADB_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STOAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DENABLE_LOCAL_INFILE=1 \
    -DWITH_EXTRA_CHARSES=1 \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DEXTRA_CHARSETS=all \
    -DWITH_BIG_TABLES=1 \
    -DWITH_DEGUG=0
    
    useradd mysql
    make && make install 
    cd $MYSQL_DIR
    chown -R mysql:mysql .
    \cp support-files/my-large.cnf
    \cp support-files/mysql.server /etc/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    chkconfig --add mysql 
    chkconfig --level 35 mysqld on
     
    cd $MYSQL_DIR
    ./scripts/mysql_install_db --user=mysql --datadir=${MYSQL_DATA} --basedir=${MYSQL_DIR}
    ln -s $MYSQL_DIR/bin/* /usr/bin/
    service mysqld start    
}
####################################################
PHP_VAR="5.6.28"
PHP_SOFT="php-${PHP_VAR}"
PHP_SRC="${PHP_SOFT}.tar.bz2"
PHP_URL="http://mirrors.sohu.com/php/$PHP_SRC"
PHP_DIR="/usr/local/php5"
auto_install_php(){
    if [ -d /usr/local/php ];then
        break
    fi
    cd $HOME
    yum -y install gcc-c++ gd libjpeg-devel libjpeg libpng libpng-devel libxml2 libxml2-devel freetype freetype-devel bison bison-devel 
    wget -c $PHP_URL
    tar -xjvf $PHP_SRC
    cd $PHP_SOFT
./configure  \
--prefix=${PHP_DIR} \
--enable-fpm \
--enable-debug \
--enable-mbstring \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-curl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-config-file-path=${PHP_DIR}/etc 
    make
    make install
    \cp php.ini-development $PHP_DIR/etc/php.ini
    \cp $PHP_DIR/etc/php-fpm.conf.default $PHP_DIR/etc/php-fpm.conf
    \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod 755 /etc/init.d/php-fpm
    chkconfig --add php-fpm
    service php-fpm start
}
TEMP=$(mktemp -t test.XXXXXX)
while [ 1 ]
do
    dialog --menu "安装LNMP服务" 20 30 10 1 "安装Nginx" 2 "安装MySQL" 3 "安装PHP" 0 "退出" 2>$TEMP
    if [ $? -eq 1 ];then
        break
    fi
    selection=$(cat $TEMP)
    case $selection in
        1)
        auto_install_nginx
        ;;
        2)
        auto_install_mysql
        ;;
        3)
        auto_install_php
        ;;
        0)
        break
        ;;
        *)
        dialog --msgbox "选择错误,请重选" 15 30
        esac
done
rm -r $TEMP 2> /dev/null

 

posted @ 2019-07-29 15:04  IMSCZ  阅读(216)  评论(0编辑  收藏  举报