1.准备工作,下载源码包

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
wget http://cn2.php.net/distributions/php-5.6.27.tar.gz

wget http://nginx.org/download/nginx-1.12.2.tar.gz

2.一键安装LNMP脚本

#!/bin/bash
# DATE:2018-10-17
#this is a lnmp-install
 
# The Nginx service is being installed
ROOT_ID=0
ML=`pwd`
NGINX_ML=${ML}/nginx-1.12.2
PML=${ML}/php-5.6.27
QD=`netstat -anpt | grep 80 | awk '{print $7}' | cut -d "/" -f2 | cut -d ":" -f1`
ADDR=`ip a | grep ens33$ | awk '{print $2}' | cut -d "/" -f1`
MMM=`netstat -anput | grep mysqld | awk '{print $4}' | cut -d ":" -f4`
MAR=`rpm -qa | grep mariadb`
cd $ML && {
wget http://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
mv Centos-7.repo /etc/yum.repos.d/Centos-Base.repo
yum clean all &> /dev/null
yum makecache &> /dev/null
}
 
if [ $? -eq 0 ]
    then
          echo "Yum源更新完毕,开始安装!!!"
    else
        echo "Yum源error"
        exit 1
fi
echo "Yum源配置成功"
 
if [ "$UID" -eq "$ROOT_ID" ]
        then
               echo "root用户运行中" && systemctl stop firewalld && yum install -y gcc gcc-c++  pcre-devel zlib-devel openssl-devel &> /dev/null
        else
               echo "请使用Root用户运行"
               exit 1
fi
echo "依赖包安装完成!"
cd $ML || {
        echo "进入目录失败!!!"
        exit 1
}
 
#wget http://nginx.org/download/nginx-1.12.2.tar.gz &> /dev/null && {
#tar zxf nginx-1.12.2.tar.gz && groupadd nginx && useradd -g nginx nginx -s /sbin/nologin
#}
tar zxf nginx-1.12.2.tar.gz && groupadd nginx && useradd -g nginx nginx -s /sbin/nologin
#echo "Nginx包下载成功"
cd $NGINX_ML && {
    ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx &> /dev/null && make &> /dev/null && make install &> /dev/null 
}
 
if [ $? -eq "0" ]
        then
               ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin ;nginx && echo "Nginx启动成功,请访问http://$ADDR:80"
        else
              echo "Nginx启动失败!!!"
              exit 1
fi
 
 
#Start installing MySQL5.7!
#echo "开始下载MySQL二进制安装包,请稍等..."
if [ -z "$MAR" ]
                then
                        echo "开始安装MySQL"
fi
if [ -n "$MAR" ]
               then
                        rpm -e mariadb-libs --nodeps && echo "卸载mariadb成功!正式安装MySQL"
fi
 
cd $ML || {
    echo "进入目录失败!!!"
    exit 1
}
 
#wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz &> /dev/null && {
#wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz && {
tar zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz  && mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql && cd /usr/local/mysql/ && mkdir data  && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile && source /etc/profile && groupadd mysql && useradd -r -g mysql -s /bin/false mysql
#}
cat << EOF >/etc/my.cnf
[client]  
socket=/usr/local/mysql/data/mysql.sock  
[mysqld]  
basedir=/usr/local/mysql  
datadir=/usr/local/mysql/data  
pid-file=/usr/local/mysql/data/mysqld.pid  
socket=/usr/local/mysql/data/mysql.sock  
log_error=/usr/local/mysql/data/mysql.err
EOF
if [ ! -d /etc/my.cnf ]
                then
                        chmod 750 data/ && chown -R mysql:mysql .  && bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --initialize-insecure && cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && service mysqld start &> /dev/null
                else
                         echo "错误!!!"
fi
if [ $? -eq "0" ]
    then
        echo "MySQL安装完成!"
    else
        echo "MySQL安装失败!!!"
        exit 1
fi
#PHP install sccessy
yum -y install libxml2-devel libcurl-devel openssl-devel bzip2-devel &> /dev/null
if [ $? -eq 0 ]
        then
                echo "依赖包安装成功!!!"
        else
                echo "依赖包安装失败!!!"
