#!/bin/bash
#########################################################
#by:chenhao #
#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
#安裝依賴(lài)包
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...."
#創(chuàng)建軟鏈接
ln -s /lnmp/nginx-1.15.1 /lnmp/nginx
fi
}
#開(kāi)啟腳本
start_nginx(){
service iptables stop
setenforce 0
/lnmp/nginx/sbin/nginx -c /lnmp/nginx-1.15.1//conf/nginx.conf
$nginx_install_dir/sbin/nginx -t
if [ $(echo $?) -eq 0 ]
then
$nginx_install_dir/sbin/nginx -s reload
if [ $(netstat -lutnp|grep 80|wc -l) -eq 1 ]
then
action "nginx success..." /bin/true
else
echo "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 ]
then
mkdir -p $mysql_install_dir
fi
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
mkdir -p /lnmp/mysql-5.6.41/data
cd $dir/mysql-5.6.41
cmake -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=0
make && 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
#授權(quán)
chown -R mysql:mysql /lnmp/mysql-5.6.41/
#創(chuàng)建目錄,默認(rèn)不會(huì)創(chuàng)建,但是啟動(dòng)會(huì)報(bào)錯(cuò)
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
# 加權(quán)限
chmod +x /etc/init.d/mysqld
# 自啟
chkconfig --add mysqld
chkconfig mysqld on
# 加環(huán)境
PATH=$PATH:/lnmp/mysql-5.6.41/bin/
#添加環(huán)境
echo "export PATH=$PATH:/lnmp/mysql/bin/" >>/etc/profile
source /etc/profile
fi
}
#啟動(dòng)函數(shù)
start_mysql(){
/etc/init.d/mysqld start
if [ $(netstat -lutnp|grep 3306|wc -l) -eq 1 ]
then
action "mysql success" /bin/true
else
echo "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.8
echo "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>&1
make 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
#授予權(quán)限最好是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
}
# 啟動(dòng)函數(shù)
start_phpfpm(){
/etc/init.d/php-fpm start
if [ $(netstat -lutnp|grep 9000|wc -l) -eq 1 ]
then
action "php-fpm success" /bin/true
else
echo "php-fpm error"
fi
}
main(){
install_nginx
sleep 3
install_mysql
sleep 3
install_php
start_nginx
sleep 2
start_mysql
sleep 2
start_phpfpm
}
main