脚本一键安装lnmp  (centos6版本)

#!/bin/bash

echo "It will install lnmp."

sleep 1

##check last command is OK or not.

check_ok() {

if [ $? != 0 ]

then

echo "Error, Check the error log."

exit 1

fi

}

##get the archive of the system,i686 orx86_64.

ar=`arch`

##close seliux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/'    /etc/selinux/config

selinux_s=`getenforce`

if [ $selinux_s =="Enforcing"  -o $selinux_s =="enforcing" ]

then

setenforce 0

fi

##close iptables

iptables  -save >/etc/sysconfig/iptables_`date +%s`

iptables -F

service iptables save

##if the packge installed ,then omit.

myum() {

if ! rpm -qa|grep -q "^$1"

then

yum install -y $1

check_ok

else

echo $1 already installed.

fi

}

myum

##install some packges.

for p in gcc gcc-c++ wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel openssl openssl-devel ncurses  ncurses-devel libxml2 libxml2-devel bzip2  bzip2-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libtool-ltdl-devel

do

myum $p

done

##install epel.

if ! rpm -qa epel-release >/dev/null

then

yum install -y  epel-release

check_ok

fi

if  ls /etc/yum.repos.d/epel-6.repo*> /dev/null 2>&1

then

rm -f /etc/yum.repos.d/epel-6.repo*

fi

wget -P /etc/yum.repos.d/  http://mirrors.aliyun.com/repo/epel-6.repo

##function of install mysqld

install_mysqld() {

echo "Install mysql version5.1.72"

cd /usr/local/src

[ -f mysql-5.1.72.tar.gz ] || wget   http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72.tar.gz

check_ok

[ -d mysql-5.1.72  ]  ||   tar -zvxf   mysql-5.1.72.tar.gz

[ -d /usr/local/mysql ] && /bin/mv     /usr/local/mysql /usr/local/mysql_`date +%s`

cd mysql-5.1.72

sed -i 's/$RM "$cfgfile"/#$RM "$cfgfile"/'  configure

./configure --prefix=/usr/local/mysql    --with-unix-socket-path=/tmp/mysql.sock  --with-client-ldflags=-static'CFLAGS=-g -O3'  'CXXFLAGS=-g -O3'   --with-extra-charsets=gbk,utf8,ascii,big5,latin1,binary  --enable-assembler  --enable-local-infile  --enable-profiling  --enable-thread-safe-client

check_ok

make  &&   make install

check_ok

}

install_mysqld

if ! grep '^mysql:' /etc/passwd

then

useradd -M mysql  -s   /sbin/nologin

check_ok

fi

if ! grep '^php-fpm' /etc/passwd

then

useradd -M php-fpm -s    /sbin/nologin

check_ok

fi

myum compat-libstdc++-33

[ -d /data/mysql ] && /bin/mv /data/mysql  /data/mysql_`date +%s`

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql

/usr/local/mysql/bin/mysql_install_db  --user=mysql  --datadir=/data/mysql

check_ok

cd /usr/local/src/mysql-5.1.72

[ -f /etc/my.cnf ] ||  /bin/cp    support-files/my-medium.cnf   /etc/my.cnf

[ -f /etc/init.d/mysqld] || /bin/cp   support-files/mysql.server   /etc/init.d/mysqld

#sed-i 's/^port =@MYSQL_TCP_PORT@ /port= 3306/'   /etc/my.cnf

#sed-i 's#^socket=@MYSQL_UNIX_ADDR@#socket=/tmp/mysql.sock#'   /etc/my.cnf

#sed-i 's/^user=@MYSQLD_USER@/user=mysql/’   /etc/init.d/mysqld

#sed-i 's# basedir=@prefix@# basedir=/usr/local/mysql#'     /etc/init.d/mysqld

#sed-i 's# bindir=@bindir@# bindir=/usr/local/mysql/bin#'    /etc/init.d/mysqld

#sed-i 's# datadir=@localstatedir@#datadir=/usr/local/mysql/var#'   /etc/init.d/mysqld

#sed-i 's#sbindir=@sbindir@#sbindir=/usr/local/mysql/sbin#'   /etc/init.d/mysqld

#sed-i 's#libexecdir=@libexecdir@#libexecdir=/usr/local/mysql/libexec#'  /etc/init.d/mysqld

sed-i  's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld

sed -i  's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld

sed -i 's#@HOSTNAME@# /bin/hostname# '  /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld

service mysqld restart

chkconfig --add mysqld

chkconfig mysqld on

check_ok