fi
cd $ML || {
        echo "进入目录失败!!!"
        exit 1
}
#wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz &> /dev/null  && {
tar zxf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7/ && ./configure --prefix=/usr/local/libmcrypt &> /dev/null && make &> /dev/null && make install &> /dev/null
#}
if [ $? -eq 0 ]
        then
                echo "Libmcrypt安装成功!"
        else
                echo "Libmcrypt-ERROR!"
        exit 1
fi
# PHP install
cd $ML || {
        echo "进入目录失败!!!"
        exit 1
}
#wget http://cn2.php.net/distributions/php-5.6.27.tar.gz &> /dev/null && {
tar zxf php-5.6.27.tar.gz && cd php-5.6.27/ &&  ./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts  &> /dev/null
#}
if [ $? -eq 0 ]
            then
                 make &> /dev/null  && make install &> /dev/null  &&  echo "PHP编译安装成功,正在配置请稍等...."
            else
                 echo "PHP安装失败"
fi
cd $PML || {
                echo "进入目录失败!!!"
                exit 1
}
cp php.ini-production /etc/php.ini && {
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on
}
if [ $? -eq 0 ]
                        then
                                cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf && echo "复制主配置成功"
                        else
                                echo "PHP权限失败,请重试!"
fi
if [ ! -d /usr/local/php5.6/etc/php-fpm.conf ]
        then
                sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php5.6/etc/php-fpm.conf
                sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9000/g' /usr/local/php5.6/etc/php-fpm.conf
                sed -i 's/pm.max_children = 5/pm.max_children = 300/g' /usr/local/php5.6/etc/php-fpm.conf
                sed -i 's/pm.start_servers = 2/pm.start_servers = 20/g' /usr/local/php5.6/etc/php-fpm.conf
                sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 20/g' /usr/local/php5.6/etc/php-fpm.conf
                sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 100/g' /usr/local/php5.6/etc/php-fpm.conf
        else
                echo "NONONO"
fi
if [ $? -eq 0 ]
                        then
                                systemctl start php-fpm && echo "PHP启动成功"
                        else
                                echo "启动PHP失败"
fi
#配置nginx解析php
if [ ! -d /usr/local/nginx/conf/nginx.conf ]
        then
               sed -i 's/index  index.html index.htm;/index  index.php index.html index.htm;/g' /usr/local/nginx/conf/nginx.conf
               sed -i 's/#    root           html;/    root           html;/g' /usr/local/nginx/conf/nginx.conf
               sed -i 's/#    fastcgi_pass   127.0.0.1:9000;/    fastcgi_pass   127.0.0.1:9000;/g' /usr/local/nginx/conf/nginx.conf
               sed -i 's/#    fastcgi_index  index.php;/    fastcgi_index  index.php;/g' /usr/local/nginx/conf/nginx.conf
               sed -i 's*#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;*    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;*g' /usr/local/nginx/conf/nginx.conf
               sed -i 's/#    include        fastcgi_params;/    include        fastcgi.conf;/g' /usr/local/nginx/conf/nginx.conf
               sed -i '71d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;70a}' /usr/local/nginx/conf/nginx.conf
               sed -i '65d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;64alocation ~ \\.php$ {' /usr/local/nginx/conf/nginx.conf
        else
               echo "解析PHP失败!!!"
fi
touch /usr/local/nginx/html/phptest.php
cat << EOF >/usr/local/nginx/html/phptest.php
<?php
phpinfo();
?>
EOF
if [ ! -d /usr/local/nginx/html/phptest.php ]
    then
        nginx -s reload && systemctl restart php-fpm
    else
        echo "测试目录文件失败"
fi
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo  &> /dev/null && yum install -y sl &> /dev/null
sl
if [ $? -eq 0 ]
        then
                echo "LNMP安装成功,请您访问http://$ADDR/phptest.php"
        else
                echo "安装失败"
fi
#############################################LNMP installed successfully!!!#####################################################

