一键安装LNMP

#!/bin/bash
#2020年3月1日
#auto_install_lnmp.
#by fly
################################
NGX_VER="$1"
NGX_SOFT="nginx-${1}"
NGX_YUM="yum install -y"
NGX_DIR="/usr/local/nginx"
NGX_SRC="nginx-${1}.tar.gz"
NGX_URL="http://nginx.org/download"
NGX_ASGC="--user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module"

#安装nginx
function install_nginx(){
	$NGX_YUM gcc-c++ pcre pcre-devel zlib zlib-devel
	$NGX_YUM wget make openssl openssl-devel net-tools
	cd /usr/src
	wget -c $NGX_URL/$NGX_SRC
	tar -zxvf $NGX_SRC
	cd $NGX_SOFT
	useradd nginx
	./configure --prefix=$NGX_DIR $NGX_ASGC
	make && make install
	$NGX_DIR/sbin/nginx -t 
	$NGX_DIR/sbin/nginx 
	#setenforce 0
	systemctl stop firewalld.service
	echo "$NGX_DIR/sbin/nginx" >>/etc/rc.local
	ps -ef|grep nginx
	netstat -nutlp|grep 80
	echo -e "33[32m nginx安装成功. 33[0m"
	$NGX_DIR/sbin/nginx -v
	exit
}
SQL_USER="mysql"
SQL_DB="/data/mysql"
SQL_SOFT="mysql-5.5.60"
SQL_YUM="yum install -y"
SQL_SER="/etc/init.d/mysqld"
SQL_DIR="/usr/local/mysql55"
SQL_SRC="mysql-5.5.60.tar.gz"
SQL_ASGC="${SQL_DIR}/scripts/mysql_install_db"
SQL_URL="http://mirrors.sohu.com/mysql/MySQL-5.5"

#安装mysql
function install_mysql(){
	$SQL_YUM ncurses ncurses-devel cmake make
	cd /usr/src
	wget -c $SQL_URL/$SQL_SRC
	tar zxvf $SQL_SRC
	cd $SQL_SOFT
	cmake  . -DCMAKE_INSTALL_PREFIX=$SQL_DIR 
	-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
	-DMYSQL_DATADIR=$SQL_DB 
	-DSYSCONFDIR=/etc 
	-DMYSQL_USER=$SQL_USER 
	-DMYSQL_TCP_PORT=3306 
	-DWITH_XTRADB_STORAGE_ENGINE=1 
	-DWITH_INNOBASE_STORAGE_ENGINE=1 
	-DWITH_PARTITION_STORAGE_ENGINE=1 
	-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
	-DWITH_MYISAM_STORAGE_ENGINE=1 
	-DWITH_READLINE=1 
	-DENABLED_LOCAL_INFILE=1 
	-DWITH_EXTRA_CHARSETS=1 
	-DDEFAULT_CHARSET=utf8 
	-DDEFAULT_COLLATION=utf8_general_ci 
	-DEXTRA_CHARSETS=all 
	-DWITH_BIG_TABLES=1 
	-DWITH_DEBUG=0
	make && make install
	cd $SQL_DIR/
	cp support-files/my-large.cnf /etc/my.cnf
	cp support-files/mysql.server $SQL_SER
	chmod +x $SQL_SER
	chkconfig --add mysqld
	chkconfig --level 35 mysqld on
	mkdir  -p  $SQL_DB
	useradd  $SQL_USER
	$SQL_ASGC --user=${SQL_USER} --datadir=${SQL_DB}/ --basedir=${SQL_DIR}
	ln  -s  $SQL_DIR/bin/* /usr/bin/
	service  mysqld  restart
	ps -ef|grep mysqld
	netstat -nutlp|grep 3306
	echo -e "33[32m MySQL安装成功. 33[0m"
	exit
}
#PHP_VER="$1"
PHP_SOFT="php-5.6.22" PHP_YUM="yum install -y" PHP_SRC="php-$5.6.22.tar.gz" PHP_DIR="/usr/local/php" PHP_SER="/etc/init.d/php-fpm" PHP_URL="http://mirrors.sohu.com/php" PHP_ASGC="--prefix=/usr/local/php --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysql=/usr/local/mysql55 --with-mysqli=/usr/local/mysql55/bin/mysql_config --with-gettext --enable-mbstring --enable-bcmath --with-libxml-dir --enable-sockets --with-curl --with-zlib --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir--with-config-file-path=/usr/local/php5/etc --with-zlib-dir " #安装PHP function install_php(){ $PHP_YUM freetype freetype-devel libxml2 libxml2-devel $PHP_YUM gd curl curl-devel libjpeg libjpeg-devel libpeg libpeg-devel cd /usr/src wget -c $PHP_URL/$PHP_SRC tar xf $PHP_SRC cd $PHP_SOFT ./configure $PHP_ASGC 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 $PHP_SER chmod o+x $PHP_SER $PHP_SER start ps -ef|grep php-fpm netstat -nutlp|grep 9000 echo -e "33[32m php安装成功. 33[0m" exit } #LNMP_CONFIG整合 function lnmp_config(){ echo " worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }" >$NGX_DIR/conf/nginx.conf echo " <?php phpinfo(); ?>">$NGX_DIR/html/index.php sed -i '/user/s/nobody/nginx/g;/group/s/nobody/nginx/g' /usr/local/php5/etc/php-fpm.conf $NGX_DIR/sbin/nginx -s reload $PHP_SER restart cat $NGX_DIR/conf/nginx.conf cat $NGX_SIR/html/index.php echo -e "33[32m lnmp_config_web 整合ok!!! 33[0m" exit } PS3=`echo -e "33[32m/usr/bin/ auto_install_lnmp.sh 1)|2)|3)|4)|5)| 版本:33[0m"` select i in nginx_install mysql_install php_install lnmp_config_web exit do case $i in nginx_install ) install_nginx ;; mysql_install ) install_mysql ;; php_install ) install_php ;; lnmp_config_web ) lnmp_config ;; exit ) ;; * ) echo -e "33[33m------------------------33[0m" echo -e "33[32m1)安装nginx. 2)安装mysql.33[0m" echo -e "33[32m3)安装php. 4)lnmp-web整合33[0m" echo -e "33[33m/usr/bin/ auto_install_lnmp.sh 1)|2)|3)|4) :33[0m" exit ;; esac done

  

原文地址:https://www.cnblogs.com/fengyuanfei/p/13797632.html