LNMP安装shell脚本

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

脚本一键安装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,如需转载请自行联系原作者





相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
16天前
|
Shell Linux
【linux】Shell脚本中basename和dirname的详细用法教程
本文详细介绍了Linux Shell脚本中 `basename`和 `dirname`命令的用法,包括去除路径信息、去除后缀、批量处理文件名和路径等。同时,通过文件备份和日志文件分离的实践应用,展示了这两个命令在实际脚本中的应用场景。希望本文能帮助您更好地理解和应用 `basename`和 `dirname`命令,提高Shell脚本编写的效率和灵活性。
79 32
|
1天前
|
JavaScript Shell C#
多种脚本批量下载 Docker 镜像:Shell、PowerShell、Node.js 和 C#
本项目提供多种脚本(Shell、PowerShell、Node.js 和 C#)用于批量下载 Docker 镜像。配置文件 `docker-images.txt` 列出需要下载的镜像及其标签。各脚本首先检查 Docker 是否安装,接着读取配置文件并逐行处理,跳过空行和注释行,提取镜像名称和标签,调用 `docker pull` 命令下载镜像,并输出下载结果。使用时需创建配置文件并运行相应脚本。C# 版本需安装 .NET 8 runtime。
31 1
|
4月前
|
Shell Linux 测试技术
6种方法打造出色的Shell脚本
6种方法打造出色的Shell脚本
115 2
6种方法打造出色的Shell脚本
|
4月前
|
XML JSON 监控
Shell脚本要点和难点以及具体应用和优缺点介绍
Shell脚本在系统管理和自动化任务中扮演着重要角色。尽管存在调试困难、可读性差等问题,但其简洁高效、易于学习和强大的功能使其在许多场景中不可或缺。通过掌握Shell脚本的基本语法、常用命令和函数,并了解其优缺点,开发者可以编写出高效的脚本来完成各种任务,提高工作效率。希望本文能为您在Shell脚本编写和应用中提供有价值的参考和指导。
146 1
|
4月前
|
Ubuntu Shell 开发工具
ubuntu/debian shell 脚本自动配置 gitea git 仓库
这是一个自动配置 Gitea Git 仓库的 Shell 脚本,支持 Ubuntu 20+ 和 Debian 12+ 系统。脚本会创建必要的目录、下载并安装 Gitea,创建 Gitea 用户和服务,确保 Gitea 在系统启动时自动运行。用户可以选择从官方或小绿叶技术博客下载安装包。
144 2
|
5月前
|
监控 网络协议 Shell
ip和ip网段攻击拦截系统-绿叶结界防火墙系统shell脚本
这是一个名为“小绿叶技术博客扫段攻击拦截系统”的Bash脚本,用于监控和拦截TCP攻击。通过抓取网络数据包监控可疑IP,并利用iptables和firewalld防火墙规则对这些IP进行拦截。同时,该系统能够查询数据库中的白名单,确保合法IP不受影响。此外,它还具备日志记录功能,以便于后续分析和审计。
104 6
|
4月前
|
运维 监控 Shell
深入理解Linux系统下的Shell脚本编程
【10月更文挑战第24天】本文将深入浅出地介绍Linux系统中Shell脚本的基础知识和实用技巧,帮助读者从零开始学习编写Shell脚本。通过本文的学习,你将能够掌握Shell脚本的基本语法、变量使用、流程控制以及函数定义等核心概念,并学会如何将这些知识应用于实际问题解决中。文章还将展示几个实用的Shell脚本例子,以加深对知识点的理解和应用。无论你是运维人员还是软件开发者,这篇文章都将为你提供强大的Linux自动化工具。
|
关系型数据库 Shell Linux
|
关系型数据库 Shell 应用服务中间件
|
5月前
|
Shell
一个用于添加/删除定时任务的shell脚本
一个用于添加/删除定时任务的shell脚本
155 1