一键安装LNMP(适合centos7)的更多相关文章

  1. Centos6.5中 一键安装LNMP 安装Yii2.0 手工配置

    1.一键安装LNMP cd /usr wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz tar zxf lnmp1.-full.tar.gz ...

  2. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  3. Linux一键安装LNMP环境

    Linux一键安装LNMP环境 官方地址:https://lnmp.org/. 参考安装步骤:https://lnmp.org/install.html. 一键安装可以选择mysql版本.php版本, ...

  4. Linux安装swoole拓展 (一键安装lnmp后安装可用完美)

    一键安装lnmp后安装可用完美 swoole(一键安装完lnmp重启下,之前出现502一直解决不了,不清楚啥情况) 找到对应php版本,在lnmp文件夹的src 1.安装swoole cd /usr/ ...

  5. Vultr VPS建站攻略 – 一键安装LNMP无面板高性能WEB环境

    在"Vultr VPS建站攻略 - 一键安装宝塔面板架设LNMP/LAMP Web环境"文章中,VULTR中文网分享到我们常用的可视化面板宝塔面板安装在VULTR VPS主机中建站 ...

  6. 一键安装Lnmp教程

    LNMP一键安装包 系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP ...

  7. 【Linux】Centos6.8下一键安装Lnmp/Lamp环境

    [下载一键安装软件包] 百度云地址:https://pan.baidu.com/s/1TZqGKtE-46gxW96Ptfp4gA 网址:https://lnmp.org/ [步骤] 通过第三方远程工 ...

  8. 一键安装LNMP/LAMP

    安装步骤:1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:yum install screen安装  screen screen -S lnmp创建一个名字为lnmp的会话 2. ...

  9. 一键安装 lnmp/lamp/lanmp

    1.使用putty或类似的SSH工具登陆VPS或服务器 # screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum install scr ...

随机推荐

  1. codeforces 391E2 (【Codeforces Rockethon 2014】E2)

    题目:http://codeforces.com/problemset/problem/391/E2    题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树 ...

  2. double x = 10 ,y = 0;y = x % 2; 这个表达式正确吗?

    The remainder function and % operator. 以下这段代码过不了编译的(gcc) #include <stdio.h> #include <fenv. ...

  3. 利用keepalive和timeout来推断死连接

    问题是这样出现的. 操作:client正在向服务端请求数据的时候,突然拔掉client的网线. 现象:client死等.服务端socket一直存在. 在网上搜索后,须要设置KEEPALIVE属性. 于 ...

  4. Codeforces Round #390 (Div. 2) D. Fedor and coupons

    题意:题目简化了就是要给你n个区间,然后让你选出k个区间  使得这k个区间有公共交集:问这个公共交集最大能是多少,并且输出所选的k个区间.如果有多组答案,则输出任意一种.   这题是用优先队列来处理区 ...

  5. 本地项目上传虚拟机的gitlab

    前提:在虚拟机安装了gitlab服务,并且本机可以访问到虚拟机的gitlab 自己本机项目上传到gitlab 1.先在gitlab上建立项目 拷贝项目地址: http://192.168.1.105/ ...

  6. Lightoj 1235 - Coin Change (IV) 【二分】

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1235 题意: 有N个硬币(N<=18).问是否能在每一个硬币使用不超过两 ...

  7. zoj 3822 Domination 概率dp 2014牡丹江站D题

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  8. ios 得用代理反向传值

    应用场景:有时时候从界面A跳转到界面B,界面B在返回的时候须要将处理的结果传递给A. 实现思路:1,定义一个负责传值的协义,界面A拥有该协义属性,并实现该协义中的方法 2.界面B也拥有该协义属性(代理 ...

  9. Android+Jquery Mobile学习系列(2)-HTML5/Jquery Mobile基础

    本章介绍两个关键字[HTML5]和[Jquery Mobile],简单说这两者的关系是:HTML5作为主体,Jquery Mobile在HTML5的基础上对其进行了优化.装饰. HTML5 HTML5 ...

  10. 【BZOJ 3942】 Censoring

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3942 [算法] 栈 + KMP [代码] #include<bits/stdc ...