lnmp mysql 脚本_Centos7下一键安装LNMP环境脚本

#!/bin/bash

read -p 'The installation process takes about 5 to 10 minutes, depending on the performance of your server. To confirm the installation of the lnmp environment, press the Enter key.'

function red(){

echo -e "\t\033[31m$1\033[0m"

}

function green(){

echo -e "\t\033[32m$1\033[0m"

}

yum clean all &> /dev/null

yum -y install epel-release &> /dev/null

while :

do

cat /etc/ld.so.conf | grep lib64 &> /dev/null

if [ $? -ne 0 ];then

echo '''/usr/local/lib

/usr/local/lib64

/usr/lib

/usr/lib64''' >> /etc/ld.so.conf

ldconfig -v &> /dev/null

fi

libzip_stat=`rpm -qa |grep libzip &> /dev/null && echo 'yes' || echo 'no'`

mariadb_stat=`rpm -qa |grep mariadb &> /dev/null && echo 'yes' || echo 'no'`

yum_stat=`yum repolist |tail -1 |awk '{print $2}'`

if [ $libzip_stat = yes ];then

rpm -e --nodeps `rpm -qa | grep libzip`

continue

elif [ $mariadb_stat = yes ];then

rpm -e --nodeps `rpm -qa | grep mariadb`

continue

elif [ $yum_stat = 0 ];then

red 'Yum error,Check your yum source!!!(maybe network,yum configure...)'

exit

else

echo -e "\033[05m\033[35mStart testing the environment...\033[0m"

echo -e "\t\033[32mStart testing the environment... [ OK ]\033[0m"

break

fi

done

function need_rpm()

{

yum -y install make

yum -y install gmake

yum -y install gcc

yum -y install gcc-c++

yum -y install wget

yum -y install openssl

yum -y install openssl-devel

yum -y install curl

yum -y install curl-devel

yum -y install libjpeg

yum -y install libjpeg-devel

yum -y install libpng

yum -y install libpng-devel

yum -y install freetype

yum -y install freetype-devel

yum -y install pcre

yum -y install pcre-devel

yum -y install libxslt

yum -y install libxslt-devel

yum -y install bzip2

yum -y install bzip2-devel

yum -y install libxml2

yum -y install libxml2-devel

}

function down_app()

{

wget -P /lnmp/ https://nginx.org/download/nginx-1.14.2.tar.gz &> /dev/null && echo -e "\t\033[32mNginx Download completed!\033[0m" || echo -e "\t\033[31mNginx Download Faild!\033[0m"

wget -P /lnmp/ http://cn2.php.net/get/php-7.3.0.tar.gz/from/this/mirror &> /dev/null && echo -e "\t\033[32mPHP Download completed!\033[0m" || echo -e "\t\033[31mPHP Download Faild!\033[0m"

wget -P /lnmp/ https://nih.at/libzip/libzip-1.2.0.tar.gz &> /dev/null && echo -e "\t\033[32mLibzip Download completed!\033[0m" || echo -e "\t\033[31mLibzip Download Faild!\033[0m"

wget -P /lnmp/ https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz &> /dev/null && green 'Mysql Download completed!' || red 'Mysql Download Faild!'

}

function nginx_install_configure()

{

id nginx &> /dev/null && userdel nginx

useradd -M -s /sbin/nologin nginx &>/dev/null

cd /lnmp / && tar -xf nginx-1.14.2.tar.gz && cd nginx-1.14.2/

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream &>> /tmp/.nginx.configure.log

if [ $? -ne 0 ];then

red 'Nginx configure error!!! See /tmp/.nginx.configure.log'

exit

else

echo ''' Configuration summary:

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/sbin/nginx"

nginx modules path: "/usr/local/nginx/modules"

nginx configuration prefix: "/usr/local/nginx/conf"

nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

nginx pid file: "/usr/local/nginx/logs/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

'''

fi

make &>> /tmp/.nginx.make.log

if [ $? -ne 0 ];then

red 'Nginx make error!!! See /tmp/.nginx.make.log'

fi

make install &>> /tmp/.nginx.makeinstall.log

if [ $? -ne 0 ];then

red 'Nginx make install error!!! See /tmp/.nginx.makeinstall.log'

fi

cd /usr/local/nginx/

cp -p conf/nginx.conf conf/nginx.conf.bak

sed -i '65,68s/#//g' conf/nginx.conf

sed -i '70,71s/#//g' conf/nginx.conf

sed -i 's/fastcgi_params/fastcgi.conf/g' conf/nginx.conf

green 'Nginx installed and configure successful.'

/usr/local/nginx/sbin/nginx -t &> /dev/null && /usr/local/nginx/sbin/nginx

netstat -nutlp |grep 80 &> /dev/null

if [ $? -ne 0 ];then

red 'Nginx start error!!!'

else

green 'Nginx started.'

fi

}

function mysql_install_configure()

