码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp环境自动化部署

时间:2016-10-28 22:55:13      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:cli   wget   path   fast   inf   config   mat   上传   style   

lnmp.sh

 

#!/bin/bash
#This project to install lnmp
#Author:菜逼cd命令玩家
#Time:2016.10.13
#objective:简化人工手动操作,完成一键部署lnmp环境
#email:1071179133@qq.com
#Blog address:http://www.cnblogs.com/chenjw-note/

#安装必须环境
yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-* openssl* -y
cd /home
#wget下载nginx
wget http://nginx.org/download/nginx-1.11.5.tar.gz
#解压缩
tar zxvf nginx-1.11.5.tar.gz
cd nginx-1.11.5
#运行编译安装
./configure --prefix=/usr/local/nginx-1.11.5 --with-http_ssl_module --with-http_stub_status_module --with-pcre
make && make install
#运行nginx
#/usr/local/nginx-1.11.5/sbin/nginx
#设置开机启动
echo "/usr/local/nginx-1.11.5/sbin/nginx" >> /etc/rc.local

#安装mysql
yum install -y mysql mysql-server
#设置开机启动
chkconfig mysqld on
#启动mysqld
service mysqld start

#安装PHP
cd /home
#wget下载php
wget http://cn2.php.net/distributions/php-7.0.11.tar.gz
#解压缩
tar zxvf php-7.0.11.tar.gz
cd php-7.0.11
#运行编译安装
./configure --prefix=/usr/local/php-7.0.11 --with-config-file-path=/usr/local/php-7.0.11/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make && make install
#文件配置
cp php.ini-production /usr/local/php-7.0.11/etc/php.ini
cp /usr/local/php-7.0.11/etc/php-fpm.conf.default /usr/local/php-7.0.11/etc/php-fpm.conf
cp /usr/local/php-7.0.11/etc/php-fpm.d/www.conf.default /usr/local/php-7.0.11/etc/php-fpm.d/www.conf
#设置开机启动
echo "/usr/local/php-7.0.10/sbin/php-fpm" >> /etc/rc.local
#启动php-fpm
/usr/local/php-7.0.11/sbin/php-fpm

#整合nginx+php:
cd /home
#备份nginx配置文件
cp /usr/local/nginx-1.11.5/conf/nginx.conf /usr/local/nginx-1.11.5/conf/nginx.conf.bak
#删除原nginx.conf 35-79行的内容
sed -i ‘35,79d‘ /usr/local/nginx-1.11.5/conf/nginx.conf
#在配置文件nginx.conf 35行插入整合内容 n+p.txt上传在/home目录下
sed -i ‘35 r /home/n+p.txt‘ /usr/local/nginx-1.11.5/conf/nginx.conf

#启动nginx
#/usr/local/nginx-1.11.5/sbin/nginx -s stop
/usr/local/nginx-1.11.5/sbin/nginx

#创建测试页面
mkdir -p /data/lnmp
touch /data/lnmp/info.php
echo "<?php phpinfo(); ?>" > /data/lnmp/info.php

echo "==========================安装成功============================"

 

n+p.txt

 

server {
listen 80;
server_name localhost;
#access_log /data/logs/access.log main;

index index.php index.html index.html;
root /data/lnmp;

location /
{
try_files $uri $uri/ /index.php?$args;
}

location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;

}
}

 

部署说明:

1.利用rz命令将lnmp.sh 和 n+p.txt 两个文件上传到服务器的/home下

2.赋予安装文件执行权限:chmod a+x lnmp.sh

3.运行安装文件:sh lnmp.sh

4.关闭防火墙或修改端口权限 service iptables stop

5.关闭selinux vim /etc/selinux/conf selinux=disable

 

 

拓展:

  在此基础下,还可以自动化安装zabbix!

 

有建议或有问题随时可以联系qq1071179133

 

lnmp环境自动化部署

标签:cli   wget   path   fast   inf   config   mat   上传   style   

原文地址:http://www.cnblogs.com/chenjw-note/p/6009398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!