##function of install php_libmcrypt.

install_php_libmcrypt(){

cd /usr/local/src

[ -f libmcrypt-2.5.7.tar.gz ] || wget    http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz

[-d libmcrypt-2.5.7 ] || tar -zvxf   libmcrypt-2.5.7.tar.gz

check_ok

cd libmcrypt-2.5.7

./configure --prefix=/usr/local/libmcrypt

check_ok

make && make install

check_ok

}

install_php_libmcrypt

##function of install php.

install_php(){

cd/usr/local/src

[ -f  php-5.5.32.tar.gz ] || wget   http://cn2.php.net/distributions/php-5.5.32.tar.gz

yum install -y  php-mcrypt  libmcrypt libmcrypt-devel

[-d  php-5.5.32 ] || tar -zxf php-5.5.32.tar.gz

[ -d  /usr/local/php ] && /bin/mv /usr/local/php /usr/local/php_`date +%s`

cd  php-5.5.32

./configure  --prefix=/usr/local/php  --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm  --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir=/usr/local  --enable-xml --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir=/usr/include/freetype2/freetype    --with-iconv-dir=/usr/local --with-zlib-dir --with-bz2  --with-openssl --with-mcrypt --enable-soap  --enable-gd-native-ttf  --enable-mbstring --enable-sockets  --enable-exif  --enable-bcmath --enable-shmop --enable-sysvsem --disable-ipv6

check_ok

make  && make install

check_ok

}

install_php

[ -f /usr/local/php/etc/php.ini ] ||  /bin/cp php.ini-production   /usr/local/php/etc/php.ini

if /usr/local/php/bin/php -i |grep -iq 'date.timezone => no value'

then

sed -i '/;date.timezone=$/a\date.timezone = "Asia\/Chongqing"'  /usr/local/php/etc/php.ini

check_ok

fi

[ -f /usr/local/php/etc/php-fpm.conf ] || curl  http://www.apelearn.com/study_v2/.phpfpm_conf   -o     /usr/local/php/etc/php-fpm.conf

[ -f /etc/init.d/phpfpm ] || /bin/cp     sapi/fpm/init.d.php-fpm  /etc/init.d/phpfpm

sed -i  '/pid/s/php-fpm/php/;/error_log/s/php-fpm/php/;/listen/s/-fcgi/fpm/'      /usr/local/php/etc/php-fpm.conf

chmod 755 /etc/init.d/phpfpm

chkconfig phpfpm on

service phpfpm start

check_ok

##function of check service is running ornot, example nginx, php-fpm.

check_service() {

if [ "$1" == "phpfpm" ]

then

s="php-fpm"

else

s=$1

fi

n=`ps aux | grep "$s" |wc -l`

if  [ $n -gt 1 ]

then

echo "$1 service is already   started."

else

if   [ -f /etc/init.d/$1 ]

then

/etc/init.d/$1 start

check_ok

else

install_$1

fi

fi

}

check_service

##function ofinstall nginx.

install_nginx(){

echo"Install nginx version 2.2."

cd /usr/local/src

[ -f  nginx-1.8.0.tar.gz ] || wget  http://nginx.org/download/nginx-1.8.0.tar.gz

[ -d nginx-1.8.0 ] || tar zxf   nginx-1.8.0.tar.gz

[ -d /usr/local/nginx ] &&  /bin/mv  /usr/local/nginx /usr/local/nginx_`date +%s`

cd nginx-1.8.0

myum pcre-devel

./configure   --prefix=/usr/local/nginx

check_ok

make && make install

check_ok

}

install_nginx

if [ -f /etc/init.d/nginx ]

then

/bin/mv /etc/init.d/nginx  /etc/init.d/nginx_`date +%s`

fi

curl  http://www.apelearn.com/study_v2/.nginx_init  -o /etc/init.d/nginx

check_ok

chmod 755 /etc/init.d/nginx

chkconfig --add nginx

chkconfig nginx on

curl http://www.apelearn.com/study_v2/.nginx_conf  -o  /usr/local/nginx/conf/nginx.conf

check_ok

service nginx restart

check_ok

echo -e"<?php\n   phpinfo();\n?>" > /usr/local/nginx/html/index.php

check_ok

##function of install lnmp.

lnmp(){

check_service mysqld

check_service nginx

check_service phpfpm

echo "The lnmp done, Please use'http://your ip/index.php' to access."

}

lnmp

本文转自super李导51CTO博客,原文链接: http://blog.51cto.com/superleedo/1890624,如需转载请自行联系原作者