{

id mysql &> /dev/null && userdel mysql

useradd -M -s /sbin/nologin mysql &> /dev/null

cd /lnmp/

tar -xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

cd /usr/local/mysql/

mkdir data && chown -R mysql:mysql /usr/local/mysql/

./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize &>> /tmp/.mysql.initialize.log

if [ $? -ne 0 ];then

red 'Mysql initialize error!!! See /tmp/.mysql.initialize.log'

else

pass=`tail -1 /tmp/.mysql.initialize.log | awk '{print $NF}'`

green 'Mysql initialize successful.)'

green "Initial password: $pass"

echo ''' Configuration summary:

Mysql path prefix: "/usr/local/mysql"

Mysql data path: "/usr/local/mysql/data"

'''

fi

./support-files/mysql.server start &>> /tmp/.mysql.start.log

netstat -nutlp | grep mysql &> /dev/null

if [ $? -ne 0 ];then

red 'Mysql start error!!! See /tmp/.mysql.start.log'

else

green 'Mysql started.'

fi

}

function libzip_install_configure()

{

cd /lnmp/

tar -xf libzip-1.2.0.tar.gz

cd libzip-1.2.0

./configure &> /dev/null

make &> /dev/null

make install &> /dev/null

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

green 'Libzip installed.'

}

function php_install_configure()

{

cd /lnmp/

tar -xf mirror

cd php-7.3.0/

while :

do

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip &>> /tmp/.php.configure.log

if [ $? -ne 0 ];then

red 'PHP configure error!!! See /tmp/.php.configure.log'

exit

else

green 'PHP configure is ok'

while :

do

make &>> /tmp/.php.make.log

if [ $? -ne 0 ];then

red 'PHP make error!!! See /tmp/.php.make.log'

exit

else

green 'PHP make is ok'

while :

do

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

make install &>> /tmp/.php.makeinstall.log

if [ $? -ne 0 ];then

red 'PHP makeinstall error!!! See /tmp/.php.makeinstall.log'

exit

else

green 'PHP Installed.'

break

fi

done

break

fi

done

break

fi

done

cp php.ini-development /usr/local/php/lib/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp sapi/fpm/php-fpm /usr/local/bin

sed -i 's/; cgi.fix_pathinfo=1/ cgi.fix_pathinfo=0/g' /usr/local/php/lib/php.ini

groupadd www-data &> /dev/null

useradd -g www-data www-data &> /dev/null

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

sed -i 's/user = nobody/user = www-data/g' /usr/local/php/etc/php-fpm.d/www.conf

sed -i 's/group = nobody/group = www-data/g' /usr/local/php/etc/php-fpm.d/www.conf

/usr/local/bin/php-fpm

netstat -nutlp |grep 9000

if [ $? -ne 0 ];then

red 'PHP-FPM start error!!!'

else

green 'PHP-FPM started'

fi

}

#start execute

echo -e "\033[05m\033[35mInstall dependent software...\033[0m"

need_rpm &> /dev/null

green "Install dependent software...\t\t[ OK ]"

echo -e "\033[05m\033[35mStart download apps...\033[0m"

down_app

echo -e "\033[05m\033[35mStart install nginx and configure it...\033[0m"

nginx_install_configure

echo -e "\033[05m\033[35mStart install mysql and configure it...\033[0m"

mysql_install_configure

echo -e "\033[05m\033[35mStart install Libzip and configure it...\033[0m"

libzip_install_configure

echo -e "\033[05m\033[35mStart install php and configure it...\033[0m"

php_install_configure

/usr/local/nginx/sbin/nignx -s stop &> /dev/null && /usr/local/nginx/sbin/nginx

echo '''

phpinfo();

?>''' >> /usr/local/nginx/html/test.php

curl http://127.0.0.1/test.php

if [ $? -eq '0'];then

green 'LNMP is ok !!!'

else

red 'Access PHP Faild!!!'

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基本的 LNMP 编译安装脚本示例,适用于 CentOS 7: ```bash #!/bin/bash # 安装必要的依赖 yum -y install epel-release yum -y install wget gcc pcre-devel openssl-devel # 下载并编译安装 Nginx NGINX_VERSION=1.19.6 wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz tar -zxvf nginx-${NGINX_VERSION}.tar.gz cd nginx-${NGINX_VERSION} ./configure --prefix=/usr/local/nginx --with-http_ssl_module make && make install # 下载并编译安装 MariaDB MARIADB_VERSION=10.5.8 wget https://downloads.mariadb.org/f/mariadb-${MARIADB_VERSION}/source/mariadb-${MARIADB_VERSION}.tar.gz tar -zxvf mariadb-${MARIADB_VERSION}.tar.gz cd mariadb-${MARIADB_VERSION} cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DENABLE_SSL=1 make && make install # 下载并编译安装 PHP PHP_VERSION=7.4.15 wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz tar -zxvf php-${PHP_VERSION}.tar.gz cd php-${PHP_VERSION} ./configure --prefix=/usr/local/php --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-openssl --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mbstring --enable-sockets --enable-opcache --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir make && make install # 配置 Nginx、MariaDB 和 PHP # 这里省略具体的配置步骤,可以根据需要自行配置 # 启动服务 /usr/local/nginx/sbin/nginx /usr/local/mariadb/bin/mysqld_safe & /usr/local/php/sbin/php-fpm # 设置开机自启 echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local echo "/usr/local/mariadb/bin/mysqld_safe &" >> /etc/rc.local echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local chmod +x /etc/rc.d/rc.local # 完成安装 echo "LNMP 安装成功!" ``` 请注意,此脚本仅用于示例目的,实际使用时可能需要根据自己的需求进行适当的修改和配置。另外,建议在执行脚本之前备份重要的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值