lnmp mysql 脚本_lnmp 一键搭建脚本

#!/bin/bash

#########################################################

#by:kingle #

#use: fast lnmp #

#version:1.0 #

#php:php-7.2.8 #

#nginx:1.15.1 #

#mysql:5.6.41 #

#cenos:2.6.32-754.2.1.el6.x86_64 #

#########################################################

dir=/root/opt

nginx_install_dir="/lnmp/nginx"mysql_install_dir="/lnmp/mysql"php_install_dir="/lnmp/php"nginx_name="nginx-1.15.1.tar.gz"mysql_name="mysql-5.6.41.tar.gz"php_name="php-7.2.8.tar.gz"[-f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1

#安装nginx

install_nginx(){#跟新源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

#安装依赖包

yum install-y pcre pcre-devel openssl openssl-devel gcc make gcc-c++[-e $dir ] && cd $dir

if [ -f $nginx_name]

then

echo'nginx need have'

#t解压文件

tar zxf $nginx_name && cd nginx-1.15.1

#添加僵尸用户

useradd nginx -s /sbin/nologin -M#编译安装

./configure --user=nginx --group=nginx --prefix=/lnmp/nginx-1.15.1/ --with-http_stub_status_module --with-http_ssl_module

[ $(echo $?) -eq 0 ] && make &&make install

[ $(echo $?) -eq 0 ] && echo "nginx install success...."

#创建软链接

ln -s /lnmp/nginx-1.15.1 /lnmp/nginx

fi

}#开启脚本

start_nginx(){

service iptables stop

setenforce0

/lnmp/nginx/sbin/nginx -c /lnmp/nginx-1.15.1//conf/nginx.conf$nginx_install_dir/sbin/nginx -tif [ $(echo $?) -eq 0]

then$nginx_install_dir/sbin/nginx -s reloadif [ $(netstat -lutnp|grep 80|wc -l) -eq 1]

then

action"nginx success..." /bin/trueelseecho"nginx error!"fi

fi

}

install_mysql(){

yum install-y ncurses-devel automake autoconf bison libtool-ltdl-devel

[-e $dir ] && cd $dir

if [ -f $mysql_name]

then

yum install cmake-y

tar zxvf$mysql_name

if [ ! -d $mysql_install_dir]

thenmkdir -p $mysql_install_dirfi

groupadd mysql

useradd-s /sbin/nologin -g mysql -M mysqlmkdir -p /lnmp/mysql-5.6.41/data

cd$dir/mysql-5.6.41cmake-DCMAKE_INSTALL_PREFIX=/lnmp/mysql-5.6.41 -DMYSQL_DATADIR=/lnmp/mysql-5.6.41/data -DMYSQL_UNIX_ADDR=/lnmp/mysql-5.6.41/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0make&&make install

ln-s /lnmp/mysql-5.6.41/ /lnmp/mysql/lnmp/mysql-5.6.41/scripts/mysql_install_db --user=mysql --basedir=/lnmp/mysql-5.6.41 --datadir=/lnmp/mysql-5.6.41/data --user=mysql#授权

chown -R mysql:mysql /lnmp/mysql-5.6.41/

#创建目录,默认不会创建,但是启动会报错

mkdir /lnmp/mysql/tmp

[ $(echo $?) -eq 0 ] && \cp -f /lnmp/mysql-5.6.41/support-files/my*.cnf /etc/my.cnf

cp/lnmp/mysql-5.6.41/support-files/mysql.server /etc/init.d/mysqld#加权限

chmod +x /etc/init.d/mysqld#自启

chkconfig --add mysqld

chkconfig mysqld on#加环境

PATH=$PATH:/lnmp/mysql-5.6.41/bin/

#添加环境

echo "export PATH=$PATH:/lnmp/mysql/bin/" >>/etc/profile

source/etc/profile

fi

}#启动函数

start_mysql(){/etc/init.d/mysqld startif [ $(netstat -lutnp|grep 3306|wc -l) -eq 1]

then

action"mysql success" /bin/trueelseecho"mysql error!"fi

}#安装php

install_php(){

yum install zlib-devel openssl-devel openssl libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel libmcrypt-devel mcrypt mhash -y

[-e $dir ] && cd $dir

if [ -f $php_name]

then

tar zxf$php_name && cd php-7.2.8echo"Please witing loding................................................................"

#编译安装

./configure --prefix=/lnmp/php7.2.8 --with-mysql=/lnmp/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp

[ $(echo $?) -eq 0 ] && ln -s /lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/ && touch ext/phar/phar.phar

make>> /dev/null 2>&1make install

ln-s /lnmp/php7.2.8 /lnmp/php

cp./php.ini-production /lnmp/php/lib/php.ini

cp/lnmp/php/etc/php-fpm.conf.default /lnmp/php/etc/php-fpm.conf

cp/lnmp/php/etc/php-fpm.d/www.conf.default /lnmp/php/etc/php-fpm.d/www.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm#授予权限最好是700

chmod +x /etc/init.d/php-fpm

PATH=$PATH:/lnmp/php/bin/echo"export PATH=$PATH:/lnmp/php/bin/" >>/etc/profile

source/etc/profile

chkconfig--add php-fpm

chkconfig php-fpm on

fi

}#启动函数

start_phpfpm(){/etc/init.d/php-fpm startif [ $(netstat -lutnp|grep 9000|wc -l) -eq 1]

then

action"php-fpm success" /bin/trueelseecho"php-fpm error"fi

}

main(){

install_nginxsleep 3install_mysqlsleep 3install_php

start_nginxsleep 2start_mysqlsleep 2start_phpfpm

}

main

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值