LNMP安装shell脚本相关推荐

  1. mysql 5.6.28安装图解_mysql 5.6.28 自动安装shell脚本

    mysql5.6.28自动安装shell脚本,为了包装源码包的可靠性,请自行下载mysql-5.6.28.tar.gz,接着我就不说废话,附上自动安装脚本.#!/bin/bash #author ab ...

  2. 关于jq工具安装shell脚本

    关于jq工具安装shell脚本 需要clone的源码: jq onig(若系统没有该库时使用) onig #!/bin/sh CWD=`pwd` if [ ! -d $CWD/jq/ ] ;theng ...

  3. 简单的一键部署LNMP架构shell脚本

    两种部署方式: 一. 手工搭建 分析:最终效果,通过Nginx搭建两个网站blog和zh,通过域名访问.在lnmp的基础上,域名访问,要么搭建DNS服务器,要么修改主机hosts文件. 1.安装Ngi ...

  4. 趣味三大彩蛋命令安装shell脚本

    今天看到无聊打发的命令写了一份安装的脚本 #!/bin/bash echo "./havefun 1 >>>>安装小火车;./havefun 2 >>&g ...

  5. 【Linux_Shell 脚本编程学习笔记五、Oracle JDK1.8 安装shell 脚本】

    脚本使用说明: 首先在脚本的同级目录下有个 jdk的安装包 脚本和安装包必须在同级目录下才能够安装(脚本没有优化,还可以使用  wget  从网上下载指定版本的  jdk 安装包) #!/bin/sh ...

  6. LNMP一键安装shell脚本

    前段时间维护服务器,需要安装LNMP环境,所以就整理了一下,做为脚本,记录下来. #!/bin/sh #Copyright(c) 2010-2015 redapple (16325975@qq.com ...

  7. pgsql自动安装shell脚本整理

    前面不断在vm虚拟机上测试pgsql,发觉安装还是有些麻烦的. 所以就收集了一些 1,http://www.davidghedini.com/pg/entry/postgresql_9_5_scrip ...

  8. linux csh 安装,linux安装gcc的shell脚本

    原标题:linux安装gcc的shell脚本 GCC是GUN Compiler Collection的简称,除了编译程序之外,它还含其他相关工具,它能把易于人类使用的高级语言编写的源代码构建成计算机能 ...

  9. 编写shell脚本实现自动化搭建安装LNMP平台全过程配置详解

    注意:如果是输入的是字母的或者是输入等于0时,则会出现以下两种情况!!! 查看端口: 进到Nginx根目录查看创建好的测试网页: 注意:关闭防火墙或者设置防火墙规则!!! 访问Nginx网页: 访问P ...

最新文章

  1. 获取线程结束代码(Exit Code)
  2. const常量和readonly常量区别
  3. 面试必备:synchronized的底层原理?
  4. How to test software requirements specification (SRS)?
  5. Android传感器编程入门(三)
  6. C语言求一个文件的长度,求二进制文件的长度
  7. 背包问题2 (lintcode)
  8. 数据挖掘肿瘤预测_给你一个基因,利用数据挖掘能做什么?
  9. 怎么删除内网计算机IP地址,如何能在局域网中隐藏电脑及IP地址
  10. C语言10进制转2进制
  11. python中dic的操作
  12. MySQL DBA 必读:万字归总表设计与 SQL 编写技巧
  13. 印象笔记,石墨笔记和Effie哪个更适合影评人?
  14. U 需要知道的反射知识 -- 大白话
  15. 中国大陆网站TOP100
  16. 谷歌中国开发者网站地址
  17. word: 插入或修改文字时后面的字消失 解决办法
  18. 【Keras+计算机视觉+Tensorflow】DCGAN对抗生成网络在MNIST手写数据集上实战(附源码和数据集 超详细)
  19. NodeMCU(ESP-12E)+阿里云实现数据上传和控制继电器开锁
  20. 迈克菲实验室报告揭示全新的移动应用合谋威胁

热门文章

  1. 萤石云API (4年前分享)
  2. 情人节——微信朋友圈浓浓爱意的9张拼图
  3. 论文笔记:SIFT(Scale-invariant feature transform 尺度不变特征变换)
  4. 适合BS模式项目的录入页面
  5. 编程中保护眼睛的颜色
  6. 秘制牛肉团队博客目录
  7. Nerdctl 原生支持 Nydus 加速镜像
  8. 如何禁止Chrome弹出无法更新的提示窗?
  9. axure学习帖-中继器二级菜单
  10. 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明